org.apache.xbean.naming.context
Class AbstractContext

java.lang.Object
  extended by org.apache.xbean.naming.context.AbstractContext
All Implemented Interfaces:
Serializable, Context, NestedContextFactory
Direct Known Subclasses:
AbstractFederatedContext, ImmutableContext, ImmutableContext.NestedImmutableContext

public abstract class AbstractContext
extends Object
implements Context, NestedContextFactory, Serializable

See Also:
Serialized Form

Field Summary
 
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
protected AbstractContext(String nameInNamespace)
           
  AbstractContext(String nameInNamespace, ContextAccess contextAccess)
           
 
Method Summary
protected  void addBinding(Context context, String name, Object value, boolean rebind)
          Binds the specified value to the specified name within the specified context.
protected abstract  boolean addBinding(String name, Object value, boolean rebind)
           
protected  void addDeepBinding(Name name, Object value, boolean rebind, boolean createIntermediateContexts)
           
 Object addToEnvironment(String propName, Object propVal)
           
 void bind(Name name, Object obj)
           
 void bind(String name, Object obj)
           
 void close()
           
 Name composeName(Name name, Name prefix)
           
 String composeName(String name, String prefix)
           
 Context createSubcontext(Name name)
           
 Context createSubcontext(String name)
           
protected  Context createSubcontextTree(String path, Name name, Object value)
          Creates a context tree which will be rooted at the specified path and contain a single entry located down a path specified by the name.
 void destroySubcontext(Name name)
           
 void destroySubcontext(String name)
           
protected  Object faultLookup(String stringName, Name parsedName)
          When a value can not be found within this context, this method is called as a last ditch effort befrore thowing a null pointer exception.
protected  Object getBinding(String name)
          Gets the object bound to the name.
protected abstract  Map<String,Object> getBindings()
          Gets a map of the bindings for the current node (i.e., no names with slashes).
protected  ContextAccess getContextAccess()
           
protected  Object getDeepBinding(String name)
          Gets the object bound to the name.
 Hashtable getEnvironment()
          Always returns a new (empty) Hashtable.
 String getNameInNamespace()
          Gets the name of this context withing the global namespace.
protected  Name getNameInNamespace(Name path)
          Gets the name of a path withing the global namespace context.
protected  String getNameInNamespace(String path)
          Gets the name of a path withing the global namespace context.
protected  NameParser getNameParser()
          A parser that can turn Strings into javax.naming.Name objects.
 NameParser getNameParser(Name name)
           
 NameParser getNameParser(String name)
           
protected  Name getParsedNameInNamespace()
          Gets the name of this context withing the global namespace.
protected static int getSize(Context context)
           
protected static boolean isEmpty(Context context)
           
protected  NamingEnumeration<NameClassPair> list()
           
 NamingEnumeration<NameClassPair> list(Name name)
           
 NamingEnumeration<NameClassPair> list(String name)
           
protected  NamingEnumeration<Binding> listBindings()
           
 NamingEnumeration<Binding> listBindings(Name name)
           
 NamingEnumeration<Binding> listBindings(String name)
           
 Object lookup(Name name)
           
 Object lookup(String name)
           
protected  Object lookup(String stringName, Name parsedName)
          Finds the specified entry.
protected  Context lookupFinalContext(Name name)
           
 Object lookupLink(Name name)
           
 Object lookupLink(String name)
           
 void rebind(Name name, Object obj)
           
 void rebind(String name, Object obj)
           
protected abstract  boolean removeBinding(String name, boolean removeNotEmptyContext)
          Removes the binding from the context.
protected  void removeDeepBinding(Name name, boolean pruneEmptyContexts)
           
