org.apache.beehive.controls.runtime.bean
Class ControlBeanContext

Object
  extended by BeanContextChildSupport
      extended by BeanContextSupport
          extended by BeanContextServicesSupport
              extended by ControlBeanContext
All Implemented Interfaces:
BeanContext, BeanContextChild, BeanContextServiceRevokedListener, BeanContextServices, BeanContextServicesListener, DesignMode, PropertyChangeListener, VetoableChangeListener, Visibility, Serializable, Iterable, Collection, EventListener, ControlBeanContext
Direct Known Subclasses:
ControlContainerContext

public class ControlBeanContext
extends BeanContextServicesSupport
implements BeanContextServiceRevokedListener, ControlBeanContext, PropertyChangeListener, VetoableChangeListener

The ControlBeanContext implements the basic BeanContextServices implementation for ControlBeans. It provides several basic functions: - it defines the generic services that are available for all control containers - it acts as the base class for other container service implementations - it acts as the BeanContextServicesRevokedListener when an associated control bean has lost access to services.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class BeanContextServicesSupport
BeanContextServicesSupport.BCSSChild, BeanContextServicesSupport.BCSSProxyServiceProvider, BeanContextServicesSupport.BCSSServiceProvider
 
Nested classes/interfaces inherited from class BeanContextSupport
BeanContextSupport.BCSChild, BeanContextSupport.BCSIterator
 
Nested classes/interfaces inherited from interface ControlBeanContext
ControlBeanContext.LifeCycle
 
Field Summary
static String INTERCEPTOR_CONFIG_FILE
          Filename that contains ordering priority for controls interceptor services.
 
Fields inherited from class BeanContextServicesSupport
bcsListeners, proxy, serializable, services
 
Fields inherited from class BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
 
Fields inherited from class BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
 
Fields inherited from interface BeanContext
globalHierarchyLock
 
Fields inherited from interface DesignMode
PROPERTYNAME
 
Constructor Summary
protected ControlBeanContext(ControlBean bean)
          Creates a new ControlBeanContext instance associated with a specific control bean.
 
Method Summary
 boolean add(Object targetChild)
          Overrides the BeanContextSupport.add() method to perform additional validation that is unique for ControlBeans containers.
 void addLifeCycleListener(ControlBeanContext.LifeCycle listener)
          Registers a new listener for LifeCycle events on the context.
 String generateUniqueID(Class clazz)
          Generates a new unique control ID for an instance of the target class
 PropertyMap getAnnotationMap(AnnotatedElement annotElem)
          Returns the PropertyMap containing default properties for an AnnotatedElement in the current context.
 ControlBean getBean(String id)
          Returns a ControlBean instance nested the current BeanContext.
protected  PropertyMap getBeanAnnotationMap(ControlBean bean, AnnotatedElement annotElem)
          The default implementation of getBeanAnnotationMap.
 ClassLoader getClassLoader()
          Returns the ClassLoader used to load the ControlBean class associated with the control implementation instance.
 ControlBean getControlBean()
          Returns the ControlBean associated directly with the ControlBeanContext.
 ControlHandle getControlHandle()
          Returns a ControlHandle instance that enables operations and events to be dispatched to the target control, if it is running inside of a container that supports external event dispatch.
 Class getControlInterface()
          Returns the public or extension interface associated with the context
 PropertyMap getControlPropertyMap()
          Returns the current set of properties (in PropertyMap format) for the control associated with the context.
<T extends Annotation>
T
getControlPropertySet(Class<T> propertySet)
          Returns the current value of PropertySet for the associated control, or null if the property set has not been bound.
static String getDefaultControlBinding(Class controlIntf)
          Returns the default binding based entirely upon annotations or naming conventions.
<T extends Annotation>
T
getMethodPropertySet(Method m, Class<T> propertySet)
          Returns the current value of PropertySet for the provided method, or null if the property set has not been bound for this method.
 String[] getParameterNames(Method m)
          Returns an array containing the parameter names for the specified method
<T extends Annotation>
T
getParameterPropertySet(Method m, int i, Class<T> propertySet)
          Returns the current value of PropertySet for the selected (by index) method parameter, or null if the property set has not been bound for this method.
 Object getParameterValue(Method m, String parameterName, Object[] parameters)
          Returns the value of a named method parameter from the input parameter array.
<T> T
getService(Class<T> serviceClass, Object selector)
          Returns an instance of a contextual service based upon the local context.
 boolean hasSingleThreadedParent()
           
 void initialize()
          Called by BeanContextSupport superclass during construction and deserialization to initialize subclass transient state
 void initializeControl()
          The initializeControl method is invoked when the implementation instance associated with the context has been instantiated and initialized.
 boolean isSingleThreadedContainer()
          Returns true if this container associated with this context service enforces single-threaded invocation, false otherwise.
