Class Binder.BinderModel<S,​T>

java.lang.Object
org.nuiton.util.beans.Binder.BinderModel<S,​T>
Type Parameters:
S - the source type
T - the target type
All Implemented Interfaces:
java.io.Serializable
Enclosing class:
Binder<I,​O>

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<?,​?>> 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.Class<?>,​com.google.common.base.Function<?,​?>> functions
    Dictonnary of function to apply by source class type.
    protected InstanceFactory<T> instanceFactory
    factory of target Instance
    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

    Constructors 
    Constructor Description
    BinderModel​(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)  
  • Method Summary

    Modifier and Type Method Description
    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)  
    boolean containsBinderProperty​(java.lang.String propertyName)  
    boolean containsCollectionProperty​(java.lang.String propertyName)  
    boolean containsSourceProperty​(java.lang.String sourceProperty)  
    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)  
    com.google.common.base.Function getFunction​(java.lang.Class<?> aClass)  
    InstanceFactory<T> getInstanceFactory()  
    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)  
    boolean isUseFunctions()  
    protected void removeBinding​(java.lang.String source)  
    void setInstanceFactory​(InstanceFactory<T> instanceFactory)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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
    • instanceFactory

      protected InstanceFactory<T> instanceFactory
      factory of target Instance
    • functions

      protected final java.util.Map<java.lang.Class<?>,​com.google.common.base.Function<?,​?>> functions
      Dictonnary of function to apply by source class type.
  • Constructor Details

    • BinderModel

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

    • 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

      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

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

      public void setInstanceFactory​(InstanceFactory<T> instanceFactory)
    • getInstanceFactory

      public InstanceFactory<T> getInstanceFactory()
    • getFunction

      public com.google.common.base.Function getFunction​(java.lang.Class<?> aClass)
    • isUseFunctions

      public boolean isUseFunctions()