Class JNDIConfiguration
java.lang.Object
org.apache.commons.configuration2.event.BaseEventSource
org.apache.commons.configuration2.AbstractConfiguration
org.apache.commons.configuration2.JNDIConfiguration
- All Implemented Interfaces:
Configuration
,EventSource
,ImmutableConfiguration
,SynchronizerSupport
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionprotected void
addPropertyDirect
(String key, Object obj) This operation is not supported and will throw an UnsupportedOperationException.protected void
Removes the specified property.protected boolean
Checks whether the specified key is contained in this configuration.protected boolean
containsValueInternal
(Object value) Tests whether this configuration contains one or more matches to this value.Gets the base context with the prefix applied.Gets the initial context used by this configuration.private Context
getContext
(List<String> 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.Gets an iterator with all property keys stored in this configuration.getKeysInternal
(String prefix) Gets an iterator with all property keys starting with the given prefix.Gets the prefix.protected Object
Gets the value of the specified property.protected boolean
Returns a flag whether this configuration is empty.private void
This method recursive traverse the JNDI tree, looking for Context objects.void
setContext
(Context context) Sets the initial context of the configuration.void
Sets the prefix.protected void
setPropertyInternal
(String key, Object value) This operation is not supported and will throw an UnsupportedOperationException.Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearInternal, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, sizeInternal, subset, unlock
Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, clone, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
getEnum, getEnum
-
Field Details
-
prefix
The prefix of the context. -
context
The initial JNDI context. -
baseContext
The base JNDI context. -
clearedProperties
The Set of keys that have been virtually cleared.
-
-
Constructor Details
-
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
Creates a JNDIConfiguration using the specified initial context as the root of the properties.- Parameters:
context
- the initial context
-
JNDIConfiguration
Creates a JNDIConfiguration using the specified initial context shifted by the specified prefix as the root of the properties.- Parameters:
context
- the initial contextprefix
- the prefix
-
JNDIConfiguration
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
-
-
Method Details
-
addPropertyDirect
This operation is not supported and will throw an UnsupportedOperationException.
- Specified by:
addPropertyDirect
in classAbstractConfiguration
- Parameters:
key
- the keyobj
- the value- Throws:
UnsupportedOperationException
- always thrown as this method is not supported
-
clearPropertyDirect
Removes the specified property.- Specified by:
clearPropertyDirect
in classAbstractConfiguration
- Parameters:
key
- the key of the property to remove
-
containsKeyInternal
Checks whether the specified key is contained in this configuration.- Specified by:
containsKeyInternal
in classAbstractConfiguration
- Parameters:
key
- the key to check- Returns:
- a flag whether this key is stored in this configuration
-
containsValueInternal
Tests whether this configuration contains one or more matches to this value. This operation stops at first match but may be more expensive than the containsKey method.- Specified by:
containsValueInternal
in classAbstractConfiguration
- Parameters:
value
- the value in question- Returns:
true
if and only if some key maps to thevalue
argument in this configuration as determined by theequals
method;false
otherwise.- Since:
- 2.11.0
-
getBaseContext
Gets the base context with the prefix applied.- Returns:
- the base context
- Throws:
NamingException
- if an error occurs
-
getContext
Gets the initial context used by this configuration. This context is independent of the prefix specified.- Returns:
- the initial context
-
getContext
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 contextcontext
- 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
-
getKeysInternal
Gets an iterator with all property keys stored in this configuration.- Specified by:
getKeysInternal
in classAbstractConfiguration
- Returns:
- an iterator with all keys
-
getKeysInternal
Gets an iterator with all property keys starting with the given prefix.- Overrides:
getKeysInternal
in classAbstractConfiguration
- Parameters:
prefix
- the prefix- Returns:
- an iterator with the selected keys
-
getPrefix
Gets the prefix.- Returns:
- the prefix
-
getPropertyInternal
Gets the value of the specified property.- Specified by:
getPropertyInternal
in classAbstractConfiguration
- Parameters:
key
- the key of the property- Returns:
- the value of this property
-
isEmptyInternal
protected boolean isEmptyInternal()Returns a flag whether this configuration is empty.- Specified by:
isEmptyInternal
in classAbstractConfiguration
- Returns:
- the empty flag
-
recursiveGetKeys
private void recursiveGetKeys(Set<String> keys, Context context, String prefix, Set<Context> processedCtx) throws NamingException 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 contextprefix
- What prefix we are building on.processedCtx
- a set with the so far processed objects- Throws:
NamingException
- If JNDI has an issue.
-
setContext
Sets the initial context of the configuration.- Parameters:
context
- the context
-
setPrefix
Sets the prefix.- Parameters:
prefix
- The prefix to set
-
setPropertyInternal
This operation is not supported and will throw an UnsupportedOperationException.
- Overrides:
setPropertyInternal
in classAbstractConfiguration
- Parameters:
key
- the keyvalue
- the value- Throws:
UnsupportedOperationException
- always thrown as this method is not supported
-