org.nuiton.util.beans
Class Binder<I,O>

java.lang.Object
  extended by org.nuiton.util.beans.Binder<I,O>
Type Parameters:
I - the source bean type
O - the destination bean type
All Implemented Interfaces:
Serializable

public class Binder<I,O>
extends Object
implements Serializable

A binder permits to copy some properties from an object to another one.

It is based on a BinderModel which contains the mapping of properties to transfert from the source object to the destination object.

Use the method copy(Object, Object,String...) to transfert properties.

Use the method obtainProperties(Object,String...) to obtain

Since:
1.1.5
Author:
tchemit
See Also:
Serialized Form

Field Summary
protected  BinderModel<I,O> model
          the model of the binder
 
Constructor Summary
Binder()
           
 
Method Summary
 void copy(I source, O target, String... propertyNames)
          Copy properties from a source bean to a destination one according to the model of the binder.
protected  BinderModel<I,O> getModel()
          Get the model of the binder.
protected  String[] getProperties(String... propertyNames)
          Obtain the properties, if none is given in propertyNames parameter, will use all property names defined in binder's model, otherwise, check that all given property names are safe (registred in binder's model).
 Map<String,Object> obtainProperties(I source, String... propertyNames)
          Obtain from the given object all properties registred in the binder model.
protected  void setModel(BinderModel<?,?> model)
          Set the model of the binder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

model

protected BinderModel<I,O> model
the model of the binder

Constructor Detail

Binder

public Binder()
Method Detail

obtainProperties

public Map<String,Object> obtainProperties(I source,
                                           String... propertyNames)
Obtain from the given object all properties registred in the binder model.

Note: If a property's value is null, it will not be injected in the result.

Parameters:
source - the bean to read
propertyNames - subset of properties to load
Returns:
the map of properties obtained indexed by their property name, or an empty map is the given from is null.

copy

public void copy(I source,
                 O target,
                 String... propertyNames)
          throws NullPointerException
Copy properties from a source bean to a destination one according to the model of the binder.

Note: If from object is null, then null values will be set to mapped properties into dst

Parameters:
source - the bean to read
target - the bean to write
propertyNames - optional subset of properties to copy (if none is specifed, will use all the properties defined in binder)
Throws:
NullPointerException - if target parameter is null

getProperties

protected String[] getProperties(String... propertyNames)
Obtain the properties, if none is given in propertyNames parameter, will use all property names defined in binder's model, otherwise, check that all given property names are safe (registred in binder's model).

Parameters:
propertyNames - optional subset of properties to get
Returns:
the array of property names

getModel

protected BinderModel<I,O> getModel()
Get the model of the binder.

Returns:
the model of the binder

setModel

protected void setModel(BinderModel<?,?> model)
Set the model of the binder.

Parameters:
model - the model of the binder


Copyright © 2004-2010 CodeLutin. All Rights Reserved.