protected  void removeDeepBinding(Name name, boolean pruneEmptyContexts, boolean removeNotEmptyContext)
           
 Object removeFromEnvironment(String propName)
           
 void rename(Name oldName, Name newName)
           
 void rename(String oldName, String newName)
           
 void unbind(Name name)
           
 void unbind(String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.xbean.naming.context.NestedContextFactory
createNestedSubcontext, isNestedSubcontext
 

Constructor Detail

AbstractContext

protected AbstractContext(String nameInNamespace)

AbstractContext

public AbstractContext(String nameInNamespace,
                       ContextAccess contextAccess)
Method Detail

close

public void close()
           throws NamingException
Specified by:
close in interface Context
Throws:
NamingException

getContextAccess

protected ContextAccess getContextAccess()

getDeepBinding

protected Object getDeepBinding(String name)
Gets the object bound to the name. The name may contain slashes.

Parameters:
name - the name
Returns:
the object bound to the name, or null if not found

getBinding

protected Object getBinding(String name)
                     throws NamingException
Gets the object bound to the name. The name will not contain slashes.

Parameters:
name - the name
Returns:
the object bound to the name, or null if not found
Throws:
NamingException - on error

lookup

protected Object lookup(String stringName,
                        Name parsedName)
                 throws NamingException
Finds the specified entry. Normally there is no need to override this method; instead you should simply implement the getDeepBindings(String) and getBindings(String) method. This method will follow links except for the final element which is always just returned without inspection. This means this method can be used to implement lookupLink.

Parameters:
stringName - the string version of the name; maybe null
parsedName - the parsed name; may be null
Returns:
the value bound to the name
Throws:
NamingException - if no value is bound to that name or if a problem occurs during the lookup

faultLookup

protected Object faultLookup(String stringName,
                             Name parsedName)
When a value can not be found within this context, this method is called as a last ditch effort befrore thowing a null pointer exception.

Parameters:
stringName - the string version of the name; will not be null
parsedName - the parsed name; will not be null
Returns:
the value or null if no fault value could be found

lookupFinalContext

protected Context lookupFinalContext(Name name)
                              throws NamingException
Throws:
NamingException

getBindings

protected abstract Map<String,Object> getBindings()
                                           throws NamingException
Gets a map of the bindings for the current node (i.e., no names with slashes). This method must not return null.

Returns:
a Map from binding name to binding value
Throws:
NamingException - if a problem occurs while getting the bindigns

addDeepBinding

protected void addDeepBinding(Name name,
                              Object value,
                              boolean rebind,
                              boolean createIntermediateContexts)
                       throws NamingException
Throws:
NamingException

addBinding

protected void addBinding(Context context,
                          String name,
                          Object value,
                          boolean rebind)
                   throws NamingException
Binds the specified value to the specified name within the specified context. If the specified context is an AbstractContext and is a nested subcontext, this method will call the direct addBinding method, otherwise it will call public (re)bind method.

Parameters:
context - the context to add the binding to
name - the binding name
value - the value to bind
rebind - if true, this method will replace any exsiting binding, otherwise a NamingException will be thrown
Throws:
NamingException - if a problem occurs while (re)binding

addBinding

protected abstract boolean addBinding(String name,
                                      Object value,
                                      boolean rebind)
                               throws NamingException
Throws:
NamingException

createSubcontextTree

protected Context createSubcontextTree(String path,
                                       Name name,
                                       Object value)
                                throws NamingException
Creates a context tree which will be rooted at the specified path and contain a single entry located down a path specified by the name. All necessary intermediate contexts will be created using the createContext method.

Parameters:
path - the path to the context that will contains this context
name - the name under which the value should be bound
value - the value
Returns:
a context with the value bound at the specified name
Throws:
NamingException - if a problem occurs while creating the subcontext tree

removeBinding

protected abstract boolean removeBinding(String name,
                                         boolean removeNotEmptyContext)
                                  throws NamingException
Removes the binding from the context. The name will not contain a path and the value will not be a nested context although it may be a foreign context.

Parameters:
name - name under which the value should be bound
removeNotEmptyContext - ??? TODO figure this out
Returns:
whether removal was successful
Throws:
NamingException - if a problem occurs during the bind such as a value already being bound

removeDeepBinding

protected void removeDeepBinding(Name name,
                                 boolean pruneEmptyContexts)
                          throws NamingException
Throws:
NamingException

removeDeepBinding

protected void removeDeepBinding(Name name,
                                 boolean pruneEmptyContexts,
                                 boolean removeNotEmptyContext)
                          throws NamingException
Throws:
NamingException

isEmpty

protected static boolean isEmpty(Context context)
                          throws NamingException
Throws:
NamingException

getSize

protected static int getSize(Context context)
                      throws NamingException
Throws:
NamingException

getEnvironment

public Hashtable getEnvironment()
Always returns a new (empty) Hashtable.

Specified by:
getEnvironment in interface Context
Returns:
a new (empty) Hashtable

addToEnvironment

public Object addToEnvironment(String propName,
                               Object propVal)
                        throws NamingException
Specified by:
addToEnvironment in interface Context
Throws:
NamingException

removeFromEnvironment

public Object removeFromEnvironment(String propName)
                             throws NamingException
Specified by:
removeFromEnvironment in interface Context
Throws:
NamingException

getNameInNamespace

public String getNameInNamespace()
Gets the name of this context withing the global namespace. This method may return null if the location of the node in the global namespace is not known

Specified by:
getNameInNamespace in interface Context
Returns:
the name of this context within the global namespace or null if unknown.

getParsedNameInNamespace

protected Name getParsedNameInNamespace()
Gets the name of this context withing the global namespace. This method may return null if the location of the node in the global namespace is not known

Returns:
the name of this context within the global namespace or null if unknown.

getNameInNamespace

protected String getNameInNamespace(String path)
Gets the name of a path withing the global namespace context.

Parameters:
path - path to extend
Returns:
full path in namespace

getNameInNamespace

protected Name getNameInNamespace(Name path)
                           throws NamingException
Gets the name of a path withing the global namespace context.

Parameters:
path - path to extend
Returns:
full path in namespace
Throws:
NamingException - on error

getNameParser

protected NameParser getNameParser()
A parser that can turn Strings into javax.naming.Name objects.

Returns:
ContextUtil.NAME_PARSER

getNameParser

public NameParser getNameParser(Name name)
Specified by:
getNameParser in interface Context

getNameParser

public NameParser getNameParser(String name)
Specified by:
getNameParser in interface Context

composeName

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

composeName

public String composeName(String name,
                          String prefix)
                   throws NamingException
Specified by:
composeName in interface Context
Throws:
NamingException

lookup

public Object lookup(String name)
              throws NamingException
Specified by:
lookup in interface Context
Throws:
NamingException

lookup

public Object lookup(Name name)
              throws NamingException
Specified by:
lookup in interface Context
Throws:
NamingException

lookupLink

public Object lookupLink(String name)
                  throws NamingException
Specified by:
lookupLink in interface Context
Throws:
NamingException

lookupLink

public Object lookupLink(Name name)
                  throws NamingException
Specified by:
lookupLink in interface Context
Throws:
NamingException

bind

public void bind(String name,
                 Object obj)
          throws NamingException
Specified by:
bind in interface Context
Throws:
NamingException

bind

public void bind(Name name,
                 Object obj)
          throws NamingException
Specified by:
bind in interface Context
Throws:
NamingException

rebind

public void rebind(String name,
                   Object obj)
            throws NamingException
Specified by:
rebind in interface Context
Throws:
NamingException

rebind

public void rebind(Name name,
                   Object obj)
            throws NamingException
Specified by:
rebind in interface Context
Throws:
NamingException

rename

public void rename(String oldName,
                   String newName)
            throws NamingException
Specified by:
rename in interface Context
Throws:
NamingException

rename

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

unbind

public void unbind(String name)
            throws NamingException
Specified by:
unbind in interface Context
Throws:
NamingException

unbind

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

list

protected NamingEnumeration<NameClassPair> list()
                                         throws NamingException
Throws:
NamingException

listBindings

protected NamingEnumeration<Binding> listBindings()
                                           throws NamingException
Throws:
NamingException

list

public NamingEnumeration<NameClassPair> list(String name)
                                      throws NamingException
Specified by:
list in interface Context
Throws:
NamingException

list

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

listBindings

public NamingEnumeration<Binding> listBindings(String name)
                                        throws NamingException
Specified by:
listBindings in interface Context
Throws:
NamingException

listBindings

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

createSubcontext

public Context createSubcontext(String name)
                         throws NamingException
Specified by:
createSubcontext in interface Context
Throws:
NamingException

createSubcontext

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

destroySubcontext

public void destroySubcontext(String name)
                       throws NamingException
Specified by:
destroySubcontext in interface Context
Throws:
NamingException

destroySubcontext

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


Copyright © 2005-2013. All Rights Reserved.