Skip navigation links

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

B28219-01


oracle.toplink.ox.mappings
Class XMLAnyObjectMapping

java.lang.Object
  extended byoracle.toplink.mappings.DatabaseMapping
      extended byoracle.toplink.ox.mappings.XMLAnyObjectMapping

All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class XMLAnyObjectMapping
extends DatabaseMapping

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

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

Constructor Summary
XMLAnyObjectMapping()
           

 

Method Summary
 void buildCloneFromRow(DatabaseRow databaseRow, java.lang.Object clone, ObjectLevelReadQuery sourceQuery, UnitOfWork unitOfWork, Session executionSession)
          INTERNAL: A combination of readFromRowIntoObject and buildClone.
 java.lang.Object clone()
          INTERNAL: Clones itself.
 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.
 void initialize(Session session)
          INTERNAL: Allow for initialization of properties and validation.
 boolean isXMLMapping()
          INTERNAL: All relational mappings should implement this method to return true.
 void setField(DatabaseField field)
           
 void setXPath(java.lang.String xpath)
           
 java.lang.Object valueFromRow(DatabaseRow row, ObjectLevelReadQuery sourceQuery, Session executionSession)
          INTERNAL:
 void writeFromObjectIntoRow(java.lang.Object object, DatabaseRow row, Session session)
          INTERNAL: A subclass should implement this method if it wants different behaviour.

 

Methods inherited from class oracle.toplink.mappings.DatabaseMapping
getAttributeAccessor, getAttributeClassification, 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

XMLAnyObjectMapping

public XMLAnyObjectMapping()

Method Detail

buildCloneFromRow

public void buildCloneFromRow(DatabaseRow databaseRow,
                              java.lang.Object clone,
                              ObjectLevelReadQuery sourceQuery,
                              UnitOfWork unitOfWork,
                              Session 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

clone

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

getField

public 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

setXPath

public void setXPath(java.lang.String xpath)

setField

public void setField(DatabaseField field)

valueFromRow

public java.lang.Object valueFromRow(DatabaseRow row,
                                     ObjectLevelReadQuery sourceQuery,
                                     Session executionSession)
                              throws DatabaseException
Description copied from class: DatabaseMapping
INTERNAL:
Overrides:
valueFromRow in class DatabaseMapping
Throws:
DatabaseException

writeFromObjectIntoRow

public void writeFromObjectIntoRow(java.lang.Object object,
                                   DatabaseRow row,
                                   Session session)
                            throws DescriptorException
Description copied from class: DatabaseMapping
INTERNAL: A subclass should implement this method if it wants different behaviour. Write the attribute value from the object to the row.
Overrides:
writeFromObjectIntoRow in class DatabaseMapping
Throws:
DescriptorException

initialize

public void initialize(Session 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

Skip navigation links

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