EclipseLink 1.1.4, build 'v20100812-r7860' API Reference

org.eclipse.persistence.oxm.mappings
Class XMLDirectMapping

java.lang.Object
  extended by org.eclipse.persistence.mappings.DatabaseMapping
      extended by org.eclipse.persistence.mappings.foundation.AbstractDirectMapping
          extended by org.eclipse.persistence.oxm.mappings.XMLDirectMapping
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, MapComponentMapping, MapKeyMapping, XMLMapping, XMLNillableMapping
Direct Known Subclasses:
XMLBinaryDataMapping, XMLFragmentMapping

public class XMLDirectMapping
extends AbstractDirectMapping
implements XMLMapping, 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.

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

Field Summary
protected static java.lang.String EMPTY_STRING
          Empty String identifier
 boolean isCDATA
           
 
Fields inherited from class org.eclipse.persistence.mappings.foundation.AbstractDirectMapping
attributeClassification, attributeClassificationName, attributeObjectClassification, converter, converterClassName, field, isMutable, nullValue
 
Fields inherited from class org.eclipse.persistence.mappings.DatabaseMapping
attributeAccessor, attributeName, descriptor, fields, isLazy, isOptional, isPrimaryKeyMapping, isReadOnly, isRemotelyInitialized, NO_FIELDS, NO_WEIGHT, properties, weight, WEIGHT_1
 
