org.mortbay.jndi

Class NamingContext

Implemented Interfaces:
Cloneable, Context

public class NamingContext
extends java.lang.Object
implements Context, Cloneable

NamingContext

Implementation of Context interface.

Notes

All Names are expected to be Compound, not Composite.

Usage

Nested Class Summary

class
NamingContext.BindingEnumeration
BindingEnumeration

Implementation of NamingEnumeration

Notes

Used to return results of Context.listBindings();

Usage

class
NamingContext.NameEnumeration
NameEnumeration

Implementation of NamingEnumeration interface.

Field Summary

static Enumeration
EMPTY_ENUM
static String
IMMUTABLE_PROPERTY
protected Hashtable
_bindings
protected Hashtable
_env
protected String
_name
protected Context
_parent
protected NameParser
_parser

Constructor Summary

NamingContext()
Constructor
NamingContext(Hashtable env)
Creates a new NamingContext instance.
NamingContext(Hashtable env, String name, Context parent, NameParser parser)
Constructor

Method Summary

protected void
addBinding(Name name, Object obj)
Add a name to object binding to this Context.
Object
addToEnvironment(String propName, Object propVal)
Add an environment setting to this Context
void
bind(Name name, Object obj)
Bind a name to an object
void
bind(String name, Object obj)
Bind a name (as a String) to an object
Object
clone()
Clone this NamingContext
void
close()
Do nothing
Name
composeName(Name name, Name prefix)
Join two names together.
String
composeName(String name, String prefix)
Join two names together.
Context
createSubcontext(Name name)
Create a context as a child of this one
Context
createSubcontext(String name)
Create a Context as a child of this one
void
destroySubcontext(Name name)
Not supported
void
destroySubcontext(String name)
Not supported
protected Binding
getBinding(Name name)
Get a name to object binding from this Context
protected Binding
getBinding(String name)
Get a name to object binding from this Context
Hashtable
getEnvironment()
Get the environment of this Context.
String
getName()
Getter for _name
String
getNameInNamespace()
Get the full name of this Context node by visiting it's ancestors back to root.
NameParser
getNameParser(Name name)
Return a NameParser for this Context.
NameParser
getNameParser(String name)
Return a NameParser for this Context.
Context
getParent()
Getter for _parent
NamingEnumeration
list(Name name)
List all names bound at Context named by Name
NamingEnumeration
list(String name)
List all names bound at Context named by Name
NamingEnumeration
listBindings(Name name)
List all Bindings present at Context named by Name
NamingEnumeration
listBindings(String name)
List all Bindings at Name
Object
lookup(Name name)
Lookup a binding by name
Object
lookup(String name)
Lookup binding of an object by name
Object
lookupLink(Name name)
Lookup link bound to name
Object
lookupLink(String name)
Lookup link bound to name
void
rebind(Name name, Object obj)
Overwrite or create a binding
void
rebind(String name, Object obj)
Overwrite or create a binding from Name to Object
Object
removeFromEnvironment(String propName)
Remove a property from this Context's environment.
void
rename(Name oldName, Name newName)
Not supported
void
rename(String oldName, String newName)
Not supported
void
setNameParser(NameParser parser)
Setter for _parser
Name
toCanonicalName(Name name)
Remove leading or trailing empty components from name.
void
unbind(Name name)
Not supported.
void
unbind(String name)
Not supported.

Field Details

EMPTY_ENUM

public static final Enumeration EMPTY_ENUM

IMMUTABLE_PROPERTY

public static final String IMMUTABLE_PROPERTY

_bindings

protected Hashtable _bindings

_env

protected Hashtable _env

_name

protected String _name

_parent

protected Context _parent

_parser

protected NameParser _parser

Constructor Details

NamingContext

public NamingContext()
Constructor

NamingContext

public NamingContext(Hashtable env)
Creates a new NamingContext instance.
Parameters:
env - a Hashtable value

NamingContext

public NamingContext(Hashtable env,
                     String name,
                     Context parent,
                     NameParser parser)
Constructor
Parameters:
env - environment properties
name - relative name of this context
parent - immediate ancestor Context (can be null)
parser - NameParser for this Context

Method Details

addBinding

protected void addBinding(Name name,
                          Object obj)
Add a name to object binding to this Context.
Parameters:
name - a Name value
obj - an Object value

addToEnvironment

public Object addToEnvironment(String propName,
                               Object propVal)
            throws NamingException
Add an environment setting to this Context
Parameters:
propName - name of the property to add
propVal - value of the property to add
Returns:
propVal or previous value of the property

bind

public void bind(Name name,
                 Object obj)
            throws NamingException
Bind a name to an object
Parameters:
name - Name of the object
obj - object to bind

bind

public void bind(String name,
                 Object obj)
            throws NamingException
Bind a name (as a String) to an object
Parameters:
name - a String value
obj - an Object value

clone

public Object clone()
            throws CloneNotSupportedException
