Class CNCtx

java.lang.Object
org.glassfish.jndi.cosnaming.CNCtx
All Implemented Interfaces:
Context

public class CNCtx extends Object implements Context
Provides a bridge to the CosNaming server provided by JavaIDL. This class provides the InitialContext from CosNaming.
  • Field Details

  • Constructor Details

    • CNCtx

      CNCtx(Hashtable<?,?> env) throws NamingException
      Create a CNCtx object. Gets the initial naming reference for the COS Naming Service from the ORB. The ORB can be passed in via the java.naming.corba.orb property or be created using properties in the environment properties.
      Parameters:
      env - Environment properties for initializing name service.
      Throws:
      NamingException - Cannot initialize ORB or naming context.
    • CNCtx

      private CNCtx()
    • CNCtx

      CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, Hashtable<String,Object> env, NameComponent[] name) throws NamingException
      Creates a CNCtx object which supports the javax.naming apis given a COS Naming Context object.
      Parameters:
      orb - The ORB used by this context
      tracker - The ORB reuse tracker for tracking references to the orb object
      nctx - The COS NamingContext object associated with this context
      name - The name of this context relative to the root
      Throws:
      NamingException
  • Method Details

    • getDefaultOrb

      private static ORB getDefaultOrb()
    • createUsingURL

      public static ResolveResult createUsingURL(String url, Hashtable<?,?> env) throws NamingException
      This method is used by the iiop and iiopname URL Context factories.
      Throws:
      NamingException
    • makeFullName

      NameComponent[] makeFullName(NameComponent[] child)
    • getNameInNamespace

      public String getNameInNamespace() throws NamingException
      Specified by:
      getNameInNamespace in interface Context
      Throws:
      NamingException
    • isCorbaUrl

      private static boolean isCorbaUrl(String url)
      These are the URL schemes that need to be processed. IOR and corbaloc URLs can be passed directly to ORB.string_to_object()
    • initOrbAndRootContext

      private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException
      Initializes the COS Naming Service. This method initializes the three instance fields: _nc : The root naming context. _orb: The ORB to use for connecting RMI/IIOP stubs and for getting the naming context (_nc) if one was not specified explicitly via PROVIDER_URL. _name: The name of the root naming context.

      _orb is obtained from java.naming.corba.orb if it has been set. Otherwise, _orb is created using the host/port from PROVIDER_URL (if it contains an "iiop" or "iiopname" URL), or from initialization properties specified in env.

      _nc is obtained from the IOR stored in PROVIDER_URL if it has been set and does not contain an "iiop" or "iiopname" URL. It can be a stringified IOR, "corbaloc" URL, "corbaname" URL, or a URL (such as file/http/ftp) to a location containing a stringified IOR. If PROVIDER_URL has not been set in this way, it is obtained from the result of ORB.resolve_initial_reference("NameService");

      _name is obtained from the "iiop", "iiopname", or "corbaname" URL. It is the empty name by default.

      Parameters:
      env - Environment The possibly null environment.
      Throws:
      NamingException - When an error occurs while initializing the ORB or the naming context.
    • initUsingUrl

      private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env) throws NamingException
      Throws:
      NamingException
    • initUsingIiopUrl

      private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env) throws NamingException
      Handles "iiop" and "iiopname" URLs (INS 98-10-11)
      Throws:
      NamingException
    • initUsingCorbanameUrl

      private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env) throws NamingException
      Initializes using "corbaname" URL (INS 99-12-03)
      Throws:
      NamingException
    • setOrbAndRootContext

      private void setOrbAndRootContext(ORB orb, String ncIor) throws NamingException
      Throws:
      NamingException
    • setOrbAndRootContext

      private void setOrbAndRootContext(ORB orb, Object ncRef) throws NamingException
      Throws:
      NamingException
    • getStringifiedIor

      private String getStringifiedIor(String url) throws NamingException
      Throws:
      NamingException
    • callResolve

      Object callResolve(NameComponent[] path) throws NamingException
      Does the job of calling the COS Naming API, resolve, and performs the exception mapping. If the resolved object is a COS Naming Context (sub-context), then this function returns a new JNDI naming context object.
      Parameters:
      path - the NameComponent[] object.
      Returns:
      Resolved object returned by the COS Name Server.
      Throws:
      NotFound - No objects under the name.
      CannotProceed - Unable to obtain a continuation context
      InvalidName - Name not understood.
      NamingException
    • lookup

      public Object lookup(String name) throws NamingException
      Converts the "String" name into a CompositeName returns the object resolved by the COS Naming api, resolve. Returns the current context if the name is empty. Returns either an org.omg.CORBA.Object or javax.naming.Context object.
      Specified by:
      lookup in interface Context
      Parameters:
      name - string used to resolve the object.
      Returns:
      the resolved object
      Throws:
      NamingException - See callResolve.
    • lookup

      public Object lookup(Name name) throws NamingException
      Converts the "Name" name into a NameComponent[] object and returns the object resolved by the COS Naming api, resolve. Returns the current context if the name is empty. Returns either an org.omg.CORBA.Object or javax.naming.Context object.
      Specified by:
      lookup in interface Context
      Parameters:
      name - JNDI Name used to resolve the object.
      Returns:
      the resolved object
      Throws:
      NamingException - See callResolve.
    • callBindOrRebind

      private void callBindOrRebind(NameComponent[] pth, Name name, Object obj, boolean rebind) throws NamingException
      Performs bind or rebind in the context depending on whether the flag rebind is set. The only objects allowed to be bound are of types org.omg.CORBA.Object, org.omg.CosNaming.NamingContext. You can use a state factory to turn other objects (such as Remote) into these acceptable forms. Uses the COS Naming apis bind/rebind or bind_context/rebind_context.
      Parameters:
      pth - NameComponent[] object
      obj - Object to be bound.
      rebind - perform rebind ? if true performs a rebind.
      Throws:
      NotFound - No objects under the name.
      CannotProceed - Unable to obtain a continuation context
      AlreadyBound - An object is already bound to this name.
      NamingException
    • bind

      public void bind(Name name, Object obj) throws NamingException
      Converts the "Name" name into a NameComponent[] object and performs the bind operation. Uses callBindOrRebind. Throws an invalid name exception if the name is empty. We need a name to bind the object even when we work within the current context.
      Specified by:
      bind in interface Context
      Parameters:
      name - JNDI Name object
      obj - Object to be bound.
      Throws:
      NamingException - See callBindOrRebind
    • getContinuationContext

      private static Context getContinuationContext(CannotProceedException cpe) throws NamingException
      Throws:
      NamingException
    • bind

      public void bind(String name, Object obj) throws NamingException
      Converts the "String" name into a CompositeName object and performs the bind operation. Uses callBindOrRebind. Throws an invalid name exception if the name is empty.
      Specified by:
      bind in interface Context
      Parameters:
      name - string
      obj - Object to be bound.
      Throws:
      NamingException - See callBindOrRebind
    • rebind

      public void rebind(Name name, Object obj) throws NamingException
      Converts the "Name" name into a NameComponent[] object and performs the rebind operation. Uses callBindOrRebind. Throws an invalid name exception if the name is empty. We must have a name to rebind the object to even if we are working within the current context.
      Specified by:
      rebind in interface Context
      Parameters:
      name - string
      obj - Object to be bound.
      Throws:
      NamingException - See callBindOrRebind
    • rebind

      public void rebind(String name, Object obj) throws NamingException
      Converts the "String" name into a CompositeName object and performs the rebind operation. Uses callBindOrRebind. Throws an invalid name exception if the name is an empty string.
      Specified by:
      rebind in interface Context
      Parameters:
      name - string
      obj - Object to be bound.
      Throws:
      NamingException - See callBindOrRebind
    • callUnbind

      private void callUnbind(NameComponent[] path) throws NamingException
      Calls the unbind api of COS Naming and uses the exception mapper class to map the exceptions
      Parameters:
      path - NameComponent[] object
      Throws:
      NotFound - No objects under the name. If leaf is not found, that's OK according to the JNDI spec
      CannotProceed - Unable to obtain a continuation context
      InvalidName - Name not understood.
      NamingException
    • leafNotFound

      private boolean leafNotFound(NotFound e, NameComponent leaf)
    • unbind

      public void unbind(String name) throws NamingException
      Converts the "String" name into a CompositeName object and performs the unbind operation. Uses callUnbind. If the name is empty, throws an invalid name exception. Do we unbind the current context (JNDI spec says work with the current context if the name is empty) ?
      Specified by:
      unbind in interface Context
      Parameters:
      name - string
      Throws:
      NamingException - See callUnbind
    • unbind

      public void unbind(Name name) throws NamingException
      Converts the "Name" name into a NameComponent[] object and performs the unbind operation. Uses callUnbind. Throws an invalid name exception if the name is empty.
      Specified by:
      unbind in interface Context
      Parameters:
      name - string
      Throws:
      NamingException - See callUnbind
    • rename

      public void rename(String oldName, String newName) throws NamingException
      Renames an object. Since COS Naming does not support a rename api, this method unbinds the object with the "oldName" and creates a new binding.
      Specified by:
      rename in interface Context
      Parameters:
      oldName - string, existing name for the binding.
      newName - string, name used to replace.
      Throws:
      NamingException - See bind
    • rename

      public void rename(Name oldName, Name newName) throws NamingException
      Renames an object. Since COS Naming does not support a rename api, this method unbinds the object with the "oldName" and creates a new binding.
      Specified by:
      rename in interface Context
      Parameters:
      oldName - JNDI Name, existing name for the binding.
      newName - JNDI Name, name used to replace.
      Throws:
      NamingException - See bind
    • list

      Returns a NameClassEnumeration object which has a list of name class pairs. Lists the current context if the name is empty.
      Specified by:
      list in interface Context
      Parameters:
      name - string
      Returns:
      a list of name-class objects as a NameClassEnumeration.
      Throws:
      NamingException - All exceptions thrown by lookup with a non-null argument
    • list

      Returns a NameClassEnumeration object which has a list of name class pairs. Lists the current context if the name is empty.
      Specified by:
      list in interface Context
      Parameters:
      name - JNDI Name
      Returns:
      a list of name-class objects as a NameClassEnumeration.
      Throws:
      NamingException - All exceptions thrown by lookup
    • listBindings

      public NamingEnumeration<Binding> listBindings(String name) throws NamingException
      Returns a BindingEnumeration object which has a list of name object pairs. Lists the current context if the name is empty.
      Specified by:
      listBindings in interface Context
      Parameters:
      name - string
      Returns:
      a list of bindings as a BindingEnumeration.
      Throws:
      NamingException - all exceptions returned by lookup
    • listBindings

      public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
      Returns a BindingEnumeration object which has a list of name class pairs. Lists the current context if the name is empty.
      Specified by:
      listBindings in interface Context
      Parameters:
      name - JNDI Name
      Returns:
      a list of bindings as a BindingEnumeration.
      Throws:
      NamingException - all exceptions returned by lookup.
    • callDestroy

      private void callDestroy(NamingContext nc) throws NamingException
      Calls the destroy on the COS Naming Server
      Parameters:
      nc - The NamingContext object to use.
      Throws:
      NotEmpty - when the context is not empty and cannot be destroyed.
      NamingException
    • destroySubcontext

      public void destroySubcontext(String name) throws NamingException
      Uses the callDestroy function to destroy the context. If name is empty destroys the current context.
      Specified by:
      destroySubcontext in interface Context
      Parameters:
      name - string
      Throws:
      OperationNotSupportedException - when list is invoked with a non-null argument
      NamingException
    • destroySubcontext

      public void destroySubcontext(Name name) throws NamingException
      Uses the callDestroy function to destroy the context. Destroys the current context if name is empty.
      Specified by:
      destroySubcontext in interface Context
      Parameters:
      name - JNDI Name
      Throws:
      OperationNotSupportedException - when list is invoked with a non-null argument
      NamingException
    • callBindNewContext

      private Context callBindNewContext(NameComponent[] path) throws NamingException
      Calls the bind_new_context COS naming api to create a new subcontext.
      Parameters:
      path - NameComponent[] object
      Returns:
      the new context object.
      Throws:
      NotFound - No objects under the name.
      CannotProceed - Unable to obtain a continuation context
      InvalidName - Name not understood.
      AlreadyBound - An object is already bound to this name.
      NamingException
    • createSubcontext

      public Context createSubcontext(String name) throws NamingException
      Uses the callBindNewContext convenience function to create a new context. Throws an invalid name exception if the name is empty.
      Specified by:
      createSubcontext in interface Context
      Parameters:
      name - string
      Returns:
      the new context object.
      Throws:
      NamingException - See callBindNewContext
    • createSubcontext

      public Context createSubcontext(Name name) throws NamingException
      Uses the callBindNewContext convenience function to create a new context. Throws an invalid name exception if the name is empty.
      Specified by:
      createSubcontext in interface Context
      Parameters:
      name - string
      Returns:
      the new context object.
      Throws:
      NamingException - See callBindNewContext
    • lookupLink

      public Object lookupLink(String name) throws NamingException
      Is mapped to resolve in the COS Naming api.
      Specified by:
      lookupLink in interface Context
      Parameters:
      name - string
      Returns:
      the resolved object.
      Throws:
      NamingException - See lookup.
    • lookupLink

      public Object lookupLink(Name name) throws NamingException
      Is mapped to resolve in the COS Naming api.
      Specified by:
      lookupLink in interface Context
      Parameters:
      name - string
      Returns:
      the resolved object.
      Throws:
      NamingException - See lookup.
    • getNameParser

      public NameParser getNameParser(String name) throws NamingException
      Allow access to the name parser object.
      Specified by:
      getNameParser in interface Context
      Parameters:
      name - JNDI name, is ignored since there is only one Name Parser object.
      Returns:
      NameParser object
      Throws:
      NamingException - --
    • getNameParser

      public NameParser getNameParser(Name name) throws NamingException
      Allow access to the name parser object.
      Specified by:
      getNameParser in interface Context
      Parameters:
      name - JNDI name, is ignored since there is only one Name Parser object.
      Returns:
      NameParser object
      Throws:
      NamingException - --
    • getEnvironment

      public Hashtable<String,Object> getEnvironment() throws NamingException
      Returns the current environment.
      Specified by:
      getEnvironment in interface Context
      Returns:
      Environment.
      Throws:
      NamingException
    • composeName

      public String composeName(String name, String prefix) throws NamingException
      Specified by:
      composeName in interface Context
      Throws:
      NamingException
    • composeName

      public Name composeName(Name name, Name prefix) throws NamingException
      Specified by:
      composeName in interface Context
      Throws:
      NamingException
    • addToEnvironment

      public Object addToEnvironment(String propName, Object propValue) throws NamingException
      Adds to the environment for the current context. Record change but do not reinitialize ORB.
      Specified by:
      addToEnvironment in interface Context
      Parameters:
      propName - The property name.
      propValue - The ORB.
      Returns:
      the previous value of this property if any.
      Throws:
      NamingException
    • removeFromEnvironment

      public Object removeFromEnvironment(String propName) throws NamingException
      Specified by:
      removeFromEnvironment in interface Context
      Throws:
      NamingException
    • incEnumCount

      public void incEnumCount()
    • decEnumCount

      public void decEnumCount() throws NamingException
      Throws:
      NamingException
    • close

      public void close() throws NamingException
      Specified by:
      close in interface Context
      Throws:
      NamingException
    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object