001/* DynSequenceHelper.java --
002   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package org.omg.DynamicAny;
040
041import gnu.CORBA.OrbRestricted;
042
043import org.omg.CORBA.BAD_OPERATION;
044import org.omg.CORBA.BAD_PARAM;
045import org.omg.CORBA.TypeCode;
046import org.omg.CORBA.Any;
047import org.omg.CORBA.portable.InputStream;
048import org.omg.CORBA.MARSHAL;
049import org.omg.CORBA.portable.OutputStream;
050
051/**
052 * The helper operations for {@link DynSequence}. Following the 1.5 JDK
053 * specifications, DynSequence is always a local object, so the two methods of
054 * this helper ({@link #read} and {@link #write} are not in use, always
055 * throwing {@link MARSHAL}.
056 *
057 * @specnote always throwing MARSHAL in read and write ensures compatibility
058 * with other popular implementations like Sun's.
059 *
060 * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
061 */
062public abstract class DynSequenceHelper
063{
064  /**
065   * Cast the passed object into the DynSequence. As DynSequence is a local
066   * object, the method just uses java type cast.
067   *
068   * @param obj the object to narrow.
069   * @return narrowed instance.
070   * @throws BAD_PARAM if the passed object is not a DynSequence.
071   */
072  public static DynSequence narrow(org.omg.CORBA.Object obj)
073  {
074    try
075      {
076        return (DynSequence) obj;
077      }
078    catch (ClassCastException cex)
079      {
080        throw new BAD_PARAM(obj.getClass().getName() + " is not a DynSequence");
081      }
082  }
083
084  /**
085   * Narrow the given object to the DynSequence. For the objects that are
086   * always local, this operation does not differ from the ordinary
087   * {@link #narrow} (ClassCastException will be thrown if narrowing something
088   * different). See OMG issue 4158.
089   *
090   * @param obj the object to cast.
091   *
092   * @return the casted DynSequence.
093   *
094   * @since 1.5
095   */
096  public static DynSequence unchecked_narrow(org.omg.CORBA.Object obj)
097  {
098    return narrow(obj);
099  }
100
101  /**
102   * Get the type code of the {@link DynSequence}.
103   */
104  public static TypeCode type()
105  {
106    return OrbRestricted.Singleton.create_interface_tc(id(), "DynSequence");
107  }
108
109  /**
110   * Insert the DynSequence into the given Any.
111   *
112   * @param any the Any to insert into.
113   *
114   * @param that the DynSequence to insert.
115   */
116  public static void insert(Any any, DynSequence that)
117  {
118    any.insert_Object(that);
119  }
120
121  /**
122   * Extract the DynSequence from given Any.
123   *
124   * @throws BAD_OPERATION if the passed Any does not contain DynSequence.
125   */
126  public static DynSequence extract(Any any)
127  {
128    return narrow(any.extract_Object());
129  }
130
131  /**
132   * Get the DynSequence repository id.
133   *
134   * @return "IDL:omg.org/DynamicAny/DynSequence:1.0", always.
135   */
136  public static String id()
137  {
138    return "IDL:omg.org/DynamicAny/DynSequence:1.0";
139  }
140
141  /**
142   * This should read DynSequence from the CDR input stream, but (following the
143   * JDK 1.5 API) it does not.
144   *
145   * @param input a org.omg.CORBA.portable stream to read from.
146   *
147   * @specenote Sun throws the same exception.
148   *
149   * @throws MARSHAL always.
150   */
151  public static DynSequence read(InputStream input)
152  {
153    throw new MARSHAL(DynAnyFactoryHelper.not_applicable(id()));
154  }
155
156  /**
157   * This should read DynSequence from the CDR input stream, but (following the
158   * JDK 1.5 API) it does not.
159   *
160   * @param output a org.omg.CORBA.portable stream to write into.
161   *
162   * @specenote Sun throws the same exception.
163   *
164   * @throws MARSHAL always.
165   */
166  public static void write(OutputStream output, DynSequence value)
167  {
168    throw new MARSHAL(DynAnyFactoryHelper.not_applicable(id()));
169  }
170}