org.openorb.tns
Class MapNamingContext

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap
          extended by org.openorb.tns.MapNamingContext
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map, java.util.SortedMap

public class MapNamingContext
extends java.util.TreeMap

This class can be used for an easy to use transient naming context. The context implements the SortedMap interface, and stores all it's bindings as name/value pairs. Using the put operation with a key containing a non-existent context parent(s) will result in the parent contexts being created.

Special notes:

Deleting an internal context with the remove operation on any of the associated iterators or collections will cause undefined behaviour. This may change in the future.

Author:
Chris Wood
See Also:
Serialized Form

Field Summary
static java.lang.String DEFAULT_FORMAT
           
static int SHUTDOWN_DESTROY_ORB
           
static int SHUTDOWN_DESTROY_POA
           
static int SHUTDOWN_DISALLOW
           
 
Constructor Summary
MapNamingContext(org.omg.CORBA.ORB orb, org.omg.PortableServer.POA rootPOA, org.apache.avalon.framework.logger.Logger logger)
          Create a new MapNamingContext.
 
Method Summary
 void activate()
          Start the NamingService.
 org.omg.CosNaming.NamingContextExt addContext(org.omg.CosNaming.NameComponent[] name)
          Add a context to the map, adding ancestor contexts as neccicary.
 org.omg.CosNaming.NamingContextExt addContext(java.lang.String context)
          Add a context to the map, adding ancestor contexts as neccicary.
static org.apache.avalon.framework.logger.Logger createLogger(java.lang.String name)
           
 void deactivate(boolean waitForComplete)
          Deactivate the server reference, and all other naming contexts created with the create_context operation.
 boolean getAllowSelfDestruct()
          Will the destroy_context operation work on the root context?
 java.lang.String getCorbaname(org.omg.CosNaming.NameComponent[] name)
          Return a corbaname style address for the name passed.
 java.lang.String getCorbaname(java.lang.String str)
          Return a corbaname style address for the string name passed.
 org.apache.avalon.framework.logger.Logger getLogger()
           
 org.omg.CosNaming.NamingContextExt getRootCtxt()
          Get a reference to the root naming context.
 boolean isContext(java.lang.String context)
          Determine if the specified name is a subcontext and must be removed with the removeContext operation.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Add a binding to the map.
 void putAll(java.util.Map p1)
           
 org.omg.CORBA.Object putName(org.omg.CosNaming.NameComponent[] name, org.omg.CORBA.Object obj)
          Add a binding to the map, creating ancestor contexts as neccicary.
 org.omg.CORBA.Object putStr(java.lang.String str, org.omg.CORBA.Object obj)
          Add a binding to the map, creating ancestor contexts as neccicary.
 boolean removeContext(java.lang.String context)
          Remove a context.
 void setAllowSelfDestruct(boolean allowSelfDestruct)
          When this is set to true the root context may be destroyed with the destroy operation.
 void setShutdownMode(int shutdownMode)
          When this is set to true the root context may be destroyed with the destroy operation.
 
Methods inherited from class java.util.TreeMap
clear, clone, comparator, containsKey, containsValue, entrySet, firstKey, get, headMap, keySet, lastKey, remove, size, subMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty
 

Field Detail

DEFAULT_FORMAT

public static final java.lang.String DEFAULT_FORMAT
See Also:
Constant Field Values

SHUTDOWN_DISALLOW

public static final int SHUTDOWN_DISALLOW
See Also:
Constant Field Values

SHUTDOWN_DESTROY_POA

public static final int SHUTDOWN_DESTROY_POA
See Also:
Constant Field Values

SHUTDOWN_DESTROY_ORB

public static final int SHUTDOWN_DESTROY_ORB
See Also:
Constant Field Values
Constructor Detail

MapNamingContext

public MapNamingContext(org.omg.CORBA.ORB orb,
                        org.omg.PortableServer.POA rootPOA,
                        org.apache.avalon.framework.logger.Logger logger)
Create a new MapNamingContext. The context's poa name will be somthing like NameServ_10.

Parameters:
orb - orb under which the context is to be activated.
rootPOA - parent POA under which to create the context's poa. If null the orb's root POA is used.
logger - for use in class -- may not be null.
Method Detail

createLogger

public static org.apache.avalon.framework.logger.Logger createLogger(java.lang.String name)

getLogger

public org.apache.avalon.framework.logger.Logger getLogger()

activate

public void activate()
Start the NamingService.


getRootCtxt

