Class ImmutableConfigurationInvocationHandler

java.lang.Object
org.apache.commons.configuration2.ImmutableConfigurationInvocationHandler
All Implemented Interfaces:
InvocationHandler

class ImmutableConfigurationInvocationHandler extends Object implements InvocationHandler

A specialized InvocationHandler implementation for supporting immutable configurations.

An instance of this class is constructed with a reference to a Configuration object. All method invocations (which stem from the ImmutableConfiguration interface) are delegated to this object. That way all functionality is actually backed by the underlying Configuration implementation, but because the associated proxy only implements the ImmutableConfiguration interface manipulations are not possible.

There is one caveat however: Some methods of the ImmutableConfiguration interface return an Iterator object. Using the iterator's remove() method it may be possible to remove keys from the underlying Configuration object. Therefore, in these cases a specialized Iterator is returned which does not support the remove operation.

Since:
2.0
  • Field Details

    • wrappedConfiguration

      private final Configuration wrappedConfiguration
      The underlying configuration object.
  • Constructor Details

    • ImmutableConfigurationInvocationHandler

      public ImmutableConfigurationInvocationHandler(Configuration configuration)
      Creates a new instance of ImmutableConfigurationInvocationHandler and initializes it with the wrapped configuration object.
      Parameters:
      configuration - the wrapped Configuration (must not be null)
      Throws:
      NullPointerException - if the Configuration is null
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      This implementation delegates to the wrapped configuration object. Result objects are wrapped if necessary.
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • handleResult

      private static Object handleResult(Object result)
      Handles the result from the method invocation on the wrapped configuration. This implementation wraps result objects if necessary so that the underlying configuration cannot be manipulated.
      Parameters:
      result - the result object
      Returns:
      the processed result object