org.apache.beehive.netui.pageflow.requeststate
Class NameService

Object
  extended by NameService
All Implemented Interfaces:
Serializable

public final class NameService
extends Object
implements Serializable

This class implements a service that will name and track objects which implement the INameable interface. The typical use of this class is in the XmlHttpRequest request processing to lookup the object that should handle the request.

See Also:
Serialized Form

Field Summary
static String NAME_SERVICE_MUTEX_ATTRIBUTE
           
 
Method Summary
 void addNamingObjectListener(NamingObjectListener nol)
          This method will add a NamingObjectListener to the set of listeners for the NamingObject event.
 void debugSetNameIntValue(int val)
          This is a debug method that will set the next integer value.
 INameable get(String name)
          Given the name, return the INameable object stored by the NameService.
 Map getMap(String name, boolean create)
          This method will return the state map associated with the Nameable object if the object has been stored in the NameService and something has been stored into the Map.
static NameService instance(HttpSession session)
          This will return the session specific instance of a NameService.
 void nameObject(String namePrefix, INameable object)
          This method will create a unique name for an INameable object.
 void put(INameable object)
          This method will store an INameable object into the NameService.
 void removeNamingObjectListener(NamingObjectListener nol)
          This method will remove a NamingObjectListener from the set of listeners.
static NameService staticInstance()
          This will return a create a static name service.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_SERVICE_MUTEX_ATTRIBUTE

public static final String NAME_SERVICE_MUTEX_ATTRIBUTE
Method Detail

instance

public static NameService instance(HttpSession session)
This will return the session specific instance of a NameService. There will only be a single NameService per session.

Parameters:
session - the HttpSession that contains the NameService
Returns:
the NameService associated with the session.

staticInstance

public static NameService staticInstance()
This will return a create a static name service. This is used mainly to test the Name service class.

Returns:
The statically scoped NameService

addNamingObjectListener

public void addNamingObjectListener(NamingObjectListener nol)
This method will add a NamingObjectListener to the set of listeners for the NamingObject event.

Parameters:
nol - The NamingObjectListener to add as a listener. This must not be null.
Throws:
IllegalArgumentException - when nol is null.

removeNamingObjectListener

public void removeNamingObjectListener(NamingObjectListener nol)
This method will remove a NamingObjectListener from the set of listeners. If the It is safe to call this if the NamingObjectListener hasn't been added to the listener list.

Parameters:
nol - The NamingObjectListener to remove as a listener. This must not be null.
Throws:
IllegalArgumentException - when nol is null.

nameObject

public void nameObject(String namePrefix,
                       INameable object)
This method will create a unique name for an INameable object. The name will be unque within the session. This will throw an IllegalStateException if INameable.setObjectName has previously been called on object.

Parameters:
namePrefix - The prefix of the generated name.
object - the INameable object.
Throws:
IllegalStateException - if this method is called more than once for an object

debugSetNameIntValue

public void debugSetNameIntValue(int val)
This is a debug method that will set the next integer value. This is used so tests can force the name.

Parameters:
val - the integer value that will be forced to be the next value.

put

public void put(INameable object)
This method will store an INameable object into the NameService. The name is obtained from the INameable. The object will be stored in the NameService with a WeakReference so the NameService will not keep an object alive.

Parameters:
object - The INameable to be stored in the name service.

get

public INameable get(String name)
Given the name, return the INameable object stored by the NameService. Objects are stored in the NameService using WeakReferences so this will not keep an object alive. If the object is not found or has been reclaimed, this method will return null.

Parameters:
name - The name of the object to get from the NameService
Returns:
INameable If the named object is stored by the name service, it will be returned otherwise null is returned.

getMap

public Map getMap(String name,
                  boolean create)
This method will return the state map associated with the Nameable object if the object has been stored in the NameService and something has been stored into the Map. Otherwise this will return null indicating that the map is empty. If the create parameter is true, we will always return the Map object.

Parameters:
name - The name of the object to return the named object. This must not be null.
create - This will create the map if necessary.
Returns:
A Map Object for the named object. This will return null if nothing has been stored in the map and create is false.