jTransfo, 0.10

org.jtransfo
Class JTransfoImpl

java.lang.Object
  extended by org.jtransfo.JTransfoImpl
All Implemented Interfaces:
ConvertSourceTarget, JTransfo

public class JTransfoImpl
extends Object
implements JTransfo, ConvertSourceTarget

jTransfo main access point standard implementation.


Field Summary
 
Fields inherited from interface org.jtransfo.JTransfo
DEFAULT_TAG_WHEN_NO_TAGS
 
Constructor Summary
JTransfoImpl()
          Constructor.
 
Method Summary
 Object convert(Object source)
          Create a new domain object from the source transfer object.
<T> T
convert(Object source, T target, boolean targetIsTo, String... tags)
          Fill the target object with the values from the source object.
<T> T
convert(Object source, T target, String... tags)
          Fill the target object with the values from the source object.
<T> List<T>
convertList(List<?> source, Class<T> targetClass, String... tags)
          Convert a list of object to the given type.
<T> T
convertTo(Object source, Class<T> targetClass, String... tags)
          Create a new domain object from the source transfer object.
<T> T
findTarget(Object source, Class<T> targetClass)
          Get the base target (domain) object for the source (transfer) object.
 List<ConvertInterceptor> getConvertInterceptors()
          Get the list of ConvertInterceptors to allow customization.
 Class<?> getDomainClass(Class<?> toClass)
          Get domain class for transfer object.
 List<ObjectFinder> getObjectFinders()
          Get the list of ObjectFinders to allow customization.
 Class<?> getToSubType(Class<?> toType, Object domainObject)
          Get the correct transfer object type for the given domain object.
 List<TypeConverter> getTypeConverters()
          Get the set of type converters which are used by this jTransfo instance.
 boolean isToClass(Class<?> toClass)
          Is the given class a transfer object class?

