I - the source bean typeO - the destination bean typepublic class Binder<I,O> extends Object implements Serializable
binder permits to copy some properties from an object to another
one.
It is based on a Binder.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 some
properties from a given object.
For more informations about how to obtain a binder, see the
BinderFactory or the package info javadoc or unit tests...BinderFactory,
BinderModelBuilder,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
Binder.BinderModel<S,T>
Model of a
Binder. |
static class |
Binder.CollectionStrategy
Types of loading of collections.
|
| Modifier and Type | Field and Description |
|---|---|
protected Binder.BinderModel<I,O> |
model
the model of the binder
|
| Constructor and Description |
|---|
Binder() |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
bind(Binder binder,
Object read) |
protected Object |
bindCollection(String sourceProperty,
Object read) |
protected Object |
bindProperty(String sourceProperty,
Object read) |
protected void |
copy(I source,
O target,
boolean excludeProperties,
String... propertyNames)
Copy properties from a source bean to a destination one according to
the model of the binder.
|
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.
|
void |
copyExcluding(I source,
O target,
String... propertyNames)
Copy properties from a source bean to a destination one according to
the model of the binder excluding
propertyNames. |
List<PropertyDiff> |
diff(I source,
O target)
Compare two beans property by property according to the model.
|
protected List<PropertyDiff> |
diff(I source,
O target,
boolean excludeProperties,
String... propertyNames) |
List<PropertyDiff> |
diffExcluding(I source,
O target,
String... propertyNames)
Compare two beans property by property according to the model.
|
protected String[] |
getAllPropertiesExclude(String... propertyNameExcludes)
Obtains all properties from binder's model except those
propertyNameExcludes. |
protected Object |
getCollectionValue(String sourceProperty,
Object readValue) |
protected Binder.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). |
Class<I> |
getSourceType()
Obtains the type of the source bean.
|
Class<O> |
getTargetType()
Obtains the type of the target bean.
|
Map<String,Object> |
obtainProperties(I source,
boolean includeNullValues,
String... propertyNames)
Obtain from the given object all properties registered in the binder
model.
|
Map<String,Object> |
obtainProperties(I source,
String... propertyNames)
Obtain from the given object all properties registered in the binder
model.
|
protected Object |
readProperty(String sourceProperty,
Object source,
Method readMethod) |
protected void |
setModel(Binder.BinderModel<I,O> model)
Set the model of the binder.
|
protected Binder.BinderModel<I,O> model
public Class<I> getSourceType()
public Class<O> getTargetType()
public Map<String,Object> obtainProperties(I source, boolean includeNullValues, String... propertyNames)
source - the bean to readpropertyNames - subset of properties to loadincludeNullValues - get all the properties and
values for the given bean. If false, you'll get only the valuesfrom is null.public Map<String,Object> obtainProperties(I source, String... propertyNames)
source - the bean to readpropertyNames - subset of properties to loadfrom is null.public void copy(I source, O target, String... propertyNames)
propertyNames is defined, only
those properties will be copied.
Note: If from object is null, then null values
will be set to mapped properties into dstsource - the bean to readtarget - the bean to writepropertyNames - optional subset of properties to copy (if none is
specifed, will use all the properties defined in
binder)NullPointerException - if target parameter is nullpublic void copyExcluding(I source, O target, String... propertyNames)
propertyNames.
Note: If from object is null, then null values
will be set to mapped properties into dst.source - the bean to readtarget - the bean to writepropertyNames - optional subset of properties to copy (if none is
specifed, will use all the properties defined in
binder)NullPointerException - if target parameter is nullprotected void copy(I source, O target, boolean excludeProperties, String... propertyNames) throws RuntimeException
from object is null, then null values
will be set to mapped properties into dst.source - the bean to readtarget - the bean to writeexcludeProperties - true to exclude following propertyNamespropertyNames - optional subset of properties to copy (if none is
specifed, will use all the properties defined in
binder)NullPointerException - if target parameter is nullRuntimeException - if a property can not be copied to the target objectprotected List<PropertyDiff> diff(I source, O target, boolean excludeProperties, String... propertyNames)
public List<PropertyDiff> diff(I source, O target)
source - a bean of type Itarget - a bean of type Opublic List<PropertyDiff> diffExcluding(I source, O target, String... propertyNames)
source - a bean of type Itarget - a bean of type OpropertyNames - property names to exclude from the diffprotected Binder.BinderModel<I,O> getModel()
protected void setModel(Binder.BinderModel<I,O> model)
model - the model of the binderprotected String[] getProperties(String... propertyNames)
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).propertyNames - optional subset of properties to getprotected String[] getAllPropertiesExclude(String... propertyNameExcludes)
propertyNameExcludes. Unknown properties will be ignored.propertyNameExcludes - name of properties to excludeprotected Object bindProperty(String sourceProperty, Object read) throws IllegalAccessException, InstantiationException
protected Object bindCollection(String sourceProperty, Object read) throws IllegalAccessException, InstantiationException
protected Object bind(Binder binder, Object read) throws IllegalAccessException, InstantiationException
Copyright © 2004–2014 CodeLutin. All rights reserved.