|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjfun.yan.Component<T>
public abstract class Component<T>
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)
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. |
|
|
bind(Binder<T,To> binder)
Monadic 'bind' operation. |
|
|
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. |
|
|
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. |
|
|
factory(java.lang.Class<F> factory_type)
Create a Component that instantiates a factory interface. |
|
|
factory(java.lang.Class<F> factory_type,
java.lang.ClassLoader loader,
java.lang.String toString)
Create a Component that instantiates a factory interface. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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 |
|---|
public Component()
| Method Detail |
|---|
public java.lang.Object getState()
getState in interface Statefulpublic Component<T> withState(java.lang.Object obj)
obj - the user state object.
public abstract java.lang.Class getType()
getType in interface Creator<T>getType in interface Typefulpublic Component<T> singleton()
public Component<T> singleton(Pool scope)
scope - the scope of the singleton pattern.
public <F> Component<F> factory(java.lang.Class<F> factory_type,
java.lang.ClassLoader loader,
java.lang.String toString)
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.
public <F> Component<F> factory(java.lang.Class<F> factory_type,
java.lang.String toString)
factory_type - the class object of the factory interface.toString - the string returned by the toString() method of the proxy.
public <F> Component<F> factory(java.lang.Class<F> factory_type)
factory_type - the class object of the factory interface.
public Component<Factory<T>> factory(java.lang.String toString)
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.
toString - the string returned by the toString() method of the factory.
public Component<Factory<T>> factory()
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.
public Component<T> guard()
public Component withArgument(int i,
Creator factory)
i - the ordinal position of the parameter.factory - the creator object for creating that argument.
public Component<T> withArgument(int i,
Part part)
i - the ordinal position of the parameter.part - the Part object for creating that argument.
public Component<T> withArguments(Creator[] factories)
factories - the creator objects for creating arguments.
public Component<T> bindArguments(ParameterBinder binder)
binder - the ParameterBinder object for creating arguments.
public Component<T> bindArgument(int k,
ParameterBinder binder)
k - the ordinal position of the parameter.binder - the ParameterBinder object for creating arguments.
public Component<T> withArguments(Part part)
part - the Part object.
public Component<T> withProperty(java.lang.Object k,
Creator factory)
k - the property key.factory - the Creator object.
public Component<T> withProperty(java.lang.Object k,
Part p)
k - the property key.p - the Part object.
public Component<T> withProperties(java.util.Map props)
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.
public Component<T> withProperties(java.lang.String[] keys,
Creator[] creators)
keys - the property keys. Duplicate key is not allowed in this array.
Keys are case-sensitive.creators - the creators for creating property values.
public Component<T> bindProperties(PropertyBinder binder)
binder - the PropertyBinder object for creating properties.
public Component<T> bindProperty(java.lang.Object k,
PropertyBinder binder)
k - the property key.binder - the PropertyBinder object for creating properties.
public Component<T> withProperties(Part p)
p - the Part object.
public <Super> Component<Super> subsume(java.lang.Class<Super> type)
type - the target type.
public <X> Component<X> cast(java.lang.Class<X> type)
type - the target type.
public Component proxy(java.lang.Class[] itfs)
itfs - the interfaces to proxy to.
public <I> Component<I> proxy(java.lang.Class<I> itf)
itf - the interface to proxy to.
public Component proxy()
public <To> Component<To> map(Map<T,To> m)
m - the Map object.
public Component<T> mutate(Mutation<T> m)
m - the Mutation object.
public Component<T> incomplete()
public Component<T> label(java.lang.Object lbl)
lbl - the label.
public Component<T> label()
public Component<T> ignoreProperty(java.lang.Object key)
key - the property key.
public Component<T> optionalProperty(java.lang.Object key)
key - the property key.
public Component<T> optionalProperties()
public Component<T> optionalParameter(int ind)
ind - the ordinal position of the parameter.
public Component<T> optionalParameters()
public Component<T> withDefaultProperty(java.lang.Object key,
Creator def)
key - the property key.def - the alternative Creator object.
public Component<T> withDefaultArgument(int ind,
Creator def)
ind - the ordinal position of the parameter.def - the alternative Creator object.
public Component<T> optional()
public Component<T> option(T val)
val - the alternative value.
public Component<T> recover(Recovery<T> r)
r - the Recovery object.
public <To> Component<To> bind(Binder<T,To> binder)
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.
binder - the Binder object.
public <To> Component<To> bind(ComponentBinder<T,To> binder)
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.
binder - the ComponentBinder object.
public <R> Component<R> ifelse(Component<R> yes,
Component<R> no)
yes - the Component when the condition is true.no - the Component when the condition is false;
public Component<T> followedBy(ComponentBinder<T,?> binder)
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.
ComponentBinder object also takes care of verification
of the base component type.
binder - the ComponentBinder object to do the side effect.
public Component<T> followedBy(Binder<T,?> binder)
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.
binder - the Binder object to do the side effect.
public Component<T> followedBy(Creator<?> c2)
c2 - the Component object to do the side-effect.
public <R> Component<R> seq(Creator<R> c2)
c2 - the next component.
public Component<T> fromProperties(java.lang.Object[] keys)
keys - the property keys for parameters.
The ordinal position of each key indicates the position of the parameter.
public Component<T> fromArguments(java.lang.Object[] keys)
keys - the property keys to redirect.
The ordinal position of each key indicates the position of the parameter.
public Component<T> seal()
public Component<T> bean()
throws java.beans.IntrospectionException
java.beans.IntrospectionException - if java bean introspection fails.
public Component<T> bean(java.lang.String[] props)
throws java.beans.IntrospectionException,
IllegalPropertyNameException,
NonWritablePropertyException,
java.lang.IllegalArgumentException
props - the names of the properties used.
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.
public Component<T> bean(java.util.Set props)
throws java.beans.IntrospectionException,
IllegalPropertyNameException,
NonWritablePropertyException
props - the names of the properties used.
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.public Component method(java.lang.reflect.Method mtd)
mtd - the method to call against the instance.
public Component method(java.lang.String name)
throws java.lang.IllegalArgumentException
name - the method name.
java.lang.IllegalArgumentException - if the static resolution of the method
fails.
public Component method(java.lang.String name,
boolean suppress_security)
throws java.lang.IllegalArgumentException
name - the method name.suppress_security - whether access to non-public methods is allowed.
java.lang.IllegalArgumentException - if the static resolution of the method
fails.public Component field(java.lang.reflect.Field fld)
fld - the field to read.
public Component field(java.lang.String name)
throws java.lang.IllegalArgumentException
name - the field name.
java.lang.IllegalArgumentException - if the static resolution of the field
fails.
public Component field(java.lang.String name,
boolean suppress_security)
throws java.lang.IllegalArgumentException
name - the field name.suppress_security - whether access to non-public field is allowed.
java.lang.IllegalArgumentException - if the static resolution of the field
fails.
public Component method(java.lang.String name,
java.lang.Class[] param_types)
throws java.lang.IllegalArgumentException
name - the method name.param_types - the parameter types of the method. null indicates
a parameter-less method.
java.lang.IllegalArgumentException - if the static resolution of the method
fails.
public Component method(java.lang.String name,
java.lang.Class[] param_types,
boolean suppress_security)
throws java.lang.IllegalArgumentException
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.
java.lang.IllegalArgumentException - if the static resolution of the method
fails.
public Component getter(java.lang.String name)
throws java.beans.IntrospectionException
name - the property name.
java.beans.IntrospectionException - if introspection fails.
public Component<T> setter(java.lang.String name)
throws java.beans.IntrospectionException
name - the property name.
java.beans.IntrospectionException - if introspection fails.
public Component getter(java.lang.String name,
int ind)
throws java.beans.IntrospectionException
name - the property name.ind - the index.
java.beans.IntrospectionException - if introspection fails.
public Component<T> setter(java.lang.String name,
int ind)
throws java.beans.IntrospectionException
name - the property name.ind - the index.
java.beans.IntrospectionException - if introspection fails.public Component<T> repeat(int times)
times - the number of times to repeat.
public Component<T> synchronize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||