org.inria.ns.reflex.util
Class Registry

java.lang.Object
  extended by org.inria.ns.reflex.util.Registry

public class Registry
extends Object

A Registry is a structure used to store typed resources.

Registries may be backed by another registry, that is to say when a resource is looked up, a chain of registry may be used to retrieve the resource. The lookup order (top-down or bottom-up) depends on the nature of the resource to research.

Several registries can be backed by the same single registry ; when one of them is involved, it can't access to other registries except to its parent : registries are organized in trees and browsed by branchs.

To retrieve a resource bound to a key, the key must be wrapped in a LookupKey.

Author:
Philippe Poulard

Constructor Summary
Registry()
          Create a new registry backed by the static registry.
Registry(Registry registry)
          Create a new registry backed by a given registry.
 
Method Summary
 Object get(Key key)
          Return the object stored in this registry, without lookup in the back registries.
 Object getFromParent(Key key)
          Return the object stored in the parent registry, if any.
 Object lookup(LookupKey lookupKey)
          Looks up for a resource in this registry.
 void store(Key key, Object resource)
          Store a resource with a given key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Registry

public Registry()
Create a new registry backed by the static registry.


Registry

public Registry(Registry registry)
Create a new registry backed by a given registry.

Parameters:
registry - The registry that backs this one.
Method Detail

store

public void store(Key key,
                  Object resource)
Store a resource with a given key. The registry used for storing is really those involved (this), not one of its branch ; that's why the key doesn't need to be wrapped in a LookupKey

Parameters:
key - The key with which the resource is stored. To retrieve the resource, this key must be wrapped in a LookupKey.
resource - The resource to store.
See Also:
LookupKey, lookup(LookupKey)

lookup

public Object lookup(LookupKey lookupKey)
Looks up for a resource in this registry.

Parameters:
lookupKey - The lookup key, that embeds in itself the lookup method and the real key with which the resource is stored.
Returns:
The resource found, or null

get

public Object get(Key key)
Return the object stored in this registry, without lookup in the back registries.

Parameters:
key - The key of the object to find.
Returns:
The object registered with the given key, or null.

getFromParent

public Object getFromParent(Key key)
Return the object stored in the parent registry, if any.

Parameters:
key - The key of the object to find.
Returns:
The object registered with the given key, or null.