jfun.yan
Class Component<T>

java.lang.Object
  extended by jfun.yan.Component<T>
All Implemented Interfaces:
java.io.Serializable, Creator<T>, Stateful, Typeful, Verifiable
Direct Known Subclasses:
Creator2Component, DelegatingComponent, SimpleComponent

public abstract class Component<T>
extends java.lang.Object
implements Creator<T>, Typeful, Stateful

Responsible for component instance creation and verification.

Component is immutable. All update functions such as the ones started with "with" are functional-update, which means a new Component object is created to reflect the change, while the state of the old object remains the same.

Component is the core of Yan in the sense that most customizations of instance creation strategy can be done by combining existing Component objects.

This is called a "combinator" approach where complex components can be constructed by combining simpler components who may be combinations of yet simpler components.

Common combinators are included in this class to make the syntax simpler for combining components. For example:
comp1.withArguments(args) rather than Components.withArguments(comp1, args)

Codehaus.org.

Author:
Ben Yu
See Also:
Components, Monad, Serialized Form

Constructor Summary
Component()
           
 
Method Summary
 Component<T> bean()
          Create a Component object that calls Java Bean setters after an instance is created by this Component object.
 Component<T> bean(java.util.Set props)
          Create a Component object that calls Java Bean setters after an instance is created by this Component.
 Component<T> bean(java.lang.String[] props)
          Create a Component object that calls Java Bean setters after an instance is created by this Component.
<To> Component<To>
bind(Binder<T,To> binder)
          Monadic 'bind' operation.
<To> Component<To>
bind(ComponentBinder<T,To> binder)
          Monadic 'bind' operation.
 Component<T> bindArgument(int k, ParameterBinder binder)
          Create a new Component object that uses a given ParameterBinder object to create one of its argument identified by its ordinal position.
 Component<T> bindArguments(ParameterBinder binder)
          Create a new Component object that uses given ParameterBinder object to create its parameters.
 Component<T> bindProperties(PropertyBinder binder)
          Create a new Component object that uses given PropertyBinder object to create its properties.
 Component<T> bindProperty(java.lang.Object k, PropertyBinder binder)
          Create a new Component object that uses given PropertyBinder object to create one of its property identified by a property key.
<X> Component<X>
cast(java.lang.Class<X> type)
          Create a new Component object that returns the given type as its component instance type when getType() or verify(Dependency) is called.
 Component<Factory<T>> factory()
          Create a Component that instantiates the Factory interface.
<F> Component<F>
factory(java.lang.Class<F> factory_type)
          Create a Component that instantiates a factory interface.
<F> Component<F>
factory(java.lang.Class<F> factory_type, java.lang.ClassLoader loader, java.lang.String toString)
          Create a Component that instantiates a factory interface.
<F> Component<F>
factory(java.lang.Class<F> factory_type, java.lang.String toString)
          Create a Component that instantiates a factory interface.
 Component<Factory<T>> factory(java.lang.String toString)
          Create a Component that instantiates the Factory interface.
 Component field(java.lang.reflect.Field fld)
          Creates a Component that will read a certain field from the instance created by this Component.
 Component field(java.lang.String name)
          Creates a Component that will read a public field from the instance created by this Component.
 Component field(java.lang.String name, boolean suppress_security)
          Creates a Component that will read a field from the instance created by this Component.
 Component<T> followedBy(Binder<T,?> binder)
          Create a staged component.
 Component<T> followedBy(ComponentBinder<T,?> binder)
          Create a staged component.
 Component<T> followedBy(Creator<?> c2)
          Create a staged component.
 Component<T> fromArguments(java.lang.Object[] keys)
          Redirects resolution of properties to arguments.
 Component<T> fromProperties(java.lang.Object[] keys)
          Redirects resolution of arguments to properties.
 java.lang.Object getState()
          Gets the user state of this component.
 Component getter(java.lang.String name)
          Create a Component that will return a bean property of the instance created by this component.
 Component getter(java.lang.String name, int ind)
          Create a Component that will get an indexed property of the Java Bean instance created by this component.
abstract  java.lang.Class getType()
          Get the type of instances that this component is responsible to create.
 Component<T> guard()
          Decorate this Component so that the new Component object guards against infinite dependency loop.
