FileDocCategorySizeDatePackage
TransientNamingContext.javaAPI DocJava SE 5 API12964Fri Aug 26 14:54:26 BST 2005com.sun.corba.se.impl.naming.cosnaming

TransientNamingContext

public class TransientNamingContext extends NamingContextImpl implements NamingContextDataStore
Class TransientNamingContext implements the methods defined by NamingContextDataStore, and extends the NamingContextImpl class to provide a servant implementation of CosNaming::NamingContext. The TransientNamingContext uses a hash table to store the mappings between bindings and object references and the hash table is not persistent; thereby the name "transient". This class should not be used directly; instead, the class TransientNameService should be instantiated.

The keys in the hash table are InternalBindingKey objects, containing a single NameComponent and implementing the proper functions, i.e., equals() and hashCode() in an efficient manner. The values in the hash table are InternalBindingValues and store a org.omg.CosNaming::Binding and the object reference associated with the binding. For iteration, TransientBindingIterator objects are created, which are passed a cloned copy of the hashtable. Since elements are inserted and deleted and never modified, this provides stable iterators at the cost of cloning the hash table.

To create and destroy object references, the TransientNamingContext uses the orb.connect() and orb.disconnect() methods.

see
NamingContextImpl
see
NamingContextDataStore
see
TransientBindingIterator
see
TransientNameService

Fields Summary
private Logger
readLogger
private Logger
updateLogger
private Logger
lifecycleLogger
private com.sun.corba.se.impl.logging.NamingSystemException
wrapper
private final Hashtable
theHashtable
public org.omg.CORBA.Object
localRoot
The local root naming context.
Constructors Summary
public TransientNamingContext(com.sun.corba.se.spi.orb.ORB orb, org.omg.CORBA.Object initial, org.omg.PortableServer.POA nsPOA)
Constructs a new TransientNamingContext object.

param
orb an orb object.
param
initial the initial naming context.
exception
Exception a Java exception thrown of the base class cannot initialize.

	super(orb, nsPOA );
	wrapper = NamingSystemException.get( orb, CORBALogDomains.NAMING ) ;

	this.localRoot = initial;
        readLogger = orb.getLogger( CORBALogDomains.NAMING_READ);
        updateLogger = orb.getLogger( CORBALogDomains.NAMING_UPDATE);
        lifecycleLogger = orb.getLogger( 
            CORBALogDomains.NAMING_LIFECYCLE);
        lifecycleLogger.fine( "Root TransientNamingContext LIFECYCLE.CREATED" );
    
Methods Summary
public final voidBind(org.omg.CosNaming.NameComponent n, org.omg.CORBA.Object obj, org.omg.CosNaming.BindingType bt)
Binds the object to the name component as the specified binding type. It creates a InternalBindingKey object and a InternalBindingValue object and inserts them in the hash table.

param
n A single org.omg.CosNaming::NameComponent under which the object will be bound.
param
obj An object reference to be bound under the supplied name.
param
bt The type of the binding (i.e., as object or as context).
exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	// Create a key and a value
	InternalBindingKey key = new InternalBindingKey(n);
	NameComponent[] name = new NameComponent[1];
	name[0] = n;
	Binding b = new Binding(name,bt);
	InternalBindingValue value = new InternalBindingValue(b,null);
	value.theObjectRef = obj;
	// insert it
	InternalBindingValue oldValue =
	    (InternalBindingValue)this.theHashtable.put(key,value);

	if (oldValue != null) {
            updateLogger.warning( LogKeywords.NAMING_BIND + "Name " + 
                getName( n ) + " Was Already Bound" );
	    throw wrapper.transNcBindAlreadyBound() ;
	}
        if( updateLogger.isLoggable( Level.FINE ) ) {
            updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + 
                "Name Component: " + n.id + "." + n.kind );
        }
    
public final voidDestroy()
Destroys this NamingContext by disconnecting from the ORB.

exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	// Destroy the object reference by disconnecting from the ORB
	try {
            byte[] objectId = nsPOA.servant_to_id( this );
            if( objectId != null ) {
                nsPOA.deactivate_object( objectId );
            }
            if( lifecycleLogger.isLoggable( Level.FINE ) ) {
                lifecycleLogger.fine( 
                    LogKeywords.LIFECYCLE_DESTROY_SUCCESS );
            }
	} catch (org.omg.CORBA.SystemException e) {
            lifecycleLogger.log( Level.WARNING, 
                LogKeywords.LIFECYCLE_DESTROY_FAILURE, e ); 
	    throw e;
	} catch (Exception e) { 
            lifecycleLogger.log( Level.WARNING, 
                LogKeywords.LIFECYCLE_DESTROY_FAILURE, e ); 
	    throw wrapper.transNcDestroyGotExc( e ) ;
	}
    
public final booleanIsEmpty()
Return whether this NamingContext contains any bindings. It forwards this request to the hash table.

return
true if this NamingContext contains no bindings.

	return this.theHashtable.isEmpty();
    
