EclipseLink1.0 - 20080707 API Reference

org.eclipse.persistence.oxm.mappings
Class XMLAnyObjectMapping

java.lang.Object
  extended by org.eclipse.persistence.mappings.DatabaseMapping
      extended by org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, XMLMapping

public class XMLAnyObjectMapping
extends DatabaseMapping
implements XMLMapping

Any object XML mappings map an attribute that contains a single object to an XML element. The referenced object may be of any type (including String), and does not need not be related to any other particular type through inheritance or a common interface. The corresponding object attribute value should be generic enough for all possible application values. Note that each of the referenced objects (except String) must specify a default root element on their descriptor.

Any object XML mappings are useful with the following XML schema constructs:

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. Note that for XML Any Object Mappings the XPath is optional.

The following XPath statements may be used to specify the location of XML data relating to an object's name attribute:

XPath Description
contact-method The name information is stored in the contact-method element.
contact-method/info The XPath statement may be used to specify any valid path.
contact-method[2] The XPath statement may contain positional information. In this case the contact information is stored in the second occurrence of the contact-method element.

Mapping an element of type xs:anyType as an Any Object Mapping:

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="contact-method" type="xsd:anyType"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:element name="address">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="street" type="xsd:string"/>
        <xsd:element name="city" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="phone-number" type="xsd:string"/>
</xsd:schema>

Code Sample
XMLAnyObjectMapping contactMethodMapping = new XMLAnyObjectMapping();
contactMethodMapping.setAttributeName("contactMethod");
contactMethodMapping.setXPath("contact-method");

More Information: For more information about using the XML Any Object 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
 
Fields inherited from class org.eclipse.persistence.mappings.DatabaseMapping
attributeAccessor, attributeName, descriptor, fields, isLazy, isOptional, isReadOnly, isRemotelyInitialized, NO_FIELDS, NO_WEIGHT, primaryKeyMapping, properties, weight, WEIGHT_1
 
Constructor Summary
XMLAnyObjectMapping()
           
 
Method Summary
 void buildBackupClone(java.lang.Object clone, java.lang.Object backup, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork)
          INTERNAL: Clone the attribute from the clone and assign it to the backup.
 void buildClone(java.lang.Object original, java.lang.Object clone, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork)
          INTERNAL: Clone the attribute from the original and assign it to the clone.
 void buildCloneFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, java.lang.Object clone, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork, org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
          INTERNAL: A combination of readFromRowIntoObject and buildClone.
