Nuxeo Enterprise Platform 5.4

org.nuxeo.common.jndi
Class NamingContext

java.lang.Object
  extended by org.nuxeo.common.jndi.NamingContext
All Implemented Interfaces:
javax.naming.Context

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

Provides implementation of javax.naming.Context interface for hierarchical in memory single-namespace naming system. A name in the NamingContext namespace is a sequence of one or more atomic names, relative to a root initial context. When a name consist of more than one atomic names it is a CompoundName where atomic names are separated with separator character - '/' or '.'. It is possible to use both separator characters in the same name. In such cases any occurrences of '.' are replaced with '/' before parsing.

Leading and terminal components of a CompoundName can not be empty - for example "name1/name2/name3" is a valid name, while the following names are not valid - "/name1/name2/name3", "name1/name2/name3/", "/name1/name2/name3/". If such name is passed, all empty leading/terminal components will be removed before the name is actually used (this will not affect the original value) - from the above three examples the actual name will be "name1/name2/name3". If a name contains intermediate empty components (for example "a//b") then InvalidNameException will be thrown.

Composite names (instances of CompositeName) must contain zero or one component from the NamingContext namespace.

The namespace of NamingContext can be represented as a tree of atomic names. Each name is bound to an instance of NamingContext (subcontext) or to an arbitrary object. Each subcontext has collection of names bound to other subcontexts or arbitrary objects.

When instance of Name is used as parameter to any of the NamingContext methods, if the object is not CompositeName then it is assumed that it is CompoundName

Example:


 myContext = initialContext.lookup("foo");
 myObject = myContext.lookup("bar");
 
 is equivalent to
 myObject = initialContext.lookup("foo/bar");
 

Instances of NamingContext are created only through NamingContextFactory, when InitialContext is instantiated.

If a remote context is provided, this class will search in that remote context if the object is not found locally.

For overloaded methods that accept name as String or Name only the version for Name is documented. The String version creates CompoundName, from the string name passed as parameter, and calls the Name version of the same method.

Author:
Alexander Ananiev, Dimitar Gospodinov

Nested Class Summary
static class NamingContext.NamingContextNameParser
          NamingContext name parser.
 
Field Summary
 
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
 
Method Summary
 java.lang.Object addToEnvironment(java.lang.String arg0, java.lang.Object arg1)
          Not implemented.
 void bind(javax.naming.Name name, java.lang.Object obj)
          Binds object obj to name name in this context.
 void bind(java.lang.String name, java.lang.Object obj)
          Binds object obj to name name in this context.
 void close()
          Does nothing.
 javax.naming.Name composeName(javax.naming.Name name, javax.naming.Name prefix)
          Returns composition of prefix and name.
 java.lang.String composeName(java.lang.String name, java.lang.String prefix)
          Composes the name of this context with a name relative to this context.
 javax.naming.Context createSubcontext(javax.naming.Name name)
          Creates subcontext with name name, relative to this Context.
 javax.naming.Context createSubcontext(java.lang.String name)
          Creates subcontext with name name, relative to this Context.
 void destroySubcontext(javax.naming.Name name)
          Destroys subcontext with name name.
 void destroySubcontext(java.lang.String name)
          Destroys subcontext with name name.
 java.util.Hashtable<?,?> getEnvironment()
          Not implemented.
 java.lang.String getNameInNamespace()
          Not implemented.
 javax.naming.NameParser getNameParser(javax.naming.Name name)
          Retrieves name parser used to parse context with name name.
 javax.naming.NameParser getNameParser(java.lang.String name)
          Retrieves name parser used to parse context with name name.
 javax.naming.NamingEnumeration list(javax.naming.Name name)
          The same as listBindings(String).
 javax.naming.NamingEnumeration list(java.lang.String name)
          The same as listBindings(String).
 javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(javax.naming.Name name)
          Lists all bindings for Context with name name.
 javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(java.lang.String name)
          Lists all bindings for Context with name name.
 java.lang.Object lookup(javax.naming.Name name)
          Looks up object with name name in this context.
 java.lang.Object lookup(java.lang.String name)
          Looks up the object in this context.
 java.lang.Object lookupLink(javax.naming.Name arg0)
          Not implemented.
 java.lang.Object lookupLink(java.lang.String arg0)
          Not implemented.
 void rebind(javax.naming.Name name, java.lang.Object obj)
          Rebinds object obj to name name.
 void rebind(java.lang.String name, java.lang.Object obj)
          Same as bind except that if name is already bound in the context, it will be re-bound to object obj.
 java.lang.Object removeFromEnvironment(java.lang.String arg0)
          Not implemented.
 void rename(javax.naming.Name arg0, javax.naming.Name arg1)
          Not implemented.
 void rename(java.lang.String arg0, java.lang.String arg1)
          Not implemented.
 java.lang.String toString()
           
 void unbind(javax.naming.Name name)
          Removes name and its associated object from the context.
 void unbind(java.lang.String name)
          Removes object from the object map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