public final voidList(int how_many, org.omg.CosNaming.BindingListHolder bl, org.omg.CosNaming.BindingIteratorHolder bi)
List the contents of this NamingContext. It creates a new TransientBindingIterator object and passes it a clone of the hash table and an orb object. It then uses the newly created object to return the required number of bindings.

param
how_many The number of requested bindings in the BindingList.
param
bl The BindingList as an out parameter.
param
bi The BindingIterator as an out parameter.
exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	try {
	    // Create a new binding iterator servant with a copy of this 
            // hashtable. nsPOA is passed to the object so that it can 
            // de-activate itself from the Active Object Map when 
            // Binding Iterator.destroy is called.
	    TransientBindingIterator bindingIterator =
		new TransientBindingIterator(this.orb,
	        (Hashtable)this.theHashtable.clone(), nsPOA);
	    // Have it set the binding list
            bindingIterator.list(how_many,bl);
            
            byte[] objectId = nsPOA.activate_object( bindingIterator );
            org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId );
      
	    // Get the object reference for the binding iterator servant
	    org.omg.CosNaming.BindingIterator bindingRef = 
                org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
      
	    bi.value = bindingRef;
	} catch (org.omg.CORBA.SystemException e) {
            readLogger.warning( LogKeywords.NAMING_LIST_FAILURE + e );
	    throw e;
	} catch (Exception e) {
	    // Convert to a CORBA system exception
            readLogger.severe( LogKeywords.NAMING_LIST_FAILURE + e );
	    throw wrapper.transNcListGotExc( e ) ;
	}
    
public final org.omg.CosNaming.NamingContextNewContext()
Create a new NamingContext. It creates a new TransientNamingContext object, passing it the orb object.

return
an object reference for a new NamingContext object implemented by this Name Server.
exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	try {
	    // Create a new servant
	    TransientNamingContext transContext =
		new TransientNamingContext(
                (com.sun.corba.se.spi.orb.ORB) orb,localRoot, nsPOA);

            byte[] objectId = nsPOA.activate_object( transContext );
            org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId );
            lifecycleLogger.fine( "TransientNamingContext " +
                "LIFECYCLE.CREATE SUCCESSFUL" ); 
            return org.omg.CosNaming.NamingContextHelper.narrow( obj );

	} catch (org.omg.CORBA.SystemException e) {
            lifecycleLogger.log( 
                Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e );
	    throw e;
	} catch (Exception e) {
            lifecycleLogger.log( 
                Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e );
	    throw wrapper.transNcNewctxGotExc( e ) ;
	}
    
public final org.omg.CORBA.ObjectResolve(org.omg.CosNaming.NameComponent n, org.omg.CosNaming.BindingTypeHolder bth)
Resolves the supplied name to an object reference and returns the type of the resolved binding. It creates a InternalBindingKey and uses the key for looking up in the hash table. If nothing is found an exception is thrown, otherwise the object reference is returned and the binding type set.

param
n a NameComponent which is the name to be resolved.
param
bth the BindingType as an out parameter.
return
the object reference bound under the supplied name, null if not found.
exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	// Is the initial naming context requested?
	if ( (n.id.length() == 0)
           &&(n.kind.length() == 0 ) )
        {
	    bth.value = BindingType.ncontext;
	    return localRoot;
	}
    
	// Create a key and lookup the value
	InternalBindingKey key = new InternalBindingKey(n);

	InternalBindingValue value = 
            (InternalBindingValue) this.theHashtable.get(key);
	if (value == null) return null;
        if( readLogger.isLoggable( Level.FINE ) ) {
            readLogger.fine( LogKeywords.NAMING_RESOLVE_SUCCESS 
                + "Namecomponent :" + getName( n ) );
        }
    
        // Copy out binding type and object reference
	bth.value = value.theBinding.binding_type;
	return value.theObjectRef;
    
public final org.omg.CORBA.ObjectUnbind(org.omg.CosNaming.NameComponent n)
Deletes the binding with the supplied name. It creates a InternalBindingKey and uses it to remove the value associated with the key. If nothing is found an exception is thrown, otherwise the element is removed from the hash table.

param
n a NameComponent which is the name to unbind
return
the object reference bound to the name, or null if not found.
exception
org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.

	// Create a key and remove it from the hashtable
	InternalBindingKey key = new InternalBindingKey(n);
	InternalBindingValue value = 
            (InternalBindingValue)this.theHashtable.remove(key);

	// Return what was found
	if (value == null) {
            if( updateLogger.isLoggable( Level.FINE ) ) {
                updateLogger.fine( LogKeywords.NAMING_UNBIND_FAILURE +
                    " There was no binding with the name " + getName( n ) + 
                    " to Unbind " ); 
            }
	    return null;
        } else {
            if( updateLogger.isLoggable( Level.FINE ) ) {
                updateLogger.fine( LogKeywords.NAMING_UNBIND_SUCCESS +
                    " NameComponent:  " + getName( n ) ); 
            }
	    return value.theObjectRef;
       }
    
private java.lang.StringgetName(org.omg.CosNaming.NameComponent n)
A Utility Method For Logging..

        return n.id + "." + n.kind;