Class XMLField
- All Implemented Interfaces:
Serializable
,Cloneable
,org.eclipse.persistence.internal.core.helper.CoreField
,org.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
- Direct Known Subclasses:
XMLUnionField
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 name="customer" type="customer-type"/>
<xsd:complexType name="customer-type">
<xsd:sequence>
<xsd:element name="picture" type="xsd:hexBinary"/>
<xsd:element name="resume" type="xsd:base64Binary"/>
</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.
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 | 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 |
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected QName
protected HashMap
protected HashMap
Fields inherited from class org.eclipse.persistence.internal.helper.DatabaseField
columnDefinition, index, isCreatable, isInsertable, isNullable, isPrimaryKey, isTranslated, isUnique, isUpdatable, keepInRow, length, name, nameForComparisons, NULL_SQL_TYPE, precision, qualifiedName, scale, sqlType, table, type, typeName, useDelimiters, useUpperCaseForComparisons
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addConversion
(QName qname, Class javaClass) Add an entry for both an XML Conversion and a Java Conversion entryvoid
addJavaConversion
(Class javaClass, QName qname) Add a Java to XML Conversion pair entryvoid
addXMLConversion
(QName qname, Class javaClass) Add an XML to Java Conversion pair entryconvertValueBasedOnSchemaType
(Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record) INTERNAL: Called from DOMRecord and XMLReader.boolean
Determine whether the receiver is equal to a DatabaseField.getJavaClass
(QName qname) INTERNAL Return the class for a given qualified XML Schema typegetJavaClass
(QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager) INTERNALorg.eclipse.persistence.internal.oxm.XPathFragment
INTERNAL: Return the last XPathFragment.Get the NamespaceResolver associated with this XMLFieldReturn the schema type associated with this fieldgetSchemaTypeForValue
(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session) INTERNAL:INTERNAL:INTERNAL:getXMLType
(Class javaClass) Return the qualified XML Schema type for a given classgetXMLType
(Class javaClass, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager) Return the qualified XML Schema type for a given classgetXPath()
Returns the xpath statement associated with this XMLFieldorg.eclipse.persistence.internal.oxm.XPathFragment
INTERNAL: Maintain a direct pointer to the first XPathFragment.int
hashCode()
Return the hashcode of the name, because it is fairly unique.boolean
INTERNAL:void
boolean
isCDATA()
INTERNAL:boolean
INTERNAL:boolean
Indicates if this XMLField represents a "required" XML element or attribute ([minOccurs="1"] for elements, [use="required"] for attributes).boolean
isSchemaType
(QName schemaType) INTERNALboolean
INTERNAL: Indicates if the xpath for this field is "."boolean
Returns if the field is a typed text field True when we should base conversions on the "type" attribute on elementsboolean
INTERNAL: Returns false since this is a union field The subclass XMLUnionField returns true for thisvoid
removeConversion
(QName qname, Class javaClass) Remove both a Java to XML Conversion and the corresponding XML to Java Conversion entryvoid
removeJavaConversion
(Class javaClass) Remove a Java to XML Conversion entryvoid
removeXMLConversion
(QName qname) Remove an XML to Java Conversion entryvoid
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 elementsvoid
setLastXPathFragment
(org.eclipse.persistence.internal.oxm.XPathFragment lastXPathFragment) INTERNAL: Maintain a direct pointer to the last XPathFragment.void
setLeafElementType
(QName type) Assumes type is in the format prefix:localPart, or localPart.void
This has the same effect as calling the setXPath methodvoid
Override setName in superclassvoid
setNamespaceResolver
(NamespaceResolver newNamespaceResolver) Set the NamespaceResolver associated with this XMLFieldvoid
setNestedArray
(boolean nestedArray) Set nested array flag.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
(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 appropriatelyvoid
INTERNAL:void
INTERNAL:void
setUsesSingleNode
(boolean usesSingleNode) PUBLIC: Sets whether the mapping uses a single node.void
Set the xpath statment for this XMLField.void
setXPathFragment
(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment) INTERNAL: Return the first XPathFragment.boolean
PUBLIC: Checks whether the mapping uses a single node.Methods inherited from class org.eclipse.persistence.internal.helper.DatabaseField
clone, convertClassNamesToClasses, equals, getColumnDefinition, getIndex, getLength, getName, getNameDelimited, getNameForComparisons, getPrecision, getQualifiedName, getQualifiedNameDelimited, getScale, getSqlType, getTable, getTableName, getType, getTypeName, getUseUpperCaseForComparisons, hasTableName, initDDLFields, isCreatable, isInsertable, isNullable, isObjectRelationalDatabaseField, isPrimaryKey, isReadOnly, isTranslated, isUnique, isUpdatable, keepInRow, resetQualifiedName, setColumnDefinition, setCreatable, setIndex, setInsertable, setIsTranslated, setKeepInRow, 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
Methods inherited from interface org.eclipse.persistence.internal.core.helper.CoreField
setType
Methods inherited from interface org.eclipse.persistence.internal.oxm.mappings.Field
getName, getType
-
Field Details
-
userXMLTypes
-
userJavaTypes
-
isTypedTextField
protected boolean isTypedTextField -
leafElementType
-
-
Constructor Details
-
XMLField
public XMLField()Default constructor, create a new XMLField -
XMLField
Default constructor, create a new XMLField based on the specified xPath- Parameters:
xPath
- The xPath statement for this field
-
-
Method Details
-
initialize
public void initialize()- Specified by:
initialize
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
getXPath
Returns the xpath statement associated with this XMLField- Specified by:
getXPath
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- The xpath statement associated with this XMLField
-
setXPath
Set the xpath statment for this XMLField.- Specified by:
setXPath
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
xPath
- The xpath statement to be associated with this XMLField
-
getNamespaceResolver
Get the NamespaceResolver associated with this XMLField- Specified by:
getNamespaceResolver
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- The NamespaceResolver associated with this XMLField
- See Also:
-
setNamespaceResolver
Set the NamespaceResolver associated with this XMLField- Specified by:
setNamespaceResolver
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
newNamespaceResolver
- The namespaceResolver to be associated with this XMLField- See Also:
-
setUsesSingleNode
public void setUsesSingleNode(boolean usesSingleNode) PUBLIC: Sets whether the mapping uses a single node.- Specified by:
setUsesSingleNode
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
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 node
-
usesSingleNode
public boolean usesSingleNode()PUBLIC: Checks whether the mapping uses a single node.- Specified by:
usesSingleNode
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- 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 node.
-
setSchemaType
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- Specified by:
setSchemaType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
value
- QName to be added to the list of schema types
-
getSchemaType
Return the schema type associated with this field- Specified by:
getSchemaType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- the schema type
-
isTypedTextField
public boolean isTypedTextField()Returns if the field is a typed text field True when we should base conversions on the "type" attribute on elements- Specified by:
isTypedTextField
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- True when we should base conversions on the "type" attribute on elements, otherwise false
-
setIsTypedTextField
public 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- Specified by:
setIsTypedTextField
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
value
- The boolean value specifiy if this is a typed text field
-
isSelfField
public boolean isSelfField()INTERNAL: Indicates if the xpath for this field is "."- Specified by:
isSelfField
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- true if the xpath is ".", false otherwise
-
isUnionField
public boolean isUnionField()INTERNAL: Returns false since this is a union field The subclass XMLUnionField returns true for this- Specified by:
isUnionField
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
setName
Override setName in superclass- Overrides:
setName
in classorg.eclipse.persistence.internal.helper.DatabaseField
-
setName
This has the same effect as calling the setXPath method- Specified by:
setName
in interfaceorg.eclipse.persistence.internal.core.helper.CoreField
- Overrides:
setName
in classorg.eclipse.persistence.internal.helper.DatabaseField
- Parameters:
xPath
- The xPath associated with this XMLField
-
getXPathFragment
public org.eclipse.persistence.internal.oxm.XPathFragment getXPathFragment()INTERNAL: Maintain a direct pointer to the first XPathFragment. For example given the following XPath first/middle/@last, first is the first XPathFragment.- Specified by:
getXPathFragment
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
setXPathFragment
public void setXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment) INTERNAL: Return the first XPathFragment. -
getLastXPathFragment
public org.eclipse.persistence.internal.oxm.XPathFragment getLastXPathFragment()INTERNAL: Return the last XPathFragment.- Specified by:
getLastXPathFragment
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
setLastXPathFragment
public void setLastXPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment lastXPathFragment) INTERNAL: Maintain a direct pointer to the last XPathFragment. For example given the following XPath first/middle/@last, @last is the last XPathFragment. -
getJavaClass
INTERNAL Return the class for a given qualified XML Schema type- Parameters:
qname
- The qualified name of the XML Schema type to use as a key in the lookup- Returns:
- The class corresponding to the specified schema type, if no corresponding match found returns null
-
getJavaClass
public Class getJavaClass(QName qname, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager) INTERNAL- Specified by:
getJavaClass
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
qname
- The qualified name of the XML Schema type to use as a key in the lookup- Returns:
- the class for a given qualified XML Schema type.
-
getXMLType
Return the qualified XML Schema type for a given class- Parameters:
javaClass
- The class to use as a key in the lookup- Returns:
- QName The qualified XML Schema type, if no corresponding match found returns null
-
getXMLType
public QName getXMLType(Class javaClass, org.eclipse.persistence.internal.oxm.ConversionManager conversionManager) Description copied from interface:org.eclipse.persistence.internal.oxm.mappings.Field
Return the qualified XML Schema type for a given class- Specified by:
getXMLType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
javaClass
- The class to use as a key in the lookup- Returns:
- the XML Schema type for a given class.
-
getUserXMLTypesForDeploymentXML
INTERNAL: -
setUserXMLTypesForDeploymentXML
INTERNAL:- Throws:
Exception
-
getUserJavaTypesForDeploymentXML
INTERNAL: -
setUserJavaTypesForDeploymentXML
INTERNAL:- Throws:
Exception
-
convertValueBasedOnSchemaType
public Object convertValueBasedOnSchemaType(Object value, org.eclipse.persistence.internal.oxm.XMLConversionManager xmlConversionManager, org.eclipse.persistence.internal.oxm.record.AbstractUnmarshalRecord record) INTERNAL: Called from DOMRecord and XMLReader. MappingNodeValues call XMLReader which calls this method so that other XMLReader subclasses can override.- Specified by:
convertValueBasedOnSchemaType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
addXMLConversion
Add an XML to Java Conversion pair entry- Parameters:
qname
- The qualified name of the XML schema typejavaClass
- The class to add
-
addJavaConversion
Add a Java to XML Conversion pair entry- Parameters:
javaClass
- The class to addqname
- The qualified name of the XML schema type
-
addConversion
Add an entry for both an XML Conversion and a Java Conversion entry- Parameters:
qname
- The qualified name of the XML schema typejavaClass
-
-
removeXMLConversion
Remove an XML to Java Conversion entry- Parameters:
qname
-
-
removeJavaConversion
Remove a Java to XML Conversion entry- Parameters:
javaClass
-
-
removeConversion
Remove both a Java to XML Conversion and the corresponding XML to Java Conversion entry- Parameters:
qname
-javaClass
-
-
setLeafElementType
Assumes type is in the format prefix:localPart, or localPart.- Parameters:
type
-
-
getLeafElementType
- Specified by:
getLeafElementType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
hasLastXPathFragment
public boolean hasLastXPathFragment()INTERNAL:- Specified by:
hasLastXPathFragment
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
-
getSchemaTypeForValue
public QName getSchemaTypeForValue(Object value, org.eclipse.persistence.internal.core.sessions.CoreAbstractSession session) INTERNAL:- Specified by:
getSchemaTypeForValue
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
setIsCDATA
public void setIsCDATA(boolean CDATA) INTERNAL:- Specified by:
setIsCDATA
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
CDATA
-
-
isCDATA
public boolean isCDATA()INTERNAL:- Specified by:
isCDATA
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
-
isSchemaType
INTERNAL- Specified by:
isSchemaType
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver>
-
isRequired
public boolean isRequired()Indicates if this XMLField represents a "required" XML element or attribute ([minOccurs="1"] for elements, [use="required"] for attributes). NOTE: This API is used only for Schema Generation.- Specified by:
isRequired
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - See Also:
-
SchemaModelGenerator
-
setRequired
public void setRequired(boolean isRequired) Set whether this XMLField represents a "required" XML element or attribute ([minOccurs="1"] for elements, [use="required"] for attributes). NOTE: This API is used only for Schema Generation.- Specified by:
setRequired
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - See Also:
-
SchemaModelGenerator
-
equals
Description copied from class:org.eclipse.persistence.internal.helper.DatabaseField
Determine whether the receiver is equal to a DatabaseField. Return true if the receiver and field have the same name and table. Also return true if the table of the receiver or field are unspecified, ie. have no name.- Overrides:
equals
in classorg.eclipse.persistence.internal.helper.DatabaseField
-
setNestedArray
public void setNestedArray(boolean nestedArray) Set nested array flag. Used in JSON marshalling.- Specified by:
setNestedArray
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Parameters:
nestedArray
- flag.
-
isNestedArray
public boolean isNestedArray()INTERNAL:- Specified by:
isNestedArray
in interfaceorg.eclipse.persistence.internal.oxm.mappings.Field<org.eclipse.persistence.internal.oxm.XMLConversionManager,
NamespaceResolver> - Returns:
- True if content is nested array.
-
hashCode
public int hashCode()Description copied from class:org.eclipse.persistence.internal.helper.DatabaseField
Return the hashcode of the name, because it is fairly unique.- Overrides:
hashCode
in classorg.eclipse.persistence.internal.helper.DatabaseField
-