static String[] prioritizeInterceptors(String[] interceptors)
          Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for controls interceptor services.
 void propertyChange(PropertyChangeEvent pce)
           
 boolean remove(Object targetChild)
          Overrides the BeanContextSupport.remove() method to perform additional post-processing on child removal.
 void removeLifeCycleListener(ControlBeanContext.LifeCycle listener)
          Removes a currently registered LifeCycle event listener on the context.
static String resolveDefaultBinding(String implBinding, String controlClass)
          Implements the default control implementation binding algorithm ( + "Impl" ).
 void serviceRevoked(BeanContextServiceRevokedEvent bcsre)
          Implements the BeanContextServicesRevokedListener.servicesRevoked method.
 void setBeanContext(BeanContext beanContext)
          Overrides the BeanContextChild.setBeanContext() method.
protected static void setDelegateMap(PropertyMap map, ControlBean bean, AnnotatedElement annotElem)
           
 void vetoableChange(PropertyChangeEvent pce)
           
 
Methods inherited from class BeanContextServicesSupport
addBeanContextServicesListener, addService, addService, bcsPreDeserializationHook, bcsPreSerializationHook, childJustRemovedHook, createBCSChild, createBCSSServiceProvider, fireServiceAdded, fireServiceAdded, fireServiceRevoked, fireServiceRevoked, getBeanContextServicesPeer, getChildBeanContextServicesListener, getCurrentServiceClasses, getCurrentServiceSelectors, getService, hasService, initializeBeanContextResources, releaseBeanContextResources, releaseService, removeBeanContextServicesListener, revokeService, serviceAvailable
 
Methods inherited from class BeanContextSupport
addAll, addBeanContextMembershipListener, avoidingGui, bcsChildren, childDeserializedHook, childJustAddedHook, classEquals, clear, contains, containsAll, containsKey, copyChildren, deserialize, dontUseGui, fireChildrenAdded, fireChildrenRemoved, getBeanContextPeer, getChildBeanContextChild, getChildBeanContextMembershipListener, getChildPropertyChangeListener, getChildSerializable, getChildVetoableChangeListener, getChildVisibility, getLocale, getResource, getResourceAsStream, instantiateChild, isDesignTime, isEmpty, isSerializing, iterator, needsGui, okToUseGui, readChildren, remove, removeAll, removeBeanContextMembershipListener, retainAll, serialize, setDesignTime, setLocale, size, toArray, toArray, validatePendingAdd, validatePendingRemove, writeChildren
 
Methods inherited from class BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, isDelegated, removePropertyChangeListener, removeVetoableChangeListener, validatePendingSetBeanContext
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface BeanContextServices
addBeanContextServicesListener, addService, getCurrentServiceClasses, getCurrentServiceSelectors, getService, hasService, releaseService, removeBeanContextServicesListener, revokeService
 
Methods inherited from interface BeanContext
addBeanContextMembershipListener, getResource, getResourceAsStream, instantiateChild, removeBeanContextMembershipListener
 
Methods inherited from interface BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener
 
Methods inherited from interface Collection
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface DesignMode
isDesignTime, setDesignTime
 
Methods inherited from interface Visibility
avoidingGui, dontUseGui, needsGui, okToUseGui
 
Methods inherited from interface BeanContextServicesListener
serviceAvailable
 

Field Detail

INTERCEPTOR_CONFIG_FILE

public static final String INTERCEPTOR_CONFIG_FILE
Filename that contains ordering priority for controls interceptor services. Each line in the file is a fully qualified interface name. 1st line in the file is highest priority.

See Also:
Constant Field Values
Constructor Detail

ControlBeanContext

protected ControlBeanContext(ControlBean bean)
Creates a new ControlBeanContext instance associated with a specific control bean.

Parameters:
bean - The control bean that contains/scopes the ControlBeanContext. If null, it means the ControlBeanContext is for a top-level container.
Method Detail

initialize

public void initialize()
Called by BeanContextSupport superclass during construction and deserialization to initialize subclass transient state

Overrides:
initialize in class BeanContextServicesSupport

serviceRevoked

public void serviceRevoked(BeanContextServiceRevokedEvent bcsre)
Implements the BeanContextServicesRevokedListener.servicesRevoked method. This is called if the associated ControlBean has requested a service that is being subsequently revoked.

Specified by:
serviceRevoked in interface BeanContextServiceRevokedListener
Overrides:
serviceRevoked in class BeanContextServicesSupport

