|
Oracle Fusion Middleware Java API Reference for Oracle TopLink 11g Release 1 (11.1.1) E28847-01 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
org.eclipse.persistence.internal.helper.DatabaseField
org.eclipse.persistence.oxm.XMLField
public class XMLField
TopLink XML mappings make use of XMLFields based on 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 field using the setXPath
method or by using the appropriate constructor.
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 />
<xsd:complexType >
<xsd:sequence>
<xsd:element />
<xsd:element />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Code Sample
XMLField pictureField = new XMLField("picture/text()")
pictureField.setSchemaType(XMLConstants.HEX_BINARY_QNAME);
Setting custom conversion pairs: By default in TopLink XML built-in schema types are associated with java classes and vice versa. These default pairs can be modified by the user using the addJavaConversion and addXMLConversion api. For example by default a java.util.Calendar is mapped to the dateTime schema type so the XML will be formated based on that type. Below are the default schema type to java type conversion pairs and the default java type to schema type conversion pairs.
XML schema type to Java type default conversion pairs
Schema Type | Java Type |
---|---|
base64Binary | byte[] |
boolean | boolean |
byte | byte |
date | java.util.Calendar |
dateTime | java.util.Calendar |
decimal | java.math.BigDecimal |
double | double |
float | float |
hexBinary | byte[] |
int | int |
integer | java.math.BigInteger |
long | long |
QName | javax.xml.namespace.QName |
time | java.util.Calendar |
unsignedByte | short |
unsignedInt | long |
unsignedShort | int |
anySimpleType | java.lang.String |
Java type to XML schema type default conversion pairs
Java Type | Schema Type |
---|---|
byte[] | hexBinary |
java.lang.Byte[] | hexBinary |
java.math.BigDecimal | decimal |
java.math.BigInteger | integer |
boolean | boolean |
java.lang.Boolean | boolean |
java.lang.Byte | Byte |
byte | byte |
java.util.Calendar | dateTime |
java.util.GregorianCalendar | dateTime |
double | double |
java.lang.Double | double |
float | float |
java.lang.Float | float |
int | int |
java.lang.Integer | int |
long | long |
java.lang.Long | long |
short | short |
java.lang.Short | short |
javax.xml.namespace.QName | QName |
java.lang.String | string |
XMLUnionField
, Serialized FormField Summary | |
---|---|
private boolean |
isCDATA |
private boolean |
isInitialized |
private boolean |
isRequired |
private boolean |
isTypedTextField |
private org.eclipse.persistence.internal.oxm.XPathFragment |
lastXPathFragment |
private javax.xml.namespace.QName |
leafElementType |
private NamespaceResolver |
namespaceResolver |
private javax.xml.namespace.QName |
schemaType |
protected java.util.HashMap |
userJavaTypes |
protected java.util.HashMap |
userXMLTypes |
private boolean |
usesSingleNode Makes this maintain the collection of items in a single attribute or element instead of having one element per item in the collection. |
private org.eclipse.persistence.internal.oxm.XPathFragment |
xPathFragment |
Fields inherited from class org.eclipse.persistence.internal.helper.DatabaseField |
---|
columnDefinition, index, isInsertable, isNullable, isPrimaryKey, isUnique, isUpdatable, length, name, NULL_SQL_TYPE, precision, qualifiedName, scale, sqlType, table, type, typeName, useDelimiters |
Constructor Summary | |
---|---|
XMLField() Default constructor, create a new XMLField |
|
XMLField(java.lang.String xPath) Default constructor, create a new XMLField based on the specified xPath |
Method Summary | |
---|---|
void |
addConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass) Add an entry for both an XML Conversion and a Java Conversion entry |
void |
addJavaConversion(java.lang.Class javaClass, javax.xml.namespace.QName qname) Add a Java to XML Conversion pair entry |
void |
addXMLConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass) Add an XML to Java Conversion pair entry |
private void |
buildFragments(java.lang.String xpathString) |
java.lang.Object |
convertValueBasedOnSchemaType(java.lang.Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, XMLRecord record) INTERNAL: |
boolean |
equals(java.lang.Object object) |
java.lang.Class |
getJavaClass(javax.xml.namespace.QName qname) Return the class for a given qualified XML Schema type |
org.eclipse.persistence.internal.oxm.XPathFragment |
getLastXPathFragment() INTERNAL: Return the last XPathFragment. |
javax.xml.namespace.QName |
getLeafElementType() |
NamespaceResolver |
getNamespaceResolver() Get the NamespaceResolver associated with this XMLField |
javax.xml.namespace.QName |
getSchemaType() Return the schema type associated with this field |
private java.util.HashMap |
getUserJavaTypes() |
java.util.ArrayList |
getUserJavaTypesForDeploymentXML() INTERNAL: |
private java.util.HashMap |
getUserXMLTypes() |
java.util.ArrayList |
getUserXMLTypesForDeploymentXML() INTERNAL: |
javax.xml.namespace.QName |
getXMLType(java.lang.Class javaClass) Return the qualified XML Schema type for a given class |
java.lang.String |
getXPath() Returns the xpath statement associated with this XMLField |
org.eclipse.persistence.internal.oxm.XPathFragment |
getXPathFragment() INTERNAL: Maintain a direct pointer to the first XPathFragment. |
int |
hashCode() |
boolean |
hasLastXPathFragment() INTERNAL: |
private boolean |
hasPath(java.lang.String xpathString) |
void |
initialize() |
private void |
initializeXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment) |
boolean |
isCDATA() INTERNAL: |
boolean |
isRequired() Indicates if this XMLField represents a "required" XML element or attribute ([minOccurs="1"] for elements, [use="required"] for attributes). |
boolean |
isSchemaType(javax.xml.namespace.QName schemaType) INTERNAL |
boolean |
isSelfField() INTERNAL: Indicates if the xpath for this field is "." |
boolean |
isTypedTextField() Returns if the field is a typed text field True when we should base conversions on the "type" attribute on elements |
boolean |
isUnionField() INTERNAL: Returns false since this is a union field The subclass XMLUnionField returns true for this |
void |
removeConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass) Remove both a Java to XML Conversion and the corresponding XML to Java Conversion entry |
void |
removeJavaConversion(java.lang.Class javaClass) Remove a Java to XML Conversion entry |
void |
removeXMLConversion(javax.xml.namespace.QName qname) Remove an XML to Java Conversion entry |
void |
setIsCDATA(boolean CDATA) INTERNAL: |
void |
setIsTypedTextField(boolean value) Set if the field is a typed text field True when we should base conversions on the "type" attribute on elements |
void |
setLastXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment lastXPathFragment) INTERNAL: Maintain a direct pointer to the last XPathFragment. |
void |
setLeafElementType(javax.xml.namespace.QName type) Assumes type is in the format prefix:localPart, or localPart. |
void |
setName(java.lang.String xPath) This has the same effect as calling the setXPath method |
void |
setName(java.lang.String xPath, java.lang.String startDelimiter, java.lang.String endDelimiter) Override setName in superclass |
void |
setNamespaceResolver(NamespaceResolver newNamespaceResolver) Set the NamespaceResolver associated with this XMLField |
void |
setRequired(boolean isRequired) Set whether this XMLField represents a "required" XML element or attribute ([minOccurs="1"] for elements, [use="required"] for attributes). |
void |
setSchemaType(javax.xml.namespace.QName value) Sets the schematype associated with this XMLField This is an optional setting; when set the schema type will be used to format the XML appropriately |
void |
setUserJavaTypesForDeploymentXML(java.util.ArrayList pairs) INTERNAL: |
void |
setUserXMLTypesForDeploymentXML(java.util.ArrayList pairs) INTERNAL: |
void |
setUsesSingleNode(boolean usesSingleNode) PUBLIC: Sets whether the mapping uses a single node. |
void |
setXPath(java.lang.String xPath) Set the xpath statment for this XMLField. |
void |
setXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment) INTERNAL: Return the first XPathFragment. |
boolean |
usesSingleNode() PUBLIC: Checks whether the mapping uses a single node. |
Methods inherited from class org.eclipse.persistence.internal.helper.DatabaseField |
---|
clone, equals, getColumnDefinition, getIndex, getLength, getName, getNameDelimited, getNameForComparisons, getPrecision, getQualifiedName, getQualifiedNameDelimited, getScale, getSqlType, getTable, getTableName, getType, getTypeName, getUseUpperCaseForComparisons, hasTableName, initDDLFields, isInsertable, isNullable, isObjectRelationalDatabaseField, isPrimaryKey, isReadOnly, isUnique, isUpdatable, resetQualifiedName, setColumnDefinition, setIndex, setInsertable, setLength, setName, setNameForComparisons, setNullable, setPrecision, setPrimaryKey, setScale, setSqlType, setTable, setTableName, setType, setTypeName, setUnique, setUpdatable, setUseDelimiters, shouldUseDelimiters, toString, useUpperCaseForComparisons |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private NamespaceResolver namespaceResolver
private javax.xml.namespace.QName schemaType
private org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment
private org.eclipse.persistence.internal.oxm.XPathFragment lastXPathFragment
private boolean isCDATA
private boolean isRequired
private boolean isInitialized
private boolean usesSingleNode
protected java.util.HashMap userXMLTypes
protected java.util.HashMap userJavaTypes
private boolean isTypedTextField
private javax.xml.namespace.QName leafElementType
Constructor Detail |
---|
public XMLField()
public XMLField(java.lang.String xPath)
xPath
- The xPath statement for this fieldMethod Detail |
---|
public void initialize()
private void initializeXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment)
public java.lang.String getXPath()
public void setXPath(java.lang.String xPath)
xPath
- The xpath statement to be associated with this XMLFieldpublic NamespaceResolver getNamespaceResolver()
NamespaceResolver
public void setNamespaceResolver(NamespaceResolver newNamespaceResolver)
newNamespaceResolver
- The namespaceResolver to be associated with this XMLFieldNamespaceResolver
public void setUsesSingleNode(boolean usesSingleNode)
usesSingleNode
- True if the items in the collection are in a single node or false if each of the items in the collection is in its own nodepublic boolean usesSingleNode()
public void setSchemaType(javax.xml.namespace.QName value)
value
- QName to be added to the list of schema typespublic javax.xml.namespace.QName getSchemaType()
public boolean isTypedTextField()
public void setIsTypedTextField(boolean value)
value
- The boolean value specifiy if this is a typed text fieldpublic boolean isSelfField()
public boolean isUnionField()
public void setName(java.lang.String xPath, java.lang.String startDelimiter, java.lang.String endDelimiter)
setName
in class org.eclipse.persistence.internal.helper.DatabaseField
public void setName(java.lang.String xPath)
setName
in class org.eclipse.persistence.internal.helper.DatabaseField
xPath
- The xPath associated with this XMLFieldprivate boolean hasPath(java.lang.String xpathString)
private void buildFragments(java.lang.String xpathString)
public org.eclipse.persistence.internal.oxm.XPathFragment getXPathFragment()
public void setXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment)
public org.eclipse.persistence.internal.oxm.XPathFragment getLastXPathFragment()
public void setLastXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment lastXPathFragment)
public java.lang.Class getJavaClass(javax.xml.namespace.QName qname)
qname
- The qualified name of the XML Schema type to use as a key in the lookuppublic javax.xml.namespace.QName getXMLType(java.lang.Class javaClass)
javaClass
- The class to use as a key in the lookupprivate java.util.HashMap getUserJavaTypes()
private java.util.HashMap getUserXMLTypes()
public java.util.ArrayList getUserXMLTypesForDeploymentXML()
public void setUserXMLTypesForDeploymentXML(java.util.ArrayList pairs) throws java.lang.Exception
java.lang.Exception
public java.util.ArrayList getUserJavaTypesForDeploymentXML()
public void setUserJavaTypesForDeploymentXML(java.util.ArrayList pairs) throws java.lang.Exception
java.lang.Exception
public java.lang.Object convertValueBasedOnSchemaType(java.lang.Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, XMLRecord record)
public void addXMLConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass)
qname
- The qualified name of the XML schema typejavaClass
- The class to addpublic void addJavaConversion(java.lang.Class javaClass, javax.xml.namespace.QName qname)
javaClass
- The class to addqname
- The qualified name of the XML schema typepublic void addConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass)
qname
- The qualified name of the XML schema typejavaClass
-public void removeXMLConversion(javax.xml.namespace.QName qname)
qname
-public void removeJavaConversion(java.lang.Class javaClass)
javaClass
-public void removeConversion(javax.xml.namespace.QName qname, java.lang.Class javaClass)
qname
-javaClass
-public void setLeafElementType(javax.xml.namespace.QName type)
type
-public javax.xml.namespace.QName getLeafElementType()
public boolean hasLastXPathFragment()
public void setIsCDATA(boolean CDATA)
CDATA
-public boolean isCDATA()
public boolean isSchemaType(javax.xml.namespace.QName schemaType)
public boolean isRequired()
SchemaModelGenerator
public void setRequired(boolean isRequired)
SchemaModelGenerator
public boolean equals(java.lang.Object object)
equals
in class org.eclipse.persistence.internal.helper.DatabaseField
public int hashCode()
hashCode
in class org.eclipse.persistence.internal.helper.DatabaseField
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |