org.apache.commons.configuration

Class JNDIConfiguration

public class JNDIConfiguration extends AbstractConfiguration

This Configuration class allows you to interface with a JNDI datasource. A JNDIConfiguration is read-only, write operations will throw an UnsupportedOperationException. The clear operations are supported but the underlying JNDI data source is not changed.

Version: $Id: JNDIConfiguration.java 497181 2007-01-17 21:35:28Z oheger $

Author: Eric Pugh

Field Summary
ContextbaseContext
The base JNDI context.
SetclearedProperties
The Set of keys that have been virtually cleared.
Contextcontext
The initial JNDI context.
Stringprefix
The prefix of the context.
Constructor Summary
JNDIConfiguration()
Creates a JNDIConfiguration using the default initial context as the root of the properties.
JNDIConfiguration(String prefix)
Creates a JNDIConfiguration using the default initial context, shifted with the specified prefix, as the root of the properties.
JNDIConfiguration(Context context)
Creates a JNDIConfiguration using the specified initial context as the root of the properties.
JNDIConfiguration(Context context, String prefix)
Creates a JNDIConfiguration using the specified initial context shifted by the specified prefix as the root of the properties.
Method Summary
protected voidaddPropertyDirect(String key, Object obj)

This operation is not supported and will throw an UnsupportedOperationException.

voidclearProperty(String key)
Removes the specified property.
booleancontainsKey(String key)
Checks whether the specified key is contained in this configuration.
ContextgetBaseContext()
Return the base context with the prefix applied.
ContextgetContext(List path, Context context)
Because JNDI is based on a tree configuration, we need to filter down the tree, till we find the Context specified by the key to start from.
ContextgetContext()
Return the initial context used by this configuration.
IteratorgetKeys()
Returns an iterator with all property keys stored in this configuration.
IteratorgetKeys(String prefix)
Returns an iterator with all property keys starting with the given prefix.
StringgetPrefix()
Returns the prefix.
ObjectgetProperty(String key)
Returns the value of the specified property.
booleanisEmpty()
Returns a flag whether this configuration is empty.
voidrecursiveGetKeys(Set keys, Context context, String prefix)
This method recursive traverse the JNDI tree, looking for Context objects.
voidsetContext(Context context)
Set the initial context of the configuration.
voidsetPrefix(String prefix)
Sets the prefix.
voidsetProperty(String key, Object value)

This operation is not supported and will throw an UnsupportedOperationException.

Field Detail

baseContext

private Context baseContext
The base JNDI context.

clearedProperties

private Set clearedProperties
The Set of keys that have been virtually cleared.

context

private Context context
The initial JNDI context.

prefix

private String prefix
The prefix of the context.

Constructor Detail

JNDIConfiguration

public JNDIConfiguration()
Creates a JNDIConfiguration using the default initial context as the root of the properties.

Throws: NamingException thrown if an error occurs when initializing the default context

JNDIConfiguration

public JNDIConfiguration(String prefix)
Creates a JNDIConfiguration using the default initial context, shifted with the specified prefix, as the root of the properties.

Parameters: prefix the prefix

Throws: NamingException thrown if an error occurs when initializing the default context

JNDIConfiguration

public JNDIConfiguration(Context context)
Creates a JNDIConfiguration using the specified initial context as the root of the properties.

Parameters: context the initial context

JNDIConfiguration

public JNDIConfiguration(Context context, String prefix)
Creates a JNDIConfiguration using the specified initial context shifted by the specified prefix as the root of the properties.

Parameters: context the initial context prefix the prefix

Method Detail

addPropertyDirect

protected void addPropertyDirect(String key, Object obj)

This operation is not supported and will throw an UnsupportedOperationException.

Parameters: key the key obj the value

Throws: UnsupportedOperationException

clearProperty

public void clearProperty(String key)
Removes the specified property.

Parameters: key the key of the property to remove

containsKey

public boolean containsKey(String key)
Checks whether the specified key is contained in this configuration.

Parameters: key the key to check

Returns: a flag whether this key is stored in this configuration

getBaseContext

public Context getBaseContext()
Return the base context with the prefix applied.

Returns: the base context

Throws: NamingException if an error occurs

getContext

private Context getContext(List path, Context context)
Because JNDI is based on a tree configuration, we need to filter down the tree, till we find the Context specified by the key to start from. Otherwise return null.

Parameters: path the path of keys to traverse in order to find the context context the context to start from

Returns: The context at that key's location in the JNDI tree, or null if not found

Throws: NamingException if JNDI has an issue

getContext

public Context getContext()
Return the initial context used by this configuration. This context is independent of the prefix specified.

Returns: the initial context

getKeys

public Iterator getKeys()
Returns an iterator with all property keys stored in this configuration.

Returns: an iterator with all keys

getKeys

public Iterator getKeys(String prefix)
Returns an iterator with all property keys starting with the given prefix.

Parameters: prefix the prefix

Returns: an iterator with the selected keys

getPrefix

public String getPrefix()
Returns the prefix.

Returns: the prefix

getProperty

public Object getProperty(String key)
Returns the value of the specified property.

Parameters: key the key of the property

Returns: the value of this property

isEmpty

public boolean isEmpty()
Returns a flag whether this configuration is empty.

Returns: the empty flag

recursiveGetKeys

private void recursiveGetKeys(Set keys, Context context, String prefix)
This method recursive traverse the JNDI tree, looking for Context objects. When it finds them, it traverses them as well. Otherwise it just adds the values to the list of keys found.

Parameters: keys All the keys that have been found. context The parent context prefix What prefix we are building on.

Throws: NamingException If JNDI has an issue.

setContext

public void setContext(Context context)
Set the initial context of the configuration.

Parameters: context the context

setPrefix

public void setPrefix(String prefix)
Sets the prefix.

Parameters: prefix The prefix to set

setProperty

public void setProperty(String key, Object value)

This operation is not supported and will throw an UnsupportedOperationException.

Parameters: key the key value the value

Throws: UnsupportedOperationException