addToEnvironment

public java.lang.Object addToEnvironment(java.lang.String arg0,
                                         java.lang.Object arg1)
                                  throws javax.naming.NamingException
Not implemented.

Specified by:
addToEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.addToEnvironment(java.lang.String, java.lang.Object)

bind

public void bind(javax.naming.Name name,
                 java.lang.Object obj)
          throws javax.naming.NamingException
Binds object obj to name name in this context. Intermediate contexts that do not exist will be created.

Specified by:
bind in interface javax.naming.Context
Parameters:
name - name of the object to bind
obj - object to bind. Can be null.
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
javax.naming.NotContextException - if name has more than one atomic name and intermediate atomic name is bound to object that is not context.
javax.naming.NamingException
See Also:
Context.bind(javax.naming.Name, java.lang.Object)

bind

public void bind(java.lang.String name,
                 java.lang.Object obj)
          throws javax.naming.NamingException
Binds object obj to name name in this context.

Specified by:
bind in interface javax.naming.Context
Parameters:
name - name of the object to add
obj - object to bind
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
bind(Name, Object)

close

public void close()
           throws javax.naming.NamingException
Does nothing.

Specified by:
close in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.close()

composeName

public javax.naming.Name composeName(javax.naming.Name name,
                                     javax.naming.Name prefix)
                              throws javax.naming.NamingException
Returns composition of prefix and name.

Specified by:
composeName in interface javax.naming.Context
Parameters:
name - name relative to this context
prefix - name of this context
Throws:
javax.naming.NamingException
See Also:
Context.composeName(javax.naming.Name, javax.naming.Name)

composeName

public java.lang.String composeName(java.lang.String name,
                                    java.lang.String prefix)
                             throws javax.naming.NamingException
Composes the name of this context with a name relative to this context. Given a name (name) relative to this context, and the name (prefix) of this context relative to one of its ancestors, this method returns the composition of the two names using the syntax appropriate for the naming system(s) involved.

Example:

 composeName("a","b")  b/a
 composeName("a","")  a
 

Specified by:
composeName in interface javax.naming.Context
Parameters:
name - name relative to this context
prefix - name of this context
Throws:
javax.naming.NamingException
See Also:
Context.composeName(java.lang.String, java.lang.String)

createSubcontext

public javax.naming.Context createSubcontext(javax.naming.Name name)
                                      throws javax.naming.NamingException
Creates subcontext with name name, relative to this Context.

Specified by:
createSubcontext in interface javax.naming.Context
Parameters:
name - subcontext name.
Returns:
new subcontext named name relative to this context
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
javax.naming.NameAlreadyBoundException - if name is already bound in this Context
javax.naming.NotContextException - if any intermediate name from name is not bound to instance of javax.naming.Context
javax.naming.NamingException
See Also:
Context.createSubcontext(javax.naming.Name)

createSubcontext

public javax.naming.Context createSubcontext(java.lang.String name)
                                      throws javax.naming.NamingException
Creates subcontext with name name, relative to this Context.

