org.springframework.mock.jndi
Class SimpleNamingContext

java.lang.Object
  extended by org.springframework.mock.jndi.SimpleNamingContext
All Implemented Interfaces:
javax.naming.Context

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

Simple implementation of a JNDI naming context. Only supports binding plain Objects to String names. Mainly for test environments, but also usable for standalone applications.

This class is not intended for direct usage by applications, although it can be used for example to override JndiTemplate's createInitialContext method in unit tests. Typically, SimpleNamingContextBuilder will be used to set up a JVM-level JNDI environment.

Author:
Rod Johnson, Juergen Hoeller
See Also:
SimpleNamingContextBuilder, JndiTemplate.createInitialContext()

Nested Class Summary
private static class SimpleNamingContext.AbstractNamingEnumeration<T>
           
private static class SimpleNamingContext.BindingEnumeration
           
private static class SimpleNamingContext.NameClassPairEnumeration
           
 
Field Summary
private  java.util.Hashtable<java.lang.String,java.lang.Object> boundObjects
           
private  java.util.Hashtable<java.lang.String,java.lang.Object> environment
           
private  Log logger
           
private  java.lang.String root
           
 
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
SimpleNamingContext()
          Create a new naming context.
SimpleNamingContext(java.lang.String root)
          Create a new naming context with the given naming root.
SimpleNamingContext(java.lang.String root, java.util.Hashtable<java.lang.String,java.lang.Object> boundObjects, java.util.Hashtable<java.lang.String,java.lang.Object> env)
          Create a new naming context with the given naming root, the given name/object map, and the JNDI environment entries.
 
