Class NamingContext

  • All Implemented Interfaces:
    javax.naming.Context, Dumpable

    public class NamingContext
    extends java.lang.Object
    implements javax.naming.Context, Dumpable
    NamingContext

    Implementation of Context interface.

    Notes: All Names are expected to be Compound, not Composite.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  NamingContext.Listener
      Naming Context Listener.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.ConcurrentMap<java.lang.String,​javax.naming.Binding> _bindings  
      protected java.util.Hashtable<java.lang.String,​java.lang.Object> _env  
      protected java.lang.String _name  
      protected NamingContext _parent  
      protected javax.naming.NameParser _parser  
      static java.lang.String DEEP_BINDING  
      static java.lang.String LOCK_PROPERTY  
      static java.lang.String UNLOCK_PROPERTY  
      • Fields inherited from interface javax.naming.Context

        APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES
      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        NamingContext​(java.util.Hashtable<java.lang.String,​java.lang.Object> env, java.lang.String name, NamingContext parent, javax.naming.NameParser parser)
      Constructor
      protected NamingContext​(java.util.Hashtable<java.lang.String,​java.lang.Object> env, java.lang.String name, NamingContext parent, javax.naming.NameParser parser, java.util.concurrent.ConcurrentMap<java.lang.String,​javax.naming.Binding> bindings)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addBinding​(javax.naming.Name name, java.lang.Object obj)
      Add a name to object binding to this Context.
      void addListener​(NamingContext.Listener listener)  
      java.lang.Object addToEnvironment​(java.lang.String propName, java.lang.Object propVal)
      Add an environment setting to this Context
      void bind​(java.lang.String name, java.lang.Object obj)
      Bind a name (as a String) to an object
      void bind​(javax.naming.Name name, java.lang.Object obj)
      Bind a name to an object
      void close()
      Do nothing
      java.lang.String composeName​(java.lang.String name, java.lang.String prefix)
      Join two names together.
      javax.naming.Name composeName​(javax.naming.Name name, javax.naming.Name prefix)
      Join two names together.
      javax.naming.Context createSubcontext​(java.lang.String name)
      Create a Context as a child of this one
      javax.naming.Context createSubcontext​(javax.naming.Name name)
      Create a context as a child of this one
      void destroySubcontext​(java.lang.String name)  
      void destroySubcontext​(javax.naming.Name name)  
      java.lang.String dump()  
      void dump​(java.lang.Appendable out, java.lang.String indent)
      Dump this object (and children) into an Appendable using the provided indent after any new lines.
      javax.naming.Binding getBinding​(java.lang.String name)
      Get a name to object binding from this Context
      javax.naming.Binding getBinding​(javax.naming.Name name)
      Get a name to object binding from this Context
      java.util.Hashtable getEnvironment()
      Get the environment of this Context.
      java.lang.String getName()
      Getter for _name
      java.lang.String getNameInNamespace()
      Get the full name of this Context node by visiting it's ancestors back to root.
      javax.naming.NameParser getNameParser​(java.lang.String name)
      Return a NameParser for this Context.
      javax.naming.NameParser getNameParser​(javax.naming.Name name)
      Return a NameParser for this Context.
      javax.naming.Context getParent()
      Getter for _parent
      boolean isDeepBindingSupported()  
      boolean isLocked()  
      javax.naming.NamingEnumeration list​(java.lang.String name)
      List all names bound at Context named by Name
      javax.naming.NamingEnumeration list​(javax.naming.Name name)
      List all names bound at Context named by Name
      javax.naming.NamingEnumeration listBindings​(java.lang.String name)
      List all Bindings at Name
      javax.naming.NamingEnumeration listBindings​(javax.naming.Name name)
      List all Bindings present at Context named by Name
      java.lang.Object lookup​(java.lang.String name)
      Lookup binding of an object by name
      java.lang.Object lookup​(javax.naming.Name name)
      Lookup a binding by name
      java.lang.Object lookupLink​(java.lang.String name)
      Lookup link bound to name
      java.lang.Object lookupLink​(javax.naming.Name name)
      Lookup link bound to name
      void rebind​(java.lang.String name, java.lang.Object obj)
      Overwrite or create a binding from Name to Object
      void rebind​(javax.naming.Name name, java.lang.Object obj)
      Overwrite or create a binding
      void removeBinding​(javax.naming.Name name)  
      java.lang.Object removeFromEnvironment​(java.lang.String propName)
      Remove a property from this Context's environment.
      boolean removeListener​(NamingContext.Listener listener)  
      void rename​(java.lang.String oldName, java.lang.String newName)
      Not supported
      void rename​(javax.naming.Name oldName, javax.naming.Name newName)
      Not supported
      void setEnv​(java.util.Hashtable<java.lang.String,​java.lang.Object> env)  
      void setNameParser​(javax.naming.NameParser parser)  
      javax.naming.Context shallowCopy​(java.util.Hashtable<java.lang.String,​java.lang.Object> env)  
      javax.naming.Name toCanonicalName​(javax.naming.Name name)
      Remove leading or trailing empty components from name.
      java.lang.String toString()  
      void unbind​(java.lang.String name)
      Not supported.
      void unbind​(javax.naming.Name name)
      Not supported.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

        dumpSelf
    • Field Detail

      • _env

        protected final java.util.Hashtable<java.lang.String,​java.lang.Object> _env
      • _bindings

        protected final java.util.concurrent.ConcurrentMap<java.lang.String,​javax.naming.Binding> _bindings
      • _name

        protected java.lang.String _name
      • _parser

        protected javax.naming.NameParser _parser
    • Constructor Detail

      • NamingContext

        public NamingContext​(java.util.Hashtable<java.lang.String,​java.lang.Object> env,
                             java.lang.String name,
                             NamingContext parent,
                             javax.naming.NameParser parser)
        Constructor
        Parameters:
        env - environment properties which are copied into this Context's environment
        name - relative name of this context
        parent - immediate ancestor Context (can be null)
        parser - NameParser for this Context
      • NamingContext

        protected NamingContext​(java.util.Hashtable<java.lang.String,​java.lang.Object> env,
                                java.lang.String name,
                                NamingContext parent,
                                javax.naming.NameParser parser,
                                java.util.concurrent.ConcurrentMap<java.lang.String,​javax.naming.Binding> bindings)
    • Method Detail

      • shallowCopy

        public javax.naming.Context shallowCopy​(java.util.Hashtable<java.lang.String,​java.lang.Object> env)
        Returns:
        A shallow copy of the Context with the same bindings, but with the passed environment
      • isDeepBindingSupported

        public boolean isDeepBindingSupported()
      • getName

        public java.lang.String getName()
        Getter for _name
        Returns:
        name of this Context (relative, not absolute)
      • getParent

        public javax.naming.Context getParent()
        Getter for _parent
        Returns:
        parent Context
      • setNameParser

        public void setNameParser​(javax.naming.NameParser parser)
      • setEnv

        public final void setEnv​(java.util.Hashtable<java.lang.String,​java.lang.Object> env)
      • bind

        public void bind​(javax.naming.Name name,
                         java.lang.Object obj)
                  throws javax.naming.NamingException
        Bind a name to an object
        Specified by:
        bind in interface javax.naming.Context
        Parameters:
        name - Name of the object
        obj - object to bind
        Throws:
        javax.naming.NamingException - if an error occurs
      • bind

        public void bind​(java.lang.String name,
                         java.lang.Object obj)
                  throws javax.naming.NamingException
        Bind a name (as a String) to an object
        Specified by:
        bind in interface javax.naming.Context
        Parameters:
        name - a String value
        obj - an Object value
        Throws:
        javax.naming.NamingException - if an error occurs
      • createSubcontext

        public javax.naming.Context createSubcontext​(javax.naming.Name name)
                                              throws javax.naming.NamingException
        Create a context as a child of this one
        Specified by:
        createSubcontext in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a Context value
        Throws:
        javax.naming.NamingException - if an error occurs
      • createSubcontext

        public javax.naming.Context createSubcontext​(java.lang.String name)
                                              throws javax.naming.NamingException
        Create a Context as a child of this one
        Specified by:
        createSubcontext in interface javax.naming.Context
        Parameters:
        name - a String value
        Returns:
        a Context value
        Throws:
        javax.naming.NamingException - if an error occurs
      • destroySubcontext

        public void destroySubcontext​(java.lang.String name)
                               throws javax.naming.NamingException
        Specified by:
        destroySubcontext in interface javax.naming.Context
        Parameters:
        name - name of subcontext to remove
        Throws:
        javax.naming.NamingException - if an error occurs
      • destroySubcontext

        public void destroySubcontext​(javax.naming.Name name)
                               throws javax.naming.NamingException
        Specified by:
        destroySubcontext in interface javax.naming.Context
        Parameters:
        name - name of subcontext to remove
        Throws:
        javax.naming.NamingException - if an error occurs
      • lookup

        public java.lang.Object lookup​(javax.naming.Name name)
                                throws javax.naming.NamingException
        Lookup a binding by name
        Specified by:
        lookup in interface javax.naming.Context
        Parameters:
        name - name of bound object
        Throws:
        javax.naming.NamingException - if an error occurs
      • lookup

        public java.lang.Object lookup​(java.lang.String name)
                                throws javax.naming.NamingException
        Lookup binding of an object by name
        Specified by:
        lookup in interface javax.naming.Context
        Parameters:
        name - name of bound object
        Returns:
        object bound to name
        Throws:
        javax.naming.NamingException - if an error occurs
      • lookupLink

        public java.lang.Object lookupLink​(javax.naming.Name name)
                                    throws javax.naming.NamingException
        Lookup link bound to name
        Specified by:
        lookupLink in interface javax.naming.Context
        Parameters:
        name - name of link binding
        Returns:
        LinkRef or plain object bound at name
        Throws:
        javax.naming.NamingException - if an error occurs
      • lookupLink

        public java.lang.Object lookupLink​(java.lang.String name)
                                    throws javax.naming.NamingException
        Lookup link bound to name
        Specified by:
        lookupLink in interface javax.naming.Context
        Parameters:
        name - name of link binding
        Returns:
        LinkRef or plain object bound at name
        Throws:
        javax.naming.NamingException - if an error occurs
      • list

        public javax.naming.NamingEnumeration list​(javax.naming.Name name)
                                            throws javax.naming.NamingException
        List all names bound at Context named by Name
        Specified by:
        list in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a NamingEnumeration value
        Throws:
        javax.naming.NamingException - if an error occurs
      • list

        public javax.naming.NamingEnumeration list​(java.lang.String name)
                                            throws javax.naming.NamingException
        List all names bound at Context named by Name
        Specified by:
        list in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a NamingEnumeration value
        Throws:
        javax.naming.NamingException - if an error occurs
      • listBindings

        public javax.naming.NamingEnumeration listBindings​(javax.naming.Name name)
                                                    throws javax.naming.NamingException
        List all Bindings present at Context named by Name
        Specified by:
        listBindings in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a NamingEnumeration value
        Throws:
        javax.naming.NamingException - if an error occurs
      • listBindings

        public javax.naming.NamingEnumeration listBindings​(java.lang.String name)
                                                    throws javax.naming.NamingException
        List all Bindings at Name
        Specified by:
        listBindings in interface javax.naming.Context
        Parameters:
        name - a String value
        Returns:
        a NamingEnumeration value
        Throws:
        javax.naming.NamingException - if an error occurs
      • rebind

        public void rebind​(javax.naming.Name name,
                           java.lang.Object obj)
                    throws javax.naming.NamingException
        Overwrite or create a binding
        Specified by:
        rebind in interface javax.naming.Context
        Parameters:
        name - a Name value
        obj - an Object value
        Throws:
        javax.naming.NamingException - if an error occurs
      • rebind

        public void rebind​(java.lang.String name,
                           java.lang.Object obj)
                    throws javax.naming.NamingException
        Overwrite or create a binding from Name to Object
        Specified by:
        rebind in interface javax.naming.Context
        Parameters:
        name - a String value
        obj - an Object value
        Throws:
        javax.naming.NamingException - if an error occurs
      • unbind

        public void unbind​(java.lang.String name)
                    throws javax.naming.NamingException
        Not supported.
        Specified by:
        unbind in interface javax.naming.Context
        Parameters:
        name - a String value
        Throws:
        javax.naming.NamingException - if an error occurs
      • unbind

        public void unbind​(javax.naming.Name name)
                    throws javax.naming.NamingException
        Not supported.
        Specified by:
        unbind in interface javax.naming.Context
        Parameters:
        name - a String value
        Throws:
        javax.naming.NamingException - if an error occurs
      • rename

        public void rename​(javax.naming.Name oldName,
                           javax.naming.Name newName)
                    throws javax.naming.NamingException
        Not supported
        Specified by:
        rename in interface javax.naming.Context
        Parameters:
        oldName - a Name value
        newName - a Name value
        Throws:
        javax.naming.NamingException - if an error occurs
      • rename

        public void rename​(java.lang.String oldName,
                           java.lang.String newName)
                    throws javax.naming.NamingException
        Not supported
        Specified by:
        rename in interface javax.naming.Context
        Parameters:
        oldName - a Name value
        newName - a Name value
        Throws:
        javax.naming.NamingException - if an error occurs
      • composeName

        public javax.naming.Name composeName​(javax.naming.Name name,
                                             javax.naming.Name prefix)
                                      throws javax.naming.NamingException
        Join two names together. These are treated as CompoundNames.
        Specified by:
        composeName in interface javax.naming.Context
        Parameters:
        name - a Name value
        prefix - a Name value
        Returns:
        a Name value
        Throws:
        javax.naming.NamingException - if an error occurs
      • composeName

        public java.lang.String composeName​(java.lang.String name,
                                            java.lang.String prefix)
                                     throws javax.naming.NamingException
        Join two names together. These are treated as CompoundNames.
        Specified by:
        composeName in interface javax.naming.Context
        Parameters:
        name - a Name value
        prefix - a Name value
        Returns:
        a Name value
        Throws:
        javax.naming.NamingException - if an error occurs
      • close

        public void close()
                   throws javax.naming.NamingException
        Do nothing
        Specified by:
        close in interface javax.naming.Context
        Throws:
        javax.naming.NamingException - if an error occurs
      • getNameParser

        public javax.naming.NameParser getNameParser​(javax.naming.Name name)
        Return a NameParser for this Context.
        Specified by:
        getNameParser in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a NameParser value
      • getNameParser

        public javax.naming.NameParser getNameParser​(java.lang.String name)
        Return a NameParser for this Context.
        Specified by:
        getNameParser in interface javax.naming.Context
        Parameters:
        name - a Name value
        Returns:
        a NameParser value
      • getNameInNamespace

        public java.lang.String getNameInNamespace()
                                            throws javax.naming.NamingException
        Get the full name of this Context node by visiting it's ancestors back to root. NOTE: if this Context has a URL namespace then the URL prefix will be missing
        Specified by:
        getNameInNamespace in interface javax.naming.Context
        Returns:
        the full name of this Context
        Throws:
        javax.naming.NamingException - if an error occurs
      • addToEnvironment

        public java.lang.Object addToEnvironment​(java.lang.String propName,
                                                 java.lang.Object propVal)
                                          throws javax.naming.NamingException
        Add an environment setting to this Context
        Specified by:
        addToEnvironment in interface javax.naming.Context
        Parameters:
        propName - name of the property to add
        propVal - value of the property to add
        Returns:
        propVal or previous value of the property
        Throws:
        javax.naming.NamingException - if an error occurs
      • removeFromEnvironment

        public java.lang.Object removeFromEnvironment​(java.lang.String propName)
                                               throws javax.naming.NamingException
        Remove a property from this Context's environment.
        Specified by:
        removeFromEnvironment in interface javax.naming.Context
        Parameters:
        propName - name of property to remove
        Returns:
        value of property or null if it didn't exist
        Throws:
        javax.naming.NamingException - if an error occurs
      • getEnvironment

        public java.util.Hashtable getEnvironment()
        Get the environment of this Context.
        Specified by:
        getEnvironment in interface javax.naming.Context
        Returns:
        a copy of the environment of this Context.
      • addBinding

        public void addBinding​(javax.naming.Name name,
                               java.lang.Object obj)
                        throws javax.naming.NameAlreadyBoundException
        Add a name to object binding to this Context.
        Parameters:
        name - a Name value
        obj - an Object value
        Throws:
        javax.naming.NameAlreadyBoundException - if name already bound
      • getBinding

        public javax.naming.Binding getBinding​(javax.naming.Name name)
        Get a name to object binding from this Context
        Parameters:
        name - a Name value
        Returns:
        a Binding value
      • getBinding

        public javax.naming.Binding getBinding​(java.lang.String name)
        Get a name to object binding from this Context
        Parameters:
        name - as a String
        Returns:
        null or the Binding
      • removeBinding

        public void removeBinding​(javax.naming.Name name)
      • toCanonicalName

        public javax.naming.Name toCanonicalName​(javax.naming.Name name)
        Remove leading or trailing empty components from name. Eg "/comp/env/" -> "comp/env"
        Parameters:
        name - the name to normalize
        Returns:
        normalized name
      • isLocked

        public boolean isLocked()
      • dump

        public java.lang.String dump()
        Specified by:
        dump in interface Dumpable
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object