Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | 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.

Table 35-13 Mapping Support for Simple Type Translator

Mapping | Using TopLink Workbench | Using Java
--- | --- | ---
EIS Mappings |  |
EIS Direct Mapping |  |
EIS Composite Direct Collection Mapping |  |
XML Mappings |  |
XML Direct Mapping |  |
XML Composite Direct Collection Mapping |  |

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