Skip navigation links

Oracle TopLink Java API Reference
10g Release 3 (10.1.3.1)

B28219-01


oracle.toplink.ox.mappings
Class XMLDirectMapping

java.lang.Object
  extended byoracle.toplink.mappings.DatabaseMapping
      extended byoracle.toplink.mappings.foundation.AbstractDirectMapping
          extended byoracle.toplink.ox.mappings.XMLDirectMapping

All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable, oracle.toplink.ox.mappings.XMLMapping

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

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 />
  <xsd:complexType >
    <xsd:sequence>
      <xsd:element />
      <xsd:element />
    </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 />
  <xsd:complexType >
    <xsd:sequence>
      <xsd:element />
    </xsd:sequence>
  </xsd:complexType>
  <xsd:simpleType >
    <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

Constructor Summary
XMLDirectMapping()
           

 

Method Summary
 java.lang.String getXPath()
          Get the XPath String
 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, getAttributeClassificationName, getConverter, getFieldClassification, getFieldName, getNullValue, isMutable, setAttributeClassification, setConverter, setField, setFieldClassification, setFieldType, setIsMutable, setNullValue

 

Methods inherited from class oracle.toplink.mappings.DatabaseMapping
getAttributeAccessor, getAttributeName, getGetMethodName, getProperty, getReferenceClassDescriptor, getSetMethodName, isUsingMethodAccess, readOnly, readWrite, setAttributeAccessor, setAttributeName, setGetMethodName, setIsReadOnly, setProperty, setSetMethodName, setWeight, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

XMLDirectMapping

public XMLDirectMapping()

Method Detail

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 *

Skip navigation links

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