Skip Headers
Oracle TopLink Developer's Guide
10g Release 3 (10.1.3)
B13593-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Configuring a Simple Type Translator

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.

Using TopLink Workbench

Use this table to qualify elements from the XML schema

  1. Select the mapped attribute in the Navigator. Its properties appear in the Editor.

  2. Click the General tab. The General tab appears.

    Figure 35-13 General Tab, Field Uses XML Schema "Type" Attribute

    Description of Figure 35-13  follows
    Description of "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.

Using Java

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);