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
028 * configuration files, which can be created at runtime. This is especially
029 * useful if you program against interfaces and want to define the concrete
030 * implementation class is a configuration file.
031 * </p>
032 * <p>
033 * This interface defines methods for retrieving all information about a bean
034 * that should be created from a configuration file, e.g. the bean's properties
035 * or the factory to use for creating the instance. With different
036 * implementations different &quot;layouts&quot; of bean declarations can be
037 * supported. For instance if an XML configuration file is used, all features of
038 * XML (e.g. attributes, nested elements) can be used to define the bean. In a
039 * properties file the declaration format is more limited. The purpose of this
040 * interface is to abstract from the concrete declaration format.
041 * </p>
042 *
043 * @since 1.3
044 * @author <a
045 * href="http://commons.apache.org/configuration/team-list.html">Commons
046 * Configuration team</a>
047 */
048public interface BeanDeclaration
049{
050    /**
051     * Returns the name of the {@code BeanFactory} that should be used
052     * for creating the bean instance. This can be <b>null</b>, then a default
053     * factory will be used.
054     *
055     * @return the name of the bean factory
056     */
057    String getBeanFactoryName();
058
059    /**
060     * Here an arbitrary object can be returned that will be passed to the bean
061     * factory. Its meaning is not further specified. The purpose of this
062     * additional parameter is to support a further configuration of the bean
063     * factory that can be placed directly at the bean declaration.
064     *
065     * @return a parameter for the bean factory
066     */
067    Object getBeanFactoryParameter();
068
069    /**
070     * Returns the name of the bean class, from which an instance is to be
071     * created. This value must be defined unless a default class is provided
072     * for the bean creation operation.
073     *
074     * @return the name of the bean class
075     */
076    String getBeanClassName();
077
078    /**
079     * Returns a map with properties that should be initialized on the newly
080     * created bean. The map's keys are the names of the properties; the
081     * corresponding values are the properties' values. The return value can be
082     * <b>null</b> if no properties should be set.
083     *
084     * @return a map with properties to be initialized
085     */
086    Map<String, Object> getBeanProperties();
087
088    /**
089     * Returns a map with declarations for beans that should be set as
090     * properties of the newly created bean. This allows for complex
091     * initialization scenarios: a bean for a bean that contains complex
092     * properties (e.g. other beans) can have nested declarations for defining
093     * these complex properties. The returned map's key are the names of the
094     * properties to initialize. The values are either {@code BeanDeclaration}
095     * implementations or collections thereof. They will be treated like this
096     * declaration (in a recursive manner), and the resulting beans are
097     * assigned to the corresponding properties.
098     *
099     * @return a map with nested bean declarations
100     */
101    Map<String, Object> getNestedBeanDeclarations();
102
103    /**
104     * Returns a collection with constructor arguments. This data is used to
105     * determine the constructor of the bean class to be invoked. The values of
106     * the arguments are passed to the constructor. An implementation can return
107     * <b>null</b> or an empty collection; then the standard constructor of the
108     * bean class is called.
109     *
110     * @return a collection with the arguments to be passed to the bean class's
111     *         constructor
112     */
113    Collection<ConstructorArg> getConstructorArgs();
114}