util
Class CreateClass

java.lang.Object
  extended by util.CreateClass
All Implemented Interfaces:
Cloneable

public class CreateClass
extends Object
implements Cloneable

This is a try to allow dynamic creation of classes without methods using a description. This is only a very crude work-around and not really a dynamical class definition. The other way, writing a ClassLoader appears to be too sophisticated for this simple task. Still, remeber that using this interface may not be the fastest choice, since it completely relies on standard java methods, like Hashtable and the Wrapper classes for the prmitive data types.


Field Summary
private static Class KEY
           
private static String[] NAME
           
private  Hashtable<String,Class> Names
           
private static Class NUMBER
           
private static char[] SHORT
           
private static Class[] TYPE
           
private  Hashtable<String,Object> Values
           
 
Constructor Summary
private CreateClass(int size)
           
 
Method Summary
 void clearField(String name)
          Removes the definition of the field with the given name.
 Object clone()
          Clone this instance of CreateClass.
private  boolean compareHashtable(Hashtable one, Hashtable two)
          Check, if keys/values in the two Hashtables match.
 boolean equals(Object that)
          Test for equal CreateClass objects.
 boolean equalType(Object that)
          Test for equal type of CreateClass objects.
 Enumeration getAllNames()
          Returns an Enumeration of all fields found in this CreateClass.
 Object getField(String name)
          This method retrieves values by field names.
static CreateClass getInstance(String[] name, char[] type)
          This method retrives a new Instance of createClass.
static CreateClass getInstance(String[] name, Class[] type)
          This method retrives a new Instance of createClass.
static CreateClass getInstance(String[] name, String[] type)
          This method retrives a new Instance of createClass.
 Enumeration getNames()
          Returns an Enumeration of all fields assigned a value.
 Class getType(String name)
          This method retrieves the prototype class of the field with the given name.
 void loadField(String name, String value)
          This method assigns a value to a named field.
 String toString()
          Returns a String representation of this CreateClass.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY

private static Class KEY

NUMBER

private static Class NUMBER

SHORT

private static final char[] SHORT

NAME

private static final String[] NAME

TYPE

private static Class[] TYPE

Names

private Hashtable<String,Class> Names

Values

private Hashtable<String,Object> Values
Constructor Detail

CreateClass

private CreateClass(int size)
Method Detail

getInstance

public static CreateClass getInstance(String[] name,
                                      char[] type)
This method retrives a new Instance of createClass. Class variables, if you want to call them this way, can be retrieved with getField(name). This method uses the short, though slower routine of providing short (one char) identifiers for the java native Wrapper classes.
Valid appreviations for the native types are:

See Also:
loadField(java.lang.String, java.lang.String), getField(java.lang.String)

getInstance

public static CreateClass getInstance(String[] name,
                                      String[] type)
This method retrives a new Instance of createClass. Class variables, if you want to call them this way, can be retrieved with getField(name). This method uses the names for the java native Wrapper classes.


getInstance

public static CreateClass getInstance(String[] name,
                                      Class[] type)
This method retrives a new Instance of createClass. Class variables, if you want to call them this way, can be retrieved with getField(name). Note that we only create the Classes, but do not assign a value to the fields here.

See Also:
loadField(java.lang.String, java.lang.String), getField(java.lang.String)

clone

public Object clone()
Clone this instance of CreateClass. It returns a shallow copy of this creatClass in the sense that the Names Hashtable is cloned (which is already a shallow copy), but the Values Hashtable is empty. This clone method differs somehow from the original purpose since it calls the constructor of CreateClass.

Overrides:
clone in class Object
See Also:
Hashtable.clone()

clearField

public void clearField(String name)
Removes the definition of the field with the given name. If no value is asigned to the field, nothing happens. Subsequent calls to getField return null.

Parameters:
name - The field to unset.
See Also:
Hashtable.remove(java.lang.Object)

loadField

public void loadField(String name,
                      String value)
This method assigns a value to a named field. All primitive data types understand a constructor with a single String argument, so this is how we assign the value to it. If you ever try to expand the class for some peculiar, user-defined classes, make sure that they can be constructed with a single String!

Parameters:
name - The field name
value - The value that should be assigned to the field

getField

public Object getField(String name)
This method retrieves values by field names. You get an Object, for primitive data types a wrapper, which can be cast directly to the appropriate type. If the calling class is only interested in the type of field, use the method fieldType instead.

Parameters:
name - The name of the field to retrieve.
See Also:
getType(java.lang.String)

getType

public Class getType(String name)
This method retrieves the prototype class of the field with the given name. Use this, if you are interested only in the type of the field, but not it's value.

Parameters:
name - The name of the field to retrieve.
See Also:
getField(java.lang.String)

getNames

public Enumeration getNames()
Returns an Enumeration of all fields assigned a value. Uses the Hashtable.keys() function of the values to retrieve an Enumeration of all fields in this class that have a value assigned to it.


getAllNames

public Enumeration getAllNames()
Returns an Enumeration of all fields found in this CreateClass. Uses the Hashtable.keys() function of the Names to retrieve an Enumeration of all fields in this class that are ready to take a value.


compareHashtable

private boolean compareHashtable(Hashtable one,
                                 Hashtable two)
Check, if keys/values in the two Hashtables match.


equalType

public boolean equalType(Object that)
Test for equal type of CreateClass objects. Comparison is done by checking and comparing the entries in the Names Hashtable.

Parameters:
that - The CreateClass instance to be compared to.

equals

public boolean equals(Object that)
Test for equal CreateClass objects. Additionally to a equalType-check, all the fields in the Values Hashtable are compared. Note that this method will return false, if either of the Values Hashtable is null.

Overrides:
equals in class Object
Parameters:
that - The CreateClass instance to be compared to.

toString

public String toString()
Returns a String representation of this CreateClass. In this one-line String, every Value entry is listed as the key name plus its value. Key/value pairs are separated by an equal sign, the different pairs are separated by a space.

Overrides:
toString in class Object