001/* OutputStream.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.CORBA_2_3.portable;
040
041import gnu.CORBA.CDR.Vio;
042
043import org.omg.CORBA.portable.BoxedValueHelper;
044import org.omg.CORBA.portable.CustomValue;
045import org.omg.CORBA.portable.StreamableValue;
046import org.omg.CORBA.portable.ValueBase;
047
048import java.io.Serializable;
049
050/**
051 * This class defines a new CDR input stream methods, added since
052 * CORBA 2.3.
053 *
054 * This class is abstract; no direct instances can be instantiated.
055 * Also, up till v 1.4 inclusive there are no methods that would
056 * return it directly.
057 *
058 * However since 1.3 all methods, declared as returning an
059 * org.omg.CORBA.portable.InputStream actually return the instance of this
060 * derived class and the new methods are accessible after the casting
061 * operation.
062 *
063 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
064 */
065public abstract class OutputStream
066  extends org.omg.CORBA.portable.OutputStream
067{
068  /**
069   * Writes an abstract interface to the stream. An abstract interface can be
070   * eithe CORBA object or value type and is written as a union with the boolean
071   * discriminator (false for objects, true for value types).
072   *
073   * The object from value is separated by fact that all values implement the
074   * {@link ValueBase} interface. Also, the passed parameter is treated as value
075   * it it does not implement CORBA Object.
076   *
077   * @param an_interface an abstract interface to write.
078   */
079  public void write_abstract_interface(java.lang.Object an_interface)
080  {
081    boolean isObject = !(an_interface instanceof ValueBase)
082      && an_interface instanceof org.omg.CORBA.Object;
083
084    write_boolean(isObject);
085
086    if (isObject)
087      write_Object((org.omg.CORBA.Object) an_interface);
088    else
089      write_value((Serializable) an_interface);
090
091  }
092
093  /**
094   * Writes a value type into the output stream.
095   *
096   * The value type must implement either {@link CustomValue} (for user-defined
097   * writing method) or {@link StreamableValue} (for standard writing using code,
098   * generated by IDL compiler).
099   *
100   * The written record will have a repository id, matching the class of the
101   * passed object. The codebase will not be written.
102   *
103   * @param value a value type object to write.
104   */
105  public void write_value(Serializable value)
106  {
107    Vio.write(this, value);
108  }
109
110  /**
111   * Write value to the stream using the boxed value helper.
112   *
113   * The value type must implement either {@link CustomValue}
114   * (for user-defined writing method) or {@link StreamableValue}
115   * (for standard writing using code, generated by IDL compiler).
116   *
117   * @param value a value to write.
118   * @param helper a helper, responsible for the writing operation.
119   */
120  public void write_value(Serializable value, BoxedValueHelper helper)
121  {
122    Vio.write(this, value, helper);
123  }
124
125  /**
126   * Writes a value type into the output stream, stating it is an
127   * instance of the given class. The written record
128   * will have a repository id, matching the passed class.
129   * The codebase will not be written. It the object
130   * being written is an instance of the different class, this results
131   * writing two Id inheritance hierarchy.
132   *
133   * The value type must implement either {@link CustomValue}
134   * (for user-defined writing method) or {@link StreamableValue}
135   * (for standard writing using code, generated by IDL compiler).
136   *
137   * @param value a value type object to write.
138   */
139  @SuppressWarnings("rawtypes") // Needed for API compatibility
140  public void write_value(Serializable value, Class clz)
141  {
142    Vio.write(this, value, clz);
143  }
144
145  /**
146   * Writes a value type into the output stream, stating it has the given
147   * repository id.
148   *
149   * The value type must implement either {@link CustomValue} (for user-defined
150   * writing method) or {@link StreamableValue} (for standard writing using code,
151   * generated by IDL compiler).
152   *
153   * @param repository_id a repository id of the value type.
154   *
155   * @param value a value type object to write.
156   */
157  public void write_value(Serializable value, String repository_id)
158  {
159    Vio.write(this, value, repository_id);
160  }
161}