org.rhq.jndi.util
Class DecoratorPicker<Type,Decorator extends Type>

java.lang.Object
  extended by org.rhq.jndi.util.DecoratorPicker<Type,Decorator>

public class DecoratorPicker<Type,Decorator extends Type>
extends Object

Given as set of decorators extending given type, this class can pick the most appropriate set of decorators for a class or a method call.

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.

Author:
Lukas Krejci

Constructor Summary
DecoratorPicker()
           
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecoratorPicker

public DecoratorPicker()
Method Detail

getContext

public DecoratorSetContext<Type,Decorator> getContext()

setContext

public void setContext(DecoratorSetContext<Type,Decorator> decoratorSetContext)

getDecoratorsForMethod

public Set<Decorator> getDecoratorsForMethod(Method method)
                                                   throws Exception
Returns a set of decorators applicable for given method. The set is established based on the declaring class of the method.

Parameters:
method - the method to inspect
Returns:
the set of decorators that can be used to wrap a method call
Throws:
Exception

getDecoratorsForClass

public Set<Decorator> getDecoratorsForClass(Class<? extends Type> cls)
                                                  throws Exception
Returns a set of decorators that can be used on instances of given class.

Parameters:
cls - the class to inspect
Returns:
Throws:
Exception

decorate

public Type decorate(Type object)
              throws Exception
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.

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.

Parameters:
object -
Returns:
Throws:
Exception

decorate

public Type decorate(Type object,
                     Class<?> significantSuperClass)
              throws Exception
Similar to 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.

Parameters:
object - the object to wrap in decorators
significantSuperClass - the class to base the decorator resolution on
Returns:
Throws:
Exception


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.