org.objectweb.jac.util
Class Repository

java.lang.Object
  |
  +--org.objectweb.jac.util.Repository
Direct Known Subclasses:
OrderedRepository, WeakRepository

public class Repository
extends Object

This class can be subclassed to create specific repositories.

A repository class should be a singleton (a sole instance class). Thus, the repository subclasses should define a static field and a static method 'get' that returns the unique repository for the class and that creates it if it does not exist.


Field Summary
 Map names
          Reverse hashtable to find an objet from its name (Object -> String)
 Map objects
          Link JAC objects to the names (String -> Object)
protected static Repository repository
          Store the sole instance of repository.
 
Constructor Summary
Repository()
           
 
Method Summary
 void dump()
          Dump all the registered objects.
static Repository get()
          Get the sole repository instance for this class.
 String getName(Object object)
          Returns the name of a registered object.
 String[] getNames()
          Return the names of the registered objects as an array.
 Object getObject(String logicalName)
          Return a registered object for a given logical name.
 Object[] getObjects()
          Return all the registered objects as an array.
 String getPrintableString()
           
protected  void init()
           
 boolean isRegistered(String logicalName)
          Returns true if an object is registered with this name.
 boolean register(String logicalName, Object object)
          Register a new object into the repository.
 void unregister(String logicalName)
          Unregister a JacObject from the repository.
 void unregisterObject(Object object)
          Unregister a JacObject from the repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

repository

protected static Repository repository
Store the sole instance of repository.

NOTE: this field MUST be defined by all subclasses.

See Also:
get()

objects

public Map objects
Link JAC objects to the names (String -> Object)


names

public Map names
Reverse hashtable to find an objet from its name (Object -> String)

Constructor Detail

Repository

public Repository()
Method Detail

get

public static Repository get()
Get the sole repository instance for this class. Creates it if it does not exist yet.

NOTE: this method MUST be defined by all subclasses.


init

protected void init()

register

public boolean register(String logicalName,
                        Object object)
Register a new object into the repository.

Parameters:
logicalName - the key that allows to find the object
object - the object to register
Returns:
true if the object registered, false if already registered
See Also:
unregister(String)

unregister

public void unregister(String logicalName)
Unregister a JacObject from the repository.

Parameters:
logicalName - the key that allows to find the object
See Also:
register(String,Object), unregisterObject(Object)

unregisterObject

public void unregisterObject(Object object)
Unregister a JacObject from the repository.

Parameters:
object - the object to unregister
See Also:
register(String,Object), unregister(String)

isRegistered

public boolean isRegistered(String logicalName)
Returns true if an object is registered with this name.

Parameters:
logicalName - the key that allows to find the object
See Also:
register(String,Object)

getObjects

public Object[] getObjects()
Return all the registered objects as an array.

Reverse operation is getNames().

Returns:
the registered objects in this repository
See Also:
register(String,Object), getNames()

getNames

public String[] getNames()
Return the names of the registered objects as an array.

Reverse operation is getObjects().

Returns:
the registered object names in this repository
See Also:
register(String,Object), getObjects()

getObject

public Object getObject(String logicalName)
Return a registered object for a given logical name.

Return null if the name does not correspond to any registered object or if logicalName is null.

Reverse operation is getName(Object).

Parameters:
logicalName - the key that allows to find the object
Returns:
the corresponding object, null if not registered
See Also:
register(String,Object), getName(Object)

getName

public String getName(Object object)
Returns the name of a registered object. Null if not registered.

Reverse operation is getObject(String).

Parameters:
object - the object to get the name of
Returns:
the object name, null if not registered
See Also:
register(String,Object), getObject(String)

dump

public void dump()
Dump all the registered objects.


getPrintableString

public String getPrintableString()