Constructor Summary
XMLDirectMapping()
           
 
Method Summary
 java.lang.Object getAttributeValue(java.lang.Object fieldValue, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLRecord record)
          INTERNAL: Allows for subclasses to convert the attribute value.
 java.lang.Object getFieldValue(java.lang.Object attributeValue, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLRecord record)
          INTERNAL: Convert the attribute value to a field value.
 AbstractNullPolicy getNullPolicy()
          INTERNAL: Get the AbstractNullPolicy from the Mapping.
 java.lang.String getXPath()
          Get the XPath String
 void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: The mapping is initialized with the given session.
 boolean isCDATA()
           
 boolean isXMLMapping()
          INTERNAL:
 void setAttributeValueInObject(java.lang.Object object, java.lang.Object value)
          INTERNAL: Set the value of the attribute mapped by this mapping.
 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
 java.lang.Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery query, org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
          INTERNAL: Return the mapping's attribute value from the row.
 void writeFromObjectIntoRow(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Get a value from the object and set that in the respective field of the row.
 void writeSingleValue(java.lang.Object value, java.lang.Object parent, XMLRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath.
protected  void writeValueIntoRow(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.helper.DatabaseField aField, java.lang.Object fieldValue)
           
 
Methods inherited from class org.eclipse.persistence.mappings.foundation.AbstractDirectMapping
buildBackupClone, buildChangeRecord, buildClone, buildCloneFromRow, buildCloneValue, buildCopy, buildExpression, buildShallowOriginalFromRow, cascadePerformRemoveIfRequired, cascadeRegisterNewIfRequired, clone, collectFields, compareForChange, compareObjects, compareObjectValues, convertClassNamesToClasses, fixObjectReferences, getAttributeClassification, getAttributeClassificationName, getAttributeValue, getConverter, getField, getFieldClassification, getFieldClassification, getFieldName, getFieldValue, getNullValue, getWeight, hasConverter, internalBuildChangeRecord, isAbstractDirectMapping, isChangeTrackingSupported, isCloningRequired, isDirectToFieldMapping, isMutable, iterate, mergeChangesIntoObject, mergeIntoObject, preInitialize, remoteInitialization, setAttributeClassification, setAttributeClassificationName, setConverter, setConverterClassName, setField, setFieldClassification, setFieldType, setIsMutable, setNullValue, toString, updateChangeRecord, validateBeforeInitialization, valueFromObject, valueFromResultSet, writeFromObjectIntoRowForUpdate, writeFromObjectIntoRowWithChangeRecord, writeInsertFieldsIntoRow
 
Methods inherited from class org.eclipse.persistence.mappings.DatabaseMapping
addToCollectionChangeRecord, buildBackupCloneForPartObject, buildCloneForPartObject, buildObjectJoinExpression, buildObjectJoinExpression, calculateDeferredChanges, cascadeDiscoverAndPersistUnregisteredNewObjects, cascadeMerge, cascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequired, cloneFields, createUnitOfWorkValueHolder, extractNestedExpressions, fixRealObjectReferences, getAttributeAccessor, getAttributeName, getAttributeValueFromObject, getContainerPolicy, getDescriptor, getFields, getGetMethodName, getObjectCorrespondingTo, getProperties, getProperty, getRealAttributeValueFromAttribute, getRealAttributeValueFromObject, getRealCollectionAttributeValueFromObject, getReferenceDescriptor, getRelationshipPartner, getSelectFields, getSelectTables, getSetMethodName, getValueFromRemoteValueHolder, hasConstraintDependency, hasDependency, hasInverseConstraintDependency, hasRootExpressionThatShouldUseOuterJoin, instantiateAttribute, isAbstractCompositeCollectionMapping, isAbstractCompositeDirectCollectionMapping, isAbstractCompositeObjectMapping, isAggregateCollectionMapping, isAggregateMapping, isAggregateObjectMapping, isCandidateForPrivateOwnedRemoval, isCascadedLockingSupported, isCollectionMapping, isDatabaseMapping, isDirectCollectionMapping, isDirectMapMapping, isDirectToXMLTypeMapping, isEISMapping, isForeignReferenceMapping, isJoiningSupported, isLazy, isManyToManyMapping, isNestedTableMapping, isObjectReferenceMapping, isOneToManyMapping, isOneToOneMapping, isOptional, isPrimaryKeyMapping, isPrivateOwned, isReadOnly, isReferenceMapping, isRelationalMapping, isRemotelyInitialized, isStructureMapping, isTransformationMapping, isUnidirectionalOneToManyMapping, isUsingMethodAccess, isVariableOneToOneMapping, isWriteOnly, iterateOnRealAttributeValue, performDataModificationEvent, postCalculateChanges, postCalculateChangesOnDeleted, postDelete, postInitialize, postInsert, postUpdate, preDelete, preInsert, prepareCascadeLockingPolicy, preUpdate, readFromResultSetIntoObject, readFromRowIntoObject, readOnly, readWrite, rehashFieldDependancies, remotelyInitialized, removeFromCollectionChangeRecord, replaceValueHoldersIn, setAttributeAccessor, setAttributeName, setChangeListener, setDescriptor, setFields, setGetMethodName, setIsLazy, setIsOptional, setIsPrimaryKeyMapping, setIsReadOnly, setProperties, setProperty, setRealAttributeValueInObject, setSetMethodName, setWeight, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, updateCollectionChangeRecord, validateAfterInitialization, valueFromResultSet, valueFromRow, verifyDelete, writeFromAttributeIntoRow, writeFromObjectIntoRowForShallowInsert, writeFromObjectIntoRowForShallowInsertWithChangeRecord, writeFromObjectIntoRowForWhereClause, writeUpdateFieldsIntoRow
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_STRING

protected static final java.lang.String EMPTY_STRING
Empty String identifier

See Also:
Constant Field Values

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 XMLNillableMapping
Parameters:
aNullPolicy -

getNullPolicy

public AbstractNullPolicy getNullPolicy()
INTERNAL: Get the AbstractNullPolicy from the Mapping.
The default policy is NullPolicy.

Specified by:
getNullPolicy in interface XMLNillableMapping
Returns:

isXMLMapping

public boolean isXMLMapping()
INTERNAL:

Overrides:
isXMLMapping in class DatabaseMapping

setXPath

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

Parameters:
xpathString - String

initialize

public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
                throws DescriptorException
Description copied from class: AbstractDirectMapping
INTERNAL: The mapping is initialized with the given session. This mapping is fully initialized after this.

Overrides:
initialize in class AbstractDirectMapping
Throws:
DescriptorException

getAttributeValue

public java.lang.Object getAttributeValue(java.lang.Object fieldValue,
                                          org.eclipse.persistence.internal.sessions.AbstractSession session,
                                          XMLRecord record)
INTERNAL: Allows for subclasses to convert the attribute value.


getFieldValue

public java.lang.Object getFieldValue(java.lang.Object attributeValue,
                                      org.eclipse.persistence.internal.sessions.AbstractSession session,
                                      XMLRecord record)
INTERNAL: Convert the attribute value to a field value. Process any converter if defined, and check for null values.


getXPath

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

Returns:
String the XPath String associated with this Mapping

valueFromRow

public java.lang.Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                     org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                     ObjectBuildingQuery query,
                                     org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
INTERNAL: Return the mapping's attribute value from the row. The execution session is passed for the case of building a UnitOfWork clone directly from a row, the session set in the query will not know which platform to use for converting the value. Allows the correct session to be passed in.

Overrides:
valueFromRow in class AbstractDirectMapping

writeFromObjectIntoRow

public void writeFromObjectIntoRow(java.lang.Object object,
                                   org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                   org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Get a value from the object and set that in the respective field of the row.

Overrides:
writeFromObjectIntoRow in class AbstractDirectMapping

writeValueIntoRow

protected void writeValueIntoRow(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                 org.eclipse.persistence.internal.helper.DatabaseField aField,
                                 java.lang.Object fieldValue)
Specified by:
writeValueIntoRow in class AbstractDirectMapping

writeSingleValue

public void writeSingleValue(java.lang.Object value,
                             java.lang.Object parent,
                             XMLRecord row,
                             org.eclipse.persistence.internal.sessions.AbstractSession session)
Description copied from interface: XMLMapping
INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling.

Specified by:
writeSingleValue in interface XMLMapping
Parameters:
value - - The value to be marshalled
row - - The Record the value is being marshalled too.

setAttributeValueInObject

public void setAttributeValueInObject(java.lang.Object object,
                                      java.lang.Object value)
                               throws DescriptorException
Description copied from class: DatabaseMapping
INTERNAL: Set the value of the attribute mapped by this mapping.

Overrides:
setAttributeValueInObject in class DatabaseMapping
Throws:
DescriptorException

setIsCDATA

public void setIsCDATA(boolean CDATA)

isCDATA

public boolean isCDATA()

EclipseLink 1.1.4, build 'v20100812-r7860' API Reference