<R> Component<R>
ifelse(Component<R> yes, Component<R> no)
          Create a Component object according to the boolean value returned from this Component.
 Component<T> ignoreProperty(java.lang.Object key)
          Ignore the property identified by a key and use the default mechanism.
 Component<T> incomplete()
          By default, all components depended by this component will be verified when this component is verified.
 Component<T> label()
          Label the frame for this Component so that whenever a YanException is thrown, the component itself will be populated in the resolution trace.
 Component<T> label(java.lang.Object lbl)
          Label the frame for this Component so that whenever a YanException is thrown, the provided label will be populated in the resolution trace.
<To> Component<To>
map(Map<T,To> m)
          Create a new Component that upon creation, transforms the component instance to another instance.
 Component method(java.lang.reflect.Method mtd)
          Creates a Component that will call a certain method against the instance created by this Component.
 Component method(java.lang.String name)
          Creates a Component that will call a certain public method against the instance created by this Component.
 Component method(java.lang.String name, boolean suppress_security)
          Creates a Component that will call a certain method against the instance created by this Component.
 Component method(java.lang.String name, java.lang.Class[] param_types)
          Creates a Component that will call a certain public method against the instance created by this Component.
 Component method(java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Creates a Component that will call a certain method against the instance created by this Component.
 Component<T> mutate(Mutation<T> m)
          Create a new Component that upon creation, mutates the component instance before it is returned.
 Component<T> option(T val)
          Creates an optional Component.
 Component<T> optional()
          Creates an optional Component.
 Component<T> optionalParameter(int ind)
          Make a parameter optional, so that when the argument cannot be resolved or any of its subcomponent cannot be resolved, the default value is used instead.
 Component<T> optionalParameters()
          Make sure the parameters are optional.
 Component<T> optionalProperties()
          Make sure the properties are optional.
 Component<T> optionalProperty(java.lang.Object key)
          Make a property identified by a key optional, so that when the property cannot be resolved or any of its subcomponent cannot be resolved, the default value is used instead.
 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[] itfs)
          Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.
<I> Component<I>
proxy(java.lang.Class<I> itf)
          Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.
 Component<T> recover(Recovery<T> r)
          Create a new Component object that will recover errors happened from this Component.
 Component<T> repeat(int times)
          Create a new Component that repeatedly call this Component for certain amount of times.
 Component<T> seal()
          Create a sealed component.
<R> Component<R>
seq(Creator<R> c2)
          Monadic 'sequence' operation.
 Component<T> setter(java.lang.String name)
          Create a Component that will set a bean property of the instance created by this component.
 Component<T> setter(java.lang.String name, int ind)
          Create a Component that will set an indexed property of the Java Bean instance created by this component.
 Component<T> singleton()
          Create a new Component that utilizes singleton pattern when creating instance.
 Component<T> singleton(Pool scope)
          Create a new Component that utilizes singleton pattern within a scope specified by the provided Pool object when creating instance.
<Super> Component<Super>
subsume(java.lang.Class<Super> type)
          Create a new Component object that returns the given type as its component instance type when getType() or verify(Dependency) is called.
 Component<T> synchronize()
          Create a Component that the "create()" method is put in a synchronized block to ensure thread safety.
 Component withArgument(int i, Creator factory)
          Create a new Component object that uses a given Creator to create one of its parameters.
 Component<T> withArgument(int i, Part part)
          Create a new Component object that uses a given Part object to create one of its parameters.
 Component<T> withArguments(Creator[] factories)
          Create a new Component object that uses given Creator objects to create its parameters.
 Component<T> withArguments(Part part)
          Create a new Component object that uses the given Part object to create all its parameters.
 Component<T> withDefaultArgument(int ind, Creator def)
          Create a Component object that will use an alternative Creator object when a certain parameter is passed in as default.
 Component<T> withDefaultProperty(java.lang.Object key, Creator def)
          Create a Component object that will use an alternative Creator object when a certain property is passed in as default.
 Component<T> withProperties(java.util.Map props)
          Create a new Component object that uses given Creator objects to create some of its properties.
 Component<T> withProperties(Part p)
          Create a new Component object that uses a Part object to create all of its property values.
 Component<T> withProperties(java.lang.String[] keys, Creator[] creators)
          Create a new Component object that uses given Creator objects to create some of its properties' value.
 Component<T> withProperty(java.lang.Object k, Creator factory)
          Create a new Component object that uses a given Creator object to create one of its property value.
 Component<T> withProperty(java.lang.Object k, Part p)
          Create a new Component object that uses a given Part object to create one of its property values.
 Component<T> withState(java.lang.Object obj)
          Create a new Component object with the specified user state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jfun.yan.Creator
