Package org.nuiton.util.beans
Class Binder.BinderModel<S,T>
java.lang.Object
org.nuiton.util.beans.Binder.BinderModel<S,T>
- Type Parameters:
S- the source typeT- the target type
- All Implemented Interfaces:
java.io.Serializable
public static class Binder.BinderModel<S,T>
extends java.lang.Object
implements java.io.Serializable
Model of a
Binder.
TODO tchemit 20100225 should have special cases for collections treatment.- Since:
- 1.1.5
- Author:
- Tony Chemit - chemit@codelutin.com
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,Binder<?,?>>bindersmapping of extra binders to use to copy propertiesprotected java.util.Map<java.lang.String,Binder.CollectionStrategy>collectionStrategiesmapping of collection properties strategiesprotected java.util.Map<java.lang.Class<?>,com.google.common.base.Function<?,?>>functionsDictonnary of function to apply by source class type.protected InstanceFactory<T>instanceFactoryfactory of target Instanceprotected java.util.Map<java.lang.String,java.lang.String>propertiesMappingproperties mapping (key are source properties, value are destination properties)protected java.util.Map<java.lang.String,java.beans.PropertyDescriptor>sourceDescriptorssource type descriptors (key are property names)protected java.lang.Class<S>sourceTypesource typeprotected java.util.Map<java.lang.String,java.beans.PropertyDescriptor>targetDescriptorsdestination descriptors (key are property names)protected java.lang.Class<T>targetTypedestination type -
Constructor Summary
Constructors Constructor Description BinderModel(java.lang.Class<S> sourceType, java.lang.Class<T> targetType) -
Method Summary
Modifier and Type Method Description voidaddBinder(java.lang.String propertyName, Binder<?,?> binder)protected voidaddBinding(java.beans.PropertyDescriptor sourceDescriptor, java.beans.PropertyDescriptor targetDescriptor)voidaddCollectionStrategy(java.lang.String propertyName, Binder.CollectionStrategy strategy)booleancontainsBinderProperty(java.lang.String propertyName)booleancontainsCollectionProperty(java.lang.String propertyName)booleancontainsSourceProperty(java.lang.String sourceProperty)booleancontainsTargetProperty(java.lang.String targetProperty)Binder<?,?>getBinder(java.lang.String sourceProperty)Binder.CollectionStrategygetCollectionStrategy(java.lang.String property)java.lang.Class<?>getCollectionType(java.lang.String sourceProperty)com.google.common.base.FunctiongetFunction(java.lang.Class<?> aClass)InstanceFactory<T>getInstanceFactory()protected java.util.Map<java.lang.String,java.lang.String>getPropertiesMapping()java.beans.PropertyDescriptorgetSourceDescriptor(java.lang.String sourceProperty)Gets the bean descriptor of the source type for the given destination property.java.lang.String[]getSourceDescriptors()Gets all registred property names of the binder's source type.java.lang.reflect.MethodgetSourceReadMethod(java.lang.String srcProperty)java.lang.Class<S>getSourceType()Gets the type of the binder's source.java.lang.reflect.MethodgetSourceWriteMethod(java.lang.String sourceProperty)java.beans.PropertyDescriptorgetTargetDescriptor(java.lang.String targetProperty)Gets the bean descriptor of the destination type for the given destination property.java.lang.String[]getTargetDescriptors()Gets all registred property names of the binder's destination type.java.lang.StringgetTargetProperty(java.lang.String sourceProperty)Gets the destination property name given thejava.lang.reflect.MethodgetTargetReadMethod(java.lang.String targetProperty)java.lang.Class<T>getTargetType()Gets the type of the binder's destinationjava.lang.reflect.MethodgetTargetWriteMethod(java.lang.String targetProperty)booleanisUseFunctions()protected voidremoveBinding(java.lang.String source)voidsetInstanceFactory(InstanceFactory<T> instanceFactory)
-
Field Details
-
sourceType
source type -
targetType
destination type -
sourceDescriptors
protected final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> sourceDescriptorssource type descriptors (key are property names) -
targetDescriptors
protected final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> targetDescriptorsdestination descriptors (key are property names) -
propertiesMapping
protected final java.util.Map<java.lang.String,java.lang.String> propertiesMappingproperties mapping (key are source properties, value are destination properties) -
collectionStrategies
mapping of collection properties strategies -
binders
mapping of extra binders to use to copy properties -
instanceFactory
factory of target Instance -
functions
protected final java.util.Map<java.lang.Class<?>,com.google.common.base.Function<?,?>> functionsDictonnary of function to apply by source class type.
-
-
Constructor Details
-
Method Details
-
getSourceType
Gets the type of the binder's source.- Returns:
- the type of the source object in the binder
-
getTargetType
Gets the type of the binder's destination- Returns:
- the type of the destination object in the binder
-
getSourceDescriptors
public java.lang.String[] getSourceDescriptors()Gets all registred property names of the binder's source type.- Returns:
- the array of all source object properties names to bind
-
getCollectionStrategy
-
getTargetDescriptors
public java.lang.String[] getTargetDescriptors()Gets all registred property names of the binder's destination type.- Returns:
- the array of all source object properties names to bind
-
getTargetProperty
public java.lang.String getTargetProperty(java.lang.String sourceProperty)Gets the destination property name given the- Parameters:
sourceProperty- the name of the source property to bind- Returns:
- the name of the destination object property to bind, or
nullifpropertySrcis unknown in the model
-
getSourceDescriptor
public java.beans.PropertyDescriptor getSourceDescriptor(java.lang.String sourceProperty)Gets the bean descriptor of the source type for the given destination property.- Parameters:
sourceProperty- name of the source type property name- Returns:
- the descriptor or
nullif not found.
-
getSourceReadMethod
public java.lang.reflect.Method getSourceReadMethod(java.lang.String srcProperty)- Parameters:
srcProperty- the name of a property of the source object.- Returns:
- the method to read in a source object for the given property.
-
getSourceWriteMethod
public java.lang.reflect.Method getSourceWriteMethod(java.lang.String sourceProperty)- Parameters:
sourceProperty- the name of a property of the source object.- Returns:
- the method to write in a source object for the given property.
-
getTargetDescriptor
public java.beans.PropertyDescriptor getTargetDescriptor(java.lang.String targetProperty)Gets the bean descriptor of the destination type for the given destination property.- Parameters:
targetProperty- name of the destination type property name- Returns:
- the descriptor or
nullif not found.
-
getTargetReadMethod
public java.lang.reflect.Method getTargetReadMethod(java.lang.String targetProperty)- Parameters:
targetProperty- the name of a property of the destination object.- Returns:
- the method to read in a destination object for the given property.
-
getTargetWriteMethod
public java.lang.reflect.Method getTargetWriteMethod(java.lang.String targetProperty)- Parameters:
targetProperty- the name of a property of the destination object.- Returns:
- the method to write in a destination object for the given property.
-
getCollectionType
public java.lang.Class<?> getCollectionType(java.lang.String sourceProperty) -
addCollectionStrategy
public void addCollectionStrategy(java.lang.String propertyName, Binder.CollectionStrategy strategy) -
addBinder
-
containsSourceProperty
public boolean containsSourceProperty(java.lang.String sourceProperty) -
containsTargetProperty
public boolean containsTargetProperty(java.lang.String targetProperty) -
containsCollectionProperty
public boolean containsCollectionProperty(java.lang.String propertyName) -
containsBinderProperty
public boolean containsBinderProperty(java.lang.String propertyName) -
addBinding
protected void addBinding(java.beans.PropertyDescriptor sourceDescriptor, java.beans.PropertyDescriptor targetDescriptor) -
removeBinding
protected void removeBinding(java.lang.String source) -
getPropertiesMapping
protected java.util.Map<java.lang.String,java.lang.String> getPropertiesMapping() -
getBinder
-
setInstanceFactory
-
getInstanceFactory
-
getFunction
public com.google.common.base.Function getFunction(java.lang.Class<?> aClass) -
isUseFunctions
public boolean isUseFunctions()
-