manager
Class ClassLookup

java.lang.Object
  extended by manager.ClassLookup

public class ClassLookup
extends java.lang.Object

Translates class names and class.attribute names to integer handles as defined by the RTI for this federation execution. This could be done by calling the RTI every time, but since handles never change through a federation, the result is cached instead.. The datastructure must be loaded with classes, each one of which must be associated with a name and a list of variable names which match the info in the .fed file used for this simulation. Once #resolveNames(RTIambassador) is called the ClassLookup is now useable.

Author:
Rob Minson

Constructor Summary
ClassLookup()
          Construct an emtpy, un-resolved ClassLookup
ClassLookup(java.lang.Class[] classes)
           
 
Method Summary
 void addClass(java.lang.Class c)
          This is a convenience method which associates the given class with the class and variable names derived from reflection.
 void addClass(java.lang.Class c, java.lang.String HLAName, java.lang.String[] varNames)
          Adds a Class to the Lookup along with the HLAName for the Class as it is recorded in a .fed file which will be used to run the federation for which this ClassLookup is valid
 java.util.Collection<java.lang.Class> getClasses()
          Get all classes registered with this lookup
 java.lang.Class getClassFor(int handle)
          Get the Class object corresponding to the given handle assigned to it by the RTI.
 int getClassHandle(java.lang.Class c)
          Gets the handle of this class as it is recorded by the RTI
 int getVariableHandle(int classHandle, java.lang.String varName)
          Get the handle assigned to the given public variable of the given class.
 java.lang.String getVariableName(int classHandle, int varHandle)
          Get the local String name associated with the given variable.
 java.lang.String[] getVarNames(java.lang.Class c)
          Get the variables associated with this class as registered with this lookup.
 boolean hasClass(java.lang.Class c)
          True if the given class has been locally registered with this lookup.
 boolean isResolved()
          Tells whether or not the .fed names have been resolved to RTI class handles in this ClassLookup
 void resolveNames()
          Resolves the .fed recorded names to HLA class handle integers.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassLookup

public ClassLookup()
Construct an emtpy, un-resolved ClassLookup


ClassLookup

public ClassLookup(java.lang.Class[] classes)
            throws hla.rti13.java1.RTIexception
Throws:
hla.rti13.java1.RTIexception
Method Detail

addClass

public void addClass(java.lang.Class c,
                     java.lang.String HLAName,
                     java.lang.String[] varNames)
Adds a Class to the Lookup along with the HLAName for the Class as it is recorded in a .fed file which will be used to run the federation for which this ClassLookup is valid

Parameters:
c - the Class to add
HLAName - the name of the class in the .fed file

addClass

public void addClass(java.lang.Class c)
This is a convenience method which associates the given class with the class and variable names derived from reflection. Specficially, this method calls PublicObject.getPublicVariables() on a new instance of the given class. If the class has no default constructor, then this method will crash and the addClass(Class, String, String[]) version of this method should be used instead.

Parameters:
c - The class to add to this ClassLookup, using the actual name of this class and the result of PublicObject.getPublicVariables() as the information in the .fed file for this federation.

resolveNames

public void resolveNames()
                  throws hla.rti13.java1.RTIexception
Resolves the .fed recorded names to HLA class handle integers. This means that the value held for each Class key will change from a String to an Integer. Do not call this method from the RTI callback thread unless your RTI is re-entrant.

Throws:
hla.rti13.java1.RTIexception - if an error occurs with the RTI. In almost all cases the exception will be a result of one of the HLANames not having been recorded in the ClassLookup correctly

isResolved

public boolean isResolved()
Tells whether or not the .fed names have been resolved to RTI class handles in this ClassLookup

Returns:
true if an int-type handle can be retrieved from this ClassLookup or whether it will still return a String

getClassHandle

public int getClassHandle(java.lang.Class c)
Gets the handle of this class as it is recorded by the RTI

Parameters:
c - the Class to find out about
Returns:
the handle of the class that can be used in communication with the RTIambassador given as the argument to resolveNames()
Throws:
java.lang.NullPointerException - if c is null or if c has not been recorded in this ClassLookup
java.lang.ClassCastException - if this ClassLookup has not been resolved (i.e. if isResolved() returns false)

hasClass

public boolean hasClass(java.lang.Class c)
True if the given class has been locally registered with this lookup.

Parameters:
c - the class to query
Returns:
true if the class has been locally registered
See Also:
addClass(Class)

getClasses

public java.util.Collection<java.lang.Class> getClasses()
Get all classes registered with this lookup

Returns:
the classes

getVarNames

public java.lang.String[] getVarNames(java.lang.Class c)
Get the variables associated with this class as registered with this lookup.

Parameters:
c - the class to query
Returns:
a list of the 'public' variables of this class, as far as the RTI is concerned

getClassFor

public java.lang.Class getClassFor(int handle)
Get the Class object corresponding to the given handle assigned to it by the RTI.

Parameters:
handle - the RTI-assigned handle
Returns:
the java Class associated with the handle in the local JVM

getVariableHandle

public int getVariableHandle(int classHandle,
                             java.lang.String varName)
Get the handle assigned to the given public variable of the given class.

Parameters:
classHandle - the RTI-assinged class handle (see getClassHandle(Class))
varName - the String name of the variable in question (see PublicObject.getPublicVariables())
Returns:
the RTI-assigned handle for the given variable.

getVariableName

public java.lang.String getVariableName(int classHandle,
                                        int varHandle)
Get the local String name associated with the given variable.

Parameters:
classHandle - the RTI-assinged class handle (see getClassHandle(Class))
varHandle - the RTI-assigned handle for the given variable (see getVariableHandle(int, String))
Returns:
the local name of the variable (see PublicObject.getPublicVariables())

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object