 
                        
        
                        
        org.apache.commons.configuration2.builder.CopyObjectDefaultHandler Maven / Gradle / Ivy
/*
 * 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.builder;
import org.apache.commons.configuration2.beanutils.BeanHelper;
import org.apache.commons.configuration2.ex.ConfigurationRuntimeException;
/**
 * 
 * A specialized implementation of {@code DefaultParametersHandler} that copies the properties of a
 * {@link BuilderParameters} object (passed at construction time) onto the object to be initialized.
 * 
 * 
 * Using this handler implementation makes specifying default values pretty straight-forward: Just create a
 * corresponding parameters object, initialize it as desired, and pass it to this class. When invoked the handler uses
 * functionality from Commons BeanUtils to copy all properties defined in the associated parameters object onto
 * the target object. This is based on reflection. Properties not available for the target object are silently ignored.
 * If an exception occurs during the copy operation, it is re-thrown as a runtime exception.
 * 
 * 
 * Note that there is no default way to create a defensive copy of the passed in parameters object; therefore, the
 * reference is stored. This makes it possible to change the parameters object later on, and the changes will be
 * effective when initializing objects afterwards. Client code should not rely on this feature.
 * 
 *
 * @since 2.0
 */
public class CopyObjectDefaultHandler implements DefaultParametersHandler