setBeanContext

public void setBeanContext(BeanContext beanContext)
                    throws PropertyVetoException
Overrides the BeanContextChild.setBeanContext() method. This hook is used to perform additional processing that needs to occur when the control is associated with a new nesting context.

Specified by:
setBeanContext in interface BeanContextChild
Overrides:
setBeanContext in class BeanContextChildSupport
Throws:
PropertyVetoException

generateUniqueID

public String generateUniqueID(Class clazz)
Generates a new unique control ID for an instance of the target class


add

public boolean add(Object targetChild)
Overrides the BeanContextSupport.add() method to perform additional validation that is unique for ControlBeans containers.

Specified by:
add in interface Collection
Overrides:
add in class BeanContextSupport

remove

public boolean remove(Object targetChild)
Overrides the BeanContextSupport.remove() method to perform additional post-processing on child removal.

Specified by:
remove in interface Collection
Overrides:
remove in class BeanContextSupport

getBean

public ControlBean getBean(String id)
Returns a ControlBean instance nested the current BeanContext.

Specified by:
getBean in interface ControlBeanContext
Parameters:
id - the identifier for the target control, relative to the current context.

getControlBean

public ControlBean getControlBean()
Returns the ControlBean associated directly with the ControlBeanContext. If the context represents a top-level container, will return null.

Specified by:
getControlBean in interface ControlBeanContext

hasSingleThreadedParent

public boolean hasSingleThreadedParent()

isSingleThreadedContainer

public boolean isSingleThreadedContainer()
Returns true if this container associated with this context service enforces single-threaded invocation, false otherwise. This MUST be overridden by container-specific subclasses. If they guarantee single-threaded behavior (such as the EJB container), they should return true.

Specified by:
isSingleThreadedContainer in interface ControlBeanContext

initializeControl

public void initializeControl()
The initializeControl method is invoked when the implementation instance associated with the context has been instantiated and initialized.


getAnnotationMap

public PropertyMap getAnnotationMap(AnnotatedElement annotElem)
Returns the PropertyMap containing default properties for an AnnotatedElement in the current context. The initialization of PropertyMap binding is always done by delegating to a ControlContainerContext, enabling containers to implement property binding mechanisms (such as external config) that may override the values contained within the element annotations.

Specified by:
getAnnotationMap in interface ControlBeanContext

getBeanAnnotationMap

protected PropertyMap getBeanAnnotationMap(ControlBean bean,
                                           AnnotatedElement annotElem)
The default implementation of getBeanAnnotationMap. This returns a map based purely upon annotation reflection


setDelegateMap

protected static void setDelegateMap(PropertyMap map,
                                     ControlBean bean,
                                     AnnotatedElement annotElem)

getDefaultControlBinding

public static String getDefaultControlBinding(Class controlIntf)
Returns the default binding based entirely upon annotations or naming conventions.


resolveDefaultBinding

public static String resolveDefaultBinding(String implBinding,
                                           String controlClass)
Implements the default control implementation binding algorithm ( + "Impl" ). See documentation for the org.apache.beehive.controls.api.bean.ControlInterface annotation.

Parameters:
implBinding - the value of the defaultBinding attribute returned from a ControlInterface annotation
controlClass - the actual name of the interface decorated by the ControlInterface annotation
Returns:
the resolved defaultBinding value

getControlInterface

public Class getControlInterface()
Description copied from interface: ControlBeanContext
Returns the public or extension interface associated with the context

Specified by:
getControlInterface in interface ControlBeanContext

getControlPropertySet

public <T extends Annotation> T getControlPropertySet(Class<T> propertySet)
Description copied from interface: ControlBeanContext
Returns the current value of PropertySet for the associated control, or null if the property set has not been bound. Actual bindings for property values may be the result of annotations on the control field or class, property setting via factory arguments or setter APIs, or external configuration.

Specified by:
getControlPropertySet in interface ControlBeanContext
Parameters:
propertySet - the PropertySet to return
Returns:
the requested PropertySet instance, or null if not bound
See Also:
PropertySet

getMethodPropertySet

public <T extends Annotation> T getMethodPropertySet(Method m,
                                                     Class<T> propertySet)
Description copied from interface: ControlBeanContext
Returns the current value of PropertySet for the provided method, or null if the property set has not been bound for this method.

Specified by:
getMethodPropertySet in interface ControlBeanContext
Parameters:
m - the Method to check for properties.
propertySet - the PropertySet to return
Returns:
the requested PropertySet instance, or null if not bound
See Also:
PropertySet

getParameterPropertySet

