Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
The simple type translator allows you to automatically translate an XML element value to an appropriate Java type based on the element's <type>
attribute, as defined in your XML schema. You can use a simple type translator only when the mapping's XPath goes to an element. You cannot use a simple type translator if the mapping's XPath goes to an attribute.
For more information, see "Simple Type Translator".
Table 35-13 summarizes which mappings support this option.
Table 35-13 Mapping Support for Simple Type Translator
Mapping | Using TopLink Workbench
|
Using Java
|
---|---|---|
|
|
|
|
|
|
EIS Composite Direct Collection Mapping |
|
|
|
|
|
|
|
|
XML Composite Direct Collection Mapping |
|
|
Use this table to qualify elements from the XML schema
Select the mapped attribute in the Navigator. Its properties appear in the Editor.
Click the General tab. The General tab appears.
Figure 35-13 General Tab, Field Uses XML Schema "Type" Attribute
Select the Field Uses XML Schema "type" attribute field to qualify elements from the XML schema.
To create an XML mapping with a simple type translator with Java code in your IDE, you need the following elements:
EISDirectMapping
or EISCompositeDirectCollectionMapping
or XMLDirectMapping
or XMLCompositeDirectCollectionMapping
instance of Converter
instance of TypedElementField
Example 35-14 shows how to implement your own simple type translator with an XMLDirectMapping
to override the built-in conversion for writing XML so that TopLink writes a Byte
array (ClassConstants.ABYTE
) as a Base64
(XMLConstants.BASE64_BINARY
) encoded string.
Example 35-14 Creating a Type Translation XML Mapping
XMLDirectMapping mapping = new XMLDirectMapping(); mapping.setConverter(new SerializedObjectConverter()); TypedElementField field = new TypedElementField("element"); field.getSimpleTypeTranslator().addJavaConversion( ClassConstants.ABYTE, new QName(XMLConstants.SCHEMA_URL, XMLConstants.BASE64_BINARY) ); mapping.setField(field);