gov.sns.xal.model.elem
Class ElementFactory

java.lang.Object
  |
  +--gov.sns.xal.model.elem.ElementFactory

public class ElementFactory
extends java.lang.Object

Utility class for instantiated XAL Model Elements. It is the class factory for all IElement based objects.

Every element class exposing the IElement interface should register itself in the static class-loader code (static {} block) in order to be recognized by this class factory. The requirements for registration are that the registering class expose the IElement interface and have a constructor taking the single argument of a DataAdaptor object. The constructor should fully initialize the object according to the data available in the data adaptor.

The factory is useful in parsing XML files in using the XAL Model Lattice DTD format. Every IElement has a type code (in String format) which may be used to identify the class.

See Also:
DataAdaptor

Field Summary
static java.lang.String s_strAttrType
          string name of 'type' attribute in DataAdaptors
 
Method Summary
static IElement createIElement(java.lang.String strType)
          Create a IElement object based on information stored in a DataAdaptor object.
static java.lang.Class[] getRegisteredClasses()
          Get array of class types for registered IElement classes.
static int getRegisteredCount()
          Get the total number of registered elements, both thin and thick.
static java.lang.String[] getRegisteredTypes()
          Get array of all element type strings, both thin and thick, that are registered to class factory.
static void main(java.lang.String[] arrArgs)
          Class test driver
static boolean registerIElement(java.lang.String strType, java.lang.Class clsType)
          Register the IElement exposing class with the class factory.
static void testCreation(java.io.PrintWriter os, java.lang.String strType)
          Test element creation mechanism
static void testRegistration(java.io.PrintWriter os)
          Test element registration mechanism
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_strAttrType

public static final java.lang.String s_strAttrType
string name of 'type' attribute in DataAdaptors

See Also:
Constant Field Values
Method Detail

getRegisteredCount

public static int getRegisteredCount()
Get the total number of registered elements, both thin and thick.

Returns:
total number of element types registered

getRegisteredTypes

public static java.lang.String[] getRegisteredTypes()
Get array of all element type strings, both thin and thick, that are registered to class factory.

Returns:
string array of supported element types

getRegisteredClasses

public static java.lang.Class[] getRegisteredClasses()
Get array of class types for registered IElement classes.

Returns:
array registered IElement class types

registerIElement

public static boolean registerIElement(java.lang.String strType,
                                       java.lang.Class clsType)
Register the IElement exposing class with the class factory. The class must have an initializing constructor with the single argument of a DataAdaptor. That is, we require the method Element(DataAdaptor daptInit).

The type string in the argument strType must be the same string returned by the IElement method getType():String. The argument clsType is the Class class of the class being registered with this factory. The class must expose the IElement interface.

Example: For the derived class ThinLens the static block should include the following: static { ... registerElement(ThinLens.s_strType, ThinLens.class) ... }

Parameters:
strType - type identifier of the class
clsType - Class class for registered class
Returns:
true if class was successfully registered, false otherwise

createIElement

public static IElement createIElement(java.lang.String strType)
                               throws java.lang.ClassNotFoundException,
                                      java.lang.InstantiationException
Create a IElement object based on information stored in a DataAdaptor object.

Parameters:
strType - string type identifier for IElement concrete class
Returns:
new IElement exposing object
Throws:
java.lang.ClassNotFoundException - unknown class or class does not have proper constructor
DataFormatException - data in adaptor does not conform to DTD
java.lang.NumberFormatException - corrupted position field
java.lang.InstantiationException - unknown error occurred during element construction

main

public static void main(java.lang.String[] arrArgs)
Class test driver


testRegistration

public static void testRegistration(java.io.PrintWriter os)
Test element registration mechanism

Parameters:
os - output stream

testCreation

public static void testCreation(java.io.PrintWriter os,
                                java.lang.String strType)
Test element creation mechanism