org.omnaest.utils.beans.adapter
Class PropertynameMapToTypeAdapter<T>

java.lang.Object
  extended by org.omnaest.utils.beans.adapter.PropertynameMapToTypeAdapter<T>
Type Parameters:
T -
All Implemented Interfaces:
Serializable

public class PropertynameMapToTypeAdapter<T>
extends Object
implements Serializable

This class creates a proxy implementation for a given Class or interface type which is used as a facade to an underlying Map<String,?>.

It supports the Converter annotation which allows to annotate getter and setter methods with ElementConverter classes which are used to convert return values or the first available parameter if present. Be aware that if there are getter and setter methods for the same property normally two different Converter annotations have to be set two support conversion in two directions.

Also the PropertyNameTemplate Annotation is supported. This allows to specify alternative property names, including dynamic names which are based on additional parameters of the method itself.

Further the DefaultValue and DefaultValues Annotation can be used to specify default values which are used instead of the return value or parameter values in the case the return value or parameter value would be null.

Example:

 {
   Map<String, Object> map = new HashMap<String, Object>();
   ExampleType exampleType = PropertynameMapToTypeAdapter.newInstance( map, ExampleType.class );
 }
 
 protected static interface ExampleType
 {
   @PropertyNameTemplate("fieldDoubleRenamed")
   public Double getFieldDouble();
   
   public void setFieldDouble( Double fieldDouble );
   
   @Converter(type = ElementConverterIntegerToString.class)
   public String getFieldString();
   
   @Converter(type = ElementConverterStringToInteger.class)
   public void setFieldString( String fieldString );
   
 }
 

Author:
Omnaest
See Also:
PropertynameMapToTypeAdapter.Configuration, newInstance(Map, Class), TypeToPropertynameMapAdapter, SourcePropertyAccessorToTypeAdapter, Converter, PropertyNameTemplate, PropertyAccessOption, DefaultValue, DefaultValues, Serialized Form

Nested Class Summary
static interface PropertynameMapToTypeAdapter.Builder<T>
          PropertynameMapToTypeAdapter.Builder which allows to create multiple instances based on the same Class type and PropertynameMapToTypeAdapter.Configuration.
static class PropertynameMapToTypeAdapter.Configuration
          The PropertynameMapToTypeAdapter.Configuration of a PropertynameMapToTypeAdapter includes following settings:

PropertynameMapToTypeAdapter.Configuration.setSimulatingToString(boolean) PropertynameMapToTypeAdapter.Configuration.setUnderlyingMapAware(boolean)

From the SourcePropertyAccessorToTypeAdapter.Configuration there are several more settings available, too.
protected static class PropertynameMapToTypeAdapter.SourePropertyAccessorForMap
           
 
Method Summary
static
<T> PropertynameMapToTypeAdapter.Builder<T>
builder(Class<? extends T> type, PropertynameMapToTypeAdapter.Configuration configuration)
          Returns a PropertynameMapToTypeAdapter.Builder for the given Class type and PropertynameMapToTypeAdapter.Configuration.
static
<T> T
newInstance(Map<String,Object> map, Class<? extends T> type)
          Factory methods to create a new PropertynameMapToTypeAdapter for a given Map with the given Class as facade.
static
<T> T
newInstance(Map<String,Object> map, Class<? extends T> type, PropertynameMapToTypeAdapter.Configuration configuration)
          Factory methods to create a new PropertynameMapToTypeAdapter for a given Map with the given Class as facade.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static <T> T newInstance(Map<String,Object> map,
                                Class<? extends T> type)
Factory methods to create a new PropertynameMapToTypeAdapter for a given Map with the given Class as facade.

Parameters:
map -
type -
Returns:
See Also:
newInstance(Map, Class)

newInstance

public static <T> T newInstance(Map<String,Object> map,
                                Class<? extends T> type,
                                PropertynameMapToTypeAdapter.Configuration configuration)
Factory methods to create a new PropertynameMapToTypeAdapter for a given Map with the given Class as facade.

Parameters:
map -
type -
configuration - PropertynameMapToTypeAdapter.Configuration
Returns:
new
See Also:
newInstance(Map, Class)

builder

public static <T> PropertynameMapToTypeAdapter.Builder<T> builder(Class<? extends T> type,
                                                                  PropertynameMapToTypeAdapter.Configuration configuration)
Returns a PropertynameMapToTypeAdapter.Builder for the given Class type and PropertynameMapToTypeAdapter.Configuration. A PropertynameMapToTypeAdapter.Builder is much faster in creating many instances than the newInstance(Map, Class, Configuration) method.

Be aware that all given decorators within the PropertynameMapToTypeAdapter.Configuration have to be stateless since they will be used by all created instances of this PropertynameMapToTypeAdapter.Builder.

Parameters:
type - Class
configuration - PropertynameMapToTypeAdapter.Configuration
Returns:
new PropertynameMapToTypeAdapter.Builder instance


Copyright © 2013. All Rights Reserved.