org.escot
Class OnDemandFeatureSupport

java.lang.Object
  |
  +--org.escot.OnDemandFeatureSupport
All Implemented Interfaces:
BeanWiringListener

public class OnDemandFeatureSupport
extends Object
implements BeanWiringListener

This is a utility class that may be used by beans which are ExplicitFeatureProviders that need to duplicate features when they are wired and remove them when they are unwired. You can use an instance of this class as a member field of your bean and delegate wiring listening to it. The bean should implement BeanWiringListener.


Field Summary
protected  ExplicitFeatureProvider mBean
           
protected  com.sun.java.util.collections.HashSet mClasses
           
 
Constructor Summary
OnDemandFeatureSupport(ExplicitFeatureProvider bean)
           
OnDemandFeatureSupport(ExplicitFeatureProvider bean, Class featureClass)
          Constructor that specifies the bean and a class of instances that should be duplicated when wired to and removed when unwired.
 
Method Summary
 void addFeatureClass(Class featureClass)
          Adds a class of instances that should be duplicated when wired and removed when unwired.
protected  void expandFeatureSet(EscotFeature targetFeature, EscotFeature associatedFeature, Wire wire)
          Expands the feature set when a feature belonging to the bean that is an instance of one of the classes designated for expansion, has been wired.
protected  String generateWiredFeatureName(EscotFeature targetFeature, EscotFeature associatedFeature, Wire wire)
          Override this if a feature that has been wired should be renamed.
protected  Object newFeature(EscotFeature feat)
          Creates a new feature based on the specified feature.
protected  void registerFeature(Object feat)
          Adds the feature to the registry.
 void removeFeatureClass(Class featureClass)
          Removes a class of instances that should be duplicated when wired and removed when unwired.
protected  void unregisterFeature(Object feat)
          Removes the feature from the registry.
 void wireAdded(BeanWiringEvent evt)
          Invoked when a wire has been added involving the bean.
 void wireRemoved(BeanWiringEvent e)
          Invoked when a wire has been removed involving the bean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mBean

protected ExplicitFeatureProvider mBean

mClasses

protected com.sun.java.util.collections.HashSet mClasses
Constructor Detail

OnDemandFeatureSupport

public OnDemandFeatureSupport(ExplicitFeatureProvider bean)

OnDemandFeatureSupport

public OnDemandFeatureSupport(ExplicitFeatureProvider bean,
                              Class featureClass)
Constructor that specifies the bean and a class of instances that should be duplicated when wired to and removed when unwired.
Method Detail

addFeatureClass

public void addFeatureClass(Class featureClass)
Adds a class of instances that should be duplicated when wired and removed when unwired.

removeFeatureClass

public void removeFeatureClass(Class featureClass)
Removes a class of instances that should be duplicated when wired and removed when unwired.

wireAdded

public void wireAdded(BeanWiringEvent evt)
Invoked when a wire has been added involving the bean. Calls expandFeatureSet to expand the number of features.
Specified by:
wireAdded in interface BeanWiringListener

wireRemoved

public void wireRemoved(BeanWiringEvent e)
Invoked when a wire has been removed involving the bean. If the bean is the subscriber in the wire and the subscriber feature is an expandable feature class, the feature is removed from the registry using unregisterFeature.
Specified by:
wireRemoved in interface BeanWiringListener

expandFeatureSet

protected void expandFeatureSet(EscotFeature targetFeature,
                                EscotFeature associatedFeature,
                                Wire wire)
Expands the feature set when a feature belonging to the bean that is an instance of one of the classes designated for expansion, has been wired. Renames the feature, getting the new name by calling generateWiredFeatureName, creates a duplicate feature by calling newFeature, and adds it to the registry by calling registerFeature.

generateWiredFeatureName

protected String generateWiredFeatureName(EscotFeature targetFeature,
                                          EscotFeature associatedFeature,
                                          Wire wire)
Override this if a feature that has been wired should be renamed. The default implementation returns the name of the feature, so it will be unchanged.

newFeature

protected Object newFeature(EscotFeature feat)
                     throws InstantiationException,
                            IllegalAccessException
Creates a new feature based on the specified feature. If this method returns null or throws one of the declared exceptions, OnDemandFeatureSupport does not register a duplicate feature.

registerFeature

protected void registerFeature(Object feat)
Adds the feature to the registry.

unregisterFeature

protected void unregisterFeature(Object feat)
Removes the feature from the registry. Override this if you don't want the feature to be removed.