Nuxeo Enterprise Platform 5.4

org.nuxeo.common.jndi
Class NamingContext

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

public class NamingContext
extends Object
implements 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
 Object addToEnvironment(String arg0, Object arg1)
          Not implemented.
 void bind(Name name, Object obj)
          Binds object obj to name name in this context.
 void bind(String name, Object obj)
          Binds object obj to name name in this context.
 void close()
          Does nothing.
 Name composeName(Name name, Name prefix)
          Returns composition of prefix and name.
 String composeName(String name, String prefix)
          Composes the name of this context with a name relative to this context.
 Context createSubcontext(Name name)
          Creates subcontext with name name, relative to this Context.
 Context createSubcontext(String name)
          Creates subcontext with name name, relative to this Context.
 void destroySubcontext(Name name)
          Destroys subcontext with name name.
 void destroySubcontext(String name)
          Destroys subcontext with name name.
 Hashtable<?,?> getEnvironment()
          Not implemented.
 String getNameInNamespace()
          Not implemented.
 NameParser getNameParser(Name name)
          Retrieves name parser used to parse context with name name.
 NameParser getNameParser(String name)
          Retrieves name parser used to parse context with name name.
 NamingEnumeration list(Name name)
          The same as listBindings(String).
 NamingEnumeration list(String name)
          The same as listBindings(String).
 NamingEnumeration<Binding> listBindings(Name name)
          Lists all bindings for Context with name name.
 NamingEnumeration<Binding> listBindings(String name)
          Lists all bindings for Context with name name.
 Object lookup(Name name)
          Looks up object with name name in this context.
 Object lookup(String name)
          Looks up the object in this context.
 Object lookupLink(Name arg0)
          Not implemented.
 Object lookupLink(String arg0)
          Not implemented.
 void rebind(Name name, Object obj)
          Rebinds object obj to name name.
 void rebind(String name, Object obj)
          Same as bind except that if name is already bound in the context, it will be re-bound to object obj.
 Object removeFromEnvironment(String arg0)
          Not implemented.
 void rename(Name arg0, Name arg1)
          Not implemented.
 void rename(String arg0, String arg1)
          Not implemented.
 String toString()
           
 void unbind(Name name)
          Removes name and its associated object from the context.
 void unbind(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 Object addToEnvironment(String arg0,
                               Object arg1)
                        throws NamingException
Not implemented.

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

bind

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

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

bind

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

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

close

public void close()
           throws NamingException
Does nothing.

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

composeName

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

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

composeName

public String composeName(String name,
                          String prefix)
                   throws 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 Context
Parameters:
name - name relative to this context
prefix - name of this context
Throws:
NamingException
See Also:
Context.composeName(java.lang.String, java.lang.String)

createSubcontext

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

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

createSubcontext

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

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

destroySubcontext

public void destroySubcontext(Name name)
                       throws 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 Context
Parameters:
name - subcontext to destroy
Throws:
NoPermissionException - if this context has been destroyed
InvalidNameException - if name is empty or is CompositeName that spans more than one naming system
ContextNotEmptyException - if Context name is not empty
NameNotFoundException - if subcontext with name name can not be found
NotContextException - if name is not bound to instance of NamingContext
NamingException
See Also:
Context.destroySubcontext(javax.naming.Name)

destroySubcontext

public void destroySubcontext(String name)
                       throws NamingException
Destroys subcontext with name name.

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

getEnvironment

public Hashtable<?,?> getEnvironment()
                              throws NamingException
Not implemented.

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

getNameInNamespace

public String getNameInNamespace()
                          throws NamingException
Not implemented.

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

getNameParser

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

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

getNameParser

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

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

list

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

Specified by:
list in interface 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:
NamingException - if naming error occurs
See Also:
listBindings(javax.naming.Name)

list

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

Specified by:
list in interface 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:
NamingException - if naming error occurs
See Also:
listBindings(java.lang.String)

listBindings

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

Specified by:
listBindings in interface 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:
NoPermissionException - if this context has been destroyed
InvalidNameException - if name is CompositeName that spans more than one naming system
NameNotFoundException - if name can not be found
NotContextException - component of name is not bound to instance of NamingContext, when name is not an atomic name
NamingException - if any other naming error occurs
See Also:
Context.listBindings(javax.naming.Name)

listBindings

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

Specified by:
listBindings in interface 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:
NamingException - if naming error occurs
See Also:
listBindings(javax.naming.Name)

lookup

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

lookup

public Object lookup(String name)
              throws 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 Context
Parameters:
name - object to search
Returns:
object reference bound to name name
Throws:
NamingException - if naming error occurs
See Also:
lookup(javax.naming.Name)

lookupLink

public Object lookupLink(Name arg0)
                  throws NamingException
Not implemented.

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

lookupLink

public Object lookupLink(String arg0)
                  throws NamingException
Not implemented.

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

rebind

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

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

rebind

public void rebind(String name,
                   Object obj)
            throws 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 Context
Parameters:
name - name of the object to rebind
obj - object to add. Can be null
Throws:
NamingException - if naming error occurs
See Also:
rebind(javax.naming.Name, Object)

removeFromEnvironment

public Object removeFromEnvironment(String arg0)
                             throws NamingException
Not implemented.

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

rename

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

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

rename

public void rename(String arg0,
                   String arg1)
            throws NamingException
Not implemented.

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

unbind

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

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

unbind

public void unbind(String name)
            throws NamingException
Removes object from the object map.

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

toString

public String toString()
Overrides:
toString in class Object

Nuxeo Enterprise Platform 5.4

Copyright © 2011 Nuxeo SAS. All Rights Reserved.