001    /* InvalidPolicyHelper.java --
002       Copyright (C) 2005 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package org.omg.PortableServer.POAPackage;
040    
041    import gnu.CORBA.Minor;
042    import gnu.CORBA.OrbRestricted;
043    import gnu.CORBA.Poa.InvalidPolicyHolder;
044    
045    import org.omg.CORBA.Any;
046    import org.omg.CORBA.BAD_OPERATION;
047    import org.omg.CORBA.ORB;
048    import org.omg.CORBA.StructMember;
049    import org.omg.CORBA.TCKind;
050    import org.omg.CORBA.TypeCode;
051    import org.omg.CORBA.portable.InputStream;
052    import org.omg.CORBA.portable.OutputStream;
053    
054    /**
055     * The helper operations for the exception {@link InvalidPolicy}.
056     *
057     * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
058     */
059    public abstract class InvalidPolicyHelper
060    {
061      /**
062       * The cached typecode value, computed only once.
063       */
064      private static TypeCode typeCode;
065    
066      /**
067       * Create the InvalidPolicy typecode (emtpy structure,
068       * named "InvalidPolicy").
069       * The typecode states that the structure contains the
070       * single field, named "index".
071       */
072      public static TypeCode type()
073      {
074        if (typeCode == null)
075          {
076            ORB orb = OrbRestricted.Singleton;
077            StructMember[] members = new StructMember[ 1 ];
078    
079            TypeCode field;
080    
081            field = orb.get_primitive_tc(TCKind.tk_ushort);
082            members [ 0 ] = new StructMember("index", field, null);
083            typeCode = orb.create_exception_tc(id(), "InvalidPolicy", members);
084          }
085        return typeCode;
086      }
087    
088      /**
089      * Insert the InvalidPolicy into the given Any.
090      * This method uses the InvalidPolicyHolder.
091      *
092      * @param any the Any to insert into.
093      * @param that the InvalidPolicy to insert.
094      */
095      public static void insert(Any any, InvalidPolicy that)
096      {
097        any.insert_Streamable(new InvalidPolicyHolder(that));
098      }
099    
100      /**
101       * Extract the InvalidPolicy from given Any.
102       * This method uses the InvalidPolicyHolder.
103       *
104       * @throws BAD_OPERATION if the passed Any does not contain InvalidPolicy.
105       */
106      public static InvalidPolicy extract(Any any)
107      {
108        try
109          {
110            return ((InvalidPolicyHolder) any.extract_Streamable()).value;
111          }
112        catch (ClassCastException cex)
113          {
114            BAD_OPERATION bad = new BAD_OPERATION("InvalidPolicy expected");
115            bad.minor = Minor.Any;
116            bad.initCause(cex);
117            throw bad;
118          }
119      }
120    
121      /**
122       * Get the InvalidPolicy repository id.
123       *
124       * @return "IDL:omg.org/PortableServer/POA/InvalidPolicy:1.0", always.
125       */
126      public static String id()
127      {
128        return "IDL:omg.org/PortableServer/POA/InvalidPolicy:1.0";
129      }
130    
131      /**
132       * Read the exception from the CDR intput stream.
133       *
134       * @param input a org.omg.CORBA.portable stream to read from.
135       */
136      public static InvalidPolicy read(InputStream input)
137      {
138        // Read the exception repository id.
139        input.read_string();
140        InvalidPolicy value = new InvalidPolicy();
141    
142        value.index = input.read_short();
143        return value;
144      }
145    
146      /**
147       * Write the exception to the CDR output stream.
148       *
149       * @param output a org.omg.CORBA.portable stream stream to write into.
150       * @param value a value to write.
151       */
152      public static void write(OutputStream output, InvalidPolicy value)
153      {
154        // Write the exception repository id.
155        output.write_string(id());
156        output.write_short(value.index);
157      }
158    }