com.caucho.naming
Class ContextImpl

java.lang.Object
  extended by com.caucho.naming.ContextImpl
All Implemented Interfaces:
javax.naming.Context
Direct Known Subclasses:
BurlapContextImpl, DirContextImpl, HessianContext, HessianContextImpl, MBeanContextImpl

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

Resin's implementation of the JNDI Context. The actual storage of the persistent data is in the AbstractModel.

The ContextImpl is just a Visitor around the AbstractModel which also encapsulate the JNDI environment.

In JNDI, each Context is a <model, env> pair. Each client might pass a different environment to the InitialContext so each ContextImpl must be unique for each client. (Granted, this is a bit wasteful of space which is why JNDI values should be cached.)

Applications which want a different model can still use ContextImpl and specify the root object for AbstractModel. ContextImpl will take care of the JNDI API for the model.


Field Summary
protected  java.util.Hashtable<java.lang.String,java.lang.Object> _env
           
protected  AbstractModel _model
           
protected  java.lang.String _name
           
protected static L10N L
           
protected static java.util.logging.Logger log
           
 
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
 
Constructor Summary
ContextImpl(AbstractModel model, java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Creates a ContextImpl.
ContextImpl(java.lang.String name, AbstractModel model, java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Creates a ContextImpl.
 
Method Summary
 java.lang.Object addToEnvironment(java.lang.String prop, java.lang.Object value)
          Adds a property to the context environment.
 void bind(javax.naming.Name name, java.lang.Object obj)
          Binds an object to the context.
 void bind(java.lang.String name, java.lang.Object obj)
          Binds an object to the context.
 void close()
          Close is intended to free any transient data, like a cached socket.
 javax.naming.Name composeName(javax.naming.Name suffix, javax.naming.Name prefix)
           
 java.lang.String composeName(java.lang.String suffix, java.lang.String prefix)
           
protected  ContextImpl create(AbstractModel model, java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Creates a new ContextImpl when the name is irrelevant.
protected  ContextImpl create(java.lang.String name, AbstractModel model, java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Creates a new instance of the ContextImpl.
protected  javax.naming.Context createSingleSubcontext(java.lang.String name)
           
 javax.naming.Context createSubcontext(javax.naming.Name name)
           
 javax.naming.Context createSubcontext(java.lang.String name)
          Creates a subcontext for the current model.
protected  void destroySingleSubcontext(java.lang.String name)
           
 void destroySubcontext(javax.naming.Name name)
           
 void destroySubcontext(java.lang.String name)
          Destroys the named subcontext.
 java.util.Hashtable getEnvironment()
          Returns the context environment.
protected  java.lang.String getFullPath(javax.naming.Name name)
          Returns the full name for the context.
protected  java.lang.String getFullPath(java.lang.String name)
          Returns the full name for the context.
 AbstractModel getModel()
          Returns the underlying storage node.
 java.lang.String getName()
          Returns the name.
 java.lang.String getNameInNamespace()
           
 javax.naming.NameParser getNameParser(javax.naming.Name name)
           
 javax.naming.NameParser getNameParser(java.lang.String name)
           
protected  char getSeparator()
           
protected  java.lang.String getSeparatorString()
           
 javax.naming.NamingEnumeration list(javax.naming.Name name)
          Lists the names for the context.
 javax.naming.NamingEnumeration list(java.lang.String name)
          List the names for a context.
 javax.naming.NamingEnumeration listBindings(javax.naming.Name name)
          Lists the bindings for the given name.
 javax.naming.NamingEnumeration listBindings(java.lang.String name)
          List the bindings for a context.
protected  java.util.Iterator listSingle()
           
 java.lang.Object lookup(javax.naming.Name name)
          Looks up an object with the given parsed JNDI name.
 java.lang.Object lookup(java.lang.String name)
          Looks up an object using its full string name.
protected  java.lang.Object lookupImpl(java.lang.String name)
          Looks up an object using its full string name.
 java.lang.Object lookupLink(javax.naming.Name name)
          Looks up an object with the given parsed JNDI name, but don't dereference the final object.
 java.lang.Object lookupLink(java.lang.String name)
          Looks up an object given the name, but doesn't dereference links.
protected  java.lang.Object lookupSingle(java.lang.String name)
          Returns the object named by the single name segment.
protected  java.lang.String parseFirst(java.lang.String name)
           
protected  java.lang.String parseRest(java.lang.String name)
           
 void rebind(javax.naming.Name name, java.lang.Object obj)
           
 void rebind(java.lang.String name, java.lang.Object obj)
          Binds an object to the context, overriding any old value.
protected  void rebindSingle(java.lang.String name, java.lang.Object obj)
           
 java.lang.Object removeFromEnvironment(java.lang.String prop)
          Removes a property from the context environment.
 void rename(javax.naming.Name oldName, javax.naming.Name newName)
           
 void rename(java.lang.String oldName, java.lang.String newName)
           
 java.lang.String toString()
          Returns a string value.
 void unbind(javax.naming.Name name)
           
 void unbind(java.lang.String name)
          Unbinds an object from the context.
protected  void unbindSingle(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final java.util.logging.Logger log

L

protected static final L10N L

_env

protected java.util.Hashtable<java.lang.String,java.lang.Object> _env

_model

protected AbstractModel _model

_name

protected java.lang.String _name
Constructor Detail

ContextImpl

public ContextImpl(AbstractModel model,
                   java.util.Hashtable<java.lang.String,java.lang.Object> env)
Creates a ContextImpl.

Parameters:
model - The underlying storage node.
env - The client's JNDI environment.

ContextImpl

public ContextImpl(java.lang.String name,
                   AbstractModel model,
                   java.util.Hashtable<java.lang.String,java.lang.Object> env)
Creates a ContextImpl.

Parameters:
name - JNDI name, used for error messages, etc.
model - The underlying storage node.
env - The client's JNDI environment.
Method Detail

create

protected ContextImpl create(java.lang.String name,
                             AbstractModel model,
                             java.util.Hashtable<java.lang.String,java.lang.Object> env)
Creates a new instance of the ContextImpl. Subclasses will override this method to return a new instance of the subclass.

Parameters:
name - the JNDI name for the new context
model - the underlying storage node
env - the client's JNDI environment.
Returns:
a new instance of the implementing class.

create

protected final ContextImpl create(AbstractModel model,
                                   java.util.Hashtable<java.lang.String,java.lang.Object> env)
Creates a new ContextImpl when the name is irrelevant.

Parameters:
model - the underlying storage node
env - the client's JNDI environment.
Returns:
a new instance of the implementing class.

getModel

public AbstractModel getModel()
Returns the underlying storage node.


getName

public java.lang.String getName()
Returns the name.


lookup

public java.lang.Object lookup(java.lang.String name)
                        throws javax.naming.NamingException
Looks up an object using its full string name. The path is searched recursively. parseFirst returns the first segment. The

Specified by:
lookup in interface javax.naming.Context
Parameters:
name - the JNDI name to lookup for the child.
Returns:
the retrieved object
Throws:
javax.naming.NamingException

lookupImpl

protected java.lang.Object lookupImpl(java.lang.String name)
                               throws javax.naming.NamingException
Looks up an object using its full string name. The path is searched recursively. parseFirst returns the first segment. The

Parameters:
name - the JNDI name to lookup for the child.
Returns:
the retrieved object
Throws:
javax.naming.NamingException

lookup

public java.lang.Object lookup(javax.naming.Name name)
                        throws javax.naming.NamingException
Looks up an object with the given parsed JNDI name.

Specified by:
lookup in interface javax.naming.Context
Throws:
javax.naming.NamingException

lookupLink

public java.lang.Object lookupLink(java.lang.String name)
                            throws javax.naming.NamingException
Looks up an object given the name, but doesn't dereference links.

Specified by:
lookupLink in interface javax.naming.Context
Throws:
javax.naming.NamingException

lookupLink

public java.lang.Object lookupLink(javax.naming.Name name)
                            throws javax.naming.NamingException
Looks up an object with the given parsed JNDI name, but don't dereference the final object.

Specified by:
lookupLink in interface javax.naming.Context
Throws:
javax.naming.NamingException

bind

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

Specified by:
bind in interface javax.naming.Context
Throws:
javax.naming.NamingException

bind

public void bind(javax.naming.Name name,
                 java.lang.Object obj)
          throws javax.naming.NamingException
Binds an object to the context.

Specified by:
bind in interface javax.naming.Context
Throws:
javax.naming.NamingException

rebind

public void rebind(java.lang.String name,
                   java.lang.Object obj)
            throws javax.naming.NamingException
Binds an object to the context, overriding any old value.

Specified by:
rebind in interface javax.naming.Context
Parameters:
name - the name to bind
obj - the object to bind
Throws:
javax.naming.NamingException

rebind

public void rebind(javax.naming.Name name,
                   java.lang.Object obj)
            throws javax.naming.NamingException
Specified by:
rebind in interface javax.naming.Context
Throws:
javax.naming.NamingException

unbind

public void unbind(java.lang.String name)
            throws javax.naming.NamingException
Unbinds an object from the context.

Specified by:
unbind in interface javax.naming.Context
Parameters:
name - the name to unbind
Throws:
javax.naming.NamingException

unbind

public void unbind(javax.naming.Name name)
            throws javax.naming.NamingException
Specified by:
unbind in interface javax.naming.Context
Throws:
javax.naming.NamingException

rename

public void rename(java.lang.String oldName,
                   java.lang.String newName)
            throws javax.naming.NamingException
Specified by:
rename in interface javax.naming.Context
Throws:
javax.naming.NamingException

rename

public void rename(javax.naming.Name oldName,
                   javax.naming.Name newName)
            throws javax.naming.NamingException
Specified by:
rename in interface javax.naming.Context
Throws:
javax.naming.NamingException

list

public javax.naming.NamingEnumeration list(java.lang.String name)
                                    throws javax.naming.NamingException
List the names for a context.

Specified by:
list in interface javax.naming.Context
Throws:
javax.naming.NamingException

list

public javax.naming.NamingEnumeration list(javax.naming.Name name)
                                    throws javax.naming.NamingException
Lists the names for the context.

Specified by:
list in interface javax.naming.Context
Throws:
javax.naming.NamingException

listBindings

public javax.naming.NamingEnumeration listBindings(java.lang.String name)
                                            throws javax.naming.NamingException
List the bindings for a context.

Specified by:
listBindings in interface javax.naming.Context
Throws:
javax.naming.NamingException

listBindings

public javax.naming.NamingEnumeration listBindings(javax.naming.Name name)
                                            throws javax.naming.NamingException
Lists the bindings for the given name.

Specified by:
listBindings in interface javax.naming.Context
Throws:
javax.naming.NamingException

createSubcontext

public javax.naming.Context createSubcontext(java.lang.String name)
                                      throws javax.naming.NamingException
Creates a subcontext for the current model.

Specified by:
createSubcontext in interface javax.naming.Context
Throws:
javax.naming.NamingException

createSubcontext

public javax.naming.Context createSubcontext(javax.naming.Name name)
                                      throws javax.naming.NamingException
Specified by:
createSubcontext in interface javax.naming.Context
Throws:
javax.naming.NamingException

destroySubcontext

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

Specified by:
destroySubcontext in interface javax.naming.Context
Throws:
javax.naming.NamingException

destroySubcontext

public void destroySubcontext(javax.naming.Name name)
                       throws javax.naming.NamingException
Specified by:
destroySubcontext in interface javax.naming.Context
Throws:
javax.naming.NamingException

getNameParser

public javax.naming.NameParser getNameParser(java.lang.String name)
                                      throws javax.naming.NamingException
Specified by:
getNameParser in interface javax.naming.Context
Throws:
javax.naming.NamingException

getNameParser

public javax.naming.NameParser getNameParser(javax.naming.Name name)
                                      throws javax.naming.NamingException
Specified by:
getNameParser in interface javax.naming.Context
Throws:
javax.naming.NamingException

composeName

public java.lang.String composeName(java.lang.String suffix,
                                    java.lang.String prefix)
                             throws javax.naming.NamingException
Specified by:
composeName in interface javax.naming.Context
Throws:
javax.naming.NamingException

composeName

public javax.naming.Name composeName(javax.naming.Name suffix,
                                     javax.naming.Name prefix)
                              throws javax.naming.NamingException
Specified by:
composeName in interface javax.naming.Context
Throws:
javax.naming.NamingException

getNameInNamespace

public java.lang.String getNameInNamespace()
                                    throws javax.naming.NamingException
Specified by:
getNameInNamespace in interface javax.naming.Context
Throws:
javax.naming.NamingException

lookupSingle

protected java.lang.Object lookupSingle(java.lang.String name)
                                 throws javax.naming.NamingException
Returns the object named by the single name segment.

Parameters:
name - the name segment.
Returns:
the object bound to the context.
Throws:
javax.naming.NamingException

rebindSingle

protected void rebindSingle(java.lang.String name,
                            java.lang.Object obj)
                     throws javax.naming.NamingException
Throws:
javax.naming.NamingException

unbindSingle

protected void unbindSingle(java.lang.String name)
                     throws javax.naming.NamingException
Throws:
javax.naming.NamingException

createSingleSubcontext

protected javax.naming.Context createSingleSubcontext(java.lang.String name)
                                               throws javax.naming.NamingException
Throws:
javax.naming.NamingException

destroySingleSubcontext

protected void destroySingleSubcontext(java.lang.String name)
                                throws javax.naming.NamingException
Throws:
javax.naming.NamingException

listSingle

protected java.util.Iterator listSingle()

parseFirst

protected java.lang.String parseFirst(java.lang.String name)
                               throws javax.naming.NamingException
Throws:
javax.naming.NamingException

parseRest

protected java.lang.String parseRest(java.lang.String name)
                              throws javax.naming.NamingException
Throws:
javax.naming.NamingException

getSeparator

protected char getSeparator()

getSeparatorString

protected java.lang.String getSeparatorString()

getFullPath

protected java.lang.String getFullPath(java.lang.String name)
Returns the full name for the context.


getFullPath

protected java.lang.String getFullPath(javax.naming.Name name)
Returns the full name for the context.


addToEnvironment

public java.lang.Object addToEnvironment(java.lang.String prop,
                                         java.lang.Object value)
                                  throws javax.naming.NamingException
Adds a property to the context environment.

Specified by:
addToEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException

removeFromEnvironment

public java.lang.Object removeFromEnvironment(java.lang.String prop)
                                       throws javax.naming.NamingException
Removes a property from the context environment.

Specified by:
removeFromEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException

getEnvironment

public java.util.Hashtable getEnvironment()
                                   throws javax.naming.NamingException
Returns the context environment.

Specified by:
getEnvironment in interface javax.naming.Context
Throws:
javax.naming.NamingException

close

public void close()
           throws javax.naming.NamingException
Close is intended to free any transient data, like a cached socket. It does not affect the JNDI tree.

Specified by:
close in interface javax.naming.Context
Throws:
javax.naming.NamingException

toString

public java.lang.String toString()
Returns a string value.

Overrides:
toString in class java.lang.Object