Class ImmutableConfigurationInvocationHandler

  • All Implemented Interfaces:
    java.lang.reflect.InvocationHandler

    final class ImmutableConfigurationInvocationHandler
    extends java.lang.Object
    implements java.lang.reflect.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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.Object handleResult​(java.lang.Object result)
      Handles the result from the method invocation on the wrapped configuration.
      java.lang.Object invoke​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
      This implementation delegates to the wrapped configuration object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • wrappedConfiguration

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

      • 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:
        java.lang.NullPointerException - if the Configuration is null
    • Method Detail

      • handleResult

        private static java.lang.Object handleResult​(java.lang.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
      • invoke

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