public class MockContext
extends java.lang.Object
implements javax.naming.Context
javax.naming.Context interface for
hierarchical in memory single-namespace naming system.
A name in the MockContext 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 MockContext namespace.
The namespace of MockContext can be represented as a tree of atomic names.
Each name is bound to an instance of MockContext (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
MockContext 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 MockContext are created only through
MockContextFactory, 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 | Constructor and Description |
|---|---|
protected |
MockContext(javax.naming.Context remoteContext)
Creates a new instance of the context.
|
| Modifier and Type | Method and Description |
|---|---|
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
The subcontext must be empty otherwise ContextNotEmptyException
is thrown. |
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 |
listBindings(javax.naming.Name name)
Lists all bindings for Context with name
name. |
javax.naming.NamingEnumeration |
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
|
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
|
protected MockContext(javax.naming.Context remoteContext)
remoteContext - remote context that MockContext will
delegate to if it fails to lookup an object locallypublic java.lang.Object addToEnvironment(java.lang.String arg0,
java.lang.Object arg1)
throws javax.naming.NamingException
addToEnvironment in interface javax.naming.Contextjavax.naming.NamingExceptionContext.addToEnvironment(java.lang.String, java.lang.Object)public void bind(javax.naming.Name name,
java.lang.Object obj)
throws javax.naming.NamingException
obj to name name in this context.
Intermediate contexts that do not exist will be created.bind in interface javax.naming.Contextname - name of the object to bindobj - object to bind. Can be null.javax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is empty or is
CompositeName that spans more than one naming systemjavax.naming.NotContextException - if name has more than one
atomic name and intermediate atomic name is bound to object that is
not context.javax.naming.NamingExceptionContext.bind(javax.naming.Name, java.lang.Object)public void bind(java.lang.String name,
java.lang.Object obj)
throws javax.naming.NamingException
obj to name name in this context.bind in interface javax.naming.Contextname - name of the object to addobj - object to bindjavax.naming.NamingException - if naming error occursbind(Name, Object)public void close()
throws javax.naming.NamingException
close in interface javax.naming.Contextjavax.naming.NamingExceptionpublic javax.naming.Name composeName(javax.naming.Name name,
javax.naming.Name prefix)
throws javax.naming.NamingException
prefix and name.composeName in interface javax.naming.Contextname - name relative to this contextprefix - name of this contextjavax.naming.NamingExceptionContext.composeName(javax.naming.Name, javax.naming.Name)public java.lang.String composeName(java.lang.String name,
java.lang.String prefix)
throws javax.naming.NamingException
composeName in interface javax.naming.Contextname - name relative to this contextprefix - name of this contextjavax.naming.NamingExceptionContext.composeName(java.lang.String, java.lang.String)public javax.naming.Context createSubcontext(javax.naming.Name name)
throws javax.naming.NamingException
name, relative to this Context.createSubcontext in interface javax.naming.Contextname - subcontext name.name relative to this contextjavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is empty or is
CompositeName that spans more than one naming systemjavax.naming.NameAlreadyBoundException - if name is already bound in this Contextjavax.naming.NotContextException - if any intermediate name from name
is not bound to instance of javax.naming.Contextjavax.naming.NamingExceptionContext.createSubcontext(javax.naming.Name)public javax.naming.Context createSubcontext(java.lang.String name)
throws javax.naming.NamingException
name, relative to this Context.createSubcontext in interface javax.naming.Contextname - subcontext namename relative to this contextjavax.naming.NamingException - if naming error occurscreateSubcontext(javax.naming.Name)public void destroySubcontext(javax.naming.Name name)
throws javax.naming.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 javax.naming.Contextname - subcontext to destroyjavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is empty or is
CompositeName that spans more than one naming systemjavax.naming.ContextNotEmptyException - if Context name is not emptyjavax.naming.NameNotFoundException - if subcontext with name name can not be foundjavax.naming.NotContextException - if name is not bound to instance of
MockContextjavax.naming.NamingExceptionContext.destroySubcontext(javax.naming.Name)public void destroySubcontext(java.lang.String name)
throws javax.naming.NamingException
namedestroySubcontext in interface javax.naming.Contextname - name of subcontext to destroyjavax.naming.NamingException - if naming error occursdestroySubcontext(javax.naming.Name)public java.util.Hashtable getEnvironment()
throws javax.naming.NamingException
getEnvironment in interface javax.naming.Contextjavax.naming.NamingExceptionContext.getEnvironment()public java.lang.String getNameInNamespace()
throws javax.naming.NamingException
getNameInNamespace in interface javax.naming.Contextjavax.naming.NamingExceptionContext.getNameInNamespace()public javax.naming.NameParser getNameParser(javax.naming.Name name)
throws javax.naming.NamingException
name.getNameParser in interface javax.naming.Contextname - context nameNameParserjavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.NamingException - if any other naming error occursContext.getNameParser(javax.naming.Name)public javax.naming.NameParser getNameParser(java.lang.String name)
throws javax.naming.NamingException
name.getNameParser in interface javax.naming.Contextname - context nameNameParserjavax.naming.NamingException - if naming error occursgetNameParser(javax.naming.Name)public javax.naming.NamingEnumeration list(javax.naming.Name name)
throws javax.naming.NamingException
listBindings(String)list in interface javax.naming.Contextname - name of Context, relative to this ContextNamingEnumeration of all name-class pairs. Each
element from the enumeration is instance of NameClassPairjavax.naming.NamingException - if naming error occurslistBindings(javax.naming.Name)public javax.naming.NamingEnumeration list(java.lang.String name)
throws javax.naming.NamingException
listBindings(String)list in interface javax.naming.Contextname - name of Context, relative to this ContextNamingEnumeration of all name-class pairs. Each
element from the enumeration is instance of NameClassPairjavax.naming.NamingException - if naming error occurslistBindings(java.lang.String)public javax.naming.NamingEnumeration listBindings(javax.naming.Name name)
throws javax.naming.NamingException
name.
If name is empty then this Context is assumed.listBindings in interface javax.naming.Contextname - name of Context, relative to this ContextNamingEnumeration of all name-object pairs. Each
element from the enumeration is instance of Bindingjavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is CompositeName
that spans more than one naming systemjavax.naming.NameNotFoundException - if name can not be foundjavax.naming.NotContextException - component of name is not bound to instance of
MockContext, when name is not an atomic namejavax.naming.NamingException - if any other naming error occursContext.listBindings(javax.naming.Name)public javax.naming.NamingEnumeration listBindings(java.lang.String name)
throws javax.naming.NamingException
name.
If name is empty then this Context is assumed.listBindings in interface javax.naming.Contextname - name of Context, relative to this ContextNamingEnumeration of all name-object pairs. Each
element from the enumeration is instance of Bindingjavax.naming.NamingException - if naming error occurslistBindings(javax.naming.Name)public java.lang.Object lookup(javax.naming.Name name)
throws javax.naming.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 javax.naming.Contextname - name to look upnamejavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is CompositeName
that spans more than one naming systemjavax.naming.NameNotFoundException - if name can not be foundjavax.naming.NotContextException - component of name is not bound to instance of
MockContext, when name is not atomic name.javax.naming.NamingException - if any other naming error occursContext.lookup(javax.naming.Name)public java.lang.Object lookup(java.lang.String name)
throws javax.naming.NamingException
lookup in interface javax.naming.Contextname - object to searchnamejavax.naming.NamingException - if naming error occurslookup(javax.naming.Name)public java.lang.Object lookupLink(javax.naming.Name arg0)
throws javax.naming.NamingException
lookupLink in interface javax.naming.Contextjavax.naming.NamingExceptionContext.lookupLink(javax.naming.Name)public java.lang.Object lookupLink(java.lang.String arg0)
throws javax.naming.NamingException
lookupLink in interface javax.naming.Contextjavax.naming.NamingExceptionContext.lookupLink(java.lang.String)public void rebind(javax.naming.Name name,
java.lang.Object obj)
throws javax.naming.NamingException
obj to name name.
If there is existing binding it will be overwritten.rebind in interface javax.naming.Contextname - name of the object to rebindobj - object to add. Can be nulljavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is empty or is
CompositeName that spans more than one naming systemjavax.naming.NotContextException - if name has more than one
atomic name and intermediate context is not foundjavax.naming.NamingException - if any other naming error occursContext.rebind(javax.naming.Name, java.lang.Object)public void rebind(java.lang.String name,
java.lang.Object obj)
throws javax.naming.NamingException
name is already bound in
the context, it will be re-bound to object objrebind in interface javax.naming.Contextname - name of the object to rebindobj - object to add. Can be nulljavax.naming.NamingException - if naming error occursrebind(javax.naming.Name, Object)public java.lang.Object removeFromEnvironment(java.lang.String arg0)
throws javax.naming.NamingException
removeFromEnvironment in interface javax.naming.Contextjavax.naming.NamingExceptionContext.removeFromEnvironment(java.lang.String)public void rename(javax.naming.Name arg0,
javax.naming.Name arg1)
throws javax.naming.NamingException
rename in interface javax.naming.Contextjavax.naming.NamingExceptionContext.rename(javax.naming.Name, javax.naming.Name)public void rename(java.lang.String arg0,
java.lang.String arg1)
throws javax.naming.NamingException
rename in interface javax.naming.Contextjavax.naming.NamingExceptionContext.rename(java.lang.String, java.lang.String)public void unbind(javax.naming.Name name)
throws javax.naming.NamingException
name and its associated object from the context.unbind in interface javax.naming.Contextname - name to removejavax.naming.NoPermissionException - if this context has been destroyedjavax.naming.InvalidNameException - if name is empty or is
CompositeName that spans more than one naming systemjavax.naming.NameNotFoundException - if intermediate context can not be foundjavax.naming.NotContextException - if name has more than one
atomic name and intermediate context is not foundjavax.naming.NamingException - if any other naming exception occursContext.unbind(javax.naming.Name)public void unbind(java.lang.String name)
throws javax.naming.NamingException
unbind in interface javax.naming.Contextname - object to removejavax.naming.NamingException - if naming error occursunbind(javax.naming.Name)