001    /* OutputStream.java --
002       Copyright (C) 2005, 2006 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.CORBA_2_3.portable;
040    
041    import gnu.CORBA.CDR.Vio;
042    
043    import org.omg.CORBA.portable.BoxedValueHelper;
044    import org.omg.CORBA.portable.CustomValue;
045    import org.omg.CORBA.portable.StreamableValue;
046    import org.omg.CORBA.portable.ValueBase;
047    
048    import 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     */
065    public 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      public void write_value(Serializable value, Class clz)
140      {
141        Vio.write(this, value, clz);
142      }
143    
144      /**
145       * Writes a value type into the output stream, stating it has the given
146       * repository id.
147       * 
148       * The value type must implement either {@link CustomValue} (for user-defined
149       * writing method) or {@link StreamableValue} (for standard writing using code,
150       * generated by IDL compiler).
151       * 
152       * @param repository_id a repository id of the value type.
153       * 
154       * @param value a value type object to write.
155       */
156      public void write_value(Serializable value, String repository_id)
157      {
158        Vio.write(this, value, repository_id);
159      }
160    }