Top Description Methods
org.eclipse.persistence.oxm.annotations

public @Interface XmlReadTransformer

extends Annotation
Annotations
@Target:METHOD, FIELD
@Retention:RUNTIME
Static Imports
java.lang.annotation.ElementType.FIELD, .ElementType.METHOD, .RetentionPolicy.RUNTIME

Purpose: XmlReadTransformer is used to allow the user direct access to the XML in order to populate their object model. XmlReadTransformer is used in conjunction with XmlWriteTransformers/XmlWriteTransformer to create a customised mapping for a specific attribute. XmlReadTransformer specifies the transformer to be invoked on the unmarshal.

Mapping a transformation: A transformer can be configured to perform both the XML instance-to-Java attribute transformation at unmarshall time (via attribute transformer) and the Java attribute-to-XML instance transformation at marshal time (via field transformer).

Example:

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="employee" type="employee-type"/>
  <xsd:complexType name="employee-type">
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string"/>
      <xsd:element name="normal-hours" type="normal-hours-type"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="normal-hours-type">
    <xsd:sequence>
      <xsd:element name="start-time" type="xsd:string"/>
      <xsd:element name="end-time" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Employee Class

 @XmlRootElement(name="employee")
 public class Employee {
   public String name;
   @XmlReadTransformer(transformerClass = NormalHoursTransformer.class)
   @XmlWriteTransformers({
     @XmlWriteTransformer(transformerClass = StartTimeTransformer.class, xmlPath= "normal-hours/start-time/text()"),
     @XmlWriteTransformer(transformerClass = EndTimeTransformer.class, xmlPath="normal-hours/end-time/text()")
   })
   public String[] normalHours;
 }
 

Normal Hours Transformer

 public class NormalHoursTransformer implements AttributeTransformer {
   public String[] buildAttributeValue(Record record, Object object, Session session) {
     String startTime = (String)record.get("normal-hours/start-time/text()");
     String endTime = (String)record.get("normal-hours/end-time/text()");
       return new String[]{startTime, endTime};
     }
     public void initialize(AbstractTransformationMapping mapping) {
     }
   }
 }
 
See Also
AttributeTransformer, XmlWriteTransformer, XmlWriteTransformers

Method Summary

Modifier and TypeMethod and Description
public String
method()

The mapped class must have a method with this name which returns a value to be assigned to the attribute (not assigns the value to the attribute).

public Class<? extends AttributeTransformer>
transformerClass()

User-defined class that must implement the org.eclipse.persistence.mappings.transformers.AttributeTransformer interface.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

methodback to summary
public String method()

The mapped class must have a method with this name which returns a value to be assigned to the attribute (not assigns the value to the attribute). Either transformerClass or method must be specified, but not both.

transformerClassback to summary
public Class<? extends AttributeTransformer> transformerClass()

User-defined class that must implement the org.eclipse.persistence.mappings.transformers.AttributeTransformer interface. The class will be instantiated, its buildAttributeValue will be used to create the value to be assigned to the attribute. Either transformerClass or method must be specified, but not both.