org.jcon.data
Class LookupDatabase

java.lang.Object
  extended by org.jcon.data.LookupDatabase
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MappingLookupDatabase, StakerData

public class LookupDatabase
extends java.lang.Object
implements java.io.Serializable

This is a sort of object database. Object sets are registered with a class and a index for looking things up in that class (for instance, NameIndex looks up things based on their toString() function). This index provides a unique indexing function whose result is used as the index to a Map (hashing the hash, as it were).

When objects are placed in the LookupDatabase, they are placed into the object set whose class is the object's closest ancestor. Once placed in the database, LookupReference objects can be created for the object, to files or passed around or whatever, and then used later to unswizzle data by dereferencing the LookupReference.

All this is simpler than it sounds.

Another function served by the database is that of defining the set of valid values for a given class in a given context. So, if different clients have different sets of valid values for a certain class, you simply create a LookupDatabase for each client, with an object set registered for the class of interest, filled with the valid values for that class.

Dictionaries automagically include object sets for all EnumeratedTypes, so there is no need to register these.

See Also:
Serialized Form

Constructor Summary
LookupDatabase()
          Create a new, empty LookupDatabase.
 
Method Summary
 void addIndex(java.lang.String className, LookupIndex index)
          Creates an object set by adding a classname/index mapping.
 void addIndex(java.lang.String className, LookupIndex index, java.util.Set lookupSet)
          Creates an object set by adding a classname/index mapping, and supplies the set of objects for that mapping too.
 void addObject(java.lang.Object ob)
          Adds an object to the database.
 boolean contains(java.lang.Object ob)
          True if object is in the database, and can therefore be looked up.
 java.lang.Object keyOf(java.lang.Object victim)
          Returns the lookup key of an object.
 java.lang.Object lookup(LookupReference ref)
          Dereference a LookupReference.
 java.lang.Object lookupObject(java.lang.Class classy, java.lang.Object parameter)
          Looks up an object based on its class and a parameter.
 java.lang.Object lookupObject(java.lang.String className, java.lang.Object parameter)
          Look up an object based on its class name and a parameter.
 LookupReference referenceFor(java.lang.Object ob)
          Returns a LookupReference for an object.
 java.util.Iterator validObjectsFor(java.lang.Class classy)
          Returns valid object set for a registered class.
 java.util.Iterator validObjectsFor(java.lang.String classname)
          Returns valid object set for a registered class by class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookupDatabase

public LookupDatabase()
Create a new, empty LookupDatabase.

Method Detail

addIndex

public void addIndex(java.lang.String className,
                     LookupIndex index)
Creates an object set by adding a classname/index mapping.


addIndex

public void addIndex(java.lang.String className,
                     LookupIndex index,
                     java.util.Set lookupSet)
Creates an object set by adding a classname/index mapping, and supplies the set of objects for that mapping too.


addObject

public void addObject(java.lang.Object ob)
Adds an object to the database. It must fall into one of a previously- defined object set; i.e., you must have called addIndex() already with one of its ancestor classes.


validObjectsFor

public java.util.Iterator validObjectsFor(java.lang.Class classy)
Returns valid object set for a registered class.


validObjectsFor

public java.util.Iterator validObjectsFor(java.lang.String classname)
Returns valid object set for a registered class by class name.


lookupObject

public java.lang.Object lookupObject(java.lang.Class classy,
                                     java.lang.Object parameter)
                              throws LookupFailedException
Looks up an object based on its class and a parameter.

Throws:
LookupFailedException

lookupObject

public java.lang.Object lookupObject(java.lang.String className,
                                     java.lang.Object parameter)
                              throws LookupFailedException
Look up an object based on its class name and a parameter.

Throws:
LookupFailedException

lookup

public java.lang.Object lookup(LookupReference ref)
                        throws LookupFailedException
Dereference a LookupReference.

Throws:
LookupFailedException

keyOf

public java.lang.Object keyOf(java.lang.Object victim)
Returns the lookup key of an object.


contains

public boolean contains(java.lang.Object ob)
True if object is in the database, and can therefore be looked up.


referenceFor

public LookupReference referenceFor(java.lang.Object ob)
Returns a LookupReference for an object.