Class ImmutableConfigurationInvocationHandler
- java.lang.Object
-
- org.apache.commons.configuration2.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 theImmutableConfiguration
interface) are delegated to this object. That way all functionality is actually backed by the underlyingConfiguration
implementation, but because the associated proxy only implements theImmutableConfiguration
interface manipulations are not possible.There is one caveat however: Some methods of the
ImmutableConfiguration
interface return anIterator
object. Using the iterator'sremove()
method it may be possible to remove keys from the underlyingConfiguration
object. Therefore, in these cases a specializedIterator
is returned which does not support the remove operation.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ImmutableConfigurationInvocationHandler.ImmutableIterator
A specializedIterator
implementation which delegates to an underlying iterator, but does not support theremove()
method.
-
Field Summary
Fields Modifier and Type Field Description private Configuration
wrappedConfiguration
The underlying configuration object.
-
Constructor Summary
Constructors Constructor Description ImmutableConfigurationInvocationHandler(Configuration configuration)
Creates a new instance ofImmutableConfigurationInvocationHandler
and initializes it with the wrapped configuration object.
-
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.
-
-
-
Field Detail
-
wrappedConfiguration
private final Configuration wrappedConfiguration
The underlying configuration object.
-
-
Constructor Detail
-
ImmutableConfigurationInvocationHandler
public ImmutableConfigurationInvocationHandler(Configuration configuration)
Creates a new instance ofImmutableConfigurationInvocationHandler
and initializes it with the wrapped configuration object.- Parameters:
configuration
- the wrappedConfiguration
(must not be null)- Throws:
java.lang.NullPointerException
- if theConfiguration
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 interfacejava.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable
-
-