public class NamingContext extends Object implements Context
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 tomyObject = 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.
Modifier and Type | Class and Description |
---|---|
static class |
NamingContext.NamingContextNameParser
NamingContext name parser.
|
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
Modifier and Type | Method and Description |
---|---|
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.
|
public Object addToEnvironment(String arg0, Object arg1) throws NamingException
addToEnvironment
in interface Context
NamingException
Context.addToEnvironment(java.lang.String, java.lang.Object)
public void bind(Name name, Object obj) throws NamingException
obj
to name name
in this
context. Intermediate contexts that do not exist will be created.bind
in interface Context
name
- name of the object to bindobj
- object to bind. Can be null
.NoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is empty or is
CompositeName
that spans more than one naming
systemNotContextException
- if name
has more than one
atomic name and intermediate atomic name is bound to object
that is not context.NamingException
Context.bind(javax.naming.Name, java.lang.Object)
public void bind(String name, Object obj) throws NamingException
obj
to name name
in this
context.bind
in interface Context
name
- name of the object to addobj
- object to bindNamingException
- if naming error occursbind(Name, Object)
public void close() throws NamingException
close
in interface Context
NamingException
Context.close()
public Name composeName(Name name, Name prefix) throws NamingException
prefix
and name
.composeName
in interface Context
name
- name relative to this contextprefix
- name of this contextNamingException
Context.composeName(javax.naming.Name,
javax.naming.Name)
public String composeName(String name, String prefix) throws NamingException
Example:
composeName("a","b") b/a composeName("a","") a
composeName
in interface Context
name
- name relative to this contextprefix
- name of this contextNamingException
Context.composeName(java.lang.String, java.lang.String)
public Context createSubcontext(Name name) throws NamingException
name
, relative to this
Context.createSubcontext
in interface Context
name
- subcontext name.name
relative to this contextNoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is empty or is
CompositeName
that spans more than one naming
systemNameAlreadyBoundException
- if name
is already bound
in this ContextNotContextException
- if any intermediate name from
name
is not bound to instance of
javax.naming.Context
NamingException
Context.createSubcontext(javax.naming.Name)
public Context createSubcontext(String name) throws NamingException
name
, relative to this
Context.createSubcontext
in interface Context
name
- subcontext namename
relative to this contextNamingException
- if naming error occurscreateSubcontext(javax.naming.Name)
public void destroySubcontext(Name name) throws NamingException
name
. The subcontext must
be empty, otherwise ContextNotEmptyException
is thrown.
Once a context is destroyed, the instance should not be used.
destroySubcontext
in interface Context
name
- subcontext to destroyNoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is empty or is
CompositeName
that spans more than one naming
systemContextNotEmptyException
- if Context name
is not
emptyNameNotFoundException
- if subcontext with name name
can not be foundNotContextException
- if name
is not bound to
instance of NamingContext
NamingException
Context.destroySubcontext(javax.naming.Name)
public void destroySubcontext(String name) throws NamingException
name
.destroySubcontext
in interface Context
name
- name of subcontext to destroyNamingException
- if naming error occursdestroySubcontext(javax.naming.Name)
public Hashtable<?,?> getEnvironment() throws NamingException
getEnvironment
in interface Context
NamingException
Context.getEnvironment()
public String getNameInNamespace() throws NamingException
getNameInNamespace
in interface Context
NamingException
Context.getNameInNamespace()
public NameParser getNameParser(Name name) throws NamingException
name
.getNameParser
in interface Context
name
- context nameNameParser
NoPermissionException
- if this context has been destroyedNamingException
- if any other naming error occursContext.getNameParser(javax.naming.Name)
public NameParser getNameParser(String name) throws NamingException
name
.getNameParser
in interface Context
name
- context nameNameParser
NamingException
- if naming error occursgetNameParser(javax.naming.Name)
public NamingEnumeration list(Name name) throws NamingException
listBindings(String)
.list
in interface Context
name
- name of Context, relative to this ContextNamingEnumeration
of all name-class pairs. Each
element from the enumeration is instance of
NameClassPair
NamingException
- if naming error occurslistBindings(javax.naming.Name)
public NamingEnumeration list(String name) throws NamingException
listBindings(String)
.list
in interface Context
name
- name of Context, relative to this ContextNamingEnumeration
of all name-class pairs. Each
element from the enumeration is instance of
NameClassPair
NamingException
- if naming error occurslistBindings(java.lang.String)
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
name
. If
name
is empty, then this Context is assumed.listBindings
in interface Context
name
- name of Context, relative to this ContextNamingEnumeration
of all name-object pairs. Each
element from the enumeration is instance of Binding
NoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is
CompositeName
that spans more than one naming
systemNameNotFoundException
- if name
can not be foundNotContextException
- component of name
is not bound
to instance of NamingContext
, when
name
is not an atomic nameNamingException
- if any other naming error occursContext.listBindings(javax.naming.Name)
public NamingEnumeration<Binding> listBindings(String name) throws NamingException
name
. If
name
is empty then this Context is assumed.listBindings
in interface Context
name
- name of Context, relative to this ContextNamingEnumeration
of all name-object pairs. Each
element from the enumeration is instance of Binding
NamingException
- if naming error occurslistBindings(javax.naming.Name)
public Object lookup(Name name) throws NamingException
name
in this context. If the
object is not found and the remote context was provided, calls the remote
context to lookup the object.lookup
in interface Context
name
- name to look upname
NoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is
CompositeName
that spans more than one naming
systemNameNotFoundException
- if name
can not be foundNotContextException
- component of name
is not bound
to instance of NamingContext
, when
name
is not atomic name.NamingException
- if any other naming error occursContext.lookup(javax.naming.Name)
public Object lookup(String name) throws NamingException
lookup
in interface Context
name
- object to searchname
NamingException
- if naming error occurslookup(javax.naming.Name)
public Object lookupLink(Name arg0) throws NamingException
lookupLink
in interface Context
NamingException
Context.lookupLink(javax.naming.Name)
public Object lookupLink(String arg0) throws NamingException
lookupLink
in interface Context
NamingException
Context.lookupLink(java.lang.String)
public void rebind(Name name, Object obj) throws NamingException
obj
to name name
. If there
is existing binding it will be overwritten.rebind
in interface Context
name
- name of the object to rebindobj
- object to add. Can be null
NoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is empty or is
CompositeName
that spans more than one naming
systemNotContextException
- if name
has more than one
atomic name and intermediate context is not foundNamingException
- if any other naming error occursContext.rebind(javax.naming.Name, java.lang.Object)
public void rebind(String name, Object obj) throws NamingException
name
is already bound in the
context, it will be re-bound to object obj
.rebind
in interface Context
name
- name of the object to rebindobj
- object to add. Can be null
NamingException
- if naming error occursrebind(javax.naming.Name, Object)
public Object removeFromEnvironment(String arg0) throws NamingException
removeFromEnvironment
in interface Context
NamingException
Context.removeFromEnvironment(java.lang.String)
public void rename(Name arg0, Name arg1) throws NamingException
rename
in interface Context
NamingException
Context.rename(javax.naming.Name, javax.naming.Name)
public void rename(String arg0, String arg1) throws NamingException
rename
in interface Context
NamingException
Context.rename(java.lang.String, java.lang.String)
public void unbind(Name name) throws NamingException
name
and its associated object from the context.unbind
in interface Context
name
- name to removeNoPermissionException
- if this context has been destroyedInvalidNameException
- if name
is empty or is
CompositeName
that spans more than one naming
systemNameNotFoundException
- if intermediate context can not be foundNotContextException
- if name
has more than one
atomic name and intermediate context is not foundNamingException
- if any other naming exception occursContext.unbind(javax.naming.Name)
public void unbind(String name) throws NamingException
unbind
in interface Context
name
- object to removeNamingException
- if naming error occursunbind(javax.naming.Name)
Copyright © 2011 Nuxeo SA. All Rights Reserved.