namingcontextimpl.java

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

JAVA
1,365
字号
    }      /**   * Implements unbinding bound names in this NamingContext. If the   * name contains only one component, the name is unbound in this   * NamingContext using Unbind(). Otherwise, the first component   * of the name is resolved in this NamingContext and   * unbind passed to the resulting NamingContext.   * This method is static for maximal reuse - even for extended naming   * context implementations where the recursive semantics still apply.   * @param impl an implementation of NamingContextDataStore   * @param n a sequence of NameComponents which is the name to be unbound.   * @exception org.omg.CosNaming.NamingContextPackage.NotFound A name with multiple   * components was supplied, but the first component could not be   * resolved.   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed   * in resolving the n-1 components of the supplied name.   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name   * is invalid (i.e., has length less than 1).   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.   * @see resolve   */    public static void doUnbind(NamingContextDataStore impl,                                NameComponent[] n)        throws org.omg.CosNaming.NamingContextPackage.NotFound,               org.omg.CosNaming.NamingContextPackage.CannotProceed,               org.omg.CosNaming.NamingContextPackage.InvalidName    {	// Name valid?        if (n.length < 1)            throw new org.omg.CosNaming.NamingContextPackage.InvalidName();        // Unbind here?        if (n.length == 1) {            // The identifier must be set            if ( (n[0].id.length() == 0) && (n[0].kind.length() == 0 ) )                throw new org.omg.CosNaming.NamingContextPackage.InvalidName();            org.omg.CORBA.Object objRef = null;            synchronized (impl) {                // Yes: unbind in this context                objRef = impl.Unbind(n[0]);            }            if (objRef == null)                // It was not bound                throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);            // Done            return;        } else {            // No: unbind in a different context      // Resolve first  - must be resolveable            NamingContext context = resolveFirstAsContext(impl,n);	                // Compute tail            NameComponent[] tail = new NameComponent[n.length - 1];            System.arraycopy(n,1,tail,0,n.length-1);      // Propagate unbind to this context            context.unbind(tail);        }    }     /**   * Implements resolving a NameComponent in this context and   * narrowing it to CosNaming::NamingContext. It will throw appropriate   * exceptions if not found or not narrowable.   * @param impl an implementation of NamingContextDataStore   * @param n a NameComponents which is the name to be found.   * @exception org.omg.CosNaming.NamingContextPackage.NotFound The   * first component could not be resolved.   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed   * in resolving the first component of the supplied name.   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.   * @see resolve   */    protected static NamingContext resolveFirstAsContext(NamingContextDataStore impl,                                                         NameComponent[] n)        throws org.omg.CosNaming.NamingContextPackage.NotFound {        org.omg.CORBA.Object topRef = null;        BindingTypeHolder bth = new BindingTypeHolder();        NamingContext context = null;        synchronized (impl) {            // Resolve first  - must be resolveable            topRef = impl.Resolve(n[0],bth);            if (topRef == null) {		// It was not bound                throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.missing_node,n);            }        }        // Was it bound as a context?        if (bth.value != BindingType.ncontext) {            // It was not a context            throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);        }        // Narrow to a naming context        try {            context = NamingContextHelper.narrow(topRef);        } catch (org.omg.CORBA.BAD_PARAM ex) {            // It was not a context            throw new org.omg.CosNaming.NamingContextPackage.NotFound(NotFoundReason.not_context,n);        }        // Hmm. must be ok        return context;    }    public static String nameToString(NameComponent[] name)    {        StringBuffer s = new StringBuffer("{");        if (name != null || name.length > 0) {            for (int i=0;i<name.length;i++) {                if (i>0)                    s.append(",");                s.append("[").                    append(name[i].id).                    append(",").                    append(name[i].kind).                    append("]");            }        }        s.append("}");        return s.toString();    }    // Debugging aids.    public static final boolean debug = false;    private static void dprint(String msg) {        NamingUtils.dprint("NamingContextImpl("  +                           Thread.currentThread().getName() + " at " +                           System.currentTimeMillis() +                           " ems): " + msg);    }  /**   * Implements all flavors of binding( bind and bindcontext)    * This method will be called from the superclass's doBind( ) method   * which takes care of all the conditions before calling this method.   * i.e., It checks whether the Name is already Bounded, Then in the   * case of rebind it calls Unbind first.   * This method does one level binding only, To have n-level binding   * with compound names, doBind( ) calls this method recursively.   * @param n a sequence of NameComponents which is the name under which   * the object will be bound.   * @param obj the object reference to be bound.   * @param bt Type of binding (as object or as context).   * @exception org.omg.CosNaming.NamingContextPackage.NotFound  raised   * if the NameComoponent list is invalid   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed    * Could not proceed in resolving the Name from the given NameComponent   * @exception org.omg.CosNaming.NamingContextPackage.AlreadyBound An object    * is already bound under the supplied name.   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA   * system exceptions    * @see Resolve   * @see Unbind   */    public void Bind(NameComponent n, org.omg.CORBA.Object obj, BindingType bt)	throws SystemException    {	if( obj == null )	{		// Raise a Valid Exception and Return		return;	}	InternalBindingKey key = new InternalBindingKey(n);	InternalBindingValue value;	try	{		if( bt.value() == BindingType._nobject )		{			// If the BindingType is an ObjectRef then Stringify this ref and			// Store it in InternalBindingValue instance. This is required 			// because the Object References has to be stored in file			value = new InternalBindingValue(bt,						orb.object_to_string(obj) );			value.setObjectRef( obj );		}		else		{			// If the BindingType is a NamingContext then get it's object key			// from the NameService and store it in the Internal Binding Value instance                        String theNCKey = theNameServiceHandle.getObjectKey(								 obj );			value = new InternalBindingValue( bt,                                            theNCKey );		        value.setObjectRef( obj );		}		InternalBindingValue oldValue =		(InternalBindingValue)this.theHashtable.put(key,value);		if( oldValue != null)		{			// There was an entry with this name in the Hashtable and hence throw CTX_ALREADY_BOUND			// exception			throw new org.omg.CORBA.INTERNAL(			MinorCodes.NAMING_CTX_REBIND_ALREADY_BOUND,			CompletionStatus.COMPLETED_NO);		}		else		{			try			{				// Everything went smooth so update the NamingContext file with the				// latest Hashtable image				theServantManagerImplHandle.updateContext( objKey,		                                           this );			}			catch( Exception e )			{				// Something went wrong while updating the context				// so speak the error				throw new org.omg.CORBA.UNKNOWN( 				(int)	3,  // Replace this with a valid constant	       			CompletionStatus.COMPLETED_MAYBE );			}		}	}	catch( Exception e )	{		// Something went wrong while Binding the Object Reference		// Speak the error again.		throw new org.omg.CORBA.UNKNOWN( 			3,  // Replace this with a valid constant	       		CompletionStatus.COMPLETED_MAYBE );	}    }  /**   * This method resolves the NamingContext or Object Reference for one level   * The doResolve( ) method calls Resolve( ) recursively to resolve n level   * Names.   * @param n a sequence of NameComponents which is the name to be resolved.   * @param bt Type of binding (as object or as context).   * @return the object reference bound under the supplied name.   * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext   * or a Corba Object reference not found under this Name   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed   * in resolving the the supplied name.   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name   * is invalid (i.e., has length less than 1).   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.   * @see Bind   */    public Object Resolve(NameComponent n, BindingTypeHolder bth)	throws SystemException    {	if( ( n.id.length() == 0 )          &&( n.kind.length() == 0 ) )	{	    // If the NameComponent list has no entry then it means the current	    // context was requested	    bth.value = BindingType.ncontext;	    return theNameServiceHandle.getObjectReferenceFromKey( 			this.objKey );	}	InternalBindingKey key = new InternalBindingKey(n);	InternalBindingValue value =             (InternalBindingValue) this.theHashtable.get(key);	if( value == null )	{		// No entry was found for the given name and hence return NULL 		// NamingContextDataStore throws appropriate exception if		// required.		return null;	}	Object theObjectFromStringifiedReference = null;	bth.value = value.theBindingType;	try	{		// Check whether the entry found in the Hashtable starts with NC		// Which means it's a name context. So get the NamingContext reference		// from ServantManager, which would either return from the cache or		// read it from the File.		if( value.strObjectRef.startsWith( "NC" ) )		{			bth.value = BindingType.ncontext;		        return theNameServiceHandle.getObjectReferenceFromKey( value.strObjectRef );		}		else		{ 			// Else, It is a Object Reference. Check whether Object Reference			// can be obtained directly, If not then convert the stringified			// reference to object and return.			theObjectFromStringifiedReference = value.getObjectRef( );			if( theObjectFromStringifiedReference == null )			{				try				{					theObjectFromStringifiedReference = 					orb.string_to_object( value.strObjectRef );  						value.setObjectRef( theObjectFromStringifiedReference );				}				catch( Exception e )				{					// Throw Invalid Reference Exception					throw new org.omg.CORBA.UNKNOWN( 					3,  // Replace this with a valid constant			        	CompletionStatus.COMPLETED_MAYBE );				}			}		}	}	catch ( Exception e )	{		// Something wrong happened while resolving the given NameComponent,		// So, Speak the UNKNOWN error		throw new org.omg.CORBA.UNKNOWN( 				3,  // Replace this with a valid constant		        	CompletionStatus.COMPLETED_MAYBE );	}	return theObjectFromStringifiedReference;    }   /**   * This method Unbinds the NamingContext or Object Reference for one level   * The doUnbind( ) method from superclass calls Unbind() to recursively   * Unbind using compound Names.   * @param n a sequence of NameComponents which is the name to be resolved.   * @return the object reference bound under the supplied name.   * @exception org.omg.CosNaming.NamingContextPackage.NotFound Neither a NamingContext   * or a Corba Object reference not found under this Name   * @exception org.omg.CosNaming.NamingContextPackage.CannotProceed Could not proceed   * in resolving the the supplied name.   * @exception org.omg.CosNaming.NamingContextPackage.InvalidName The supplied name   * is invalid (i.e., has length less than 1).   * @exception org.omg.CORBA.SystemException One of a fixed set of CORBA system exceptions.   * @see Bind   */    public Object Unbind(NameComponent n) throws SystemException

⌨️ 快捷键说明

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