org.apache.shindig.protocol.conversion
Class BeanDelegator

java.lang.Object
  extended by org.apache.shindig.protocol.conversion.BeanDelegator

public class BeanDelegator
extends Object

Class to create a delegator (proxy) from an interface to a class. It is used by the GadgetHandler to provide easy separation from interface to actual implementation classes. It uses Java reflection which require the usage of interfaces. The validate function should be used in the test code to validate that all API functions are implemented by the actual data, and it will warn us if actual implementation change and break the API. Delegation support composition, and will create a proxy for fields according To table of classes to proxy.

Since:
2.0.0

Nested Class Summary
protected  class BeanDelegator.DelegateInvocationHandler
           
 
Field Summary
static String NULL
          Indicate NULL value for a field (To overcome shortcome of immutable map)
static com.google.common.collect.ImmutableSet<Class<?>> PRIMITIVE_TYPE_CLASSES
          List of Classes that are considered primitives and are not proxied
 
Constructor Summary
BeanDelegator()
           
BeanDelegator(Map<Class<?>,Class<?>> delegatedClasses, Map<Enum<?>,Enum<?>> enumConvertionMap)
           
 
Method Summary
 Enum<?> convertEnum(Enum<?> value)
           
static Map<Enum<?>,Enum<?>> createDefaultEnumMap(Class<? extends Enum<?>> sourceEnum, Class<? extends Enum<?>> targetEnum)
          Utility function to auto generate mapping between two enums that have same values (toString) All values in the sourceEnum must have values in targetEnum, otherwise RuntimeException is thrown
 Object createDelegator(Object source)
          Create a proxy for the real object.
<T> T
createDelegator(Object source, Class<T> apiInterface)
           
<T> T
createDelegator(Object source, Class<T> apiInterface, Map<String,Object> extraFields)
           
static Object nullable(Object o)
          Gate a value to use NULL constant instead of null pointer
 void validate()
          Validate all proxied classes to see that all required functions are implemented.
 void validate(Class<?> dataClass, Class<?> interfaceClass)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final String NULL
Indicate NULL value for a field (To overcome shortcome of immutable map)

See Also:
Constant Field Values

PRIMITIVE_TYPE_CLASSES

public static final com.google.common.collect.ImmutableSet<Class<?>> PRIMITIVE_TYPE_CLASSES
List of Classes that are considered primitives and are not proxied

Constructor Detail

BeanDelegator

public BeanDelegator()

BeanDelegator

public BeanDelegator(Map<Class<?>,Class<?>> delegatedClasses,
                     Map<Enum<?>,Enum<?>> enumConvertionMap)
Method Detail

nullable

public static Object nullable(Object o)
Gate a value to use NULL constant instead of null pointer


createDelegator

public Object createDelegator(Object source)
Create a proxy for the real object.

Parameters:
source - item to proxy
Returns:
proxied object according to map of classes to proxy

createDelegator

public <T> T createDelegator(Object source,
                             Class<T> apiInterface)

createDelegator

public <T> T createDelegator(Object source,
                             Class<T> apiInterface,
                             Map<String,Object> extraFields)

convertEnum

public Enum<?> convertEnum(Enum<?> value)

validate

public void validate()
              throws SecurityException,
                     NoSuchMethodException,
                     NoSuchFieldException
Validate all proxied classes to see that all required functions are implemented. Throws exception if failed validation. Note that it ignore the extra fields support.

Throws:
SecurityException
NoSuchMethodException
NoSuchFieldException

validate

public void validate(Class<?> dataClass,
                     Class<?> interfaceClass)
              throws SecurityException,
                     NoSuchMethodException,
                     NoSuchFieldException
Throws:
SecurityException
NoSuchMethodException
NoSuchFieldException

createDefaultEnumMap

public static Map<Enum<?>,Enum<?>> createDefaultEnumMap(Class<? extends Enum<?>> sourceEnum,
                                                        Class<? extends Enum<?>> targetEnum)
Utility function to auto generate mapping between two enums that have same values (toString) All values in the sourceEnum must have values in targetEnum, otherwise RuntimeException is thrown



Copyright © 2007-2012. All Rights Reserved.