create, isConcrete, isSingleton
 
Methods inherited from interface jfun.yan.Verifiable
verify
 

Constructor Detail

Component

public Component()
Method Detail

getState

public java.lang.Object getState()
Gets the user state of this component. null is returned by default. Subclasses can either override this method to provide user states, or call Component.withState() to associate a user state. Component.withState() is preferable.

Specified by:
getState in interface Stateful
Returns:
the state.

withState

public Component<T> withState(java.lang.Object obj)
Create a new Component object with the specified user state.

Parameters:
obj - the user state object.
Returns:
the new Component object.

getType

public abstract java.lang.Class getType()
Get the type of instances that this component is responsible to create. null is returned if the type of the component cannot be determined at the time. This is typically for components that utilize late-binding strategy where the actual component type is resolved at creation time.

Specified by:
getType in interface Creator<T>
Specified by:
getType in interface Typeful
Returns:
the type of the component.

singleton

public Component<T> singleton()
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.

Returns:
the new Component.

singleton

public Component<T> singleton(Pool scope)
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.

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

factory

public <F> Component<F> factory(java.lang.Class<F> factory_type,
                                java.lang.ClassLoader loader,
                                java.lang.String toString)
Create a Component that instantiates a factory interface. 'this' component is used as the component for product object. All factory methods in the factory interface will delegate to the product component ('this' component) to create the product.

Parameters:
factory_type - the class object of the factory interface.
loader - the ClassLoader to load the proxy class.
toString - the string returned by the toString() method of the proxy.
Returns:
the factory component.

factory

public <F> Component<F> factory(java.lang.Class<F> factory_type,
                                java.lang.String toString)
Create a Component that instantiates a factory interface. 'this' component is used as the component for product object. All factory methods in the factory interface will delegate to the product component ('this' component) to create the product.

Parameters:
factory_type - the class object of the factory interface.
toString - the string returned by the toString() method of the proxy.
Returns:
the factory component.

factory

public <F> Component<F> factory(java.lang.Class<F> factory_type)
Create a Component that instantiates a factory interface. 'this' component is used as the component for product object. All factory methods in the factory interface will delegate to the product component ('this' component) to create the product.

Parameters:
factory_type - the class object of the factory interface.
Returns:
the factory component.

factory

public Component<Factory<T>> factory(java.lang.String toString)
Create a Component that instantiates the Factory interface. 'this' component is used as the component for product object. The Factory.create() method delegates to the product component ('this' component) to create the product.

Parameters:
toString - the string returned by the toString() method of the factory.
Returns:
the factory component.

factory

public Component<Factory<T>> factory()
Create a Component that instantiates the Factory interface. 'this' component is used as the component for product object. The Factory.create() method delegates to the product component ('this' component) to create the product.

Returns:
the factory component.

guard

public Component<T> guard()
Decorate this Component so that the new Component object guards against infinite dependency loop.

Returns:
the new Component object.

withArgument

public Component withArgument(int i,
                              Creator factory)
Create a new Component object that uses a given Creator to create one of its parameters.

Parameters:
i - the ordinal position of the parameter.
factory - the creator object for creating that argument.
Returns:
the new Component object.

withArgument

public Component<T> withArgument(int i,
                                 Part part)
Create a new Component object that uses a given Part object to create one of its parameters.

Parameters:
i - the ordinal position of the parameter.
part - the Part object for creating that argument.
Returns:
the new Component object.

withArguments

public Component<T> withArguments(Creator[] factories)
Create a new Component object that uses given Creator objects to create its parameters. For parameter i, factories[i] is used to create it if i is between 0 and factories.length. the default creation strategy is used otherwise.

Parameters:
factories - the creator objects for creating arguments.
Returns:
the new Component object.

bindArguments

public Component<T> bindArguments(ParameterBinder binder)
Create a new Component object that uses given ParameterBinder object to create its parameters. For each parameter identified by an ordinal position and a type, the ParameterBinder object is called to get a new Creator object, which is used to create the argument.

Parameters:
binder - the ParameterBinder object for creating arguments.
Returns:
the new Component object.

bindArgument

