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 |
org.eclipse.persistence.oxm.XMLUnionField
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private boolean | |
| private boolean | |
| protected boolean | |
| private XPathFragment | |
| protected QName | |
| private NamespaceResolver | |
| private boolean | |
| private QName | |
| protected HashMap | |
| protected HashMap | |
| 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 XPathFragment |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addConversion(QName
The qualified name of the XML schema type qname, Class<?> javaClass)Add an entry for both an XML Conversion and a Java Conversion entry |
| public void | addJavaConversion(Class<?>
The class to add javaClass, QName The qualified name of the XML schema type qname)Add a Java to XML Conversion pair entry |
| public void | addXMLConversion(QName
The qualified name of the XML schema type qname, Class<?> The class to add javaClass)Add an XML to Java Conversion pair entry |
| private void | |
| public Object | convertValueBasedOnSchemaType(Object value, XMLConversionManager xmlConversionManager, AbstractUnmarshalRecord<ABSTRACT_SESSION extends CoreAbstractSession<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, PLATFORM extends CorePlatform<CONVERSION_MANAGER extends CoreConversionManager>, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION_EVENT_MANAGER extends CoreSessionEventManager<SESSION_EVENT_LISTENER extends CoreSessionEventListener>>, FIELD extends CoreField, UNMARSHALLER extends Unmarshaller<ABSTRACT_SESSION extends CoreAbstractSession<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, PLATFORM extends CorePlatform<CONVERSION_MANAGER extends CoreConversionManager>, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION_EVENT_MANAGER extends CoreSessionEventManager<SESSION_EVENT_LISTENER extends CoreSessionEventListener>>, CONTEXT extends Context<ABSTRACT_SESSION extends CoreAbstractSession<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, PLATFORM extends CorePlatform<CONVERSION_MANAGER extends CoreConversionManager>, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION_EVENT_MANAGER extends CoreSessionEventManager<SESSION_EVENT_LISTENER extends CoreSessionEventListener>>, DESCRIPTOR extends Descriptor<?, ?, ?, ?, ?, NAMESPACE_RESOLVER, ?, ?, ?, ?>, FIELD extends Field, NAMESPACE_RESOLVER extends NamespaceResolver, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION extends CoreSession<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, PLATFORM extends CorePlatform, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION_EVENT_MANAGER extends CoreSessionEventManager>, SESSION_EVENT_LISTENER extends CoreSessionEventListener>, DESCRIPTOR extends Descriptor, ID_RESOLVER extends IDResolver, MEDIA_TYPE extends MediaType, ROOT extends Root, UNMARSHALLER_HANDLER extends UnmarshallerHandler, UNMARSHALLER_LISTENER extends Unmarshaller.
Implements org. |
| public boolean | equals(Object
the reference object with which to compare. object)Overrides org. |
| public Class | Returns: The class corresponding to the specified schema type, if no corresponding match found returns nullThe qualified name of the XML Schema type to use as a key in the lookup qname)INTERNAL Return the class for a given qualified XML Schema type |
| public Class | Returns: the class for a given qualified XML Schema type.The qualified name of the XML Schema type to use as a key in the lookup qname, ConversionManager conversionManager)Implements org. |
| public XPathFragment | getLastXPathFragment()
Implements org. |
| public QName | |
| public NamespaceResolver | Returns: The NamespaceResolver associated with this XMLFieldImplements org. |
| public QName | Returns: the schema typeImplements org. |
| public QName | getSchemaTypeForValue(Object value, CoreAbstractSession<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, PLATFORM extends CorePlatform<CONVERSION_MANAGER extends CoreConversionManager>, PROJECT extends CoreProject<DESCRIPTOR extends CoreDescriptor<ATTRIBUTE_GROUP extends CoreAttributeGroup, DESCRIPTOR_EVENT_MANAGER extends CoreDescriptorEventManager, FIELD extends CoreField, INHERITANCE_POLICY extends CoreInheritancePolicy, INSTANTIATION_POLICY extends CoreInstantiationPolicy, LIST extends List<E>, OBJECT_BUILDER extends CoreObjectBuilder>, LOGIN extends CoreLogin<PLATFORM extends CorePlatform>, SESSION extends CoreSession>, SESSION_EVENT_MANAGER extends CoreSessionEventManager<SESSION_EVENT_LISTENER extends CoreSessionEventListener>> session)
Implements org. |
| private HashMap | |
| public ArrayList | |
| private HashMap | |
| public ArrayList | |
| public QName | Returns: QName The qualified XML Schema type, if no corresponding match found returns nullThe class to use as a key in the lookup javaClass)Return the qualified XML Schema type for a given class |
| public QName | Returns: the XML Schema type for a given class.The class to use as a key in the lookup javaClass, ConversionManager conversionManager)Implements org. |
| public String | Returns: The xpath statement associated with this XMLFieldImplements org. |
| public XPathFragment | getXPathFragment()
Implements org. |
| public int | hashCode()
Overrides org. |
| public boolean | hasLastXPathFragment()
Implements org. |
| private boolean | |
| public void | |
| private void | |
| public boolean | |
| public boolean | Returns: True if content is nested array.Implements org. |
| public boolean | isRequired()
Implements org. |
| public boolean | isSchemaType(QName schemaType)
Implements org. |
| public boolean | Returns: true if the xpath is ".", false otherwiseImplements org. |
| public boolean | Returns: True when we should base conversions on the "type" attribute on elements, otherwise falseImplements org. |
| public boolean | isUnionField()
Implements org. |
| public void | removeConversion(QName qname, Class<?> javaClass)
Remove both a Java to XML Conversion and the corresponding XML to Java Conversion entry |
| public void | |
| public void | |
| public void | setIsCDATA(boolean CDATA)
Implements org. |
| public void | setIsTypedTextField(boolean
The boolean value specifiy if this is a typed text field value)Implements org. |
| public void | setLastXPathFragment(XPathFragment<XML_FIELD extends Field> lastXPathFragment)
INTERNAL: Maintain a direct pointer to the last XPathFragment. |
| public void | |
| public void | setName(String xPath, String startDelimiter, String endDelimiter)
Overrides org. |
| public void | setName(String
The xPath associated with this XMLField xPath)Overrides org. Implements org. |
| public void | setNamespaceResolver(NamespaceResolver
The namespaceResolver to be associated with this XMLField newNamespaceResolver)Implements org. |
| public void | setNestedArray(boolean
flag. nestedArray)Implements org. |
| public void | setRequired(boolean isRequired)
Implements org. |
| public void | setSchemaType(QName
QName to be added to the list of schema types value)Implements org. |
| public void | |
| public void | |
| public void | setUsesSingleNode(boolean
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)Implements org. |
| public void | setXPath(String
The xpath statement to be associated with this XMLField xPath)Implements org. |
| public void | setXPathFragment(XPathFragment<XML_FIELD extends Field> xPathFragment)
INTERNAL: Return the first XPathFragment. |
| public boolean | 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.Implements org. |