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
019/**
020 * <p>
021 * Definition of a context object storing all required information for the
022 * creation of a bean.
023 * </p>
024 * <p>
025 * An object implementing this interface is passed to a {@link BeanFactory}. The
026 * interface also contains methods for the creation and initialization of nested
027 * beans (e.g. constructor arguments or complex properties of the bean to be
028 * created).
029 * </p>
030 *
031 * @since 2.0
032 */
033public interface BeanCreationContext
034{
035    /**
036     * Returns the class of the bean to be created.
037     *
038     * @return the bean class
039     */
040    Class<?> getBeanClass();
041
042    /**
043     * Returns the {@code BeanDeclaration} with the data for the new bean. This
044     * data is used to initialize the bean's properties.
045     *
046     * @return the {@code BeanDeclaration} defining the bean to be created
047     */
048    BeanDeclaration getBeanDeclaration();
049
050    /**
051     * Returns the (optional) parameter object for the bean factory. This is a
052     * mechanism which can be used to pass custom parameters to a
053     * {@link BeanFactory}.
054     *
055     * @return the parameter for the bean factory
056     */
057    Object getParameter();
058
059    /**
060     * Initializes a bean's property based on the given {@code BeanDeclaration}.
061     *
062     * @param bean the bean to be initialized
063     * @param data the {@code BeanDeclaration} with initialization data for this
064     *        bean
065     */
066    void initBean(Object bean, BeanDeclaration data);
067
068    /**
069     * Creates a bean based on the given {@code BeanDeclaration}. This method
070     * can be used to create dependent beans needed for the initialization of
071     * the bean that is actually created.
072     *
073     * @param data the {@code BeanDeclaration} describing the bean
074     * @return the bean created based on this declaration
075     */
076    Object createBean(BeanDeclaration data);
077}