protected  org.eclipse.persistence.internal.sessions.AbstractRecord buildCompositeRow(java.lang.Object attributeValue, org.eclipse.persistence.internal.sessions.AbstractSession session, XMLDescriptor referenceDescriptor, org.eclipse.persistence.internal.sessions.AbstractRecord parentRow, org.eclipse.persistence.internal.helper.DatabaseField field, java.lang.Object originalObject, boolean wasXMLRoot)
           
 void cascadePerformRemoveIfRequired(java.lang.Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, java.util.Map visitedObjects)
          INTERNAL: Cascade perform delete through mappings that require the cascade
 void cascadeRegisterNewIfRequired(java.lang.Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, java.util.Map visitedObjects)
          INTERNAL: Cascade registerNew for Create through mappings that require the cascade
 java.lang.Object clone()
          INTERNAL: Clones itself.
 org.eclipse.persistence.internal.sessions.ChangeRecord compareForChange(java.lang.Object clone, java.lang.Object backup, org.eclipse.persistence.internal.sessions.ObjectChangeSet owner, org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: This method was created in VisualAge.
 boolean compareObjects(java.lang.Object firstObject, java.lang.Object secondObject, org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Compare the attributes belonging to this mapping for the objects.
 void fixObjectReferences(java.lang.Object object, java.util.Map objectDescriptors, java.util.Map processedObjects, ObjectLevelReadQuery query, RemoteSession session)
          INTERNAL: An object has been serialized from the server to the client.
 XMLConverter getConverter()
           
protected  XMLDescriptor getDescriptor(XMLRecord xmlRecord, org.eclipse.persistence.internal.sessions.AbstractSession session, javax.xml.namespace.QName rootQName)
           
 org.eclipse.persistence.internal.helper.DatabaseField getField()
          INTERNAL: Return the field associated with this mapping if there is exactly one.
 java.util.Vector getFields()
          INTERNAL: Returns a vector of all the fields this mapping represents.
 org.w3c.dom.Node getNodeToReplace(org.w3c.dom.Node parent)
           
 void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Allow for initialization of properties and validation.
 boolean isXMLMapping()
          INTERNAL: All relational mappings should implement this method to return true.
 void iterate(org.eclipse.persistence.internal.descriptors.DescriptorIterator iterator)
          INTERNAL: Iterate on the appropriate attribute value.
 void mergeChangesIntoObject(java.lang.Object target, org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord, java.lang.Object source, org.eclipse.persistence.internal.sessions.MergeManager mergeManager)
          INTERNAL: Merge changes from the source to the target object.
 void mergeIntoObject(java.lang.Object target, boolean isTargetUninitialized, java.lang.Object source, org.eclipse.persistence.internal.sessions.MergeManager mergeManager)
          INTERNAL: Merge changes from the source to the target object.
 void setConverter(XMLConverter converter)
           
 void setField(org.eclipse.persistence.internal.helper.DatabaseField field)
           
 void setUseXMLRoot(boolean useXMLRoot)
           
 void setXPath(java.lang.String xpath)
           
 boolean shouldAddXsiType(XMLMarshaller xmlMarshaller, XMLDescriptor xmlDescriptor, java.lang.Object originalObject, boolean wasXMLRoot)
          INTERNAL:
 boolean usesXMLRoot()
           
 java.lang.Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
          INTERNAL: A subclass should implement this method if it wants different behavior.
 void writeFromObjectIntoRow(java.lang.Object object, org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: A subclass should implement this method if it wants different behavior.
 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.
 
Methods inherited from class org.eclipse.persistence.mappings.DatabaseMapping
addToCollectionChangeRecord, buildBackupCloneForPartObject, buildChangeRecord, buildCloneForPartObject, buildCopy, buildExpression, buildObjectJoinExpression, buildObjectJoinExpression, buildShallowOriginalFromRow, calculateDeferredChanges, cascadeDiscoverAndPersistUnregisteredNewObjects, cascadeMerge, cloneFields, collectFields, convertClassNamesToClasses, createUnitOfWorkValueHolder, extractNestedExpressions, fixRealObjectReferences, getAttributeAccessor, getAttributeClassification, getAttributeName, getAttributeValueFromObject, getContainerPolicy, getDescriptor, getFieldClassification, getGetMethodName, getObjectCorrespondingTo, getProperties, getProperty, getRealAttributeValueFromObject, getRealCollectionAttributeValueFromObject, getReferenceDescriptor, getRelationshipPartner, getSelectFields, getSelectTables, getSetMethodName, getValueFromRemoteValueHolder, getWeight, hasConstraintDependency, hasDependency, hasInverseConstraintDependency, hasRootExpressionThatShouldUseOuterJoin, instantiateAttribute, isAbstractCompositeCollectionMapping, isAbstractCompositeDirectCollectionMapping, isAbstractCompositeObjectMapping, isAbstractDirectMapping, isAggregateCollectionMapping, isAggregateMapping, isAggregateObjectMapping, isCascadedLockingSupported, isChangeTrackingSupported, isCloningRequired, isCollectionMapping, isDatabaseMapping, isDirectCollectionMapping, isDirectMapMapping, isDirectToFieldMapping, isDirectToXMLTypeMapping, isEISMapping, isForeignReferenceMapping, isJoiningSupported, isLazy, isManyToManyMapping, isNestedTableMapping, isObjectReferenceMapping, isOneToManyMapping, isOneToOneMapping, isOptional, isPrimaryKeyMapping, isPrivateOwned, isReadOnly, isReferenceMapping, isRelationalMapping, isRemotelyInitialized, isStructureMapping, isTransformationMapping, isUsingMethodAccess, isVariableOneToOneMapping, isWriteOnly, iterateOnRealAttributeValue, performDataModificationEvent, postDelete, postInitialize, postInsert, postUpdate, preDelete, preInitialize, preInsert, prepareCascadeLockingPolicy, preUpdate, readFromResultSetIntoObject, readFromRowIntoObject, readFromRowIntoObject, readOnly, readWrite, rehashFieldDependancies, remoteInitialization, remotelyInitialized, removeFromCollectionChangeRecord, replaceValueHoldersIn, setAttributeAccessor, setAttributeName, setAttributeValueInObject, setChangeListener, setDescriptor, setFields, setGetMethodName, setIsLazy, setIsOptional, setIsPrimaryKeyMapping, setIsReadOnly, setProperties, setProperty, setRealAttributeValueInObject, setSetMethodName, setWeight, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, toString, updateChangeRecord, validateAfterInitialization, validateBeforeInitialization, valueFromObject, valueFromResultSet, valueFromRow, verifyDelete, writeFromAttributeIntoRow, writeFromObjectIntoRowForShallowInsert, writeFromObjectIntoRowForShallowInsertWithChangeRecord, writeFromObjectIntoRowForUpdate, writeFromObjectIntoRowForWhereClause, writeFromObjectIntoRowWithChangeRecord, writeInsertFieldsIntoRow, writeUpdateFieldsIntoRow
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLAnyObjectMapping

public XMLAnyObjectMapping()
Method Detail

buildBackupClone

public void buildBackupClone(java.lang.Object clone,
                             java.lang.Object backup,
                             org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork)
INTERNAL: Clone the attribute from the clone and assign it to the backup.

Specified by:
buildBackupClone in class DatabaseMapping

buildClone

public void buildClone(java.lang.Object original,
                       java.lang.Object clone,
                       org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork)
INTERNAL: Clone the attribute from the original and assign it to the clone.

Specified by:
buildClone in class DatabaseMapping

buildCloneFromRow

public void buildCloneFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow,
                              org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                              java.lang.Object clone,
                              ObjectBuildingQuery sourceQuery,
                              org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork,
                              org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
Description copied from class: DatabaseMapping
INTERNAL: A combination of readFromRowIntoObject and buildClone.

buildClone assumes the attribute value exists on the original and can simply be copied.

readFromRowIntoObject assumes that one is building an original.

Both of the above assumptions are false in this method, and actually attempts to do both at the same time.

Extract value from the row and set the attribute to this value in the working copy clone. In order to bypass the shared cache when in transaction a UnitOfWork must be able to populate working copies directly from the row.

Specified by:
buildCloneFromRow in class DatabaseMapping

cascadePerformRemoveIfRequired

public void cascadePerformRemoveIfRequired(java.lang.Object object,
                                           org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow,
                                           java.util.Map visitedObjects)
INTERNAL: Cascade perform delete through mappings that require the cascade

Specified by:
cascadePerformRemoveIfRequired in class DatabaseMapping

cascadeRegisterNewIfRequired

public void cascadeRegisterNewIfRequired(java.lang.Object object,
                                         org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow,
                                         java.util.Map visitedObjects)
INTERNAL: Cascade registerNew for Create through mappings that require the cascade

Specified by:
cascadeRegisterNewIfRequired in class DatabaseMapping

clone

public java.lang.Object clone()
Description copied from class: DatabaseMapping
INTERNAL: Clones itself.

Overrides:
clone in class DatabaseMapping

compareForChange

public org.eclipse.persistence.internal.sessions.ChangeRecord compareForChange(java.lang.Object clone,
                                                                               java.lang.Object backup,
                                                                               org.eclipse.persistence.internal.sessions.ObjectChangeSet owner,
                                                                               org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: This method was created in VisualAge.

Specified by:
compareForChange in class DatabaseMapping
Returns:
prototype.changeset.ChangeRecord

compareObjects

public boolean compareObjects(java.lang.Object firstObject,
                              java.lang.Object secondObject,
                              org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Compare the attributes belonging to this mapping for the objects.

Specified by:
compareObjects in class DatabaseMapping

fixObjectReferences

public void fixObjectReferences(java.lang.Object object,
                                java.util.Map objectDescriptors,
                                java.util.Map processedObjects,
                                ObjectLevelReadQuery query,
                                RemoteSession session)
INTERNAL: An object has been serialized from the server to the client. Replace the transient attributes of the remote value holders with client-side objects.

Specified by:
fixObjectReferences in class DatabaseMapping

getField

public org.eclipse.persistence.internal.helper.DatabaseField getField()
Description copied from class: DatabaseMapping
INTERNAL: Return the field associated with this mapping if there is exactly one. This is required for object relational mapping to print them, but because they are defined in Enterprise they cannot be cast to. Mappings that have a field include direct mappings and object relational mappings.

Overrides:
getField in class DatabaseMapping

iterate

public void iterate(org.eclipse.persistence.internal.descriptors.DescriptorIterator iterator)
INTERNAL: Iterate on the appropriate attribute value.

Specified by:
iterate in class DatabaseMapping

setXPath

public void setXPath(java.lang.String xpath)

mergeChangesIntoObject

public void mergeChangesIntoObject(java.lang.Object target,
                                   org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord,
                                   java.lang.Object source,
                                   org.eclipse.persistence.internal.sessions.MergeManager mergeManager)
INTERNAL: Merge changes from the source to the target object.

Specified by:
mergeChangesIntoObject in class DatabaseMapping

mergeIntoObject

public void mergeIntoObject(java.lang.Object target,
                            boolean isTargetUninitialized,
                            java.lang.Object source,
                            org.eclipse.persistence.internal.sessions.MergeManager mergeManager)
INTERNAL: Merge changes from the source to the target object.

Specified by:
mergeIntoObject in class DatabaseMapping

setField

public void setField(org.eclipse.persistence.internal.helper.DatabaseField field)

valueFromRow

public java.lang.Object valueFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                     org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                     ObjectBuildingQuery sourceQuery,
                                     org.eclipse.persistence.internal.sessions.AbstractSession executionSession)
                              throws DatabaseException
Description copied from class: DatabaseMapping
INTERNAL: A subclass should implement this method if it wants different behavior. Returns the value for the mapping from the database row. The execution session is the session the query was executed on, and its platform should be used for data conversion.

Overrides:
valueFromRow in class DatabaseMapping
Throws:
DatabaseException

getDescriptor

protected XMLDescriptor getDescriptor(XMLRecord xmlRecord,
                                      org.eclipse.persistence.internal.sessions.AbstractSession session,
                                      javax.xml.namespace.QName rootQName)
                               throws XMLMarshalException
Throws:
XMLMarshalException

writeFromObjectIntoRow

public void writeFromObjectIntoRow(java.lang.Object object,
                                   org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                   org.eclipse.persistence.internal.sessions.AbstractSession session)
                            throws DescriptorException
Description copied from class: DatabaseMapping
INTERNAL: A subclass should implement this method if it wants different behavior. Write the attribute value from the object to the row.

Overrides:
writeFromObjectIntoRow in class DatabaseMapping
Throws:
DescriptorException

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.

buildCompositeRow

protected org.eclipse.persistence.internal.sessions.AbstractRecord buildCompositeRow(java.lang.Object attributeValue,
                                                                                     org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                                                     XMLDescriptor referenceDescriptor,
                                                                                     org.eclipse.persistence.internal.sessions.AbstractRecord parentRow,
                                                                                     org.eclipse.persistence.internal.helper.DatabaseField field,
                                                                                     java.lang.Object originalObject,
                                                                                     boolean wasXMLRoot)

initialize

public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session)
                throws DescriptorException
Description copied from class: DatabaseMapping
INTERNAL: Allow for initialization of properties and validation.

Overrides:
initialize in class DatabaseMapping
Throws:
DescriptorException

isXMLMapping

public boolean isXMLMapping()
Description copied from class: DatabaseMapping
INTERNAL: All relational mappings should implement this method to return true.

Overrides:
isXMLMapping in class DatabaseMapping

getFields

public java.util.Vector getFields()
Description copied from class: DatabaseMapping
INTERNAL: Returns a vector of all the fields this mapping represents.

Overrides:
getFields in class DatabaseMapping

setUseXMLRoot

public void setUseXMLRoot(boolean useXMLRoot)

usesXMLRoot

public boolean usesXMLRoot()

shouldAddXsiType

public boolean shouldAddXsiType(XMLMarshaller xmlMarshaller,
                                XMLDescriptor xmlDescriptor,
                                java.lang.Object originalObject,
                                boolean wasXMLRoot)
INTERNAL:


getNodeToReplace

public org.w3c.dom.Node getNodeToReplace(org.w3c.dom.Node parent)

getConverter

public XMLConverter getConverter()

setConverter

public void setConverter(XMLConverter converter)

EclipseLink1.0 - 20080707 API Reference