org.progeeks.util.beans
Class BeanConfigurator

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap
              extended by org.progeeks.util.beans.BeanConfigurator
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map
Direct Known Subclasses:
SingletonConfigurator

public class BeanConfigurator
extends java.util.LinkedHashMap

Can hold property values for a bean and apply them on demand to a bean instance. This class can also be used to instantiate beans pre-configured. Property values are stored as entries in the Map.

Version:
$Revision: 1.34 $
Author:
Paul Speed
See Also:
Serialized Form

Constructor Summary
BeanConfigurator()
          Constructs a bean configurator that is not specific to any bean class.
BeanConfigurator(java.lang.Class beanClass)
          Constructs a bean configurator that can instantiate and configure beans of the specified concrete class.
 
Method Summary
 void addConfiguratorListener(ConfiguratorListener listener)
          Adds a listener that will be notified whenever a new bean is created.
 void configureBean(java.lang.Object bean)
          Configures the specified bean by applying the stored properties.
 java.lang.Object createBean()
          Creates a configures a bean of this configurator's associated bean type.
 java.lang.Object createBean(java.lang.Object[] args)
          Creates a configures a bean passing the specified arguments on the constructor.
 boolean equals(java.lang.Object obj)
           
protected  void fireBeanCreated(java.lang.Object bean)
          Notifies the registered ConfiguratorListeners about the specified bean creation.
 boolean getAppendCollections()
           
 java.lang.Class getBeanClass()
          Returns the bean class associated with this configurator or null if it is not specific to a given bean class.
 boolean getOverwriteExistingValues()
           
 boolean hasConstructor(java.lang.Class[] types)
          Returns true if the bean can be created with the specified argument types.
 boolean hasConstructor(java.lang.Object[] args)
          Returns true if the bean can be created with the specified arguments.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Overridden to provide additional type-checking for key values.
 void removeConfiguratorListener(ConfiguratorListener listener)
          Removes a previously registered configurator listener.
 void setAppendCollections(boolean flag)
          Set to true collection based values should be appended to any existing collection.
protected  void setCollectionValue(java.lang.String name, java.util.Collection value, Inspector ins)
           
protected  void setMapValue(java.lang.String name, java.util.Map value, Inspector ins)
           
 void setOverwriteExistingValues(boolean flag)
          Set to true if existing values should be overwritten.
protected  void setValue(java.lang.String name, java.lang.Object value, Inspector ins)
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Constructor Detail

BeanConfigurator

public BeanConfigurator()
Constructs a bean configurator that is not specific to any bean class.


BeanConfigurator

public BeanConfigurator(java.lang.Class beanClass)
Constructs a bean configurator that can instantiate and configure beans of the specified concrete class.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Map
Overrides:
equals in class java.util.AbstractMap

setAppendCollections

public void setAppendCollections(boolean flag)
Set to true collection based values should be appended to any existing collection. Defaults to false. This flag can work in conjunction with overwriteExistingValues to append new values instead of ignoring the field.


getAppendCollections

public boolean getAppendCollections()

setOverwriteExistingValues

public void setOverwriteExistingValues(boolean flag)
Set to true if existing values should be overwritten. Set to false if the configurator should skip fields with existing values. Defaults to true.


getOverwriteExistingValues

public boolean getOverwriteExistingValues()

addConfiguratorListener

public void addConfiguratorListener(ConfiguratorListener listener)
Adds a listener that will be notified whenever a new bean is created. Listeners will be notified after the bean has been fully configured.


removeConfiguratorListener

public void removeConfiguratorListener(ConfiguratorListener listener)
Removes a previously registered configurator listener.


getBeanClass

public java.lang.Class getBeanClass()
Returns the bean class associated with this configurator or null if it is not specific to a given bean class.


configureBean

public void configureBean(java.lang.Object bean)
Configures the specified bean by applying the stored properties.


setCollectionValue

protected void setCollectionValue(java.lang.String name,
                                  java.util.Collection value,
                                  Inspector ins)

setMapValue

protected void setMapValue(java.lang.String name,
                           java.util.Map value,
                           Inspector ins)

setValue

protected void setValue(java.lang.String name,
                        java.lang.Object value,
                        Inspector ins)

createBean

public java.lang.Object createBean()
Creates a configures a bean of this configurator's associated bean type.


createBean

public java.lang.Object createBean(java.lang.Object[] args)
Creates a configures a bean passing the specified arguments on the constructor.


hasConstructor

public boolean hasConstructor(java.lang.Object[] args)
Returns true if the bean can be created with the specified arguments.


hasConstructor

public boolean hasConstructor(java.lang.Class[] types)
Returns true if the bean can be created with the specified argument types.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Overridden to provide additional type-checking for key values.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap

fireBeanCreated

protected void fireBeanCreated(java.lang.Object bean)
Notifies the registered ConfiguratorListeners about the specified bean creation.


toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap


Copyright © 2002-2003 Paul Speed. All Rights Reserved.