001/* InputStream.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.CustomMarshal; 044import org.omg.CORBA.portable.BoxedValueHelper; 045import org.omg.CORBA.portable.StreamableValue; 046 047import java.io.Serializable; 048 049/** 050 * This class defines a new CDR input stream methods, added since 051 * CORBA 2.3. 052 * 053 * This class is abstract; no direct instances can be instantiated. 054 * Also, up till v 1.4 inclusive there are no methods that would 055 * return it, and only one unimplemented interface, 056 * {@link org.omg.CORBA.portable.ValueFactory }, needs it as a parameter. 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, Lithuania (AudriusA@Bioinformatics.org) 064 */ 065public abstract class InputStream 066 extends org.omg.CORBA.portable.InputStream 067{ 068 /** 069 * Read the abstract interface. An abstract interface can be either 070 * CORBA value type or CORBA object and is returned as an abstract 071 * java.lang.Object. 072 * 073 * As specified in OMG specification, this reads a single 074 * boolean and then delegates either to {@link #read_Object()} (for false) 075 * or to {@link #read_value()} (for true). 076 * 077 * @return an abstract interface, unmarshaled from the stream. 078 */ 079 public Object read_abstract_interface() 080 { 081 boolean isObject = read_boolean(); 082 083 if (isObject) 084 return read_Object(); 085 else 086 return read_value(); 087 } 088 089 /** 090 * Read the abstract interface, corresponding to the passed type. 091 * An abstract interface can be either CORBA value type or CORBA 092 * object and is returned as an abstract java.lang.Object. 093 * 094 * As specified in OMG specification, this reads a single 095 * boolean and then delegates either to {@link #read_Object(Class)} (for false) 096 * or to {@link #read_value(Class)} (for true). 097 * 098 * @param clz a base class for the abstract interface. 099 * 100 * @return an abstract interface, unmarshaled from the stream 101 */ 102 public Object read_abstract_interface(Class clz) 103 { 104 boolean isValue = read_boolean(); 105 106 if (isValue) 107 return read_value(clz); 108 else 109 return read_Object(clz); 110 } 111 112 /** 113 * Read a value type structure, extracting the repository id 114 * from the input stream itself. The repository id is optional 115 * in the value type record, but it must be present for this 116 * method to succeed. The {@link OutputStream} of this 117 * implementation always stores the repository id. 118 * 119 * The casts the streams ORB into a CORBA 2.3 ORB and then 120 * searched for a suitable value factory, where it delegates 121 * the functionality. 122 * 123 * If you know the exact class or can create an unitialised instance 124 * of the value type, it is recommended (faster) to use 125 * {@link #read_value(Class)} or {@link #read_value(Serializable)} 126 * instead. 127 * 128 * @return an value type structure, unmarshaled from the stream 129 */ 130 public Serializable read_value() 131 { 132 return Vio.read(this); 133 } 134 135 /** 136 * Read a value type structure, corresponing to the passed type. 137 * As the type is known, the repository Id in the input stream is 138 * optional an not required. The codebase, if present, is also ignored. 139 * 140 * The passed class must implement either {@link CustomMarshal} 141 * for the user-defined reading operations or {@link StreamableValue} 142 * for the standard (generated by IDL compiler) reading operations. 143 * Also, it must have the parameterless constructor to create a new 144 * instance. 145 * 146 * @param clz a base class for a value type. 147 * 148 * @return an value type structure, unmarshaled from the stream 149 */ 150 public Serializable read_value(Class clz) 151 { 152 return Vio.read(this, clz); 153 } 154 155 /** 156 * Read a value type structure content, when the unitialised 157 * instance is passed as a parameter. It is a fastest method to read 158 * a value type. 159 * 160 * As the type is known, the repository Id in the input stream is 161 * optional an not required. The codebase, if present, is also ignored. 162 * 163 * The passed instance must implement either {@link CustomMarshal} 164 * for the user-defined reading operations or {@link StreamableValue} 165 * for the standard (generated by IDL compiler) reading operations. 166 * 167 * @param unitialised_value the unitialised value. 168 * 169 * @return same value, filled in by the stream content. 170 */ 171 public Serializable read_value(Serializable unitialised_value) 172 { 173 return (Serializable) Vio.read(this, unitialised_value, null); 174 } 175 176 /** 177 * Read a value type structure, having the given repository id. 178 * The casts the streams ORB into a CORBA 2.3 ORB and then 179 * searched for a suitable value factory, where it delegates 180 * the functionality. 181 * 182 * If you know the exact class or can create an unitialised instance 183 * of the value type, it is recommended (faster) to use 184 * {@link #read_value(Class)} or {@link #read_value(Serializable)} 185 * instead. 186 * 187 * @param repository_id a repository id of the value type. 188 * 189 * @return an value type structure, unmarshaled from the stream 190 */ 191 public Serializable read_value(String repository_id) 192 { 193 return Vio.read(this, repository_id); 194 } 195 196 /** 197 * Use the provided boxed value helper to read the value. 198 * 199 * @param helper a helper for reading the value from the stream. 200 * 201 * @return an value type structure, unmarshaled from the stream. 202 */ 203 public Serializable read_value(BoxedValueHelper helper) 204 { 205 return Vio.read(this, helper); 206 } 207}