Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / org / omg / CORBA / WStringValueHelper.java
blob1c63a408e3df993e43240fc9f7f0bd71555a7322
1 /* WStringValueHelper.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package org.omg.CORBA;
41 import gnu.CORBA.Minor;
42 import gnu.CORBA.OrbRestricted;
44 import org.omg.CORBA.portable.BoxedValueHelper;
45 import org.omg.CORBA.portable.InputStream;
46 import org.omg.CORBA.portable.OutputStream;
48 import java.io.Serializable;
50 /**
51 * Provides helper operations for the Wide String value type, treating a
52 * Wide String as a CORBA value type rather than as a primitive type. The OMG
53 * specification states this may be convenient in some specific
54 * cases. The typecode is different, but the reading/writing format in
55 * this implementation is the same as for the ordinary wide string. This is
56 * that Sun's IDL compiler (v1.4) would generate.
58 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
60 public class WStringValueHelper
61 implements BoxedValueHelper
63 /**
64 * The Wide String value helper repository Id.
66 private static final String id = "IDL:omg.org/CORBA/WStringValue:1.0";
68 /**
69 * The cached typecode value, computed once.
71 private static TypeCode typecode;
73 /**
74 * The Wide String typecode.
76 private static final TypeCode twString =
77 OrbRestricted.Singleton.create_wstring_tc(0);
79 /**
80 * Returns the String Value repository Id.
81 * @return "IDL:omg.org/CORBA/WStringValue:1.0", always.
83 public String get_id()
85 return id;
88 /**
89 * Returns the String Value repository Id.
90 * @return "IDL:omg.org/CORBA/WStringValue:1.0", always.
92 public static String id()
94 return id;
97 /**
98 * Read the wide string value from the input stream.
100 * @param istream a stream to read from.
102 * @return a string (delegates to read_wstring()).
104 public Serializable read_value(InputStream istream)
106 return istream.read_wstring();
110 * Write the given wide string value into the output stream.
112 * @param ostream a stream to write into.
113 * @param a_string a string to write.
115 public void write_value(OutputStream ostream, Serializable a_string)
119 ostream.write_wstring((String) a_string);
121 catch (ClassCastException ex)
123 MARSHAL m = new MARSHAL("String expected");
124 m.minor = Minor.ClassCast;
125 throw m;
130 * Extract the wide string from the given Any. The operation
131 * requires Any to hold a String value and not a String.
133 * @param an_any an Any to extract from.
135 * @return the extracted string.
137 public static String extract(Any an_any)
139 if (an_any.type().equal(type()))
141 an_any.type(twString);
142 return an_any.extract_wstring();
144 else
146 BAD_OPERATION bad = new BAD_OPERATION("WString value type expected");
147 bad.minor = Minor.Any;
148 throw bad;
153 * Insert the wide string into the given Any. After the operation,
154 * the Any will have a Wide String Value typecode and not a
155 * String or WString typecode.
157 * @param an_any an Any to insert into.
159 * @param that a string to insert.
161 public static void insert(Any an_any, String that)
163 an_any.insert_wstring(that);
164 an_any.type(type());
168 * Reads a wide string as a value type.
170 * @param in a stream to read value from.
172 public static String read(InputStream in)
174 return in.read_wstring();
178 * Create and return the value box typecode, named "WStringValue",
179 * with the content typecode being unbounded string.
181 public static TypeCode type()
183 if (typecode == null)
185 ORB orb = OrbRestricted.Singleton;
186 typecode =
187 orb.create_value_box_tc(id(), "WStringValue", twString);
189 return typecode;
193 * Writes a wide string as a value type.
195 * @param out a stream to write value into.
197 * @param a_string a string to write.
199 public static void write(OutputStream out, String a_string)
201 out.write_wstring(a_string);