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.
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private XMLConverter | |
| private XMLField | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | buildBackupClone(Object
TODO clone, Object TODO backup, UnitOfWorkImpl TODO unitOfWork)Implements abstract org. |
| public void | buildClone(Object
TODO original, CacheKey TODO cacheKey, Object TODO clone, Integer TODO refreshCascade, AbstractSession TODO cloningSession)Implements abstract org. |
| public void | buildCloneFromRow(AbstractRecord
TODO databaseRow, JoinedAttributeManager TODO joinManager, Object TODO clone, CacheKey TODO sharedCacheKey, ObjectBuildingQuery TODO sourceQuery, UnitOfWorkImpl TODO unitOfWork, AbstractSession TODO executionSession)Implements abstract org. |
| protected AbstractRecord | buildCompositeRow(Object attributeValue, AbstractSession session, XMLDescriptor referenceDescriptor, AbstractRecord parentRow, DatabaseField field, Object originalObject, boolean wasXMLRoot)
|
| private Object | buildObjectValuesFromDOMRecord(DOMRecord record, AbstractSession session, ObjectBuildingQuery query, JoinedAttributeManager joinManager)
|
| public void | cascadePerformRemoveIfRequired(Object
TODO object, UnitOfWorkImpl TODO uow, Map<K, V> TODO visitedObjects)Implements abstract org. |
| public void | cascadeRegisterNewIfRequired(Object
TODO object, UnitOfWorkImpl TODO uow, Map<K, V> TODO visitedObjects)Implements abstract org. |
| public Object | |
| public ChangeRecord | Returns: prototype.changeset.ChangeRecordTODO clone, Object TODO backup, ObjectChangeSet TODO owner, AbstractSession TODO session)Implements abstract org. |
| public boolean | compareObjects(Object
TODO firstObject, Object TODO secondObject, AbstractSession TODO session)Implements abstract org. |
| public Object | convertDataValueToObjectValue(Object fieldValue, Session session, XMLUnmarshaller unmarshaller)
Implements org. |
| public Object | convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller)
Implements org. |
| public void | fixObjectReferences(Object
TODO object, Map<Object, ObjectDescriptor> TODO objectDescriptors, Map<Object, Object> TODO processedObjects, ObjectLevelReadQuery TODO query, DistributedSession TODO session)Implements abstract org. |
| public XMLConverter | |
| public DatabaseField | getField()
Overrides org. Implements org. |
| public Vector | getFields()
Overrides org. |
| private XPathFragment | |
| public Node | |
| private ArrayList | |
| public void | initialize(AbstractSession session)
Overrides org. |
| public boolean | |
| private boolean | |
| public boolean | isXMLMapping()
Overrides org. |
| public void | iterate(DescriptorIterator iterator)
Implements abstract org. |
| public void | mergeChangesIntoObject(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession)
Implements abstract org. |
| public void | mergeIntoObject(Object target, boolean isTargetUninitialized, Object source, MergeManager mergeManager, AbstractSession targetSession)
Implements abstract org. |
| public void | |
| public void | |
| public void | setMixedContent(boolean mixed)
Implements org. |
| public void | setUseXMLRoot(boolean useXMLRoot)
Implements org. |
| public void | |
| public boolean | |
| public Object | valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed)
Overrides org. |
| public void | writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, DatabaseMapping.
Overrides org. |
| private void | writeSimpleValue(XMLField xmlRootField, DOMRecord row, AbstractSession session, Object originalObject, Object value, Node root, Node toReplace, boolean wasXMLRoot)
|
| public void | writeSingleValue(Object
- The value to be marshalled value, Object parent, XMLRecord - The Record the value is being marshalled too. row, AbstractSession session)Implements org. |
| areOtherMappingInThisContext | back to summary |
|---|---|
| private boolean areOtherMappingInThisContext | |
| converter | back to summary |
|---|---|
| private XMLConverter converter | |
| field | back to summary |
|---|---|
| private XMLField field | |
| isMixedContent | back to summary |
|---|---|
| private boolean isMixedContent | |
| useXMLRoot | back to summary |
|---|---|
| private boolean useXMLRoot | |
| XMLAnyObjectMapping | back to summary |
|---|---|
| public XMLAnyObjectMapping() | |
| buildBackupClone | back to summary |
|---|---|
| public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) Implements abstract org. INTERNAL: Clone the attribute from the clone and assign it to the backup.
| |
| buildClone | back to summary |
|---|---|
| public void buildClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession) Implements abstract org. INTERNAL: Clone the attribute from the original and assign it to the clone.
| |
| buildCloneFromRow | back to summary |
|---|---|
| public void buildCloneFromRow(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) Implements abstract org. Doc from org. 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.
| |
| buildCompositeRow | back to summary |
|---|---|
| protected AbstractRecord buildCompositeRow(Object attributeValue, AbstractSession session, XMLDescriptor referenceDescriptor, AbstractRecord parentRow, DatabaseField field, Object originalObject, boolean wasXMLRoot) | |
| buildObjectValuesFromDOMRecord | back to summary |
|---|---|
| private Object buildObjectValuesFromDOMRecord(DOMRecord record, AbstractSession session, ObjectBuildingQuery query, JoinedAttributeManager joinManager) | |
| cascadePerformRemoveIfRequired | back to summary |
|---|---|
| public void cascadePerformRemoveIfRequired(Object object, UnitOfWorkImpl uow, Map<K, V> visitedObjects) Implements abstract org. INTERNAL: Cascade perform delete through mappings that require the cascade
| |
| cascadeRegisterNewIfRequired | back to summary |
|---|---|
| public void cascadeRegisterNewIfRequired(Object object, UnitOfWorkImpl uow, Map<K, V> visitedObjects) Implements abstract org. INTERNAL: Cascade registerNew for Create through mappings that require the cascade
| |
| clone | back to summary |
|---|---|
| public Object clone() Overrides org. Doc from org. INTERNAL: Clones itself. | |
| compareForChange | back to summary |
|---|---|
| public ChangeRecord compareForChange(Object clone, Object backup, ObjectChangeSet owner, AbstractSession session) Implements abstract org. INTERNAL: This method was created in VisualAge.
| |
| compareObjects | back to summary |
|---|---|
| public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) Implements abstract org. INTERNAL: Compare the attributes belonging to this mapping for the objects.
| |
| convertDataValueToObjectValue | back to summary |
|---|---|
| public Object convertDataValueToObjectValue(Object fieldValue, Session session, XMLUnmarshaller unmarshaller) Implements org. INTERNAL
| |
| convertObjectValueToDataValue | back to summary |
|---|---|
| public Object convertObjectValueToDataValue(Object value, Session session, XMLMarshaller marshaller) Implements org. INTERNAL
| |
| getConverter | back to summary |
|---|---|
| public XMLConverter getConverter() | |
| getField | back to summary |
|---|---|
| public DatabaseField getField() Overrides org. Implements org. Doc from org. 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 in an Enterprise context they cannot be cast to. Mappings that have a field include direct mappings and object relational mappings.
| |
| getFields | back to summary |
|---|---|
| public Vector Overrides org. Doc from org. INTERNAL: Returns a vector of all the fields this mapping represents. | |
| getFragmentToCompare | back to summary |
|---|---|
| private XPathFragment | |
| getNodeToReplace | back to summary |
|---|---|
| public Node getNodeToReplace(Node parent) | |
| getUnmappedChildNodes | back to summary |
|---|---|
| private ArrayList | |
| initialize | back to summary |
|---|---|
| public void initialize(AbstractSession session) throws DescriptorException Overrides org. Doc from org. INTERNAL: Allow for initialization of properties and validation.
| |
| isMixedContent | back to summary |
|---|---|
| public boolean isMixedContent() Implements org.
| |
| isUnmappedContent | back to summary |
|---|---|
| private boolean isUnmappedContent(Node node) | |
| isXMLMapping | back to summary |
|---|---|
| public boolean isXMLMapping() Overrides org. Doc from org. INTERNAL: All relational mappings should implement this method to return true.
| |
| iterate | back to summary |
|---|---|
| public void iterate(DescriptorIterator iterator) Implements abstract org. INTERNAL: Iterate on the appropriate attribute value.
| |
| mergeChangesIntoObject | back to summary |
|---|---|
| public void mergeChangesIntoObject(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) Implements abstract org. INTERNAL: Merge changes from the source to the target object.
| |
| mergeIntoObject | back to summary |
|---|---|
| public void mergeIntoObject(Object target, boolean isTargetUninitialized, Object source, MergeManager mergeManager, AbstractSession targetSession) Implements abstract org. INTERNAL: Merge changes from the source to the target object.
| |
| setConverter | back to summary |
|---|---|
| public void setConverter(XMLConverter converter) Implements org.
| |
| setField | back to summary |
|---|---|
| public void setField(DatabaseField field) Implements org.
| |
| setMixedContent | back to summary |
|---|---|
| public void setMixedContent(boolean mixed) Implements org.
| |
| setUseXMLRoot | back to summary |
|---|---|
| public void setUseXMLRoot(boolean useXMLRoot) Implements org.
| |
| setXPath | back to summary |
|---|---|
| public void setXPath(String xpath) | |
| usesXMLRoot | back to summary |
|---|---|
| public boolean usesXMLRoot() Implements org.
| |
| valueFromRow | back to summary |
|---|---|
| public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException Overrides org. Doc from org. 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.
| |
| writeFromObjectIntoRow | back to summary |
|---|---|
| public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, DatabaseMapping. Overrides org. Doc from org. INTERNAL: A subclass should implement this method if it wants different behavior. Write the attribute value from the object to the row.
| |
| writeSimpleValue | back to summary |
|---|---|
| private void writeSimpleValue(XMLField xmlRootField, DOMRecord row, AbstractSession session, Object originalObject, Object value, Node root, Node toReplace, boolean wasXMLRoot) | |
| writeSingleValue | back to summary |
|---|---|
| public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) Implements org. Doc from org. INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling. | |