org.apache.commons.configuration2.ImmutableConfigurationInvocationHandler Maven / Gradle / Ivy
Show all versions of commons-configuration2 Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.configuration2;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Objects;
/**
*
* A specialized {@code InvocationHandler} implementation for supporting immutable configurations.
*
*
* An instance of this class is constructed with a reference to a {@code Configuration} object. All method invocations
* (which stem from the {@code ImmutableConfiguration} interface) are delegated to this object. That way all
* functionality is actually backed by the underlying {@code Configuration} implementation, but because the associated
* proxy only implements the {@code ImmutableConfiguration} interface manipulations are not possible.
*
*
* There is one caveat however: Some methods of the {@code ImmutableConfiguration} interface return an {@code Iterator}
* object. Using the iterator's {@code remove()} method it may be possible to remove keys from the underlying
* {@code Configuration} object. Therefore, in these cases a specialized {@code Iterator} is returned which does not
* support the remove operation.
*
*
* @since 2.0
*/
final class ImmutableConfigurationInvocationHandler implements InvocationHandler {
/**
* A specialized {@code Iterator} implementation which delegates to an underlying iterator, but does not support the
* {@code remove()} method.
*/
private static final class ImmutableIterator implements Iterator