|
Oracle TopLink Java API Reference 10g Release 3 (10.1.3.1) B28219-01 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.toplink.mappings.DatabaseMapping
oracle.toplink.ox.mappings.XMLAnyCollectionMapping
Any collection XML mappings map an attribute that contains a heterogenous collection of objects to multiple XML elements. Unlike composite collection XML mappings, the referenced objects may be of different types (including String), and do not need to be related to each other through inheritance or a common interface. The corresponding object attribute 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 collection 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 Collection 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-methods | The name information is stored in the contact-methods element. |
contact-methods/info | The XPath statement may be used to specify any valid path. |
contact-methods[2] | The XPath statement may contain positional information. In this case the contact information is stored in the second occurrence of the contact-methods element. |
Mapping an element of type xs:anyType as an Any Collection 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
XMLAnyCollectionMapping contactMethodsMapping = new XMLAnyCollectionMapping();
contactMethodsMapping.setAttributeName("contactMethods");
contactMethodsMapping.setXPath("contact-methods");
More Information: For more information about using the XML Any Collection Mapping, see the "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.
Constructor Summary | |
XMLAnyCollectionMapping() |
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 |
setContainerPolicy(ContainerPolicy cp) PUBLIC: Set the mapping's container policy. |
void |
setField(DatabaseField field) |
void |
setXPath(java.lang.String xpath) |
void |
useCollectionClass(java.lang.Class concreteContainerClass) PUBLIC: Configure the mapping to use an instance of the specified container class to hold the target objects. |
void |
useMapClass(java.lang.Class concreteContainerClass, java.lang.String methodName) PUBLIC: Configure the mapping to use an instance of the specified container class to hold the target objects. |
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 |
public XMLAnyCollectionMapping()
Method Detail |
public void buildCloneFromRow(DatabaseRow databaseRow, java.lang.Object clone, ObjectLevelReadQuery sourceQuery, UnitOfWork unitOfWork, Session executionSession)
DatabaseMapping
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.
buildCloneFromRow
in class DatabaseMapping
public java.lang.Object clone()
DatabaseMapping
clone
in class DatabaseMapping
public DatabaseField getField()
DatabaseMapping
getField
in class DatabaseMapping
public void initialize(Session session) throws DescriptorException
DatabaseMapping
initialize
in class DatabaseMapping
DescriptorException
public void setXPath(java.lang.String xpath)
public void setContainerPolicy(ContainerPolicy cp)
ContainerMapping
setContainerPolicy
in interface ContainerMapping
public void setField(DatabaseField field)
public java.lang.Object valueFromRow(DatabaseRow row, ObjectLevelReadQuery sourceQuery, Session executionSession) throws DatabaseException
DatabaseMapping
valueFromRow
in class DatabaseMapping
DatabaseException
public void writeFromObjectIntoRow(java.lang.Object object, DatabaseRow row, Session session) throws DescriptorException
DatabaseMapping
writeFromObjectIntoRow
in class DatabaseMapping
DescriptorException
public boolean isXMLMapping()
DatabaseMapping
isXMLMapping
in class DatabaseMapping
public java.util.Vector getFields()
DatabaseMapping
getFields
in class DatabaseMapping
public void useCollectionClass(java.lang.Class concreteContainerClass)
jdk1.2.x: The container class must implement (directly or indirectly) the Collection interface.
jdk1.1.x: The container class must be a subclass of Vector.
useCollectionClass
in interface ContainerMapping
public void useMapClass(java.lang.Class concreteContainerClass, java.lang.String methodName)
ContainerMapping
Map
is the value returned by a call to the specified zero-argument method. The method must be implemented by the class (or a superclass) of any value to be inserted into the Map
.
The container class must implement (directly or indirectly) the java.util.Map
interface.
To facilitate resolving the method, the mapping's referenceClass must set before calling this method.
useMapClass
in interface ContainerMapping
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |