Source code
Description: source: package: org.apache.commons.configuration2.beanutils, interface: BeanDeclaration

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