Clone this NamingContext
Returns:
copy of this NamingContext

close

public void close()
            throws NamingException
Do nothing

composeName

public Name composeName(Name name,
                        Name prefix)
            throws NamingException
Join two names together. These are treated as CompoundNames.
Parameters:
name - a Name value
prefix - a Name value
Returns:
a Name value

composeName

public String composeName(String name,
                          String prefix)
            throws NamingException
Join two names together. These are treated as CompoundNames.
Parameters:
name - a Name value
prefix - a Name value
Returns:
a Name value

createSubcontext

public Context createSubcontext(Name name)
            throws NamingException
Create a context as a child of this one
Parameters:
name - a Name value
Returns:
a Context value

createSubcontext

public Context createSubcontext(String name)
            throws NamingException
Create a Context as a child of this one
Parameters:
name - a String value
Returns:
a Context value

destroySubcontext

public void destroySubcontext(Name name)
            throws NamingException
Not supported
Parameters:
name - name of subcontext to remove

destroySubcontext

public void destroySubcontext(String name)
            throws NamingException
Not supported
Parameters:
name - name of subcontext to remove

getBinding

protected Binding getBinding(Name name)
Get a name to object binding from this Context
Parameters:
name - a Name value
Returns:
a Binding value

getBinding

protected Binding getBinding(String name)
Get a name to object binding from this Context
Parameters:
name - as a String
Returns:
null or the Binding

getEnvironment

public Hashtable getEnvironment()
Get the environment of this Context.
Returns:
a copy of the environment of this Context.

getName

public String getName()
Getter for _name
Returns:
name of this Context (relative, not absolute)

getNameInNamespace

public String getNameInNamespace()
            throws NamingException
Get the full name of this Context node by visiting it's ancestors back to root. NOTE: if this Context has a URL namespace then the URL prefix will be missing
Returns:
the full name of this Context

getNameParser

public NameParser getNameParser(Name name)
Return a NameParser for this Context.
Parameters:
name - a Name value
Returns:
a NameParser value

getNameParser

public NameParser getNameParser(String name)
Return a NameParser for this Context.
Parameters:
name - a Name value
Returns:
a NameParser value

getParent

public Context getParent()
Getter for _parent
Returns:
parent Context

list

public NamingEnumeration list(Name name)
            throws NamingException
List all names bound at Context named by Name
Parameters:
name - a Name value
Returns:
a NamingEnumeration value

list

public NamingEnumeration list(String name)
            throws NamingException
List all names bound at Context named by Name
Parameters:
name - a Name value
Returns:
a NamingEnumeration value

listBindings

public NamingEnumeration listBindings(Name name)
            throws NamingException
List all Bindings present at Context named by Name
Parameters:
name - a Name value
Returns:
a NamingEnumeration value

listBindings

public NamingEnumeration listBindings(String name)
            throws NamingException
List all Bindings at Name
Parameters:
name - a String value
Returns:
a NamingEnumeration value

lookup

public Object lookup(Name name)
            throws NamingException
Lookup a binding by name
Parameters:
name - name of bound object

lookup

public Object lookup(String name)
            throws NamingException
Lookup binding of an object by name
Parameters:
name - name of bound object
Returns:
object bound to name

lookupLink

public Object lookupLink(Name name)
            throws NamingException
Lookup link bound to name
Parameters:
name - name of link binding
Returns:
LinkRef or plain object bound at name

lookupLink

public Object lookupLink(String name)
            throws NamingException
Lookup link bound to name
Parameters:
name - name of link binding
Returns:
LinkRef or plain object bound at name

rebind

public void rebind(Name name,
                   Object obj)
            throws NamingException
Overwrite or create a binding
Parameters:
name - a Name value
obj - an Object value

rebind

public void rebind(String name,
                   Object obj)
            throws NamingException
Overwrite or create a binding from Name to Object
Parameters:
name - a String value
obj - an Object value

removeFromEnvironment

public Object removeFromEnvironment(String propName)
            throws NamingException
Remove a property from this Context's environment.
Parameters:
propName - name of property to remove
Returns:
value of property or null if it didn't exist

rename

public void rename(Name oldName,
                   Name newName)
            throws NamingException
Not supported
Parameters:
oldName - a Name value
newName - a Name value

rename

public void rename(String oldName,
                   String newName)
            throws NamingException
Not supported
Parameters:
oldName - a Name value
newName - a Name value

setNameParser

public void setNameParser(NameParser parser)
Setter for _parser

toCanonicalName

public Name toCanonicalName(Name name)
Remove leading or trailing empty components from name. Eg "/comp/env/" -> "comp/env"
Parameters:
name - the name to normalize
Returns:
normalized name

unbind

public void unbind(Name name)
            throws NamingException
Not supported.
Parameters:
name - a String value

unbind

public void unbind(String name)
            throws NamingException
Not supported.
Parameters:
name - a String value

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.