public <T extends Annotation> T getParameterPropertySet(Method m,
                                                        int i,
                                                        Class<T> propertySet)
                                             throws IllegalArgumentException,
                                                    IndexOutOfBoundsException
Description copied from interface: ControlBeanContext
Returns the current value of PropertySet for the selected (by index) method parameter, or null if the property set has not been bound for this method.

Specified by:
getParameterPropertySet in interface ControlBeanContext
Parameters:
m - the Method to check for properties
i - the index of the method parameter to check for the request PropertySet
propertySet - the PropertySet to return
Returns:
the request PropertySet instance, or null if not bound
Throws:
IllegalArgumentException
IndexOutOfBoundsException

getParameterNames

public String[] getParameterNames(Method m)
                           throws IllegalArgumentException
Description copied from interface: ControlBeanContext
Returns an array containing the parameter names for the specified method

Specified by:
getParameterNames in interface ControlBeanContext
Parameters:
m - the Method whose parameter names should be returned.
Returns:
the array of parameter names (or an empty array if no parameters)
Throws:
IllegalArgumentException

getParameterValue

public Object getParameterValue(Method m,
                                String parameterName,
                                Object[] parameters)
                         throws IllegalArgumentException
Description copied from interface: ControlBeanContext
Returns the value of a named method parameter from the input parameter array.

Specified by:
getParameterValue in interface ControlBeanContext
Parameters:
m - the Method associated with the input parameter list
parameterName - the name of the requested parameter
parameters - the array of method parameters
Returns:
the element in the input parameter array that corresponds to the requested parameter
Throws:
IllegalArgumentException

getControlPropertyMap

public PropertyMap getControlPropertyMap()
Description copied from interface: ControlBeanContext
Returns the current set of properties (in PropertyMap format) for the control associated with the context. The return map will contain the values for all bound properties for the control.

Specified by:
getControlPropertyMap in interface ControlBeanContext
Returns:
the PropertyMap containing properties of the control. This map is read-only; any changes to it will not effect the local bean instance.
See Also:
PropertyMap

getService

public <T> T getService(Class<T> serviceClass,
                        Object selector)
Description copied from interface: ControlBeanContext
Returns an instance of a contextual service based upon the local context. If no provider for this service is available, then null will be returned.

Specified by:
getService in interface ControlBeanContext
Parameters:
serviceClass - the class of the requested service
selector - the service dependent parameter
Returns:
an instance of the request service, or null if unavailable
See Also:
BeanContextServices.getService(java.beans.beancontext.BeanContextChild, java.lang.Object, java.lang.Class, java.lang.Object, java.beans.beancontext.BeanContextServiceRevokedListener)

getControlHandle

public ControlHandle getControlHandle()
Description copied from interface: ControlBeanContext
Returns a ControlHandle instance that enables operations and events to be dispatched to the target control, if it is running inside of a container that supports external event dispatch. If the runtime container for the control does not support this functionality, a value of null will be returned.

Specified by:
getControlHandle in interface ControlBeanContext
Returns:
a ControlHandle instance for the control, or null.
See Also:
ControlHandle

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: ControlBeanContext
Returns the ClassLoader used to load the ControlBean class associated with the control implementation instance. This is useful for loading other classes or resources that may have been packaged with the public interfaces of the Control type (since they may not necessarily have been packaged directly with the implementation class).

Specified by:
getClassLoader in interface ControlBeanContext

prioritizeInterceptors

public static String[] prioritizeInterceptors(String[] interceptors)
Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for controls interceptor services.

Parameters:
interceptors -
Returns:

addLifeCycleListener

public void addLifeCycleListener(ControlBeanContext.LifeCycle listener)
Description copied from interface: ControlBeanContext
Registers a new listener for LifeCycle events on the context.

Specified by:
addLifeCycleListener in interface ControlBeanContext
See Also:
ControlBeanContext.LifeCycle

removeLifeCycleListener

public void removeLifeCycleListener(ControlBeanContext.LifeCycle listener)
Description copied from interface: ControlBeanContext
Removes a currently registered LifeCycle event listener on the context.

Specified by:
removeLifeCycleListener in interface ControlBeanContext
See Also:
ControlBeanContext.LifeCycle

propertyChange

public void propertyChange(PropertyChangeEvent pce)
Specified by:
propertyChange in interface PropertyChangeListener
Overrides:
propertyChange in class BeanContextSupport

vetoableChange

public void vetoableChange(PropertyChangeEvent pce)
                    throws PropertyVetoException
Specified by:
vetoableChange in interface VetoableChangeListener
Overrides:
vetoableChange in class BeanContextSupport
Throws:
PropertyVetoException