public class DecoratorPicker<Type,Decorator extends Type> extends Object
To configure the decorator, one has to provide a DecoratorSetContext that
is then used to obtain the list of
supported interfaces, which are
all the interfaces that should be used for decorator resolution (i.e. all other interfaces
that a class might implement are ignored during decorator resolution), the list of
decorator classes, which is a list
of decorators the picker can choose from and is also used to instantiate and initialize
the decorators.
| Constructor and Description |
|---|
DecoratorPicker() |
| Modifier and Type | Method and Description |
|---|---|
Type |
decorate(Type object)
This method first establishes the set of decorators to use based on the class of the supplied
object and then chains the decorators (in arbitrary order) with the supplied object at the
"root" of the chain.
|
Type |
decorate(Type object,
Class<?> significantSuperClass)
Similar to
decorate(Object) but instead of the class of the object itself,
uses the significantSuperClass as the basis for the decorator resolution. |
DecoratorSetContext<Type,Decorator> |
getContext() |
Set<Decorator> |
getDecoratorsForClass(Class<? extends Type> cls)
Returns a set of decorators that can be used on instances of given class.
|
Set<Decorator> |
getDecoratorsForMethod(Method method)
Returns a set of decorators applicable for given method.
|
void |
setContext(DecoratorSetContext<Type,Decorator> decoratorSetContext) |
public DecoratorSetContext<Type,Decorator> getContext()
public void setContext(DecoratorSetContext<Type,Decorator> decoratorSetContext)
public Set<Decorator> getDecoratorsForMethod(Method method) throws Exception
method - the method to inspectExceptionpublic Set<Decorator> getDecoratorsForClass(Class<? extends Type> cls) throws Exception
cls - the class to inspectExceptionpublic Type decorate(Type object) throws Exception
If a method is then called on the returned object, the methods of all the decorators are called in chain (each supposedly calling the next) and finally, at the end of the chain, the method on the original object (the one supplied to this method) is called.
Note that the above is only an intended behavior and actually depends on the implementation of
the decorators that are resposinble for the chaining. Each decorator is initialized
(@{link DecoratorSetContext.init(Object, Object) which should set it up for such chaining.
object - Exceptionpublic Type decorate(Type object, Class<?> significantSuperClass) throws Exception
decorate(Object) but instead of the class of the object itself,
uses the significantSuperClass as the basis for the decorator resolution.
This is important, because if the object implements two mutually incompatible sub-interfaces of Type,
the chained decorators might fail to execute a method later on if the decorator depends on the upper part
of the chain to implement certain sub-interface of Type.
object - the object to wrap in decoratorssignificantSuperClass - the class to base the decorator resolution onExceptionCopyright © 2008-2013 Red Hat, Inc.. All Rights Reserved.