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 */
045public interface BeanDeclaration
046{
047    /**
048     * Returns the name of the {@code BeanFactory} that should be used
049     * for creating the bean instance. This can be <b>null</b>, then a default
050     * factory will be used.
051     *
052     * @return the name of the bean factory
053     */
054    String getBeanFactoryName();
055
056    /**
057     * Here an arbitrary object can be returned that will be passed to the bean
058     * factory. Its meaning is not further specified. The purpose of this
059     * additional parameter is to support a further configuration of the bean
060     * factory that can be placed directly at the bean declaration.
061     *
062     * @return a parameter for the bean factory
063     */
064    Object getBeanFactoryParameter();
065
066    /**
067     * Returns the name of the bean class, from which an instance is to be
068     * created. This value must be defined unless a default class is provided
069     * for the bean creation operation.
070     *
071     * @return the name of the bean class
072     */
073    String getBeanClassName();
074
075    /**
076     * Returns a map with properties that should be initialized on the newly
077     * created bean. The map's keys are the names of the properties; the
078     * corresponding values are the properties' values. The return value can be
079     * <b>null</b> if no properties should be set.
080     *
081     * @return a map with properties to be initialized
082     */
083    Map<String, Object> getBeanProperties();
084
085    /**
086     * Returns a map with declarations for beans that should be set as
087     * properties of the newly created bean. This allows for complex
088     * initialization scenarios: a bean for a bean that contains complex
089     * properties (e.g. other beans) can have nested declarations for defining
090     * these complex properties. The returned map's key are the names of the
091     * properties to initialize. The values are either {@code BeanDeclaration}
092     * implementations or collections thereof. They will be treated like this
093     * declaration (in a recursive manner), and the resulting beans are
094     * assigned to the corresponding properties.
095     *
096     * @return a map with nested bean declarations
097     */
098    Map<String, Object> getNestedBeanDeclarations();
099
100    /**
101     * Returns a collection with constructor arguments. This data is used to
102     * determine the constructor of the bean class to be invoked. The values of
103     * the arguments are passed to the constructor. An implementation can return
104     * <b>null</b> or an empty collection; then the standard constructor of the
105     * bean class is called.
106     *
107     * @return a collection with the arguments to be passed to the bean class's
108     *         constructor
109     */
110    Collection<ConstructorArg> getConstructorArgs();
111}