## org.apache.commons.configuration.beanutils
Interface BeanFactory

All Known Implementing Classes:
  DefaultBeanFactory, DefaultConfigurationBuilder.ConfigurationProvider, DefaultConfigurationBuilder.FileConfigurationProvider, DefaultConfigurationBuilder.XMLConfigurationProvider

    public interface BeanFactory

Definition of an interface for bean factories.

Beans defined in configuration files are not directly created, but by so called bean factories. This additional level of indirection provides for high flexibility in the creation process. For instance one implementation of this interface could be very simple and create a new instance of the specified class for each invocation. A different implementation could cache already created beans and ensure that always the same bean of the given class will be returned - this would be an easy mean for creating singleton objects.

The interface itself is quite simple. There is a single method for creating a bean of a given class. All necessary parameters are obtained from an also passed in `BeanDeclaration` object. It is also possible (but optional) for a bean factory to declare the default class of the bean it creates. Then it is not necessary to specify a bean class in the bean declaration.

Since:
  1.3
Version:
  $Id: BeanFactory.java 1208757 2011-11-30 20:38:15Z oheger $
Author:
  Commons Configuration team

Method Summary
`Object` `createBean(Class<?> beanClass, BeanDeclaration data, Object param)` Returns a bean instance for the given class.
`Class<?>` `getDefaultBeanClass()` Returns the default bean class of this bean factory.

Method Detail

### createBean

    Object createBean(Class<?> beanClass,
                      BeanDeclaration data,
                      Object param)
                      throws Exception

  Returns a bean instance for the given class. The bean will be initialized from the specified bean declaration object. It is up to a concrete implementation how the bean will be created and initialized.

  Parameters:
    `beanClass` - the class for the bean
    `data` - the bean declaration object containing all data about the bean to be created
    `param` - an additional parameter that may be passed by calling code; it is up to a concrete implementation how this parameter is evaluated
  Returns:
    the new bean instance (should not be null)
  Throws:
    `Exception` - if an error occurs (the helper classes for creating beans will catch this unspecific exception and wrap it in a configuration exception)

### getDefaultBeanClass

    Class<?> getDefaultBeanClass()

  Returns the default bean class of this bean factory. If an implementation here returns a non null value, bean declarations using this factory do not need to provide the name of the bean class. In such a case an instance of the default class will be created.

  Returns:
    the default class of this factory or null if there is none

Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.