1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.configuration2.beanutils;
18
19 /**
20 * <p>
21 * Definition of a context object storing all required information for the creation of a bean.
22 * </p>
23 * <p>
24 * An object implementing this interface is passed to a {@link BeanFactory}. The interface also contains methods for the
25 * creation and initialization of nested beans (for example constructor arguments or complex properties of the bean to be
26 * created).
27 * </p>
28 *
29 * @since 2.0
30 */
31 public interface BeanCreationContext {
32
33 /**
34 * Creates a bean based on the given {@code BeanDeclaration}. This method can be used to create dependent beans needed
35 * for the initialization of the bean that is actually created.
36 *
37 * @param data the {@code BeanDeclaration} describing the bean
38 * @return the bean created based on this declaration
39 */
40 Object createBean(BeanDeclaration data);
41
42 /**
43 * Gets the class of the bean to be created.
44 *
45 * @return the bean class
46 */
47 Class<?> getBeanClass();
48
49 /**
50 * Gets the {@code BeanDeclaration} with the data for the new bean. This data is used to initialize the bean's
51 * properties.
52 *
53 * @return the {@code BeanDeclaration} defining the bean to be created
54 */
55 BeanDeclaration getBeanDeclaration();
56
57 /**
58 * Gets the (optional) parameter object for the bean factory. This is a mechanism which can be used to pass custom
59 * parameters to a {@link BeanFactory}.
60 *
61 * @return the parameter for the bean factory
62 */
63 Object getParameter();
64
65 /**
66 * Initializes a bean's property based on the given {@code BeanDeclaration}.
67 *
68 * @param bean the bean to be initialized
69 * @param data the {@code BeanDeclaration} with initialization data for this bean
70 */
71 void initBean(Object bean, BeanDeclaration data);
72 }