True when there is a DomainClass annotation on the class.

 void updateConvertInterceptors()
          Update the list of convert interceptors which is used based on the internal list (see getConvertInterceptors().
 void updateConvertInterceptors(List<ConvertInterceptor> newConvertInterceptors)
          Update the list of convert interceptors which is used.
 void updateObjectFinders()
          Update the list of object finders which is used based on the internal list (see getObjectFinders().
 void updateObjectFinders(List<ObjectFinder> newObjectFinders)
          Update the list of object finders which is used.
 void updateTypeConverters()
          Update the list of type converters which is used based on the internal list (see getTypeConverters().
 void updateTypeConverters(List<TypeConverter> newConverters)
          Update the list of type converters which is used.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTransfoImpl

public JTransfoImpl()
Constructor.

Method Detail

getTypeConverters

public List<TypeConverter> getTypeConverters()
Get the set of type converters which are used by this jTransfo instance.

You are explicitly allowed to change this list, but beware to do this from one thread only.

Changes in the list are not used until you call updateTypeConverters().

Returns:
current list of type converters.

updateTypeConverters

public void updateTypeConverters()
Update the list of type converters which is used based on the internal list (see getTypeConverters().


updateTypeConverters

public void updateTypeConverters(List<TypeConverter> newConverters)
Update the list of type converters which is used.

When null is passed, this updates the changes to the internal list (see getTypeConverters(). Alternatively, you can pass the new list explicitly.

Parameters:
newConverters - new list of type converters

getObjectFinders

public List<ObjectFinder> getObjectFinders()
Get the list of ObjectFinders to allow customization.

The elements are tried in reverse order (from end to start of list).

You are explicitly allowed to change this list, but beware to do this from one thread only.

Changes in the list are not used until you call updateObjectFinders().

Returns:
list of object finders

updateObjectFinders

public void updateObjectFinders()
Update the list of object finders which is used based on the internal list (see getObjectFinders().


updateObjectFinders

public void updateObjectFinders(List<ObjectFinder> newObjectFinders)
Update the list of object finders which is used.

When null is passed, this updates the changes to the internal list (see getObjectFinders(). Alternatively, you can pass the new list explicitly.

Parameters:
newObjectFinders - new list of type converters

getConvertInterceptors

public List<ConvertInterceptor> getConvertInterceptors()
Get the list of ConvertInterceptors to allow customization.

The elements are tried in reverse order (from end to start of list).

You are explicitly allowed to change this list, but beware to do this from one thread only.

Changes in the list are not used until you call updateObjectFinders().

Returns:
list of object finders

updateConvertInterceptors

public void updateConvertInterceptors()
Update the list of convert interceptors which is used based on the internal list (see getConvertInterceptors().


updateConvertInterceptors

public void updateConvertInterceptors(List<ConvertInterceptor> newConvertInterceptors)
Update the list of convert interceptors which is used.

When null is passed, this updates the changes to the internal list (see getConvertInterceptors(). Alternatively, you can pass the new list explicitly.

Parameters:
newConvertInterceptors - new list of convert interceptors

convert

public <T> T convert(Object source,
                     T target,
                     String... tags)
Description copied from interface: JTransfo
Fill the target object with the values from the source object.

This will write all values from the transfer object, other fields are not touched.

Specified by:
convert in interface JTransfo
Type Parameters:
T - type of object for target
Parameters:
source - source object. Should not be null.
target - target object. Should not be null.
tags - tags which indicate which fields can be converted based on MapOnly annotations. Tags are processed from left to right.
Returns:
target object

convert

public <T> T convert(Object source,
                     T target,
                     boolean targetIsTo,
                     String... tags)
Description copied from interface: ConvertSourceTarget
Fill the target object with the values from the source object.

This will write all values from the transfer object, other fields are not touched.

Specified by:
convert in interface ConvertSourceTarget
Type Parameters:
T - type of object for target
Parameters:
source - source object. Should not be null.
target - target object. Should not be null.
targetIsTo - is the target class the transfer object?
tags - tags which indicate which fields can be converted based on MapOnly annotations. Tags are processed from left to right.
Returns:
target object

convert

public Object convert(Object source)
Description copied from interface: JTransfo
Create a new domain object from the source transfer object.

When the source is null, the result is also null.

The object finders are used to build the object to copy to.

Specified by:
convert in interface JTransfo
Parameters:
source - source transfer object
Returns:
domain object

convertTo

public <T> T convertTo(Object source,
                       Class<T> targetClass,
                       String... tags)
Description copied from interface: JTransfo
Create a new domain object from the source transfer object.

When the source is null, the result is also null.

The object finders are used to build the object to copy to.

Specified by:
convertTo in interface JTransfo
Type Parameters:
T - type of object for target
Parameters:
source - source transfer object
targetClass - target class to convert to
tags - tags which indicate which fields can be converted based on MapOnly annotations. Tags are processed from left to right.
Returns:
domain object

convertList

public <T> List<T> convertList(List<?> source,
                               Class<T> targetClass,
                               String... tags)
Description copied from interface: JTransfo
Convert a list of object to the given type. Applies JTransfo.convertTo(Object, Class, String...) on each object.

When the source is null, the result is also null.

Specified by:
convertList in interface JTransfo
Type Parameters:
T - type of object for target
Parameters:
source - source list of objects
targetClass - target class to convert each object to
tags - tags which indicate which fields can be converted based on MapOnly annotations. Tags are processed from left to right.
Returns:
list of target objects

findTarget

public <T> T findTarget(Object source,
                        Class<T> targetClass)
Description copied from interface: JTransfo
Get the base target (domain) object for the source (transfer) object.

When the source is null, the result is also null.

The object finders are used to build the object to copy to.

Specified by:
findTarget in interface JTransfo
Type Parameters:
T - type of object for target
Parameters:
source - source transfer object
targetClass - target class to convert to
Returns:
domain object

getDomainClass

public Class<?> getDomainClass(Class<?> toClass)
Description copied from interface: JTransfo
Get domain class for transfer object.

Specified by:
getDomainClass in interface JTransfo
Parameters:
toClass - transfer object class
Returns:
domain class as annotated on class

isToClass

public boolean isToClass(Class<?> toClass)
Description copied from interface: JTransfo
Is the given class a transfer object class?

True when there is a DomainClass annotation on the class.

Specified by:
isToClass in interface JTransfo
Parameters:
toClass - object class to test
Returns:
true when object is a transfer object

getToSubType

public Class<?> getToSubType(Class<?> toType,
                             Object domainObject)
Description copied from interface: JTransfo
Get the correct transfer object type for the given domain object.

This searches the DomainClassDelegates (if present) to see of there is a better matching transfer object than the one given as parameter.

Specified by:
getToSubType in interface JTransfo
Parameters:
toType - base transfer object type
domainObject - domain object (instance)
Returns:
proper transfer object type to use

jTransfo, 0.10

Copyright © 2013. All rights reserved.