|
Oracle Fusion Middleware Java API Reference for Oracle TopLink 11g Release 1 (11.1.1) B32476-03 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.toplink.mappings.DatabaseMapping oracle.toplink.mappings.foundation.AbstractTransformationMapping oracle.toplink.ox.mappings.XMLTransformationMapping
public class XMLTransformationMapping
Transformation XML mappings are used to create a custom mapping where one or more XML nodes can be used to create the object to be stored in a Java class's attribute. To handle the custom requirements at marshal (write) and unmarshall (read) time, a transformation mapping takes instances of oracle.toplink.mappings.transformers (such as AttributeTransformer and FieldTransformer), providing a non-intrusive solution that avoids the need for domain objects to implement any 'special' interfaces.
Setting the XPath: TopLink XML mappings make use of XPath statements to find the relevant
data in an XML document. The XPath statement is relative to the context node specified in the descriptor.
The XPath may contain node type, path, and positional information. The XPath is specified on the
field transformer that is set on the mapping. The XPath is set as the first parameter of the
addFieldTransformer
method.
The following XPath statements may be used to specify the location of XML data relating to an object's name attribute:
XPath | Description |
---|---|
@name | The "@" character indicates that the node is an attribute. |
text() | "text()" indicates that the node is a text node. In this case the name value in the text node belongs to the context node. |
full-name/text() | The name information is stored in the text node of the full-name element. |
personal-info/name/text() | The XPath statement may be used to specify any valid path. |
name[2]/text() | The XPath statement may contain positional information. In this case the name information is stored in the text node of the second occurrence of the name element. |
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).
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>
Code Sample
XMLTransformationMapping mapping = new XMLTransformationMapping();
mapping.setAttributeName("normalHours");
mapping.setAttributeTransformerClassName("oracle.toplink.testing.ox.mappings.transformation.NormalHoursAttributeTransformer");
mapping.addFieldTransformer("normal-hours/start-time/text()", new StartTimeTransformer());
mapping.addFieldTransformer("normal-hours/end-time/text()", new EndTimeTransformer()");
More Information: For more information about using the XML Transformation Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.
Constructor Summary | |
---|---|
XMLTransformationMapping()
|
Method Summary | |
---|---|
void |
addFieldTransformation(java.lang.String fieldName,
java.lang.String methodName)
Add the name of field and the name of the method that returns the value to be placed in said field when the object is written to the database. |
void |
addFieldTransformer(java.lang.String fieldName,
FieldTransformer transformer)
Add the name of field and the transformer that returns the value to be placed in the field when the object is written to the database. |
Methods inherited from class oracle.toplink.mappings.foundation.AbstractTransformationMapping |
---|
addFieldTransformation, addFieldTransformer, dontUseIndirection, getAttributeMethodName, isMutable, setAttributeMethodName, setAttributeTransformation, setAttributeTransformer, setIndirectionPolicy, setIsMutable, useBasicIndirection, useContainerIndirection, useIndirection, usesIndirection |
Methods inherited from class oracle.toplink.mappings.DatabaseMapping |
---|
getAttributeAccessor, getAttributeClassification, getAttributeName, getGetMethodName, getProperty, getReferenceDescriptor, getSetMethodName, isLazy, isOptional, isUsingMethodAccess, readOnly, readWrite, setAttributeAccessor, setAttributeName, setGetMethodName, setIsLazy, setIsOptional, setIsReadOnly, setProperty, setSetMethodName, setWeight, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XMLTransformationMapping()
Method Detail |
---|
public void addFieldTransformer(java.lang.String fieldName, FieldTransformer transformer)
addFieldTransformer
in class AbstractTransformationMapping
public void addFieldTransformation(java.lang.String fieldName, java.lang.String methodName)
oracle.toplink.sessions.Session
.
addFieldTransformation
in class AbstractTransformationMapping
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |