package org.omg.Security;

/** 
 * Helper class for : SelectorValueList
 *  
 * @author OpenORB Compiler
 */ 
public class SelectorValueListHelper
{
    private static final boolean HAS_OPENORB;
    static {
        boolean hasOpenORB = false;
        try {
            Thread.currentThread().getContextClassLoader().loadClass("org.openorb.CORBA.Any");
            hasOpenORB = true;
        }
        catch(ClassNotFoundException ex) {
        }
        HAS_OPENORB = hasOpenORB;
    }
    /**
     * Insert SelectorValueList into an any
     * @param a an any
     * @param t SelectorValueList value
     */
    public static void insert(org.omg.CORBA.Any a, org.omg.Security.SelectorValue[] t)
    {
        a.insert_Streamable(new org.omg.Security.SelectorValueListHolder(t));
    }

    /**
     * Extract SelectorValueList from an any
     * @param a an any
     * @return the extracted SelectorValueList value
     */
    public static org.omg.Security.SelectorValue[] extract(org.omg.CORBA.Any a)
    {
        if (!a.type().equal(type()))
            throw new org.omg.CORBA.MARSHAL();
        if(HAS_OPENORB && a instanceof org.openorb.CORBA.Any) {
            // streamable extraction. The jdk stubs incorrectly define the Any stub
            org.openorb.CORBA.Any any = (org.openorb.CORBA.Any)a;
            try {
                org.omg.CORBA.portable.Streamable s = any.extract_Streamable();
                if(s instanceof org.omg.Security.SelectorValueListHolder)
                    return ((org.omg.Security.SelectorValueListHolder)s).value;
            } catch (org.omg.CORBA.BAD_INV_ORDER ex) {
            }
            org.omg.Security.SelectorValueListHolder h = new org.omg.Security.SelectorValueListHolder(read(a.create_input_stream()));
            a.insert_Streamable(h);
            return h.value;
        }
        return read(a.create_input_stream());
    }

    //
    // Internal TypeCode value
    //
    private static org.omg.CORBA.TypeCode _tc = null;

    /**
     * Return the SelectorValueList TypeCode
     * @return a TypeCode
     */
    public static org.omg.CORBA.TypeCode type()
    {
        if (_tc == null) {
            org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
            _tc = orb.create_alias_tc(id(),"SelectorValueList",orb.create_sequence_tc(0,org.omg.Security.SelectorValueHelper.type()));
        }
        return _tc;
    }

    /**
     * Return the SelectorValueList IDL ID
     * @return an ID
     */
    public static String id()
    {
        return _id;
    }

    private final static String _id = "IDL:omg.org/Security/SelectorValueList:1.0";

    /**
     * Read SelectorValueList from a marshalled stream
     * @param istream the input stream
     * @return the readed SelectorValueList value
     */
    public static org.omg.Security.SelectorValue[] read(org.omg.CORBA.portable.InputStream istream)
    {
        org.omg.Security.SelectorValue[] new_one;
        {
        int size7 = istream.read_ulong();
        new_one = new org.omg.Security.SelectorValue[size7];
        for (int i7=0; i7<new_one.length; i7++)
         {
            new_one[i7] = org.omg.Security.SelectorValueHelper.read(istream);

         }
        }

        return new_one;
    }

    /**
     * Write SelectorValueList into a marshalled stream
     * @param ostream the output stream
     * @param value SelectorValueList value
     */
    public static void write(org.omg.CORBA.portable.OutputStream ostream, org.omg.Security.SelectorValue[] value)
    {
        ostream.write_ulong(value.length);
        for (int i7=0; i7<value.length; i7++)
        {
            org.omg.Security.SelectorValueHelper.write(ostream,value[i7]);

        }
    }

}