public Component<T> bindArgument(int k,
                                 ParameterBinder binder)
Create a new Component object that uses a given ParameterBinder object to create one of its argument identified by its ordinal position.

Parameters:
k - the ordinal position of the parameter.
binder - the ParameterBinder object for creating arguments.
Returns:
the new Component object.

withArguments

public Component<T> withArguments(Part part)
Create a new Component object that uses the given Part object to create all its parameters.

Parameters:
part - the Part object.
Returns:
the new Component object.

withProperty

public Component<T> withProperty(java.lang.Object k,
                                 Creator factory)
Create a new Component object that uses a given Creator object to create one of its property value.

Parameters:
k - the property key.
factory - the Creator object.
Returns:
the new Component object.

withProperty

public Component<T> withProperty(java.lang.Object k,
                                 Part p)
Create a new Component object that uses a given Part object to create one of its property values.

Parameters:
k - the property key.
p - the Part object.
Returns:
the new Component object.

withProperties

public Component<T> withProperties(java.util.Map props)
Create a new Component object that uses given Creator objects to create some of its properties.

Parameters:
props - the map that contains mappings between property keys and Creator objects that creates the property value. This Map object is not modified within this method. It is allowed to subsequently change the Map object after this method is called. The new change will be picked up by the component when creating instances. If a property's key is not contained in the Map object, the creation strategy is not changed for this property.
Returns:
the new Component object.

withProperties

public Component<T> withProperties(java.lang.String[] keys,
                                   Creator[] creators)
Create a new Component object that uses given Creator objects to create some of its properties' value. For property identified by keys[i], creators[i] is used for creating value. The keys array and creators array has to be the same length.

Parameters:
keys - the property keys. Duplicate key is not allowed in this array. Keys are case-sensitive.
creators - the creators for creating property values.
Returns:
the new Component object.

bindProperties

public Component<T> bindProperties(PropertyBinder binder)
Create a new Component object that uses given PropertyBinder object to create its properties. For each property identified by a key and a type, the PropertyBinder object is called to get a new Creator object, which is used to create the property value.

Parameters:
binder - the PropertyBinder object for creating properties.
Returns:
the new Component object.

bindProperty

public Component<T> bindProperty(java.lang.Object k,
                                 PropertyBinder binder)
Create a new Component object that uses given PropertyBinder object to create one of its property identified by a property key.

Parameters:
k - the property key.
binder - the PropertyBinder object for creating properties.
Returns:
the new Component object.

withProperties

public Component<T> withProperties(Part p)
Create a new Component object that uses a Part object to create all of its property values.

Parameters:
p - the Part object.
Returns:
the new Component object.

subsume

public <Super> Component<Super> subsume(java.lang.Class<Super> type)
Create a new Component object that returns the given type as its component instance type when getType() or verify(Dependency) is called. If the component is not late-bound (where getType() returns null), the given type has to be same or super type of the component instance type of "this"

Parameters:
type - the target type.
Returns:
the new Component object.

cast

public <X> Component<X> cast(java.lang.Class<X> type)
Create a new Component object that returns the given type as its component instance type when getType() or verify(Dependency) is called. Unlike subsume(), this method allows "down-cast" where the current component instance type is a subtype of the given type. It also allows "stupid-cast" where the current component instance type has no is-a relationship with the target type.

Parameters:
type - the target type.
Returns:
the new Component object.

proxy

public 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.

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

proxy

public <I> Component<I> proxy(java.lang.Class<I> itf)
Create a new Component object that uses dynamic proxy to transform the return value 'this' Component creates to a dynamic proxy.

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

proxy

public Component proxy()
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.

Returns:
the new Component object.

map

public <To> Component<To> map(Map<T,To> m)
Create a new Component that upon creation, transforms the component instance to another instance.

Parameters:
m - the Map object.
Returns:
the new Component object.

mutate

public Component<T> mutate(Mutation<T> m)
Create a new Component that upon creation, mutates the component instance before it is returned.

Parameters:
m - the Mutation object.
Returns:
the new Component object.

incomplete

public Component<T> incomplete()
By default, all components depended by this component will be verified when this component is verified. incomplete() creates a new Component object that suppresses the verification of dependency.

Returns:
the new Component object.

label

public Component<T> label(java.lang.Object lbl)
Label the frame for this Component so that whenever a YanException is thrown, the provided label will be populated in the resolution trace.

