jfun.yan
Class DecoratingComponent

java.lang.Object
  extended by jfun.yan.Component
      extended by jfun.yan.DelegatingComponent
          extended by jfun.yan.DecoratingComponent
All Implemented Interfaces:
java.io.Serializable, Creator, Stateful, Typeful, Verifiable

public abstract class DecoratingComponent
extends DelegatingComponent

Base class for component decorators that do not change the result returned from the target component it decorates and causes no side-effect by itself other than those caused by the target component.

Some decorator classes of Component may want to forward calls to singleton(), guard(), proxy() to the Component that it delegates and then re-decorate the result.

This class provides the basic facility for this logic. Implement the decorate() method and this class will forward and re-decorate for you.

Use it with caution because it could cause infinite loop if used inappropriately

Codehaus.org.

Author:
Ben Yu
See Also:
Serialized Form

Constructor Summary
DecoratingComponent(Component cc)
          Create a new DeleratingComponent object.
 
Method Summary
protected abstract  Component decorate(Component c)
          Decorate a Component object.
 Component guard()
          Decorate this Component so that the new Component object guards against infinite dependency loop.
 boolean isSingleton()
          Determines if the component always return the same instance and has no side-effect that causes difference when called the second time.
 Component proxy()
          Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.
 Component proxy(java.lang.Class itf)
          Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.
 Component proxy(java.lang.Class[] itfs)
          Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.
 Component singleton()
          Create a new Component that utilizes singleton pattern when creating instance.
 Component singleton(Pool scope)
          Create a new Component that utilizes singleton pattern within a scope specified by the provided Pool object when creating instance.
 
Methods inherited from class jfun.yan.DelegatingComponent
create, equals, getDelegateTarget, getState, getType, hashCode, isConcrete, toString, verify
 
Methods inherited from class jfun.yan.Component
bean, bean, bean, bind, bind, bindArgument, bindArguments, bindProperties, bindProperty, cast, factory, factory, factory, factory, factory, field, field, field, followedBy, followedBy, followedBy, fromArguments, fromProperties, getter, getter, ifelse, ignoreProperty, incomplete, label, label, map, method, method, method, method, method, mutate, option, optional, optionalParameter, optionalParameters, optionalProperties, optionalProperty, recover, repeat, seal, seq, setter, setter, subsume, synchronize, withArgument, withArgument, withArguments, withArguments, withDefaultArgument, withDefaultProperty, withProperties, withProperties, withProperties, withProperty, withProperty, withState
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DecoratingComponent

public DecoratingComponent(Component cc)
Create a new DeleratingComponent object.

Parameters:
cc - the Component object to decorate.
Method Detail

decorate

protected abstract Component decorate(Component c)
Decorate a Component object.

Parameters:
c - the Component to decorate.
Returns:
the decorated Component.

singleton

public Component singleton()
Description copied from class: Component
Create a new Component that utilizes singleton pattern when creating instance. This new component will still use whatever the creation strategy "this" has, But it guarantees that the result is properly cached so that next time create() is called, the same instance will be returned.

Overrides:
singleton in class Component
Returns:
the new Component.

singleton

public Component singleton(Pool scope)
Description copied from class: Component
Create a new Component that utilizes singleton pattern within a scope specified by the provided Pool object when creating instance.
This new component will still use whatever the creation strategy "this" has, But it guarantees that the result is properly cached so that next time create() is called, the same instance will be returned.

Overrides:
singleton in class Component
Parameters:
scope - the scope of the singleton pattern.
Returns:
the new Component.

guard

public Component guard()
Description copied from class: Component
Decorate this Component so that the new Component object guards against infinite dependency loop.

Overrides:
guard in class Component
Returns:
the new Component object.

proxy

public Component proxy()
Description copied from class: Component
Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy. The dynamic proxy will implement all the public interfaces that the type of "this" component implements.

Overrides:
proxy in class Component
Returns:
the new Component object.

proxy

public Component proxy(java.lang.Class itf)
Description copied from class: Component
Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.

Overrides:
proxy in class Component
Parameters:
itf - the interface to proxy to.
Returns:
the new Component object.

proxy

public Component proxy(java.lang.Class[] itfs)
Description copied from class: Component
Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.

Overrides:
proxy in class Component
Parameters:
itfs - the interfaces to proxy to.
Returns:
the new Component object.

isSingleton

public boolean isSingleton()
Description copied from interface: Creator
Determines if the component always return the same instance and has no side-effect that causes difference when called the second time.

This information may be useful to certain optimizations.

Specified by:
isSingleton in interface Creator
Overrides:
isSingleton in class DelegatingComponent
Returns:
true if it always return the same instance. False if not singleton or non-determinable.