namingcontextimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,365 行 · 第 1/4 页

JAVA
1,365
字号
    {	try	{		InternalBindingKey key = new InternalBindingKey(n);		InternalBindingValue value = null;		try		{		      value = (InternalBindingValue) this.theHashtable.remove(key);		}		catch( Exception e )		{			// Ignore the exception in Hashtable.remove		}		theServantManagerImplHandle.updateContext( objKey,					           this );		if( value == null )		{			return null;		}		if( value.strObjectRef.startsWith( "NC" ) )		{			theServantManagerImplHandle.readInContext( value.strObjectRef );			Object theObjectFromStringfiedReference = 		        theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );			return theObjectFromStringfiedReference;		}		else		{			Object theObjectFromStringifiedReference = value.getObjectRef( );			if( theObjectFromStringifiedReference == null )			{ 				theObjectFromStringifiedReference =				orb.string_to_object( value.strObjectRef );  				}			return theObjectFromStringifiedReference;		}	}	catch( Exception e )	{		// Add a new Minor code for Unbind exception		throw new org.omg.CORBA.UNKNOWN( 				3,  // Replace this with a valid constant		        	CompletionStatus.COMPLETED_MAYBE );	}     }   /**   * List the contents of this NamingContext. It creates a new   * PersistentBindingIterator 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.   */    public void List(int how_many, BindingListHolder bl, 		     BindingIteratorHolder bi) throws SystemException    {        if( biPOA == null ) {            createbiPOA( );        }        try {            PersistentBindingIterator bindingIterator =                new PersistentBindingIterator(this.orb,                (Hashtable)this.theHashtable.clone(), biPOA);            // Have it set the binding list            bindingIterator.list(how_many,bl);            byte[] objectId = biPOA.activate_object( bindingIterator );            org.omg.CORBA.Object obj = biPOA.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) {            throw e;        } catch( Exception e ) {            throw new org.omg.CORBA.INTERNAL(MinorCodes.TRANS_NC_LIST_GOT_EXC,                                             CompletionStatus.COMPLETED_NO);        }    }    private synchronized void createbiPOA( ) {        if( biPOA != null ) {            return;        }        try {            POA rootPOA = (POA) orb.resolve_initial_references("RootPOA");            rootPOA.the_POAManager().activate( );            int i = 0;            Policy[] poaPolicy = new Policy[3];            poaPolicy[i++] = rootPOA.create_lifespan_policy(                LifespanPolicyValue.TRANSIENT);            poaPolicy[i++] = rootPOA.create_id_assignment_policy(                IdAssignmentPolicyValue.SYSTEM_ID);            poaPolicy[i++] = rootPOA.create_servant_retention_policy(                ServantRetentionPolicyValue.RETAIN);            biPOA = rootPOA.create_POA("BindingIteratorPOA", null, poaPolicy );            biPOA.the_POAManager().activate( );        } catch( Exception e ) {            throw new INTERNAL("Exception While Creating Binding Iterator POA");        }    }   /**   * Create a NamingContext object and return its object reference.   * @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.   */    public NamingContext NewContext() throws SystemException    {	try	{		return  theNameServiceHandle.NewContext( );	}	catch( org.omg.CORBA.SystemException e )	{		throw e;	}	catch( Exception e )	{			throw new org.omg.CORBA.INTERNAL(			MinorCodes.TRANS_NC_NEWCTX_GOT_EXC,			CompletionStatus.COMPLETED_NO);			}     }   /**   * Destroys the NamingContext.   */    public void Destroy() throws SystemException    {	// XXX note that orb.disconnect is illegal here, since the	// POA is used.  However, there may be some associated state	// that needs to be cleaned up in ServerManagerImpl which we will	// look into further at another time.	/*	try	{		orb.disconnect(		        theNameServiceHandle.getObjectReferenceFromKey( this.objKey ) );	}	catch( org.omg.CORBA.SystemException e )	{		throw e;	}	catch( Exception e )	{			//throw new org.omg.CORBA.INTERNAL(			//MinorCodes.TRANS_NC_DESTROY_GOT_EX,			//CompletionStatus.COMPLETED_NO );			}	*/    }    /**    * This operation creates a stringified name from the array of Name    * components.    * @param n Name of the object <p>    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName    * Indicates the name does not identify a binding.<p>    *    */    public String to_string(org.omg.CosNaming.NameComponent[] n)         throws org.omg.CosNaming.NamingContextPackage.InvalidName    {        // Name valid?        if ( (n == null ) || (n.length == 0) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        String theStringifiedName = getINSImpl().convertToString( n );        if( theStringifiedName == null )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        return theStringifiedName;    }    /**    * This operation  converts a Stringified Name into an  equivalent array    * of Name Components.    * @param sn Stringified Name of the object <p>    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName    * Indicates the name does not identify a binding.<p>    *    */    public org.omg.CosNaming.NameComponent[] to_name(String sn)         throws org.omg.CosNaming.NamingContextPackage.InvalidName    {        // Name valid?        if  ( (sn == null ) || (sn.length() == 0) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        org.omg.CosNaming.NameComponent[] theNameComponents =                getINSImpl().convertToNameComponent( sn );        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        for( int i = 0; i < theNameComponents.length; i++ ) {            // If there is a name component whose id and kind null or            // zero length string, then an invalid name exception needs to be            // raised.            if ( ( ( theNameComponents[i].id  == null )                 ||( theNameComponents[i].id.length() == 0 ) )               &&( ( theNameComponents[i].kind == null )                 ||( theNameComponents[i].kind.length() == 0 ) ) ) {                throw new InvalidName();            }             }        return theNameComponents;    }    /**    * This operation creates a URL based "iiopname://" format name    * from the Stringified Name of the object.    * @param addr internet based address of the host machine where    * Name Service is running <p>    * @param sn Stringified Name of the object <p>    * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName    * Indicates the name does not identify a binding.<p>    * @exception org.omg.CosNaming.NamingContextPackage.InvalidAddress    * Indicates the internet based address of the host machine is    * incorrect <p>    *    */    public String to_url(String addr, String sn)        throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress,               org.omg.CosNaming.NamingContextPackage.InvalidName    {        // Name valid?        if  ( (sn == null ) || (sn.length() == 0) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        if( addr == null )        {                throw new org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();        }        String urlBasedAddress = null;         try {            urlBasedAddress = getINSImpl().createURLBasedAddress( addr, sn );        } catch (Exception e ) {             urlBasedAddress = null;        }        // Extra check to see that corba name url created is valid as per        // INS spec grammer.        CorbaName corbaName = null;        try {            corbaName = ((com.sun.corba.se.internal.corba.ORB)orb).                getInitialNamingClient().checkcorbanameGrammer(                urlBasedAddress );        } catch( BAD_PARAM e ) {            throw new                org.omg.CosNaming.NamingContextExtPackage.InvalidAddress();        }        if ( corbaName == null ) {            throw new InvalidName();        }        return urlBasedAddress;    }    /**     * This operation resolves the Stringified name into the object     * reference.     * @param sn Stringified Name of the object <p>     * @exception org.omg.CosNaming.NamingContextPackage.NotFound     * Indicates there is no object reference for the given name. <p>     * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed     * Indicates that the given compound name is incorrect <p>     * @exception org.omg.CosNaming.NamingContextExtPackage.InvalidName     * Indicates the name does not identify a binding.<p>     *     */    public org.omg.CORBA.Object resolve_str(String sn)        throws org.omg.CosNaming.NamingContextPackage.NotFound,               org.omg.CosNaming.NamingContextPackage.CannotProceed,               org.omg.CosNaming.NamingContextPackage.InvalidName    {        org.omg.CORBA.Object theObject = null;        // Name valid?        if  ( (sn == null ) || (sn.length() == 0) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        org.omg.CosNaming.NameComponent[] theNameComponents =                getINSImpl().convertToNameComponent( sn );        if( ( theNameComponents == null ) || (theNameComponents.length == 0 ) )        {                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        }        theObject = resolve( theNameComponents );        return theObject;    }     /**   * This is a Debugging Method   */    public boolean IsEmpty()    {	return this.theHashtable.isEmpty();    }   /**   * This is a Debugging Method   */    public void printSize( )    {	System.out.println( "Hashtable Size = " + theHashtable.size( ) );	java.util.Enumeration e = theHashtable.keys( );	for( ; e.hasMoreElements(); )	{	      InternalBindingValue thevalue = 			(InternalBindingValue) this.theHashtable.get(e.nextElement());		if( thevalue != null )		{			System.out.println( "value = " + thevalue.strObjectRef);		}	}    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?