Parameters:
lbl - the label.
Returns:
the new Component object.

label

public Component<T> label()
Label the frame for this Component so that whenever a YanException is thrown, the component itself will be populated in the resolution trace.
It is equivalent as label(this).

Returns:
the new Component object.

ignoreProperty

public Component<T> ignoreProperty(java.lang.Object key)
Ignore the property identified by a key and use the default mechanism. Equivalent as this.withProperty(key, Components.useDefault()).

Parameters:
key - the property key.
Returns:
the new Component object.

optionalProperty

public Component<T> optionalProperty(java.lang.Object key)
Make a property identified by a key optional, so that when the property cannot be resolved or any of its subcomponent cannot be resolved, the default value is used instead.

Parameters:
key - the property key.
Returns:
the new Component object.

optionalProperties

public Component<T> optionalProperties()
Make sure the properties are optional.

Returns:
the new Component object.

optionalParameter

public Component<T> optionalParameter(int ind)
Make a parameter optional, so that when the argument cannot be resolved or any of its subcomponent cannot be resolved, the default value is used instead.

Parameters:
ind - the ordinal position of the parameter.
Returns:
the new Component object.

optionalParameters

public Component<T> optionalParameters()
Make sure the parameters are optional.

Returns:
the new Component object.

withDefaultProperty

public Component<T> withDefaultProperty(java.lang.Object key,
                                        Creator def)
Create a Component object that will use an alternative Creator object when a certain property is passed in as default.

Parameters:
key - the property key.
def - the alternative Creator object.
Returns:
the new Component object.

withDefaultArgument

public Component<T> withDefaultArgument(int ind,
                                        Creator def)
Create a Component object that will use an alternative Creator object when a certain parameter is passed in as default.

Parameters:
ind - the ordinal position of the parameter.
def - the alternative Creator object.
Returns:
the new Component object.

optional

public Component<T> optional()
Creates an optional Component. If this component fails, it returns the special default value indicator.

Returns:
the new Component object.

option

public Component<T> option(T val)
Creates an optional Component. If this component fails, it uses the provided value as return value.

Parameters:
val - the alternative value.
Returns:
the new Component object.

recover

public Component<T> recover(Recovery<T> r)
Create a new Component object that will recover errors happened from this Component.

Parameters:
r - the Recovery object.
Returns:
the new Component object.

bind

public <To> Component<To> bind(Binder<T,To> binder)
Monadic 'bind' operation. It creates a new Component object. Upon instance creation, this Component object will

1. invokes this component object to create an instance.
2. feed the instance to the Binder object to get a second Creator object.
3. Invoke the second Creator object to get a second instance.
4. return the second instance as the instance of this Component.

Since the actual component type is not known until creation time, null is returned for getType().

Parameters:
binder - the Binder object.
Returns:
the new Component object.

bind

public <To> Component<To> bind(ComponentBinder<T,To> binder)
Monadic 'bind' operation. It creates a new Component object. Upon instance creation, this Component object will

1. invokes this component object to create an instance.
2. feed the instance to the Binder object to get a second Creator object.
3. Invoke the second Creator object to get a second instance.
4. return the second instance as the instance of this Component.

Since the actual component type is not known until creation time, null is returned for getType().
The ComponentBinder object will also verifies the component type of this component when verifying.

Parameters:
binder - the ComponentBinder object.
Returns:
the new Component object.

ifelse

public <R> Component<R> ifelse(Component<R> yes,
                               Component<R> no)
Create a Component object according to the boolean value returned from this Component.

Parameters:
yes - the Component when the condition is true.
no - the Component when the condition is false;
Returns:
the conditional Component.

followedBy

public Component<T> followedBy(ComponentBinder<T,?> binder)
Create a staged component. On instantiation, it first creates the base object using this component, then the ComponentBinder object is used to do certain side-effect to complete the work. The object created by this component is finally returned as the instance.
Bean component, for example, is an application of staged component.
The ComponentBinder object also takes care of verification of the base component type.

Parameters:
binder - the ComponentBinder object to do the side effect.
Returns:
the new Component object.

followedBy

public Component<T> followedBy(Binder<T,?> binder)
Create a staged component. On instantiation, it first creates the base object using this component, then the Binder object is used to do certain side-effect to complete the work. The object created by this component is finally returned as the instance.
Bean component, for example, is an application of staged component.

