jTransfo, 0.14

org.jtransfo
Class AbstractListTypeConverter

java.lang.Object
  extended by org.jtransfo.AbstractListTypeConverter
All Implemented Interfaces:
Named, NeedsJTransfo, TypeConverter<List,List>
Direct Known Subclasses:
ListTypeConverter, ReadOnlyDomainListTypeConverter

public abstract class AbstractListTypeConverter
extends Object
implements TypeConverter<List,List>, Named, NeedsJTransfo

Abstract type converter for converting lists with object of specific type. Can only be used as declared converter.


Constructor Summary
AbstractListTypeConverter(String name, Class<?> toType)
          Construct type converter for converting a list, assign given name and use given transfer object type.
 
Method Summary
 boolean canConvert(Class<?> realToType, Class<?> realDomainType)
          Can this type converter handle conversions between the given transfer and domain object types?
 List convert(List toObjects, SyntheticField domainField, Object domainObject, String... tags)
          Convert a transfer object field value to the value for the domain object.
abstract  Object doConvertOne(JTransfo jTransfo, Object toObject, Class<?> domainObjectType, String... tags)
          Do the actual conversion of one object.
 String getName()
          Get name for the object.
 List reverse(List domainObjects, SyntheticField toField, Object toObject, String... tags)
          Convert a domain object field value to the value for the transfer object.
 void setAlwaysNewList(boolean alwaysNewList)
          Set whether a new list should be used as container for the values.
 void setJTransfo(JTransfo jTransfo)
          Set jTransfo instance which can be used recursively.
 void setKeepNullList(boolean keepNullList)
          Set whether null values should be kept (true).
 void setSortList(boolean sortList)
          Should the list be sorted if the first member is Comparable?
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractListTypeConverter

public AbstractListTypeConverter(String name,
                                 Class<?> toType)
Construct type converter for converting a list, assign given name and use given transfer object type.

Parameters:
name - name for type converter, for use in MappedBy.typeConverter()
toType - transfer object type
Method Detail

getName

public String getName()
Description copied from interface: Named
Get name for the object.

Specified by:
getName in interface Named
Returns:
object name

setJTransfo

public void setJTransfo(JTransfo jTransfo)
Description copied from interface: NeedsJTransfo
Set jTransfo instance which can be used recursively.

Specified by:
setJTransfo in interface NeedsJTransfo
Parameters:
jTransfo - jTransfo instance

canConvert

public boolean canConvert(Class<?> realToType,
                          Class<?> realDomainType)
Description copied from interface: TypeConverter
Can this type converter handle conversions between the given transfer and domain object types?

Specified by:
canConvert in interface TypeConverter<List,List>
Parameters:
realToType - real class for the type in the transfer object
realDomainType - real class for the type in the domain object
Returns:
true is this type converter can handle the type conversions

doConvertOne

public abstract Object doConvertOne(JTransfo jTransfo,
                                    Object toObject,
                                    Class<?> domainObjectType,
                                    String... tags)
                             throws JTransfoException
Do the actual conversion of one object.

Parameters:
jTransfo - jTransfo instance in use
toObject - transfer object
domainObjectType - domain object type
tags - tags which indicate which fields can be converted based on MapOnly annotations.
Returns:
domain object
Throws:
JTransfoException - oops, cannot convert

convert

public List convert(List toObjects,
                    SyntheticField domainField,
                    Object domainObject,
                    String... tags)
             throws JTransfoException
Description copied from interface: TypeConverter
Convert a transfer object field value to the value for the domain object.

Specified by:
convert in interface TypeConverter<List,List>
Parameters:
toObjects - object to convert
domainField - target domain field
domainObject - target domain object
tags - tags which indicate which fields can be converted based on MapOnly annotations.
Returns:
converted object
Throws:
JTransfoException - problem during type conversion

reverse

public List reverse(List domainObjects,
                    SyntheticField toField,
                    Object toObject,
                    String... tags)
             throws JTransfoException
Description copied from interface: TypeConverter
Convert a domain object field value to the value for the transfer object.

Specified by:
reverse in interface TypeConverter<List,List>
Parameters:
domainObjects - object to convert
toField - target transfer object field
toObject - target transfer object
tags - tags which indicate which fields can be converted based on MapOnly annotations.
Returns:
converted object
Throws:
JTransfoException - problem during type conversion

setKeepNullList

public void setKeepNullList(boolean keepNullList)
Set whether null values should be kept (true). When false (which is the default value), an empty list is set.

Parameters:
keepNullList - should null be kept as value or replaced by an empty list.

setAlwaysNewList

public void setAlwaysNewList(boolean alwaysNewList)
Set whether a new list should be used as container for the values. When false the list is reused if not null.

Parameters:
alwaysNewList - should null be kept as value or replaced by an empty list.

setSortList

public void setSortList(boolean sortList)
Should the list be sorted if the first member is Comparable?

Parameters:
sortList - true when list should be sorted

jTransfo, 0.14

Copyright © 2014. All rights reserved.