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 * http://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 import java.util.Collection; 20 import java.util.Map; 21 22 /** 23 * <p> 24 * Definition of an interface for declaring a bean in a configuration file. 25 * </p> 26 * <p> 27 * Commons Configurations allows to define beans (i.e. simple Java objects) in configuration files, which can be created 28 * at runtime. This is especially useful if you program against interfaces and want to define the concrete 29 * implementation class is a configuration file. 30 * </p> 31 * <p> 32 * This interface defines methods for retrieving all information about a bean that should be created from a 33 * configuration file, e.g. the bean's properties or the factory to use for creating the instance. With different 34 * implementations different "layouts" of bean declarations can be supported. For instance if an XML 35 * configuration file is used, all features of XML (e.g. attributes, nested elements) can be used to define the bean. In 36 * a properties file the declaration format is more limited. The purpose of this interface is to abstract from the 37 * concrete declaration format. 38 * </p> 39 * 40 * @since 1.3 41 */ 42 public interface BeanDeclaration { 43 44 /** 45 * Gets the name of the bean class, from which an instance is to be created. This value must be defined unless a 46 * default class is provided for the bean creation operation. 47 * 48 * @return the name of the bean class 49 */ 50 String getBeanClassName(); 51 52 /** 53 * Gets the name of the {@code BeanFactory} that should be used for creating the bean instance. This can be 54 * <b>null</b>, then a default factory will be used. 55 * 56 * @return the name of the bean factory 57 */ 58 String getBeanFactoryName(); 59 60 /** 61 * Gets an arbitrary object that will be passed to the bean factory. Its meaning is not further 62 * specified. The purpose of this additional parameter is to support a further configuration of the bean factory that 63 * can be placed directly at the bean declaration. 64 * 65 * @return a parameter for the bean factory 66 */ 67 Object getBeanFactoryParameter(); 68 69 /** 70 * Gets a map with properties that should be initialized on the newly created bean. The map's keys are the names of 71 * the properties; the corresponding values are the properties' values. The return value can be <b>null</b> if no 72 * properties should be set. 73 * 74 * @return a map with properties to be initialized 75 */ 76 Map<String, Object> getBeanProperties(); 77 78 /** 79 * Gets a collection with constructor arguments. This data is used to determine the constructor of the bean class to 80 * be invoked. The values of the arguments are passed to the constructor. An implementation can return <b>null</b> or an 81 * empty collection; then the standard constructor of the bean class is called. 82 * 83 * @return a collection with the arguments to be passed to the bean class's constructor 84 */ 85 Collection<ConstructorArg> getConstructorArgs(); 86 87 /** 88 * Gets a map with declarations for beans that should be set as properties of the newly created bean. This allows for 89 * complex initialization scenarios: a bean for a bean that contains complex properties (e.g. other beans) can have 90 * nested declarations for defining these complex properties. The returned map's key are the names of the properties to 91 * initialize. The values are either {@code BeanDeclaration} implementations or collections thereof. They will be 92 * treated like this declaration (in a recursive manner), and the resulting beans are assigned to the corresponding 93 * properties. 94 * 95 * @return a map with nested bean declarations 96 */ 97 Map<String, Object> getNestedBeanDeclarations(); 98 }