public org.omg.CosNaming.NamingContextExt getRootCtxt()
Get a reference to the root naming context.


getCorbaname

public java.lang.String getCorbaname(java.lang.String str)
Return a corbaname style address for the string name passed.

Parameters:
str - stringified corbaname of target.
Throws:
java.lang.IllegalArgumentException - if str is not a valid stringified name
java.lang.IllegalStateException - nameservice has not been bound as a corbaloc.

getCorbaname

public java.lang.String getCorbaname(org.omg.CosNaming.NameComponent[] name)
Return a corbaname style address for the name passed.

Parameters:
name - the name to use.
Throws:
java.lang.IllegalArgumentException - if name is invalid for some reason.
java.lang.IllegalStateException - nameservice has not been bound as a corbaloc.

getAllowSelfDestruct

public boolean getAllowSelfDestruct()
Will the destroy_context operation work on the root context?

Returns:
Value of property allowSelfDestruct.

setAllowSelfDestruct

public void setAllowSelfDestruct(boolean allowSelfDestruct)
When this is set to true the root context may be destroyed with the destroy operation.

Parameters:
allowSelfDestruct - New value of property allowSelfDestruct.

setShutdownMode

public void setShutdownMode(int shutdownMode)
When this is set to true the root context may be destroyed with the destroy operation.

Parameters:
shutdownMode - New value of property shutdownMode.

deactivate

public void deactivate(boolean waitForComplete)
Deactivate the server reference, and all other naming contexts created with the create_context operation.

Parameters:
waitForComplete - wait for completion before returning. If this parameter is true and this operation is called from a server thread an exception will be thrown.

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Add a binding to the map.

To insert a new empty context into the map use a key string ending in / The object reference in this case will be ignored.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.TreeMap
Parameters:
key - String or NameComponent[] composing the binding's name.
value - org.omg.CORBA.Object to be bound to the name.
Throws:
java.lang.NullPointerException - if key is null.
java.lang.ClassCastException - if key or value is the wrong type.
java.lang.IllegalArgumentException - the key is not a valid name.
java.lang.IllegalStateException - the name is bound to a context, or one of it's ancestors are bound to an object.

putName

public org.omg.CORBA.Object putName(org.omg.CosNaming.NameComponent[] name,
                                    org.omg.CORBA.Object obj)
Add a binding to the map, creating ancestor contexts as neccicary.

Parameters:
name - The binding's name.
obj - org.omg.CORBA.Object to be bound to the name.
Throws:
java.lang.NullPointerException - if key is null.
java.lang.IllegalArgumentException - the key is not a valid name.
java.lang.IllegalStateException - the name is bound to a context, or one of it's ancestors are bound to an object.

putStr

public org.omg.CORBA.Object putStr(java.lang.String str,
                                   org.omg.CORBA.Object obj)
Add a binding to the map, creating ancestor contexts as neccicary.

To insert a new empty context into the map use a key string ending in / The object reference in this case will be ignored.

Parameters:
str - The binding's name.
obj - org.omg.CORBA.Object to be bound to the name.
Throws:
java.lang.NullPointerException - if key is null.
java.lang.IllegalArgumentException - the key is not a valid name.
java.lang.IllegalStateException - the name is bound to a context, or one of it's ancestors are bound to an object.

addContext

public org.omg.CosNaming.NamingContextExt addContext(java.lang.String context)
Add a context to the map, adding ancestor contexts as neccicary.

Parameters:
context - Name of the context.
Throws:
java.lang.NullPointerException - if context is null.
java.lang.IllegalArgumentException - the context is not a valid name.
java.lang.IllegalStateException - the context or one of it's ancestors are bound to an object.

addContext

public org.omg.CosNaming.NamingContextExt addContext(org.omg.CosNaming.NameComponent[] name)
Add a context to the map, adding ancestor contexts as neccicary.

Parameters:
name - Name of the context.
Throws:
java.lang.NullPointerException - if name is null.
java.lang.IllegalArgumentException - the name is not a valid name.
java.lang.IllegalStateException - the name or one of it's ancestors are bound to an object.

removeContext

public boolean removeContext(java.lang.String context)
Remove a context. This will remove the context and all it's decendants.

Parameters:
context - the name of the context.
Returns:
true if the context was destroyed.

isContext

public boolean isContext(java.lang.String context)
Determine if the specified name is a subcontext and must be removed with the removeContext operation.

Parameters:
context - the name of the context.
Returns:
true if the name is bound to a context.

putAll

public void putAll(java.util.Map p1)
Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class java.util.TreeMap