Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

B32476-03

oracle.toplink.ox.mappings
Class XMLDirectMapping

java.lang.Object
  extended by oracle.toplink.mappings.DatabaseMapping
      extended by oracle.toplink.mappings.foundation.AbstractDirectMapping
          extended by oracle.toplink.ox.mappings.XMLDirectMapping
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, oracle.toplink.ox.mappings.XMLMapping, oracle.toplink.ox.mappings.XMLNillableMapping
Direct Known Subclasses:
XMLBinaryDataMapping, XMLFragmentMapping

public class XMLDirectMapping
extends AbstractDirectMapping
implements oracle.toplink.ox.mappings.XMLMapping, oracle.toplink.ox.mappings.XMLNillableMapping

XML Direct Mappings map a Java attribute directly to XML attribute or text node.

XML Direct Mappings can be used in the following scenarios:

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 mapping using the setXPath 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 to a Specific Schema Type: In most cases TopLink can determine the target format in the XML document. However, there are cases where you must specify which one of a number of possible targets TopLink should use. For example, a java.util.Calendar could be marshalled to a schema date, time, or dateTime, or a byte[] could be marshalled to a schema hexBinary or base64Binary node.

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="customer" type="customer-type"/>
  <xsd:complexType name="customer-type">
    <xsd:sequence>
      <xsd:element name="picture" type="xsd:hexBinary"/>
      <xsd:element name="resume" type="xsd:base64Binary"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>

Code Sample
XMLDirectMapping pictureMapping = new XMLDirectMapping();
pictureMapping.setAttributeName("picture");
pictureMapping.setXPath("picture/text()");
XMLField pictureField = (XMLField) pictureMapping.getField();
pictureField.setSchemaType(XMLConstants.HEX_BINARY_QNAME);

Mapping to a Union Field:

XML Schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="customer" type="customer-type"/>
  <xsd:complexType name="customer-type">
    <xsd:sequence>
      <xsd:element name="shoe-size" type="size-type"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType name="size-type">
    <xsd:union memberTypes="xsd:decimal xsd:string"/>
  </xsd:simpleType>
</xsd:schema>

Code Sample
XMLDirectMapping shoeSizeMapping = new XMLDirectMapping();
shoeSizeMapping.setAttributeName("shoeSize");
XMLUnionField shoeSizeField = new XMLUnionField();
shoeSizeField.setXPath("shoe-size/text()");
shoeSizeField.addSchemaType(XMLConstants.DECIMAL_QNAME);
shoeSizeField.addSchemaType(XMLConstants.STRING_QNAME);
shoeSizeMapping.setField(shoeSizeField);

Preserving the Node Type: If the type of a node is not defined in your XML schema, you can configure an XML Direct Mapping to use the xsi:type attribute to provide type information.

Code Sample
XMLDirectMapping numberMapping = new XMLDirectMapping();
numberMapping.setAttributeName("number");
numberMapping.setXPath("number/text()");
XMLField numberField = (XMLField) numberMapping.getField();
numberField.setIsTypedTextField(true);

More Information: For more information about using the XML Direct Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.

Since:
Oracle TopLink 10g Release 2 (10.1.3)
See Also:
Serialized Form

Field Summary
 boolean isCDATA
           
 
Constructor Summary
XMLDirectMapping()
           
 
Method Summary
 java.lang.String getXPath()
          Get the XPath String
 boolean isCDATA()
           
 void setIsCDATA(boolean CDATA)
           
 void setNullPolicy(AbstractNullPolicy aNullPolicy)
          Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.
 void setXPath(java.lang.String xpathString)
          Set the Mapping field name attribute to the given XPath String
 
Methods inherited from class oracle.toplink.mappings.foundation.AbstractDirectMapping
getAttributeClassification, getConverter, getFieldClassification, getFieldName, getNullValue, hasConverter, isMutable, setAttributeClassification, setConverter, setConverterClassName, setField, setFieldClassification, setFieldType, setIsMutable, setNullValue
 
Methods inherited from class oracle.toplink.mappings.DatabaseMapping
getAttributeAccessor, 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
 

Field Detail

isCDATA

public boolean isCDATA
Constructor Detail

XMLDirectMapping

public XMLDirectMapping()
Method Detail

setNullPolicy

public void setNullPolicy(AbstractNullPolicy aNullPolicy)
Set the AbstractNullPolicy on the mapping
The default policy is NullPolicy.

Specified by:
setNullPolicy in interface oracle.toplink.ox.mappings.XMLNillableMapping
Parameters:
aNullPolicy -

setXPath

public void setXPath(java.lang.String xpathString)
Set the Mapping field name attribute to the given XPath String

Parameters:
xpathString - String

getXPath

public java.lang.String getXPath()
Get the XPath String

Returns:
String the XPath String associated with this Mapping

setIsCDATA

public void setIsCDATA(boolean CDATA)

isCDATA

public boolean isCDATA()

Copyright © 1998, 2010, Oracle. All Rights Reserved.