org.javagroup.util
Class Namespace

java.lang.Object
  |
  +--org.javagroup.util.Namespace
Direct Known Subclasses:
ProcessNamespace

public class Namespace
extends java.lang.Object

Lightweight pseudo-namespace management class. Designed as a replacement for static code with state.

TODO: more verbose explanation, discussion of usefulness and implementation pattern essential.


Field Summary
protected  Namespace _child
          child namespace
protected  Namespace _parent
          parent namespace
 
Constructor Summary
Namespace()
          Constructs a Namespace with no root node.
 
Method Summary
 java.lang.Object getInstanceForClass(java.lang.Class klass)
          Get the registered instance for a given class.
static Namespace getNamespace()
          Accessor method for gettting the namespace for the calling code.
static void registerDefaultInstanceForClass(java.lang.Class klass, java.lang.Object instance)
          Register the default instance for a class.
 void registerInstanceForClass(java.lang.Class klass, java.lang.Object instance)
          Register an instance for a class.
 void registerNamespace(Namespace namespace)
          Register a new Namespace instance.
 void setParentNamespace(Namespace parent)
          Set the root Namespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_parent

protected Namespace _parent
parent namespace

_child

protected Namespace _child
child namespace
Constructor Detail

Namespace

public Namespace()
Constructs a Namespace with no root node. The root node is assigned when the Namespace is registered.
Method Detail

getNamespace

public static Namespace getNamespace()
Accessor method for gettting the namespace for the calling code. This method should always be used to get a Namespace instance for querying.
Returns:
The Namespace object the caller-code is supposed to use.

registerDefaultInstanceForClass

public static void registerDefaultInstanceForClass(java.lang.Class klass,
                                                   java.lang.Object instance)
Register the default instance for a class. This should only be done from the class that is being registered, and only from its static init {} block, eg:

class Foo { static { Namespace.getNamespace() .registerDefaultInstanceForClass(Foo.class, new Foo()); } }


registerNamespace

public void registerNamespace(Namespace namespace)
Register a new Namespace instance.
Parameters:
namespace - The new namespace to use.

setParentNamespace

public void setParentNamespace(Namespace parent)
Set the root Namespace.
Parameters:
root - The root namespace.

registerInstanceForClass

public void registerInstanceForClass(java.lang.Class klass,
                                     java.lang.Object instance)
Register an instance for a class.
Parameters:
klass - The class to register the instance for.
instance - The instance of that class (must be instanceof the class).

getInstanceForClass

public java.lang.Object getInstanceForClass(java.lang.Class klass)
Get the registered instance for a given class.
Parameters:
klass - The class to get an instance of.
Returns:
The registered instance for the given class.