|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex

Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2

Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki

Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services

Related projects
Spring ORM support
Spring XML factories
WS frameworks

XML
XML

XML Code Generator
XML Code Generator

JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR

Tools
Schema generator

Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice

DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping

More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration

About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name

## How to map an innner class

Intended Audience
Prerequisites
Basic concept
Mapping file
Unmarshalling
References

## Intended Audience

Anyone who wants to map an inner class with Castor XML for XML data binding.

This document helps people to get familiar with the basic concepts of mapping and shows an example.

## Prerequisites

A general understanding about XML data binding and its usage.

## Basic concept

Assume you have the following classes `Outer` and `Inner`:

    package test;

    public class Outer {

       private Inner member;

       public Inner getMember() { return member; }
       public void setMember (Inner member) { this.member = member; }

       public static class Inner {

          private String innerMember;

          public String getInnerMember() { return innerMember; }
          public void setInnerMember(String innerMember) { this.innerMember = innerMember; }

       }
    }

Please note that the i nner class needs to be declared public and static.

## Mapping file

Here's the mapping file for Castor XML, showing the class mapping for the OrderItem class:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <mapping>
       <class name="test.Outer">
          <field name="member" type="test.Outer$Inner">
             <bind-xml name="member" node="element" />
          </field>
       </class>
       <class name="test.Outer$Inner">
          <field name="innerMember" type="java.lang.String">
             <bind-xml name="innerMember" node="element" />
          </field>
       </class>
    </mapping>

## Unmarshalling

Using the Castor XML Unmarshaller with the mapping file shown above, the code to unmarshal the following XML ...

    <?xml version="1.0"?>
    <outer>
       <member>
          <innerMember>blah</innerMember>
       </member>
    </outer>

... into a variable of type `test.Outer` is as follows:

    InputSource mappingSource = ...;
    Mapping mapping = new Mapping();
    mapping.loadMapping(mappingSource);

    InputSource inputSource = ...;
    Unmarshaller unmarshaller = new Unmarshaller(test.Outer.class);
    unmarshaller.setMapping(mapping);
    test.Outer outer = (test.Outer) unmarshaller.unmarshal(inputSource);

## References

- | XML mapping

<notice> Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. </notice>
<notice> Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. </notice>