Specified by:
createSubcontext in interface javax.naming.Context
Parameters:
name - subcontext name
Returns:
new subcontext named name relative to this context
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
createSubcontext(javax.naming.Name)

destroySubcontext

public void destroySubcontext(javax.naming.Name name)
                       throws javax.naming.NamingException
Destroys subcontext with name name. The subcontext must be empty, otherwise ContextNotEmptyException is thrown.

Once a context is destroyed, the instance should not be used.

Specified by:
destroySubcontext in interface javax.naming.Context
Parameters:
name - subcontext to destroy
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
javax.naming.ContextNotEmptyException - if Context name is not empty
javax.naming.NameNotFoundException - if subcontext with name name can not be found
javax.naming.NotContextException - if name is not bound to instance of NamingContext
javax.naming.NamingException
See Also:
Context.destroySubcontext(javax.naming.Name)

destroySubcontext

public void destroySubcontext(java.lang.String name)
                       throws javax.naming.NamingException
Destroys subcontext with name name.

Specified by:
destroySubcontext in interface javax.naming.Context
Parameters:
name - name of subcontext to destroy
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
destroySubcontext(javax.naming.Name)

getEnvironment

public java.util.Hashtable<?,?> getEnvironment()
                                        throws javax.naming.NamingException
Not implemented.

Specified by:
getEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.getEnvironment()

getNameInNamespace

public java.lang.String getNameInNamespace()
                                    throws javax.naming.NamingException
Not implemented.

Specified by:
getNameInNamespace in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.getNameInNamespace()

getNameParser

public javax.naming.NameParser getNameParser(javax.naming.Name name)
                                      throws javax.naming.NamingException
Retrieves name parser used to parse context with name name.

Specified by:
getNameParser in interface javax.naming.Context
Parameters:
name - context name
Returns:
NameParser
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.NamingException - if any other naming error occurs
See Also:
Context.getNameParser(javax.naming.Name)

getNameParser

public javax.naming.NameParser getNameParser(java.lang.String name)
                                      throws javax.naming.NamingException
Retrieves name parser used to parse context with name name.

Specified by:
getNameParser in interface javax.naming.Context
Parameters:
name - context name
Returns:
NameParser
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
getNameParser(javax.naming.Name)

list

public javax.naming.NamingEnumeration list(javax.naming.Name name)
                                    throws javax.naming.NamingException
The same as listBindings(String).

Specified by:
list in interface javax.naming.Context
Parameters:
name - name of Context, relative to this Context
Returns:
NamingEnumeration of all name-class pairs. Each element from the enumeration is instance of NameClassPair
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
listBindings(javax.naming.Name)

list

public javax.naming.NamingEnumeration list(java.lang.String name)
                                    throws javax.naming.NamingException
The same as listBindings(String).

Specified by:
list in interface javax.naming.Context
Parameters:
name - name of Context, relative to this Context
Returns:
NamingEnumeration of all name-class pairs. Each element from the enumeration is instance of NameClassPair
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
listBindings(java.lang.String)

listBindings

public javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(javax.naming.Name name)
                                                                  throws javax.naming.NamingException
Lists all bindings for Context with name name. If name is empty, then this Context is assumed.

Specified by:
listBindings in interface javax.naming.Context
Parameters:
name - name of Context, relative to this Context
Returns:
NamingEnumeration of all name-object pairs. Each element from the enumeration is instance of Binding
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is CompositeName that spans more than one naming system
javax.naming.NameNotFoundException - if name can not be found
javax.naming.NotContextException - component of name is not bound to instance of NamingContext, when name is not an atomic name
javax.naming.NamingException - if any other naming error occurs
See Also:
Context.listBindings(javax.naming.Name)

listBindings

public javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(java.lang.String name)
                                                                  throws javax.naming.NamingException
Lists all bindings for Context with name name. If name is empty then this Context is assumed.

Specified by:
listBindings in interface javax.naming.Context
Parameters:
name - name of Context, relative to this Context
Returns:
NamingEnumeration of all name-object pairs. Each element from the enumeration is instance of Binding
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
listBindings(javax.naming.Name)

lookup

