gov.nih.nci.caarray.services.util.dataconverter.mapper
Class FieldMapper
java.lang.Object
gov.nih.nci.caarray.services.util.dataconverter.mapper.FieldMapper
- Direct Known Subclasses:
- ArrayManufacturerFieldMapper, BibliographicReferenceAccessionFieldMapper, BioMaterialParentsFieldMapper, BioSourceProviderFieldMapper, Date2NameValueTypeFieldMapper, Date2StringFieldMapper, DescriptionFieldMapper, ExperimentTypeFieldMapper, HardwaresSoftwaresParameterTypesFieldMapper, Id2ObjectFieldMapper, IdFieldMapper, LabelFieldMapper, NumberOfChannelsFieldMapper, ParsingSucceededFieldMapper, ProtocolApplicationFieldMapper, ProtocolApplicationPerformerFieldMapper, ProviderFieldMapper, SoftwareOrHardwareManufacturerFieldMapper, SqlDate2JavaDateFieldMapper, TechnologyTypeFieldMapper, UnitDataFieldMapper, VocabDataFieldMapper
public class FieldMapper
- extends java.lang.Object
This class describes how an attribute of a class is mapped to a attribute of
another class. The map(Object, Object)
method is used to map
or copy the source property's value to the target property's.
This class supports mapping primitive, object reference and array/collection
reference attributes.
- Primitive attributes: The source and target attributes must of the same
type, either int, long, String, etc.
- Object reference attributes: The mapping for the class type of the source
attribute to that of the target attribute must be defined in the mapper
repository file. Mapping object reference attributes is the same as mapping
a source object to a target.
- Array attributes: Array elements are always of the same type.
Only the elements of the source attribute that don't exist in the target
attribute are copied. If the element type is non-primitive, the mapping for
the source element type to the target element type must be defined in the
mapper repository.
- Collection attributes: Elements can be of different types. The
fromelementtype
and toelementtype
attributes in
the field mapping must be specified to indicate which target element type is
mapped to which source element type. More than one element type can be
specified and delimited by commas. The order of the element types specified
is important as it is how the source element type is matched up with the
target element type.
- Author:
- TranP
Method Summary |
static FieldMapper |
createFieldMapper(ClassMapper classMapper,
java.lang.Class sourceClass,
java.lang.String sourceFieldName,
java.lang.Class sourceFieldClass,
java.util.List sourceElementClasses,
java.lang.Class targetClass,
java.lang.String targetFieldName,
java.lang.Class targetFieldClass,
java.util.List targetElementClasses,
java.lang.Class mapperClass)
|
ClassMapper |
getClassMapper()
|
protected java.lang.String |
getFieldMapperInfo()
|
protected static int |
getIndexOfIndexedProperty(java.lang.String name)
|
static java.lang.Object |
getNestedProperty(java.lang.Object bean,
java.lang.String name)
|
protected static java.lang.Class |
getNestedPropertyParentType(java.lang.Object bean,
java.lang.String name)
|
static java.lang.Class |
getParameterTypeOfPropertySetter(java.lang.Object bean,
java.lang.String name)
|
static java.lang.Object |
getProperty(java.lang.Object bean,
java.lang.String name)
|
SimpleField |
getSourceField()
|
SimpleField |
getTargetField()
|
void |
map(java.lang.Object sourceObject,
java.lang.Object targetObject,
boolean overwrite)
Converts the value contained in the source field of the source object
specified by this converter to be the value for the target field of
the target object specified by this converter. |
FieldMapper |
reverse(ClassMapper classMapper)
|
static void |
setNestedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
|
static void |
setProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
|
void |
setSourceField(SimpleField field)
|
void |
setTargetField(SimpleField field)
|
protected static java.lang.String |
toAccessibleFieldName(java.lang.String fieldName)
Chops off the underscore (_) suffix from a simple field name if it's
present as it is caARRAY's coding convention, so it can be used to form
the getter/setter for this field. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FieldMapper
public FieldMapper(ClassMapper classMapper,
SimpleField sourceField,
SimpleField targetField)
getSourceField
public final SimpleField getSourceField()
- Returns:
getTargetField
public final SimpleField getTargetField()
- Returns:
setSourceField
public final void setSourceField(SimpleField field)
- Parameters:
field
-
setTargetField
public final void setTargetField(SimpleField field)
- Parameters:
field
-
createFieldMapper
public static FieldMapper createFieldMapper(ClassMapper classMapper,
java.lang.Class sourceClass,
java.lang.String sourceFieldName,
java.lang.Class sourceFieldClass,
java.util.List sourceElementClasses,
java.lang.Class targetClass,
java.lang.String targetFieldName,
java.lang.Class targetFieldClass,
java.util.List targetElementClasses,
java.lang.Class mapperClass)
getClassMapper
public final ClassMapper getClassMapper()
- Returns:
reverse
public final FieldMapper reverse(ClassMapper classMapper)
map
public void map(java.lang.Object sourceObject,
java.lang.Object targetObject,
boolean overwrite)
- Converts the value contained in the source field of the source object
specified by this converter to be the value for the target field of
the target object specified by this converter.
getFieldMapperInfo
protected final java.lang.String getFieldMapperInfo()
toAccessibleFieldName
protected static java.lang.String toAccessibleFieldName(java.lang.String fieldName)
- Chops off the underscore (_) suffix from a simple field name if it's
present as it is caARRAY's coding convention, so it can be used to form
the getter/setter for this field.
- Parameters:
fieldName
-
- Returns:
getNestedProperty
public static java.lang.Object getNestedProperty(java.lang.Object bean,
java.lang.String name)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException
- Parameters:
bean
- name
-
- Returns:
-
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
getProperty
public static java.lang.Object getProperty(java.lang.Object bean,
java.lang.String name)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException
- Parameters:
bean
- name
-
- Returns:
-
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
setNestedProperty
public static void setNestedProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException
- Parameters:
bean
- name
- value
-
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
getIndexOfIndexedProperty
protected static int getIndexOfIndexedProperty(java.lang.String name)
setProperty
public static void setProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
throws java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException
- Parameters:
bean
- name
- value
-
- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.InstantiationException
getParameterTypeOfPropertySetter
public static java.lang.Class getParameterTypeOfPropertySetter(java.lang.Object bean,
java.lang.String name)
throws java.lang.IllegalAccessException,
java.lang.NoSuchMethodException,
java.lang.reflect.InvocationTargetException
- Parameters:
bean
- name
- - Only non-indexed simple and nested property name is allowed
- Returns:
-
- Throws:
java.lang.IllegalAccessException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
getNestedPropertyParentType
protected static final java.lang.Class getNestedPropertyParentType(java.lang.Object bean,
java.lang.String name)