Class JNDIConfiguration

All Implemented Interfaces:
Configuration, EventSource, ImmutableConfiguration, SynchronizerSupport

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.
  • Field Details

    • prefix

      private String prefix
      The prefix of the context.
    • context

      private Context context
      The initial JNDI context.
    • baseContext

      private Context baseContext
      The base JNDI context.
    • clearedProperties

      private final Set<String> clearedProperties
      The Set of keys that have been virtually cleared.
  • Constructor Details

    • JNDIConfiguration

      public JNDIConfiguration() throws NamingException
      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) throws NamingException
      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 Details

    • 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 context
      prefix - What prefix we are building on.
      processedCtx - a set with the so far processed objects
      Throws:
      NamingException - If JNDI has an issue.
    • getKeysInternal

      protected Iterator<String> getKeysInternal()
      Gets an iterator with all property keys stored in this configuration.
      Specified by:
      getKeysInternal in class AbstractConfiguration
      Returns:
      an iterator with all keys
    • getKeysInternal

      protected Iterator<String> getKeysInternal(String prefix)
      Gets an iterator with all property keys starting with the given prefix.
      Overrides:
      getKeysInternal in class AbstractConfiguration
      Parameters:
      prefix - the prefix
      Returns:
      an iterator with the selected keys
    • getContext

      private Context getContext(List<String> path, Context context) throws NamingException
      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
    • isEmptyInternal

      protected boolean isEmptyInternal()
      Returns a flag whether this configuration is empty.
      Specified by:
      isEmptyInternal in class AbstractConfiguration
      Returns:
      the empty flag
    • setPropertyInternal

      protected void setPropertyInternal(String key, Object value)

      This operation is not supported and will throw an UnsupportedOperationException.

      Overrides:
      setPropertyInternal in class AbstractConfiguration
      Parameters:
      key - the key
      value - the value
      Throws:
      UnsupportedOperationException - always thrown as this method is not supported
    • clearPropertyDirect

      protected void clearPropertyDirect(String key)
      Removes the specified property.
      Specified by:
      clearPropertyDirect in class AbstractConfiguration
      Parameters:
      key - the key of the property to remove
    • containsKeyInternal

      protected boolean containsKeyInternal(String key)
      Checks whether the specified key is contained in this configuration.
      Specified by:
      containsKeyInternal in class AbstractConfiguration
      Parameters:
      key - the key to check
      Returns:
      a flag whether this key is stored in this configuration
    • getPrefix

      public String getPrefix()
      Gets the prefix.
      Returns:
      the prefix
    • setPrefix

      public void setPrefix(String prefix)
      Sets the prefix.
      Parameters:
      prefix - The prefix to set
    • getPropertyInternal

      protected Object getPropertyInternal(String key)
      Gets the value of the specified property.
      Specified by:
      getPropertyInternal in class AbstractConfiguration
      Parameters:
      key - the key of the property
      Returns:
      the value of this property
    • addPropertyDirect

      protected void addPropertyDirect(String key, Object obj)

      This operation is not supported and will throw an UnsupportedOperationException.

      Specified by:
      addPropertyDirect in class AbstractConfiguration
      Parameters:
      key - the key
      obj - the value
      Throws:
      UnsupportedOperationException - always thrown as this method is not supported
    • getBaseContext

      public Context getBaseContext() throws NamingException
      Gets the base context with the prefix applied.
      Returns:
      the base context
      Throws:
      NamingException - if an error occurs
    • getContext

      public Context getContext()
      Gets the initial context used by this configuration. This context is independent of the prefix specified.
      Returns:
      the initial context
    • setContext

      public void setContext(Context context)
      Sets the initial context of the configuration.
      Parameters:
      context - the context