public java.lang.Object lookup(javax.naming.Name name)
                        throws javax.naming.NamingException
Looks up object with name name in this context. If the object is not found and the remote context was provided, calls the remote context to lookup the object.

Specified by:
lookup in interface javax.naming.Context
Parameters:
name - name to look up
Returns:
object reference bound to name name
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is CompositeName that spans more than one naming system
javax.naming.NameNotFoundException - if name can not be found
javax.naming.NotContextException - component of name is not bound to instance of NamingContext, when name is not atomic name.
javax.naming.NamingException - if any other naming error occurs
See Also:
Context.lookup(javax.naming.Name)

lookup

public java.lang.Object lookup(java.lang.String name)
                        throws javax.naming.NamingException
Looks up the object in this context. If the object is not found and the remote context was provided, calls the remote context to lookup the object.

Specified by:
lookup in interface javax.naming.Context
Parameters:
name - object to search
Returns:
object reference bound to name name
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
lookup(javax.naming.Name)

lookupLink

public java.lang.Object lookupLink(javax.naming.Name arg0)
                            throws javax.naming.NamingException
Not implemented.

Specified by:
lookupLink in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.lookupLink(javax.naming.Name)

lookupLink

public java.lang.Object lookupLink(java.lang.String arg0)
                            throws javax.naming.NamingException
Not implemented.

Specified by:
lookupLink in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.lookupLink(java.lang.String)

rebind

public void rebind(javax.naming.Name name,
                   java.lang.Object obj)
            throws javax.naming.NamingException
Rebinds object obj to name name. If there is existing binding it will be overwritten.

Specified by:
rebind in interface javax.naming.Context
Parameters:
name - name of the object to rebind
obj - object to add. Can be null
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
javax.naming.NotContextException - if name has more than one atomic name and intermediate context is not found
javax.naming.NamingException - if any other naming error occurs
See Also:
Context.rebind(javax.naming.Name, java.lang.Object)

rebind

public void rebind(java.lang.String name,
                   java.lang.Object obj)
            throws javax.naming.NamingException
Same as bind except that if name is already bound in the context, it will be re-bound to object obj.

Specified by:
rebind in interface javax.naming.Context
Parameters:
name - name of the object to rebind
obj - object to add. Can be null
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
rebind(javax.naming.Name, Object)

removeFromEnvironment

public java.lang.Object removeFromEnvironment(java.lang.String arg0)
                                       throws javax.naming.NamingException
Not implemented.

Specified by:
removeFromEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.removeFromEnvironment(java.lang.String)

rename

public void rename(javax.naming.Name arg0,
                   javax.naming.Name arg1)
            throws javax.naming.NamingException
Not implemented.

Specified by:
rename in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.rename(javax.naming.Name, javax.naming.Name)

rename

public void rename(java.lang.String arg0,
                   java.lang.String arg1)
            throws javax.naming.NamingException
Not implemented.

Specified by:
rename in interface javax.naming.Context
Throws:
javax.naming.NamingException
See Also:
Context.rename(java.lang.String, java.lang.String)

unbind

public void unbind(javax.naming.Name name)
            throws javax.naming.NamingException
Removes name and its associated object from the context.

Specified by:
unbind in interface javax.naming.Context
Parameters:
name - name to remove
Throws:
javax.naming.NoPermissionException - if this context has been destroyed
javax.naming.InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
javax.naming.NameNotFoundException - if intermediate context can not be found
javax.naming.NotContextException - if name has more than one atomic name and intermediate context is not found
javax.naming.NamingException - if any other naming exception occurs
See Also:
Context.unbind(javax.naming.Name)

unbind

public void unbind(java.lang.String name)
            throws javax.naming.NamingException
Removes object from the object map.

Specified by:
unbind in interface javax.naming.Context
Parameters:
name - object to remove
Throws:
javax.naming.NamingException - if naming error occurs
See Also:
unbind(javax.naming.Name)

toString

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

Nuxeo Enterprise Platform 5.4

Copyright © 2010 Nuxeo SAS. All Rights Reserved.