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

Object
  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 Object
implements ControlBeanContext, PropertyChangeListener, VetoableChangeListener, Serializable

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 interface ControlBeanContext
ControlBeanContext.LifeCycle
 
Field Summary
 
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.
protected ControlBeanContext(ControlBean bean, ControlBeanContext.BeanContextServicesFactory beanContextServicesFactory)
          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.
 boolean addAll(Collection c)
           
 void addBeanContextMembershipListener(BeanContextMembershipListener bcml)
           
 void addBeanContextServicesListener(BeanContextServicesListener bcsl)
           
 void addLifeCycleListener(ControlBeanContext.LifeCycle listener)
          Registers a new listener for LifeCycle events on the context.
 void addPropertyChangeListener(String name, PropertyChangeListener pcl)
           
 boolean addService(Class serviceClass, BeanContextServiceProvider serviceProvider)
           
 void addVetoableChangeListener(String name, VetoableChangeListener vcl)
           
 boolean avoidingGui()
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 void dontUseGui()
           
 boolean equals(Object o)
           
 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.
 BeanContext getBeanContext()
           
protected  ControlBeanContext.BeanContextServicesFactory getBeanContextServicesFactory()
           
 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.
 Iterator getCurrentServiceClasses()
           
 Iterator getCurrentServiceSelectors(Class serviceClass)
           
static String getDefaultControlBinding(Class controlIntf)
          Deprecated. Use ControlUtils.getDefaultControlBinding(Class) insated. This method will be removed in the next point release.
<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.
 URL getResource(String name, BeanContextChild bcc)
           
 InputStream getResourceAsStream(String name, BeanContextChild bcc)
           
 Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl)
           
<T> T
getService(Class<T> serviceClass, Object selector)
          Returns an instance of a contextual service based upon the local context.
 int hashCode()
           
 boolean hasService(Class serviceClass)
           
 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.
 Object instantiateChild(String beanName)
           
 boolean isDesignTime()
           
 boolean isEmpty()
           
 boolean isSingleThreadedContainer()
          Returns true if this container associated with this context service enforces single-threaded invocation, false otherwise.
 Iterator iterator()
           
 boolean needsGui()
           
 void okToUseGui()
           
static String[] prioritizeInterceptors(String[] interceptors)
          Deprecated. Use InterceptorUtils.prioritizeInterceptors(String[]) instead. This method will be removed in the next point release.
 void propertyChange(PropertyChangeEvent pce)
           
 void releaseService(BeanContextChild child, Object requestor, Object service)
           
 boolean remove(Object targetChild)
          Overrides the BeanContextSupport.remove() method to perform additional post-processing on child removal.
 boolean removeAll(Collection c)
           
 void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
           
 void removeBeanContextServicesListener(BeanContextServicesListener bcsl)
           
 void removeLifeCycleListener(ControlBeanContext.LifeCycle listener)
          Removes a currently registered LifeCycle event listener on the context.
 void removePropertyChangeListener(String name, PropertyChangeListener pcl)
           
 void removeVetoableChangeListener(String name, VetoableChangeListener vcl)
           
static String resolveDefaultBinding(String implBinding, String controlClass)
          Deprecated. Use ControlUtils.resolveDefaultBinding(String, String) insated. This method will be removed in the next point release.
 boolean retainAll(Collection c)
           
 void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow)
           
 void serviceAvailable(BeanContextServiceAvailableEvent bcsae)
           
 void serviceRevoked(BeanContextServiceRevokedEvent bcsre)
          Implements the BeanContextServiceRevokedListener.serviceRevoked(java.beans.beancontext.BeanContextServiceRevokedEvent) method.
 void setBeanContext(BeanContext beanContext)
          Overrides the BeanContextChild.setBeanContext(java.beans.beancontext.BeanContext) method.
protected static void setDelegateMap(PropertyMap map, ControlBean bean, AnnotatedElement annotElem)
           
 void setDesignTime(boolean designTime)
           
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 void vetoableChange(PropertyChangeEvent pce)
           
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControlBeanContext

protected ControlBeanContext(ControlBean bean)
Creates a new ControlBeanContext instance associated with a specific control bean. If the ControlBean is null, this ControlBeanContext object represents a top-level Control container. This constructor uses the default implementation of the BeanContextServices interface from the JDK.

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

ControlBeanContext

protected ControlBeanContext(ControlBean bean,
                             ControlBeanContext.BeanContextServicesFactory beanContextServicesFactory)
Creates a new ControlBeanContext instance associated with a specific control bean. If the ControlBean is null, this ControlBeanContext object represents a top-level Control container. This constructor uses the beanContextServicesDelegate instance as the implementation of the BeanContextServices interface.

Parameters:
bean - The control bean
beanContextServicesFactory - A factory that can be used to create the BeanContextServicesFactory object that implements support for the BeanContextServices interface.
Method Detail

initialize

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


serviceRevoked

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

Specified by:
serviceRevoked in interface BeanContextServiceRevokedListener

setBeanContext

public void setBeanContext(BeanContext beanContext)
                    throws PropertyVetoException
Overrides the BeanContextChild.setBeanContext(java.beans.beancontext.BeanContext) 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
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

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

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 in order to change the default behavior. If a single-threaded container intends to guarantee single-threaded behavior (such as the EJB container), this 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)

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

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

