📄 namingcontextimpl.java
字号:
/* * @(#)NamingContextImpl.java 1.68 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.corba.se.impl.naming.cosnaming;// Imports for Loggingimport java.util.logging.Logger;import java.util.logging.Level;import com.sun.corba.se.impl.orbutil.LogKeywords;// Import general CORBA classesimport org.omg.CORBA.Object;import org.omg.CORBA.BAD_PARAM;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.CompletionStatus;import org.omg.PortableServer.POA;import org.omg.PortableServer.Servant;// Import org.omg.CosNaming classesimport org.omg.CosNaming.BindingType;import org.omg.CosNaming.BindingTypeHolder;import org.omg.CosNaming.BindingListHolder;import org.omg.CosNaming.BindingIteratorHolder;import org.omg.CosNaming.NameComponent;import org.omg.CosNaming.NamingContextHelper;import org.omg.CosNaming.NamingContext;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CosNaming._NamingContextImplBase;import org.omg.CosNaming.NamingContextExtHelper;import org.omg.CosNaming.NamingContextExt;import org.omg.CosNaming.NamingContextExtPOA;import org.omg.CosNaming.NamingContextExtPackage.*;import org.omg.CosNaming.NamingContextPackage.NotFound;import com.sun.corba.se.impl.naming.cosnaming.NamingContextDataStore;import com.sun.corba.se.impl.naming.namingutil.INSURLHandler;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.impl.logging.NamingSystemException ;import com.sun.corba.se.spi.orb.ORB;/** * Class NamingContextImpl implements the org.omg.CosNaming::NamingContext * interface, but does not implement the methods associated with * maintaining the "table" of current bindings in a NamingContext. * Instead, this implementation assumes that the derived implementation * implements the NamingContextDataStore interface, which has the necessary * methods. This allows multiple * NamingContext implementations that differ in storage of the bindings, * as well as implementations of interfaces derived from * CosNaming::NamingContext that still reuses the implementation. * <p> * The operations bind(), rebind(), bind_context() and rebind_context() * are all really implemented by doBind(). resolve() is really implemented * by doResolve(), unbind() by doUnbind(). list(), new_context() and * destroy() uses the NamingContextDataStore interface directly. All the * doX() methods are public static. * They synchronize on the NamingContextDataStore object. * <p> * An implementation a NamingContext must extend this class and implement * the NamingContextDataStore interface with the operations: * Bind(), Resolve(), * Unbind(), List(), NewContext() and Destroy(). Calls * to these methods are synchronized; these methods should * therefore not be synchronized. */public abstract class NamingContextImpl extends NamingContextExtPOA implements NamingContextDataStore{ protected POA nsPOA; private Logger readLogger, updateLogger, lifecycleLogger; private NamingSystemException wrapper ; private static NamingSystemException staticWrapper = NamingSystemException.get( CORBALogDomains.NAMING_UPDATE ) ; // The grammer for Parsing and Building Interoperable Stringified Names // are implemented in this class private InterOperableNamingImpl insImpl; /** * Create a naming context servant. * Runs the super constructor. * @param orb an ORB object. * @exception java.lang.Exception a Java exception. */ public NamingContextImpl(ORB orb, POA poa) throws java.lang.Exception { super(); this.orb = orb; wrapper = NamingSystemException.get( orb, CORBALogDomains.NAMING_UPDATE ) ; insImpl = new InterOperableNamingImpl( ); this.nsPOA = poa; readLogger = orb.getLogger( CORBALogDomains.NAMING_READ); updateLogger = orb.getLogger( CORBALogDomains.NAMING_UPDATE); lifecycleLogger = orb.getLogger( CORBALogDomains.NAMING_LIFECYCLE); } public POA getNSPOA( ) { return nsPOA; } /** * Bind an object under a name in this NamingContext. If the name * contains multiple (n) components, n-1 will be resolved in this * NamingContext and the object bound in resulting NamingContext. * An exception is thrown if a binding with the supplied name already * exists. If the * object to be bound is a NamingContext it will not participate in * a recursive resolve. * @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. * @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.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 doBind */ public void bind(NameComponent[] n, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, org.omg.CosNaming.NamingContextPackage.AlreadyBound { if( obj == null ) { updateLogger.warning( LogKeywords.NAMING_BIND + " unsuccessful because NULL Object cannot be Bound " ); throw wrapper.objectIsNull() ; } // doBind implements all four flavors of binding NamingContextDataStore impl = (NamingContextDataStore)this; doBind(impl,n,obj,false,BindingType.nobject); if( updateLogger.isLoggable( Level.FINE ) ) { // isLoggable call to make sure that we save some precious // processor cycles, if there is no need to log. updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + " Name = " + NamingUtils.getDirectoryStructuredName( n ) ); } } /** * Bind a NamingContext under a name in this NamingContext. If the name * contains multiple (n) components, n-1 will be resolved in this * NamingContext and the object bound in resulting NamingContext. * An exception is thrown if a binding with the supplied name already * exists. The NamingContext will participate in recursive resolving. * @param n a sequence of NameComponents which is the name under which * the object will be bound. * @param obj the NamingContect object reference to be bound. * @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.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 doBind */ public void bind_context(NameComponent[] n, NamingContext nc) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName, org.omg.CosNaming.NamingContextPackage.AlreadyBound { if( nc == null ) { updateLogger.warning( LogKeywords.NAMING_BIND_FAILURE + " NULL Context cannot be Bound " ); throw new BAD_PARAM( "Naming Context should not be null " ); } // doBind implements all four flavors of binding NamingContextDataStore impl = (NamingContextDataStore)this; doBind(impl,n,nc,false,BindingType.ncontext); if( updateLogger.isLoggable( Level.FINE ) ) { // isLoggable call to make sure that we save some precious // processor cycles, if there is no need to log. updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS + " Name = " + NamingUtils.getDirectoryStructuredName( n ) ); } } /** * Bind an object under a name in this NamingContext. If the name * contains multiple (n) components, n-1 will be resolved in this * NamingContext and the object bound in resulting NamingContext. * If a binding under the supplied name already exists it will be * unbound first. If the * object to be bound is a NamingContext it will not participate in * a recursive resolve. * @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. * @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 doBind */ public void rebind(NameComponent[] n, org.omg.CORBA.Object obj) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName { if( obj == null ) { updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + " NULL Object cannot be Bound " ); throw wrapper.objectIsNull() ; } try { // doBind implements all four flavors of binding NamingContextDataStore impl = (NamingContextDataStore)this; doBind(impl,n,obj,true,BindingType.nobject); } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + NamingUtils.getDirectoryStructuredName( n ) + " is already bound to a Naming Context" ); // This should not happen throw wrapper.namingCtxRebindAlreadyBound( ex ) ; } if( updateLogger.isLoggable( Level.FINE ) ) { // isLoggable call to make sure that we save some precious // processor cycles, if there is no need to log. updateLogger.fine( LogKeywords.NAMING_REBIND_SUCCESS + " Name = " + NamingUtils.getDirectoryStructuredName( n ) ); } } /** * Bind a NamingContext under a name in this NamingContext. If the name * contains multiple (n) components, the first n-1 components will be * resolved in this NamingContext and the object bound in resulting * NamingContext. If a binding under the supplied name already exists it * will be unbound first. The NamingContext will participate in recursive * resolving. * @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. * @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 doBind */ public void rebind_context(NameComponent[] n, NamingContext nc) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName { if( nc == null ) { updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + " NULL Context cannot be Bound " ); throw wrapper.objectIsNull() ; } try { // doBind implements all four flavors of binding NamingContextDataStore impl = (NamingContextDataStore)this; doBind(impl,n,nc,true,BindingType.ncontext); } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound ex) { // This should not happen updateLogger.warning( LogKeywords.NAMING_REBIND_FAILURE + NamingUtils.getDirectoryStructuredName( n ) + " is already bound to a CORBA Object" ); throw wrapper.namingCtxRebindctxAlreadyBound( ex ) ; } if( updateLogger.isLoggable( Level.FINE ) ) { // isLoggable call to make sure that we save some precious // processor cycles, if there is no need to log. updateLogger.fine( LogKeywords.NAMING_REBIND_SUCCESS + " Name = " + NamingUtils.getDirectoryStructuredName( n ) ); } } /** * Resolve a name in this NamingContext and return the object reference * bound to the name. If the name contains multiple (n) components, * the first component will be resolved in this NamingContext and the * remaining components resolved in the resulting NamingContext, provided * that the NamingContext bound to the first component of the name was * bound with bind_context(). * @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 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 doResolve */ public org.omg.CORBA.Object resolve(NameComponent[] n) throws org.omg.CosNaming.NamingContextPackage.NotFound, org.omg.CosNaming.NamingContextPackage.CannotProceed, org.omg.CosNaming.NamingContextPackage.InvalidName { // doResolve actually resolves NamingContextDataStore impl = (NamingContextDataStore)this; org.omg.CORBA.Object obj = doResolve(impl,n); if( obj != null ) { if( readLogger.isLoggable( Level.FINE ) ) { readLogger.fine( LogKeywords.NAMING_RESOLVE_SUCCESS + " Name: " + NamingUtils.getDirectoryStructuredName( n ) ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -