Just use a mapping file:
<?xml version="1.0"?>
<mapping>
<class name="TestUnion">
<map-to xml="testUnion"/>
<field name="elem1" type="int" set-method="elem1"
get-method="elem1"/>
<field name="elem2" type="string" set-method="elem2"
get-method="elem2"/>
</class>
</mapping>
--Keith
"Doyle, Joe" wrote:
>
> I'm looking for advice about writing a mapping file to go from classes
> generated from IDL unions to XML. This is my second day of looking at
> Castor, and am ready to go down the FieldHandler road, but would like to
> avoid it if someone has done this before.
>
> Based on this IDL,
>
> enum TestUnionType {
> ELEM1,
> ELEM2
> };
>
> union TestUnion switch (TestUnionType) {
> case ELEM1: long elem1;
> case ELEM2: string elem2;
> };
>
> I'd like to generate XML that looks like either
> <testUnion>
> <elem1>10000</elem1>
> </testUnion>
>
> or
>
> <testUnion>
> <elem2>test</elem2>
> </testUnion>
>
> based on which TestUnionType is specified.
>
> Here's the Java mapping for the IDL:
>
> /** * Generated from IDL definition of union "TestUnion"
> * @author JacORB IDL compiler
> */
> public final class TestUnion
> implements org.omg.CORBA.portable.IDLEntity
> {
> private TestUnionType discriminator;
> private java.lang.String elem2;
> private int elem1;
> public TestUnion ()
> { }
> public TestUnionType discriminator ()
> { return discriminator; }
>
> public java.lang.String elem2 ()
> {
> if( discriminator != TestUnionType.ELEM2)
> throw new org.omg.CORBA.BAD_OPERATION();
> return elem2;
> }
>
> public void elem2 (java.lang.String _x)
> {
> discriminator = TestUnionType.ELEM2;
> elem2 = _x;
> }
>
> public int elem1 ()
> {
> if( discriminator != TestUnionType.ELEM1)
> throw new org.omg.CORBA.BAD_OPERATION();
> return elem1;
> }
>
> public void elem1 (int _x)
> {
> discriminator = TestUnionType.ELEM1;
> elem1 = _x;
> }
> }
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev