|
Example Enumerated Type
Here is an example Frequency Enumerated type to give the big picture
of what can be generated: -
/*
* Copyright Javelin Software, All rights reserved.
*/
package com.javelin.jcommerce;
import java.io.*;
import java.util.*;
import com.javelin.jcommerce.*;
import com.javelin.beans.*;
/**
* Frequency.java
*
* @version 1.0
* @author Javelin Software
*/
public class Frequency extends AbstractEnumeratedType
{
protected static Hashtable cache = new Hashtable();
protected static Hashtable stringCache = new Hashtable();
/**
* DAILY, 1, Daily.
*/
public final static Frequency DAILY = new Frequency( new Integer( 1 ),
"Daily" );
/**
* WEEKLY, 7, Weekly.
*/
public final static Frequency WEEKLY = new Frequency( new Integer( 7 ),
"Weekly" );
/**
* MONTHLY, 30, Monthly.
*/
public final static Frequency MONTHLY = new Frequency( new Integer( 30
), "Monthly" );
/**
* QUARTERLY, 120, Quarterly.
*/
public final static Frequency QUARTERLY = new Frequency( new Integer(
120 ), "Quarterly" );
/**
* SEMI_ANNUALLY, 240, Semi-Annually.
*/
public final static Frequency SEMI_ANNUALLY = new Frequency( new Integer(
240 ), "Semi-Annually" );
/**
* ANNUALLY, 365, Annually.
*/
public final static Frequency ANNUALLY = new Frequency( new Integer( 365
), "Annually" );
/**
* Construct a fully qualified Frequency.
*/
public Frequency( java.lang.Integer key, String name ) throws IllegalArgumentException
{
super( key, name );
if( cache.get( key ) != null )
{
throw new IllegalArgumentException( "Frequency already has a key
" + key );
}
cache.put( key, this );
stringCache.put( name.toString().toUpperCase(), this );
}
/**
* Find the EnumeratedType by the Key.
*/
public static Frequency findByKey( int key ) throws FinderException
{
return (Frequency)findType( new Integer( key ), Frequency.class, cache
);
}
/**
* Find the EnumeratedType by the Key.
*/
public static Frequency findByKey( Integer key ) throws FinderException
{
return (Frequency)findType( key, Frequency.class, cache );
}
/**
* Get the EnumeratedType by the primitive Key.<br>
* This will not throw a Finder Exception.
*/
public static Frequency getByKey( int key )
{
return(Frequency)getType( new Integer( key ), Frequency.class, cache );
}
/**
* Get the EnumeratedType by the Key.<br>
* This will not throw a Finder Exception.
*/
public static Frequency getByKey( Integer key ) throws FinderException
{
return(Frequency)getType( key, Frequency.class, cache );
}
/**
* Find the EnumeratedType by the Name, as String.
*/
public static Frequency findByName( String name ) throws FinderException
{
return (Frequency)findType( name == null ? null : name.toUpperCase(),
Frequency.class, stringCache );
}
/**
* Get the EnumeratedType by the Key, as a String.<br>
* This will not throw a Finder Exception.
*/
public static Frequency getByName( String name )
{
return(Frequency)getType( name == null ? null : name.toUpperCase(), Frequency.class,
stringCache );
}
/**
* Find the EnumeratedType matching the String against the key and name.<br>
*/
public static Frequency findByMatch( String match ) throws FinderException
{
return(Frequency)findTypeByMatch( match, Frequency.class, cache );
}
/**
* Get the EnumeratedType matching the String against the key and name.<br>
*/
public static Frequency getByMatch( String match )
{
return(Frequency)getTypeByMatch( match, Frequency.class, cache );
}
private static Vector all = new Vector();
static
{
all.addElement( DAILY );
all.addElement( WEEKLY );
all.addElement( MONTHLY );
all.addElement( QUARTERLY );
all.addElement( SEMI_ANNUALLY );
all.addElement( ANNUALLY );
}
/**
* Find all.
*/
public static Enumeration findAll()
{
return all.elements();
}
/**
* Contains all.
*/
public static boolean isAll( Frequency object )
{
return all.contains( object );
}
}
|