IDL Complex Type | |
union |
The CORBA union indicates (TBD) ..... . It maps to J#'s union type. |
// CORBA IDL |
union Nums switch (char) { case 'f': float f; case 'l': long l; default: short s; }; |
e.g. Nums NumsHelper NumsHolder |
// J# package demo.unions; /** * Union definition : Nums * * @author TomORB J# Native Compiler */ public final class Nums implements org.omg.CORBA.portable.IDLEntity { /** * Union member _d */ protected char __d; /** * Union member f */ protected float _f; /** * Union member l */ protected int _l; /** * Union member s */ protected short _s; /** * Default constructor */ public Nums() { __d = 1; } /** * Get discriminator value */ public char discriminator() { return __d; } /** * Set f value */ public void f(float value) { __d = (char)('f'); _f = value; } /** * Get f value */ public float f() { return _f; } /** * Set l value */ public void l(int value) { __d = (char)('l'); _l = value; } /** * Get l value */ public int l() { return _l; } /** * Set s value */ public void s(short value) { __d = 1; _s = value; } /** * Set s value */ public void s(char dvalue, short value) { __d = dvalue; _s = value; } /** * Get s value */ public short s() { return _s; } } package demo.unions; /** * Helper class for : Nums * * @author TomORB J# Native Compiler */ public class NumsHelper { /** * Insert Nums into an any * @param a an any * @param t Nums value */ public static void insert(org.omg.CORBA.Any a, demo.unions.Nums t) { a.insert_Streamable(new demo.unions.NumsHolder(t)); } /** * Extract Nums from an any * @param a an any * @return the extracted Nums value */ public static demo.unions.Nums extract(org.omg.CORBA.Any a) { if (!a.type().equal(type())) throw new org.omg.CORBA.MARSHAL(); return read(a.create_input_stream()); } // // Internal TypeCode value // private static org.omg.CORBA.TypeCode _tc = null; private static boolean _working = false; /** * Return the Nums TypeCode * @return a TypeCode */ public static org.omg.CORBA.TypeCode type() { if (_tc == null) { synchronized(org.omg.CORBA.TypeCode.class) { if (_tc != null) return _tc; if (_working) return org.omg.CORBA.ORB.init().create_recursive_tc(id()); _working = true; org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); org.omg.CORBA.UnionMember []_members = new org.omg.CORBA.UnionMember[3]; org.omg.CORBA.Any any; any = orb.create_any(); any.insert_char((char)('f')); _members[0] = new org.omg.CORBA.UnionMember(); _members[0].name = "f"; _members[0].label = any; _members[0].type = orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_float); any = orb.create_any(); any.insert_char((char)('l')); _members[1] = new org.omg.CORBA.UnionMember(); _members[1].name = "l"; _members[1].label = any; _members[1].type = orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_long); any = orb.create_any(); any.insert_octet((byte)0); _members[2] = new org.omg.CORBA.UnionMember(); _members[2].name = "s"; _members[2].label = any; _members[2].type = orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_short); _tc = orb.create_union_tc(id(),"Nums",orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_char),_members); _working = false; } } return _tc; } /** * Return the Nums IDL ID * @return an ID */ public static java.lang.String id() { return _id; } private final static java.lang.String _id = "IDL:demo/unions/Nums:1.0"; /** * Read Nums from a marshalled stream * @param istream the input stream * @return the readed Nums value */ public static demo.unions.Nums read(org.omg.CORBA.portable.InputStream istream) { demo.unions.Nums new_one = new demo.unions.Nums(); new_one.__d = istream.read_char(); if (new_one.__d == (char)'f') { new_one._f = istream.read_float(); } else if (new_one.__d == (char)'l') { new_one._l = istream.read_long(); } else { new_one._s = istream.read_short(); } return new_one; } /** * Write Nums into a marshalled stream * @param ostream the output stream * @param value Nums value */ public static void write(org.omg.CORBA.portable.OutputStream ostream, demo.unions.Nums value) { ostream.write_char(value.__d); if (value.__d ==(char) 'f') { ostream.write_float(value._f); } else if (value.__d ==(char) 'l') { ostream.write_long(value._l); } else { ostream.write_short(value._s); } } } package demo.unions; /** * Holder class for : Nums * * @author TomORB J# Native Compiler */ final public class NumsHolder implements org.omg.CORBA.portable.Streamable { /** * Internal Nums value */ public demo.unions.Nums value; /** * Default constructor */ public NumsHolder() { } /** * Constructor with value initialisation * @param initial the initial value */ public NumsHolder(demo.unions.Nums initial) { value = initial; } /** * Read Nums from a marshalled stream * @param istream the input stream */ public void _read(org.omg.CORBA.portable.InputStream istream) { value = NumsHelper.read(istream); } /** * Write Nums into a marshalled stream * @param ostream the output stream */ public void _write(org.omg.CORBA.portable.OutputStream ostream) { NumsHelper.write(ostream,value); } /** * Return the Nums TypeCode * @return a TypeCode */ public org.omg.CORBA.TypeCode _type() { return NumsHelper.type(); } } |