    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.beanutils;
    018
    019import java.util.Collection;
    020import java.util.Map;
    021
    022/**
    023 * <p>
    024 * Definition of an interface for declaring a bean in a configuration file.
    025 * </p>
    026 * <p>
    027 * Commons Configurations allows to define beans (i.e. simple Java objects) in configuration files, which can be created
    028 * at runtime. This is especially useful if you program against interfaces and want to define the concrete
    029 * implementation class is a configuration file.
    030 * </p>
    031 * <p>
    032 * This interface defines methods for retrieving all information about a bean that should be created from a
    033 * configuration file, e.g. the bean's properties or the factory to use for creating the instance. With different
    034 * implementations different &quot;layouts&quot; of bean declarations can be supported. For instance if an XML
    035 * configuration file is used, all features of XML (e.g. attributes, nested elements) can be used to define the bean. In
    036 * a properties file the declaration format is more limited. The purpose of this interface is to abstract from the
    037 * concrete declaration format.
    038 * </p>
    039 *
    040 * @since 1.3
    041 */
    042public interface BeanDeclaration {
    043
    044    /**
    045     * Gets the name of the {@code BeanFactory} that should be used for creating the bean instance. This can be
    046     * <b>null</b>, then a default factory will be used.
    047     *
    048     * @return the name of the bean factory
    049     */
    050    String getBeanFactoryName();
    051
    052    /**
    053     * Gets an arbitrary object that will be passed to the bean factory. Its meaning is not further
    054     * specified. The purpose of this additional parameter is to support a further configuration of the bean factory that
    055     * can be placed directly at the bean declaration.
    056     *
    057     * @return a parameter for the bean factory
    058     */
    059    Object getBeanFactoryParameter();
    060
    061    /**
    062     * Gets the name of the bean class, from which an instance is to be created. This value must be defined unless a
    063     * default class is provided for the bean creation operation.
    064     *
    065     * @return the name of the bean class
    066     */
    067    String getBeanClassName();
    068
    069    /**
    070     * Gets a map with properties that should be initialized on the newly created bean. The map's keys are the names of
    071     * the properties; the corresponding values are the properties' values. The return value can be <b>null</b> if no
    072     * properties should be set.
    073     *
    074     * @return a map with properties to be initialized
    075     */
    076    Map<String, Object> getBeanProperties();
    077
    078    /**
    079     * Gets a map with declarations for beans that should be set as properties of the newly created bean. This allows for
    080     * complex initialization scenarios: a bean for a bean that contains complex properties (e.g. other beans) can have
    081     * nested declarations for defining these complex properties. The returned map's key are the names of the properties to
    082     * initialize. The values are either {@code BeanDeclaration} implementations or collections thereof. They will be
    083     * treated like this declaration (in a recursive manner), and the resulting beans are assigned to the corresponding
    084     * properties.
    085     *
    086     * @return a map with nested bean declarations
    087     */
    088    Map<String, Object> getNestedBeanDeclarations();
    089
    090    /**
    091     * Gets a collection with constructor arguments. This data is used to determine the constructor of the bean class to
    092     * be invoked. The values of the arguments are passed to the constructor. An implementation can return <b>null</b> or an
    093     * empty collection; then the standard constructor of the bean class is called.
    094     *
    095     * @return a collection with the arguments to be passed to the bean class's constructor
    096     */
    097    Collection<ConstructorArg> getConstructorArgs();
    098}