Method Summary
 java.lang.Object addToEnvironment(java.lang.String propName, java.lang.Object propVal)
           
 void bind(javax.naming.Name name, java.lang.Object obj)
           
 void bind(java.lang.String name, java.lang.Object obj)
          Bind the given object to the given name.
 void close()
           
 javax.naming.Name composeName(javax.naming.Name name, javax.naming.Name prefix)
           
 java.lang.String composeName(java.lang.String name, java.lang.String prefix)
           
 javax.naming.Context createSubcontext(javax.naming.Name name)
           
 javax.naming.Context createSubcontext(java.lang.String name)
           
 void destroySubcontext(javax.naming.Name name)
           
 void destroySubcontext(java.lang.String name)
           
 java.util.Hashtable<java.lang.String,java.lang.Object> getEnvironment()
           
 java.lang.String getNameInNamespace()
           
 javax.naming.NameParser getNameParser(javax.naming.Name name)
           
 javax.naming.NameParser getNameParser(java.lang.String name)
           
 javax.naming.NamingEnumeration<javax.naming.NameClassPair> list(javax.naming.Name name)
           
 javax.naming.NamingEnumeration<javax.naming.NameClassPair> list(java.lang.String root)
           
 javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(javax.naming.Name name)
           
 javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(java.lang.String root)
           
 java.lang.Object lookup(javax.naming.Name name)
           
 java.lang.Object lookup(java.lang.String lookupName)
          Look up the object with the given name.
 java.lang.Object lookupLink(javax.naming.Name name)
           
 java.lang.Object lookupLink(java.lang.String name)
           
 void rebind(javax.naming.Name name, java.lang.Object obj)
           
 void rebind(java.lang.String name, java.lang.Object obj)
           
 java.lang.Object removeFromEnvironment(java.lang.String propName)
           
 void rename(javax.naming.Name oldName, javax.naming.Name newName)
           
 void rename(java.lang.String oldName, java.lang.String newName)
           
 void unbind(javax.naming.Name name)
           
 void unbind(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private final Log logger

root

private final java.lang.String root

boundObjects

private final java.util.Hashtable<java.lang.String,java.lang.Object> boundObjects

environment

private final java.util.Hashtable<java.lang.String,java.lang.Object> environment
Constructor Detail

SimpleNamingContext

public SimpleNamingContext()
Create a new naming context.


SimpleNamingContext

public SimpleNamingContext(java.lang.String root)
Create a new naming context with the given naming root.


SimpleNamingContext

public SimpleNamingContext(java.lang.String root,
                           java.util.Hashtable<java.lang.String,java.lang.Object> boundObjects,
                           java.util.Hashtable<java.lang.String,java.lang.Object> env)
Create a new naming context with the given naming root, the given name/object map, and the JNDI environment entries.

Method Detail

list

public javax.naming.NamingEnumeration<javax.naming.NameClassPair> list(java.lang.String root)
                                                                throws javax.naming.NamingException
Specified by:
list in interface javax.naming.Context
Throws:
javax.naming.NamingException

listBindings

public javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(java.lang.String root)
                                                                  throws javax.naming.NamingException
Specified by:
listBindings in interface javax.naming.Context
Throws:
javax.naming.NamingException

lookup

public java.lang.Object lookup(java.lang.String lookupName)
                        throws javax.naming.NameNotFoundException
Look up the object with the given name.

Note: Not intended for direct use by applications. Will be used by any standard InitialContext JNDI lookups.

Specified by:
lookup in interface javax.naming.Context
Throws:
javax.naming.NameNotFoundException - if the object could not be found

lookupLink

public java.lang.Object lookupLink(java.lang.String name)
                            throws javax.naming.NameNotFoundException
Specified by:
lookupLink in interface javax.naming.Context
Throws:
javax.naming.NameNotFoundException

bind

public void bind(java.lang.String name,
                 java.lang.Object obj)
Bind the given object to the given name. Note: Not intended for direct use by applications if setting up a JVM-level JNDI environment. Use SimpleNamingContextBuilder to set up JNDI bindings then.

Specified by:
bind in interface javax.naming.Context
See Also:
SimpleNamingContextBuilder.bind(java.lang.String, java.lang.Object)

unbind

public void unbind(java.lang.String name)
Specified by:
unbind in interface javax.naming.Context

rebind

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

rename

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

createSubcontext

public javax.naming.Context createSubcontext(java.lang.String name)
Specified by:
createSubcontext in interface javax.naming.Context

destroySubcontext

public void destroySubcontext(java.lang.String name)
Specified by:
destroySubcontext in interface javax.naming.Context

composeName

public java.lang.String composeName(java.lang.String name,
                                    java.lang.String prefix)
Specified by:
composeName in interface javax.naming.Context

getEnvironment

public java.util.Hashtable<java.lang.String,java.lang.Object> getEnvironment()
Specified by:
getEnvironment in interface javax.naming.Context

addToEnvironment

public java.lang.Object addToEnvironment(java.lang.String propName,
                                         java.lang.Object propVal)
Specified by:
addToEnvironment in interface javax.naming.Context

removeFromEnvironment

public java.lang.Object removeFromEnvironment(java.lang.String propName)
Specified by:
removeFromEnvironment in interface javax.naming.Context

close

public void close()
Specified by:
close in interface javax.naming.Context

list

public javax.naming.NamingEnumeration<javax.naming.NameClassPair> list(javax.naming.Name name)
                                                                throws javax.naming.NamingException
Specified by:
list in interface javax.naming.Context
Throws:
javax.naming.NamingException

listBindings

public javax.naming.NamingEnumeration<javax.naming.Binding> listBindings(javax.naming.Name name)
                                                                  throws javax.naming.NamingException
Specified by:
listBindings in interface javax.naming.Context
Throws:
javax.naming.NamingException

lookup

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

lookupLink

public java.lang.Object lookupLink(javax.naming.Name name)
                            throws javax.naming.NamingException
Specified by:
lookupLink 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
Specified by:
bind in interface javax.naming.Context
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

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

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

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(javax.naming.Name name)
                       throws javax.naming.NamingException
Specified by:
destroySubcontext 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

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

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

composeName

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