vetoableChange

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

getCurrentServiceClasses

public Iterator getCurrentServiceClasses()
Specified by:
getCurrentServiceClasses in interface BeanContextServices

getCurrentServiceSelectors

public Iterator getCurrentServiceSelectors(Class serviceClass)
Specified by:
getCurrentServiceSelectors in interface BeanContextServices

getBeanContextServicesFactory

protected ControlBeanContext.BeanContextServicesFactory getBeanContextServicesFactory()

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Overrides:
hashCode in class Object

addService

public boolean addService(Class serviceClass,
                          BeanContextServiceProvider serviceProvider)
Specified by:
addService in interface BeanContextServices

revokeService

public void revokeService(Class serviceClass,
                          BeanContextServiceProvider serviceProvider,
                          boolean revokeCurrentServicesNow)
Specified by:
revokeService in interface BeanContextServices

hasService

public boolean hasService(Class serviceClass)
Specified by:
hasService in interface BeanContextServices

getService

public Object getService(BeanContextChild child,
                         Object requestor,
                         Class serviceClass,
                         Object serviceSelector,
                         BeanContextServiceRevokedListener bcsrl)
                  throws TooManyListenersException
Specified by:
getService in interface BeanContextServices
Throws:
TooManyListenersException

releaseService

public void releaseService(BeanContextChild child,
                           Object requestor,
                           Object service)
Specified by:
releaseService in interface BeanContextServices

addBeanContextServicesListener

public void addBeanContextServicesListener(BeanContextServicesListener bcsl)
Specified by:
addBeanContextServicesListener in interface BeanContextServices

removeBeanContextServicesListener

public void removeBeanContextServicesListener(BeanContextServicesListener bcsl)
Specified by:
removeBeanContextServicesListener in interface BeanContextServices

instantiateChild

public Object instantiateChild(String beanName)
                        throws IOException,
                               ClassNotFoundException
Specified by:
instantiateChild in interface BeanContext
Throws:
IOException
ClassNotFoundException

getResourceAsStream

public InputStream getResourceAsStream(String name,
                                       BeanContextChild bcc)
                                throws IllegalArgumentException
Specified by:
getResourceAsStream in interface BeanContext
Throws:
IllegalArgumentException

getResource

public URL getResource(String name,
                       BeanContextChild bcc)
                throws IllegalArgumentException
Specified by:
getResource in interface BeanContext
Throws:
IllegalArgumentException

addBeanContextMembershipListener

public void addBeanContextMembershipListener(BeanContextMembershipListener bcml)
Specified by:
addBeanContextMembershipListener in interface BeanContext

removeBeanContextMembershipListener

public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
Specified by:
removeBeanContextMembershipListener in interface BeanContext

getBeanContext

public BeanContext getBeanContext()
Specified by:
getBeanContext in interface BeanContextChild

addPropertyChangeListener

public void addPropertyChangeListener(String name,
                                      PropertyChangeListener pcl)
Specified by:
addPropertyChangeListener in interface BeanContextChild

removePropertyChangeListener

public void removePropertyChangeListener(String name,
                                         PropertyChangeListener pcl)
Specified by:
removePropertyChangeListener in interface BeanContextChild

addVetoableChangeListener

public void addVetoableChangeListener(String name,
                                      VetoableChangeListener vcl)
Specified by:
addVetoableChangeListener in interface BeanContextChild

removeVetoableChangeListener

public void removeVetoableChangeListener(String name,
                                         VetoableChangeListener vcl)
Specified by:
removeVetoableChangeListener in interface BeanContextChild

size

public int size()
Specified by:
size in interface Collection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection

clear

public void clear()
Specified by:
clear in interface Collection

setDesignTime

public void setDesignTime(boolean designTime)
Specified by:
setDesignTime in interface DesignMode

isDesignTime

public boolean isDesignTime()
Specified by:
isDesignTime in interface DesignMode

needsGui

public boolean needsGui()
Specified by:
needsGui in interface Visibility

dontUseGui

public void dontUseGui()
Specified by:
dontUseGui in interface Visibility

okToUseGui

public void okToUseGui()
Specified by:
okToUseGui in interface Visibility

avoidingGui

public boolean avoidingGui()
Specified by:
avoidingGui in interface Visibility

serviceAvailable

public void serviceAvailable(BeanContextServiceAvailableEvent bcsae)
Specified by:
serviceAvailable in interface BeanContextServicesListener

prioritizeInterceptors

public static String[] prioritizeInterceptors(String[] interceptors)
Deprecated. Use InterceptorUtils.prioritizeInterceptors(String[]) instead. This method will be removed in the next point release.

Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for controls interceptor services.

Parameters:
interceptors -
Returns:
String[]

getDefaultControlBinding

public static String getDefaultControlBinding(Class controlIntf)
Deprecated. Use ControlUtils.getDefaultControlBinding(Class) insated. This method will be removed in the next point release.

Returns the default binding based entirely upon annotations or naming conventions.

Parameters:
controlIntf - the control interface class
Returns:
the class name of the default control implementation binding

resolveDefaultBinding

public static String resolveDefaultBinding(String implBinding,
                                           String controlClass)
Deprecated. Use ControlUtils.resolveDefaultBinding(String, String) insated. This method will be removed in the next point release.

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