org.iqual.chaplin.composite
Class AbstractCompositeHandler

java.lang.Object
  extended by org.iqual.chaplin.composite.AbstractCompositeHandler
All Implemented Interfaces:
InvocationHandler, Composite, ContextHandler, Injected, Meta, MessageReceiver
Direct Known Subclasses:
BinderCompositeHandler, CompositeContextHandler

public abstract class AbstractCompositeHandler
extends Object
implements Composite, InvocationHandler

Abstract base composite class.

Since:
Jun 12, 2009 8:58:07 PM
Author:
Zbynek Slajchrt

Constructor Summary
AbstractCompositeHandler()
           
 
Method Summary
 Object $$$$$$()
           
 void $$$$$$(Object context)
           
 Map $$$meta$$$()
           
 void $$$meta$$$(Map metadata)
           
 void addComponent(String componentName, int index, Object component)
          Inserts the component to the composite.
 void addComponent(String componentName, Object component)
          Called by sub-classes when they register their components.
static void addComponentToComposite(Object component, int index, Object companion, String name)
          Attaches the component to the composite.
 void bindReceiver(MessageReceiver receiver)
          Bind the receiver to this composite.
static boolean canBeExtracted(Object composite, Class typeClass)
           
static
<T> T
createEmitter(Class<T> emitterType, Object composite)
           
static
<T> T
extract(Object composite, Class typeClass)
          Extracts a component from the composite which if of the specified type.
static
<T> T
extract(Object composite, Class typeClass, boolean checkAvailability)
          Extracts a component from the composite which if of the specified type.
protected static AbstractCompositeHandler extractHandler(Object composite)
           
static Composite getComposite(Object arg)
           
 Composite getParentComposite()
           
 Object getRole(String role)
           
 Composite getTopComposite()
           
protected  void injectCompositeContext(Object component)
           
 Object invoke(Object proxy, Method method, Object[] args)
          This method converts an exernal invocation to a messages.
static boolean isComposite(Object argument)
           
static boolean isCompositeProxy(Object instance)
           
 void onMessageReceived(Message message, MessageReplies replies, MessageReceiversChain chain)
          Called when a request is made.
protected  void outjectCompositeContext(Object component)
           
 void removeComponent(Object component)
          Pulls the component out of the composite.
static void removeComponentFromComposite(Object component)
          Removes the component from the composite.
 void unbindReceiver()
          Unbind the lastly bound receiver from this composite.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCompositeHandler

public AbstractCompositeHandler()
Method Detail

addComponent

public final void addComponent(String componentName,
                               Object component)
Called by sub-classes when they register their components.

Parameters:
componentName - the name of the component
component - the component

addComponent

public final void addComponent(String componentName,
                               int index,
                               Object component)
Description copied from interface: Composite
Inserts the component to the composite.

Specified by:
addComponent in interface Composite
Parameters:
componentName - the name (role) of the component in the composite
index - the index at which the component is inserted. The value -1 means that the component is appended at the end.
component - the component to be inserted to the composite

addComponentToComposite

public static void addComponentToComposite(Object component,
                                           int index,
                                           Object companion,
                                           String name)
Attaches the component to the composite. The composite given by the companion object which is either a component already belonging to the composite or the composite itself.

Parameters:
component - the component to be inserted to the composite
companion - the companion compoent
name - the name (role) of the component in the composite

removeComponent

public final void removeComponent(Object component)
Description copied from interface: Composite
Pulls the component out of the composite.

Specified by:
removeComponent in interface Composite
Parameters:
component - the component to removed from this composite

removeComponentFromComposite

public static void removeComponentFromComposite(Object component)
Removes the component from the composite. It finds out whether the component belongs to a composite and if it does the component is removed from it. Otherwise it does nothing.

Parameters:
component -

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
This method converts an exernal invocation to a messages. The message is then processed by onMessageReceived. The invocations of methods that belong to this class are not translated to messages, instead they are invoked on this object directly.

Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

onMessageReceived

public void onMessageReceived(Message message,
                              MessageReplies replies,
                              MessageReceiversChain chain)
                       throws Throwable
Description copied from interface: MessageReceiver
Called when a request is made. The receiver must call the chain's process method so that the subsequent receivers could be called. The receiver may manipulate with the arguments passed to that method. For example it may change the message that will be processed by the subsequent receivers in the chain or change the results of the subsequent message processing.

Specified by:
onMessageReceived in interface MessageReceiver
Throws:
Throwable

injectCompositeContext

protected void injectCompositeContext(Object component)

outjectCompositeContext

protected void outjectCompositeContext(Object component)

getParentComposite

public Composite getParentComposite()
Specified by:
getParentComposite in interface Composite
Returns:
the parent composite

getTopComposite

public Composite getTopComposite()

bindReceiver

public void bindReceiver(MessageReceiver receiver)
Description copied from interface: Composite
Bind the receiver to this composite. This binding is valid for the context thread only. The bound receivers precede other receivers in the composite.

Specified by:
bindReceiver in interface Composite
Parameters:
receiver - the receiver

unbindReceiver

public void unbindReceiver()
Description copied from interface: Composite
Unbind the lastly bound receiver from this composite.

Specified by:
unbindReceiver in interface Composite

getRole

public Object getRole(String role)
Specified by:
getRole in interface Composite
Parameters:
role - the component's role
Returns:
the component whose role is role or null

$$$$$$

public Object $$$$$$()
Specified by:
$$$$$$ in interface Injected

$$$$$$

public void $$$$$$(Object context)
Specified by:
$$$$$$ in interface Injected

$$$meta$$$

public void $$$meta$$$(Map metadata)
Specified by:
$$$meta$$$ in interface Meta

$$$meta$$$

public Map $$$meta$$$()
Specified by:
$$$meta$$$ in interface Meta

isComposite

public static boolean isComposite(Object argument)

canBeExtracted

public static boolean canBeExtracted(Object composite,
                                     Class typeClass)
                              throws Throwable
Throws:
Throwable

extract

public static <T> T extract(Object composite,
                            Class typeClass)
                 throws Throwable
Extracts a component from the composite which if of the specified type.

Parameters:
composite -
typeClass -
Returns:
Throws:
Exception
Throwable

extract

public static <T> T extract(Object composite,
                            Class typeClass,
                            boolean checkAvailability)
                 throws Throwable
Extracts a component from the composite which if of the specified type.

Parameters:
composite - the composite
typeClass - the component type
checkAvailability - if true the method throws exception if there is no component in the composite which implements typeClass. If false and typeClass is an interface it returns a dynamic proxy for the interface. If false and typeClass is not an interface it returns null.
Returns:
Throws:
Exception
Throwable

createEmitter

public static <T> T createEmitter(Class<T> emitterType,
                                  Object composite)

extractHandler

protected static AbstractCompositeHandler extractHandler(Object composite)

getComposite

public static Composite getComposite(Object arg)

isCompositeProxy

public static boolean isCompositeProxy(Object instance)


Copyright © 2009 iquality.org. All Rights Reserved.