| java.lang.Object org.mockejb.jndi.MockContext
MockContext | public class MockContext implements Context(Code) | | Provides implementation of 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 to
myObject = 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.
author: Alexander Ananiev author: Dimitar Gospodinov |
Constructor Summary | |
protected | MockContext(Context remoteContext) Creates a new instance of the context. |
Method Summary | |
public Object | addToEnvironment(String arg0, Object arg1) | public void | bind(Name name, Object obj) Binds object obj to name name in this context.
Intermediate contexts that do not exist will be created. | public void | bind(String name, Object obj) Binds object obj to name name in this context. | public void | close() Does nothing. | public Name | composeName(Name name, Name prefix) Returns composition of prefix and name . | public String | composeName(String name, String prefix) Composes the name of this context with a name relative to this context. | public Context | createSubcontext(Name name) Creates subcontext with name name , relative to this Context.
Parameters: name - subcontext name. | public Context | createSubcontext(String name) Creates subcontext with name name , relative to this Context. | public void | destroySubcontext(Name name) Destroys subcontext with name name
The subcontext must be empty otherwise ContextNotEmptyException
is thrown. | public void | destroySubcontext(String name) | String | getAtomicName() Returns the "atomic" (as opposed to "composite") name of the context. | String | getCompoundStringName() Returns the compound string name of this context.
Suppose a/b/c/d is the full name and this context is "c". | public Hashtable | getEnvironment() | public String | getNameInNamespace() | public NameParser | getNameParser(Name name) Retrieves name parser used to parse context with name name . | public NameParser | getNameParser(String name) Retrieves name parser used to parse context with name name . | MockContext | getParentContext() | boolean | isRootContext() | public NamingEnumeration | list(Name name) The same as listBindings(String)
Parameters: name - name of Context, relative to this Context NamingEnumeration of all name-class pairs. | public NamingEnumeration | list(String name) The same as listBindings(String)
Parameters: name - name of Context, relative to this Context NamingEnumeration of all name-class pairs. | public NamingEnumeration | listBindings(Name name) Lists all bindings for Context with name name .
If name is empty then this Context is assumed.
Parameters: name - name of Context, relative to this Context NamingEnumeration of all name-object pairs. | public NamingEnumeration | listBindings(String name) Lists all bindings for Context with name name .
If name is empty then this Context is assumed.
Parameters: name - name of Context, relative to this Context NamingEnumeration of all name-object pairs. | public Object | lookup(Name name) Looks up object with name name in this context. | public Object | lookup(String name) Looks up the object in this context. | public Object | lookupLink(Name arg0) | public Object | lookupLink(String arg0) | public void | rebind(Name name, Object obj) Rebinds object obj to name name .
If there is existing binding it will be overwritten.
Parameters: name - name of the object to rebind Parameters: obj - object to add. | public 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
Parameters: name - name of the object to rebind Parameters: obj - object to add. | public Object | removeFromEnvironment(String arg0) | public void | rename(Name arg0, Name arg1) | public void | rename(String arg0, String arg1) | public void | unbind(Name name) Removes name and its associated object from the context. | public void | unbind(String name) |
MockContext | protected MockContext(Context remoteContext)(Code) | | Creates a new instance of the context.
This class can only be instantiated by its factory.
Parameters: remoteContext - remote context that MockContext will delegate to if it fails to lookup an object locally |
composeName | public String composeName(String name, String prefix) throws NamingException(Code) | | 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
Parameters: name - name relative to this context Parameters: prefix - name of this context See Also: javax.naming.Context.composeName(java.lang.Stringjava.lang.String) |
getAtomicName | String getAtomicName()(Code) | | Returns the "atomic" (as opposed to "composite") name of the context.
name of the context |
getCompoundStringName | String getCompoundStringName() throws NamingException(Code) | | Returns the compound string name of this context.
Suppose a/b/c/d is the full name and this context is "c".
It's compound string name is a/b/c
compound string name of the context |
getParentContext | MockContext getParentContext()(Code) | | Returns parent context of this context
|
isRootContext | boolean isRootContext()(Code) | | Returns true if this context is the root context
true if the context is the root context |
|
|