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