Parameters:
binder - the Binder object to do the side effect.
Returns:
the new Component object.

followedBy

public Component<T> followedBy(Creator<?> c2)
Create a staged component. On instantiation, it first creates the base object using this component, then another Creator object is used to do certain side-effect to complete the work. The object created by this component is finally returned as the instance.
Bean component, for example, is an application of staged component.

Parameters:
c2 - the Component object to do the side-effect.
Returns:
the new Component object.

seq

public <R> Component<R> seq(Creator<R> c2)
Monadic 'sequence' operation. It sequentially execute this component and then another one and keep the result of the second component.

Parameters:
c2 - the next component.
Returns:
the new Component object.

fromProperties

public Component<T> fromProperties(java.lang.Object[] keys)
Redirects resolution of arguments to properties. So that a parameter-based component (such as ctor or method) can be used as if it were a bean component, for which withProperty, withProperties can be used to customize.
It is useful when applying a parameter-based component to an algorithm that relies on property-based component.

Parameters:
keys - the property keys for parameters. The ordinal position of each key indicates the position of the parameter.
Returns:
the redirected Component object.

fromArguments

public Component<T> fromArguments(java.lang.Object[] keys)
Redirects resolution of properties to arguments. So that a property-based component (such as bean) can be used as if it were a parameter-based on, for which withArgument, withArguments can be used to customize.
It is useful when applying a property-based component to an algorithm that relies on argument-based component. The factory() combinator, for example, relies on parameter-based component.

Parameters:
keys - the property keys to redirect. The ordinal position of each key indicates the position of the parameter.
Returns:
the redirected Component object.

seal

public Component<T> seal()
Create a sealed component. A sealed component assumes responsibility to resolve its own dependencies. It does not attempt to look up the container to resolve any unresolved dependency.
seal can be used to disable auto-wiring at component level.

Returns:
the sealed Component object.

bean

public Component<T> bean()
                  throws java.beans.IntrospectionException
Create a Component object that calls Java Bean setters after an instance is created by this Component object.
The Java Bean setters used to create the component instance are determined by the return value of this.getType() method. That means, if getType() returns Type1 while the actual instance created is a subtype of Type1, only the setters of Type1 are used. However, if this component is late-bound, where the getType() returns null, the Java Bean setters are resolved at creation time.
It should be noted that, for a singleton bean component obtained by calling singleton() method against the bean component, it does not cause infinite loop if any property of the component is depending on this same singleton bean componet. This is because the singleton bean component caches the instance before any of the properties are set.

Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if java bean introspection fails.

bean

public Component<T> bean(java.lang.String[] props)
                  throws java.beans.IntrospectionException,
                         IllegalPropertyNameException,
                         NonWritablePropertyException,
                         java.lang.IllegalArgumentException
Create a Component object that calls Java Bean setters after an instance is created by this Component.
The Java Bean setters used to create the component instance are determined by the return value of getType() method. That means, if getType() returns Type1 while the actual instance created is a subtype of Type1, only the setters of Type1 are used. However, if the base component is late-bound, where the getType() returns null, the Java Bean setters are resolved at creation time.
It should be noted that, for a singleton bean component obtained by calling singleton() method against the bean component, it does not cause infinite loop if any property of the component is depending on this same singleton bean componet. This is because the singleton bean component caches the instance before any of the properties are set.

Parameters:
props - the names of the properties used.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if java bean introspection fails.
IllegalPropertyNameException - if a name specified in the props Set is not a valid property name.
NonWritablePropertyException - if a property specified has no setter.
java.lang.IllegalArgumentException - if the props array has any duplicate name.

bean

public Component<T> bean(java.util.Set props)
                  throws java.beans.IntrospectionException,
                         IllegalPropertyNameException,
                         NonWritablePropertyException
Create a Component object that calls Java Bean setters after an instance is created by this Component.
The Java Bean setters used to create the component instance are determined by the return value of getType() method. That means, if getType() returns Type1 while the actual instance created is a subtype of Type1, only the setters of Type1 are used. However, if the base component is late-bound, where the getType() returns null, the Java Bean setters are resolved at creation time.
It should be noted that, for a singleton bean component obtained by calling singleton() method against the bean component, it does not cause infinite loop if any property of the component is depending on this same singleton bean componet. This is because the singleton bean component caches the instance before any of the properties are set.

