org.nuiton.util.beans
Class BinderModel<S,T>

java.lang.Object
  extended by org.nuiton.util.beans.BinderModel<S,T>
Type Parameters:
S - the source type
T - the target type
All Implemented Interfaces:
java.io.Serializable

public class BinderModel<S,T>
extends java.lang.Object
implements java.io.Serializable

Model of a Binder.

TODO-TC20100225 should have special cases for collections treatment.

Since:
1.1.5
Author:
tchemit
See Also:
Serialized Form

Field Summary
protected  java.util.Map<java.lang.String,Binder<?,?>> binders
          mapping of extra binders to use to copy properties
protected  java.util.Map<java.lang.String,Binder.CollectionStrategy> collectionStrategies
          mapping of collection properties strategies
protected  java.util.Map<java.lang.String,java.lang.String> propertiesMapping
          properties mapping (key are source properties, value are destination properties)
protected  java.util.Map<java.lang.String,java.beans.PropertyDescriptor> sourceDescriptors
          source type descriptors (key are property names)
protected  java.lang.Class<S> sourceType
          source type
protected  java.util.Map<java.lang.String,java.beans.PropertyDescriptor> targetDescriptors
          destination descriptors (key are property names)
protected  java.lang.Class<T> targetType
          destination type
 
Constructor Summary
BinderModel(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
           
 
Method Summary
 void addBinder(java.lang.String propertyName, Binder<?,?> binder)
           
protected  void addBinding(java.beans.PropertyDescriptor sourceDescriptor, java.beans.PropertyDescriptor targetDescriptor)
           
 void addCollectionStrategy(java.lang.String propertyName, Binder.CollectionStrategy strategy)
           
protected  boolean containsBinderProperty(java.lang.String propertyName)
           
protected  boolean containsCollectionProperty(java.lang.String propertyName)
           
protected  boolean containsSourceProperty(java.lang.String sourceProperty)
           
protected  boolean containsTargetProperty(java.lang.String targetProperty)
           
 Binder<?,?> getBinder(java.lang.String sourceProperty)
           
 Binder.CollectionStrategy getCollectionStrategy(java.lang.String property)
           
 java.lang.Class<?> getCollectionType(java.lang.String sourceProperty)
           
protected  java.util.Map<java.lang.String,java.lang.String> getPropertiesMapping()
           
 java.beans.PropertyDescriptor getSourceDescriptor(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.Method getSourceReadMethod(java.lang.String srcProperty)
           
 java.lang.Class<S> getSourceType()
          Gets the type of the binder's source.
 java.lang.reflect.Method getSourceWriteMethod(java.lang.String sourceProperty)
           
 java.beans.PropertyDescriptor getTargetDescriptor(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.String getTargetProperty(java.lang.String sourceProperty)
          Gets the destination property name given the
 java.lang.reflect.Method getTargetReadMethod(java.lang.String targetProperty)
           
 java.lang.Class<T> getTargetType()
          Gets the type of the binder's destination
 java.lang.reflect.Method getTargetWriteMethod(java.lang.String targetProperty)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceType

protected final java.lang.Class<S> sourceType
source type


targetType

protected final java.lang.Class<T> targetType
destination type


sourceDescriptors

protected final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> sourceDescriptors
source type descriptors (key are property names)


targetDescriptors

protected final java.util.Map<java.lang.String,java.beans.PropertyDescriptor> targetDescriptors
destination descriptors (key are property names)


propertiesMapping

protected final java.util.Map<java.lang.String,java.lang.String> propertiesMapping
properties mapping (key are source properties, value are destination properties)


collectionStrategies

protected java.util.Map<java.lang.String,Binder.CollectionStrategy> collectionStrategies
mapping of collection properties strategies


binders

protected java.util.Map<java.lang.String,Binder<?,?>> binders
mapping of extra binders to use to copy properties

Constructor Detail

BinderModel

public BinderModel(java.lang.Class<S> sourceType,
                   java.lang.Class<T> targetType)
Method Detail

getSourceType

public java.lang.Class<S> getSourceType()
Gets the type of the binder's source.

Returns:
the type of the source object in the binder

getTargetType

public java.lang.Class<T> 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

public Binder.CollectionStrategy getCollectionStrategy(java.lang.String property)

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 null if propertySrc is 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 null if 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 null if 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

public void addBinder(java.lang.String propertyName,
                      Binder<?,?> binder)

containsSourceProperty

protected boolean containsSourceProperty(java.lang.String sourceProperty)

containsTargetProperty

protected boolean containsTargetProperty(java.lang.String targetProperty)

containsCollectionProperty

protected boolean containsCollectionProperty(java.lang.String propertyName)

containsBinderProperty

protected boolean containsBinderProperty(java.lang.String propertyName)

addBinding

protected void addBinding(java.beans.PropertyDescriptor sourceDescriptor,
                          java.beans.PropertyDescriptor targetDescriptor)

getPropertiesMapping

protected java.util.Map<java.lang.String,java.lang.String> getPropertiesMapping()

getBinder

public Binder<?,?> getBinder(java.lang.String sourceProperty)


Copyright © 2004-2010 CodeLutin. All Rights Reserved.