org.sape.carbon.core.component.proxy
Class DefaultComponentProxyInvocationHandler

java.lang.Object
  |
  +--org.sape.carbon.core.util.reflection.GenericProxy
        |
        +--org.sape.carbon.core.component.proxy.DefaultComponentProxyInvocationHandler
All Implemented Interfaces:
ComponentProxyInvocationHandler, InvocationHandler

public class DefaultComponentProxyInvocationHandler
extends GenericProxy
implements ComponentProxyInvocationHandler

Provides the glue for the Component, and supporting container functionality. DefaultComponentProxyInvocationHandler is a Dynamic Proxy Invocation Handler. Its job is to masquerade as either the Component, or any one of a number of container-feature-providers. called 'Assistants'. Mappings from interfaces to delegates (being the component instance, or interceptor instances) are stored. Invocations on those interfaces are passed to the corresponding delegates. In addition, Assistants may listen for ProxyEvents - which are distributed immediately before and after an invocation being passed to a delegate. Listeners are notified in the order they are registered, according to the ComponentTemplateConfiguration . Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.44 $($Author: dvoet $ / $Date: 2003/05/05 21:21:14 $)
Author:
Chris Herron, February 2002
See Also:
Proxy, Decorator, Interceptor, ComponentTemplateConfiguration

Field Summary
protected  String componentName
          The name of wrapped component.
protected  Map delegatesByInterface
          Map of interfaces to their respective delegates.
protected  FunctionalInterface functionalImplementation
          The implementation of the true component.
private static Method GET_COMPONENT_NAME_METHOD
          Method that gets the component name if such method exists.
protected  Interceptor headInterceptor
          A reference to the first interceptor in the chain.
protected  List interceptors
          This list is a list of interceptors that will be called in the execution of the represented component.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger.
private  ReadWriteLock monitor
          The monitor object that coordinates read/write calls to the represented component.
 
Fields inherited from class org.sape.carbon.core.util.reflection.GenericProxy
 
Constructor Summary
DefaultComponentProxyInvocationHandler()
           
 
Method Summary
 void addDecorator(Decorator decorator)
          Method used during creation of the proxy object to add Assistants to the component.
protected  void addDelegate(Class[] representedInterfaces, Object delegate)
          Add a delegate.
private  void addInterceptor(Interceptor interceptor)
          Adds an interceptor the chain.
 String getComponentName()
          Gets the component name.
 Object getDelegate(Class delegateInterface)
          Gets the delegate based on the given interface.
 ReadWriteLock getMonitor()
          Gets the read-lock monitor.
protected  Object handleInvoke(Object proxy, Method method, Object[] args)
          This method implements the delegation model for the represented component.
protected  String proxyToString(Object proxy)
          Returns out the name of the component
 void setComponentName(String componentName)
          Sets the name of the component.
 void setFunctionalImplementation(Class[] implementedInterfaces, FunctionalInterface functionalImplementation)
          Method used during creation of the proxy object to add the functional implementation to the component.
 
Methods inherited from class org.sape.carbon.core.util.reflection.GenericProxy
invoke, proxyEquals, proxyHashCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.reflect.InvocationHandler
invoke
 

Field Detail

delegatesByInterface

protected Map delegatesByInterface
Map of interfaces to their respective delegates. Upon calls to this component, the target object that will have the supplied method executed will come from this map.


interceptors

protected List interceptors
This list is a list of interceptors that will be called in the execution of the represented component. These interceptors call eachother, in order of this list. The head interceptor is executed by this handler.


headInterceptor

protected Interceptor headInterceptor
A reference to the first interceptor in the chain. This interceptor is always called first.


GET_COMPONENT_NAME_METHOD

private static Method GET_COMPONENT_NAME_METHOD
Method that gets the component name if such method exists.


log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger.


monitor

private final ReadWriteLock monitor
The monitor object that coordinates read/write calls to the represented component. Read calls are considered to be calls to the component's Functional Interface and should not change the fundamental lifecylcle of the component. Write calls are considered calls to the Component Assistant Delegates that may have effect on the configuration or lifecycle of the component. Multiple readers are allowed at one time, but only a single writer (with no readers active) is allowed.


functionalImplementation

protected FunctionalInterface functionalImplementation
The implementation of the true component.


componentName

protected String componentName
The name of wrapped component.

Constructor Detail

DefaultComponentProxyInvocationHandler

public DefaultComponentProxyInvocationHandler()
Method Detail

addDecorator

public void addDecorator(Decorator decorator)
Method used during creation of the proxy object to add Assistants to the component. This mehtod should be called only from the ComponentFactory when it is creating a new component.

Specified by:
addDecorator in interface ComponentProxyInvocationHandler
Since:
carbon 2.0
See Also:
ComponentFactory

setFunctionalImplementation

public void setFunctionalImplementation(Class[] implementedInterfaces,
                                        FunctionalInterface functionalImplementation)
Method used during creation of the proxy object to add the functional implementation to the component. This mehtod should be called only from the ComponentFactory when it is creating a new component.

Specified by:
setFunctionalImplementation in interface ComponentProxyInvocationHandler
Parameters:
implementedInterfaces - all the interfaces (including super interfaces) implemented by functionalImplementation's FunctionalInterface
functionalImplementation - the object that implements the components FunctionalInterface
See Also:
ComponentFactory

addDelegate

protected void addDelegate(Class[] representedInterfaces,
                           Object delegate)
Add a delegate.

Parameters:
representedInterfaces - an array of interfaces for which this delegate may be invoked
delegate - an instance of the delegate to be delegated to

addInterceptor

private void addInterceptor(Interceptor interceptor)
Adds an interceptor the chain.

Parameters:
interceptor - the interceptor to add

getDelegate

public Object getDelegate(Class delegateInterface)
Gets the delegate based on the given interface.

Specified by:
getDelegate in interface ComponentProxyInvocationHandler
Parameters:
delegateInterface - the interface to get the delegate for
Returns:
the delegate for the given interface

getMonitor

public ReadWriteLock getMonitor()
Gets the read-lock monitor.

Specified by:
getMonitor in interface ComponentProxyInvocationHandler
Returns:
the read-lock monitor

getComponentName

public String getComponentName()
Gets the component name.

Specified by:
getComponentName in interface ComponentProxyInvocationHandler
Returns:
the component name

setComponentName

public void setComponentName(String componentName)
Sets the name of the component.

Specified by:
setComponentName in interface ComponentProxyInvocationHandler
Parameters:
componentName - the name of the component

handleInvoke

protected Object handleInvoke(Object proxy,
                              Method method,
                              Object[] args)
                       throws Throwable
This method implements the delegation model for the represented component. It will pass component calls to the implementation object for a component as well as passing other calls to configured Component Assistant instances.

Specified by:
handleInvoke in class GenericProxy
Parameters:
proxy - the object that is being represented
method - the method descriptor for the method called
args - an array of arguments passed to that method
Returns:
the return value of the delegated method.
Throws:
Throwable - when there is an exception thrown from the delegated method. This may be a Checked exception if the implemented interface declares the exception. Otherwise checked exceptions will be automatically wrapped in an UndeclaredThrowableException. Runtime exceptions are thrown as is.

proxyToString

protected String proxyToString(Object proxy)
Returns out the name of the component

Overrides:
proxyToString in class GenericProxy
Parameters:
proxy - the proxy object to toString
Returns:
the String representation of the proxy object


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.