Parameters:
props - the names of the properties used.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if java bean introspection fails.
IllegalPropertyNameException - if a name specified in the props Set is not a valid property name.
NonWritablePropertyException - if a property specified has no setter.

method

public Component method(java.lang.reflect.Method mtd)
Creates a Component that will call a certain method against the instance created by this Component. The return value of the method is used as the result of the created Component.

Parameters:
mtd - the method to call against the instance.
Returns:
the new Component object.

method

public Component method(java.lang.String name)
                 throws java.lang.IllegalArgumentException
Creates a Component that will call a certain public method against the instance created by this Component. The return value of the method is used as the result of the created Component.
If the type of the first component is statically known (getType()!=null), The method is statically resolved. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the method name.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the method fails.

method

public Component method(java.lang.String name,
                        boolean suppress_security)
                 throws java.lang.IllegalArgumentException
Creates a Component that will call a certain method against the instance created by this Component. The return value of the method is used as the result of the created Component.
If the type of the first component is statically known (getType()!=null), The method is statically resolved. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the method name.
suppress_security - whether access to non-public methods is allowed.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the method fails.

field

public Component field(java.lang.reflect.Field fld)
Creates a Component that will read a certain field from the instance created by this Component.

Parameters:
fld - the field to read.
Returns:
the new Component object.

field

public Component field(java.lang.String name)
                throws java.lang.IllegalArgumentException
Creates a Component that will read a public field from the instance created by this Component.
If the type of the first component is statically known (getType()!=null), The field is statically resolved. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the field name.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the field fails.

field

public Component field(java.lang.String name,
                       boolean suppress_security)
                throws java.lang.IllegalArgumentException
Creates a Component that will read a field from the instance created by this Component.
If the type of the first component is statically known (getType()!=null), The field is statically resolved. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the field name.
suppress_security - whether access to non-public field is allowed.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the field fails.

method

public Component method(java.lang.String name,
                        java.lang.Class[] param_types)
                 throws java.lang.IllegalArgumentException
Creates a Component that will call a certain public method against the instance created by this Component. The return value of the method is used as the result of the created Component.
If the type of the first component is statically known (getType()!=null), The method is statically resolved when bindMethod() is called. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the method name.
param_types - the parameter types of the method. null indicates a parameter-less method.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the method fails.

method

public Component method(java.lang.String name,
                        java.lang.Class[] param_types,
                        boolean suppress_security)
                 throws java.lang.IllegalArgumentException
Creates a Component that will call a certain method against the instance created by this Component. The return value of the method is used as the result of the created Component.
If the type of the first component is statically known (getType()!=null), The method is statically resolved when bindMethod() is called. Otherwise, it is resolved when the actual component instantiation happens.

Parameters:
name - the method name.
param_types - the parameter types of the method. null indicates a parameter-less method.
suppress_security - whether access to non-public method is allowed.
Returns:
the new Component object.
Throws:
java.lang.IllegalArgumentException - if the static resolution of the method fails.

getter

public Component getter(java.lang.String name)
                 throws java.beans.IntrospectionException
Create a Component that will return a bean property of the instance created by this component.

Parameters:
name - the property name.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if introspection fails.

setter

public Component<T> setter(java.lang.String name)
                    throws java.beans.IntrospectionException
Create a Component that will set a bean property of the instance created by this component.
The bean instance will still be used as the result.

Parameters:
name - the property name.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if introspection fails.

getter

public Component getter(java.lang.String name,
                        int ind)
                 throws java.beans.IntrospectionException
Create a Component that will get an indexed property of the Java Bean instance created by this component.

Parameters:
name - the property name.
ind - the index.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if introspection fails.

setter

public Component<T> setter(java.lang.String name,
                           int ind)
                    throws java.beans.IntrospectionException
Create a Component that will set an indexed property of the Java Bean instance created by this component.
The bean instance will still be used as the result.

Parameters:
name - the property name.
ind - the index.
Returns:
the new Component object.
Throws:
java.beans.IntrospectionException - if introspection fails.

repeat

public Component<T> repeat(int times)
Create a new Component that repeatedly call this Component for certain amount of times.

Parameters:
times - the number of times to repeat.
Returns:
the new Component object.

synchronize

public Component<T> synchronize()
Create a Component that the "create()" method is put in a synchronized block to ensure thread safety.

Returns:
the Component object that is "synchronized".