summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/CORBA/GIOP
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/CORBA/GIOP')
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java70
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java238
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java106
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java222
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java76
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java114
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java465
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java145
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java156
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java301
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java72
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java141
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java159
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java118
-rw-r--r--libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java222
15 files changed, 2605 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java b/libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java
new file mode 100644
index 000000000..40f373721
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java
@@ -0,0 +1,70 @@
+/* CancelHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * The message header for cancelling the request.
+ *
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public abstract class CancelHeader
+{
+ /**
+ * The Id of request being cancelled.
+ */
+ public int request_id;
+
+ /**
+ * Read the header.
+ *
+ * @param input a stream to read from.
+ */
+ public abstract void read(InputStream input);
+
+ /**
+ * Write the header.
+ *
+ * @param output a stream to write to.
+ */
+ public abstract void write(OutputStream output);
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java b/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java
new file mode 100644
index 000000000..6cefe995f
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java
@@ -0,0 +1,238 @@
+/* CharSets_OSF.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import java.nio.charset.Charset;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * This class contains the codes, used to identify character sets
+ * in CORBA. These codes are defined in Open Software Foundation (OSF)
+ * code set registry.
+ *
+ * The name of this class specially sets "OSF" apart if somebody would start
+ * searching Open Software Foundation abbreviation.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class CharSets_OSF
+{
+ public static final int ASCII = 0x00010020;
+ public static final int ISO8859_1 = 0x00010001;
+ public static final int ISO8859_2 = 0x00010002;
+ public static final int ISO8859_3 = 0x00010003;
+ public static final int ISO8859_4 = 0x00010004;
+ public static final int ISO8859_5 = 0x00010005;
+ public static final int ISO8859_6 = 0x00010006;
+ public static final int ISO8859_7 = 0x00010007;
+ public static final int ISO8859_8 = 0x00010008;
+ public static final int ISO8859_9 = 0x00010009;
+ public static final int ISO8859_15_FDIS = 0x0001000F;
+ public static final int UTF8 = 0x05010001;
+ public static final int UTF16 = 0x00010109;
+ public static final int UCS2 = 0x00010100;
+ public static final int Cp1047 = 0x10020417;
+ public static final int Cp1250 = 0x100204E2;
+ public static final int Cp1251 = 0x100204E3;
+ public static final int Cp1252 = 0x100204E4;
+ public static final int Cp1253 = 0x100204E5;
+ public static final int Cp1254 = 0x100204E6;
+ public static final int Cp1255 = 0x100204E7;
+ public static final int Cp1256 = 0x100204E8;
+ public static final int Cp1257 = 0x100204E9;
+ public static final int Cp1363 = 0x10020553;
+ public static final int Cp1363C = 0x10020553;
+ public static final int Cp1381 = 0x10020565;
+ public static final int Cp1383 = 0x10020567;
+ public static final int Cp1386 = 0x1002056A;
+ public static final int Cp33722 = 0x100283BA;
+ public static final int Cp33722C = 0x100283BA;
+ public static final int Cp930 = 0x100203A2;
+ public static final int Cp943 = 0x100203AF;
+ public static final int Cp943C = 0x100203AF;
+ public static final int Cp949 = 0x100203B5;
+ public static final int Cp949C = 0x100203B5;
+ public static final int Cp950 = 0x100203B6;
+ public static final int Cp964 = 0x100203C4;
+ public static final int Cp970 = 0x100203CA;
+ public static final int EUC_JP = 0x00030010;
+ public static final int EUC_KR = 0x0004000A;
+ public static final int EUC_TW = 0x00050010;
+
+ /**
+ * The native character set for the narrow character.
+ */
+ public static final int NATIVE_CHARACTER = ISO8859_1;
+
+ /**
+ * The native character set for the wide character.
+ */
+ public static final int NATIVE_WIDE_CHARACTER = UTF16;
+
+ /**
+ * Table to convert from the code to string name.
+ */
+ private static Hashtable code_to_string;
+
+ /**
+ * Table to convert from the string name to code.
+ */
+ private static Hashtable string_to_code;
+
+ /**
+ * Get the charset code from its name.
+ *
+ * @return the charset code of 0 if not defined.
+ */
+ public static int getCode(String name)
+ {
+ if (string_to_code == null)
+ makeMap();
+
+ Integer code = (Integer) string_to_code.get(name);
+ return code == null ? 0 : code.intValue();
+ }
+
+ /**
+ * Get the charset name from its code.
+ *
+ * @return the code set name or nullfor the unknown code set.
+ */
+ public static String getName(int code)
+ {
+ if (code_to_string == null)
+ makeMap();
+ return (String) code_to_string.get(new Integer(code));
+ }
+
+ /**
+ * Get the list of supported char sets for that the CORBA codes are
+ * also known.
+ */
+ public static int[] getSupportedCharSets()
+ {
+ Set supported_sets = Charset.availableCharsets().keySet();
+ int[] supported = new int[ supported_sets.size() ];
+ Iterator iter = supported_sets.iterator();
+
+ int i = 0;
+ int code;
+ while (iter.hasNext())
+ {
+ code = getCode(iter.next().toString());
+ if (code > 0)
+ supported [ i++ ] = code;
+ }
+
+ // Truncate the unused part.
+ int[] f = new int[ i ];
+ System.arraycopy(supported, 0, f, 0, f.length);
+
+ return f;
+ }
+
+ /**
+ * Create a convertion map.
+ */
+ private static void makeMap()
+ {
+ code_to_string = new Hashtable();
+ string_to_code = new Hashtable();
+
+ // Put standard char sets.
+ put(ASCII, "US-ASCII");
+ put(ISO8859_1, "ISO-8859-1");
+ put(UTF16, "UTF-16");
+
+ // Put other known char sets.
+ put(ISO8859_2, "ISO-8859-2");
+ put(ISO8859_3, "ISO-8859-3");
+ put(ISO8859_4, "ISO-8859-4");
+ put(ISO8859_5, "ISO-8859-5");
+ put(ISO8859_6, "ISO-8859-6");
+ put(ISO8859_7, "ISO-8859-7");
+ put(ISO8859_8, "ISO-8859-8");
+ put(ISO8859_9, "ISO-8859-9");
+
+ put(UTF8, "UTF-8");
+ put(UCS2, "UCS-2");
+
+ put(ISO8859_15_FDIS, "ISO8859-15-FDIS");
+
+ put(Cp1047, "Cp1047");
+ put(Cp1250, "Cp1250");
+ put(Cp1251, "Cp1251");
+ put(Cp1252, "Cp1252");
+ put(Cp1253, "Cp1253");
+ put(Cp1254, "Cp1254");
+ put(Cp1255, "Cp1255");
+ put(Cp1256, "Cp1256");
+ put(Cp1257, "Cp1257");
+ put(Cp1363, "Cp1363");
+ put(Cp1363C, "Cp1363C");
+ put(Cp1381, "Cp1381");
+ put(Cp1383, "Cp1383");
+ put(Cp1386, "Cp1386");
+ put(Cp33722, "Cp33722");
+ put(Cp33722C, "Cp33722C");
+ put(Cp930, "Cp930");
+ put(Cp943, "Cp943");
+ put(Cp943C, "Cp943C");
+ put(Cp949, "Cp949");
+ put(Cp949C, "Cp949C");
+ put(Cp950, "Cp950");
+ put(Cp964, "Cp964");
+ put(Cp970, "Cp970");
+
+ put(EUC_JP, "EUC-JP");
+ put(EUC_KR, "EUC-KR");
+ put(EUC_TW, "EUC-TW");
+ }
+
+ private static void put(int code, String name)
+ {
+ Integer ic = new Integer(code);
+
+ code_to_string.put(ic, name);
+ string_to_code.put(name, ic);
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java b/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java
new file mode 100644
index 000000000..c555f2b94
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java
@@ -0,0 +1,106 @@
+/* CloseMessage.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.Minor;
+
+import org.omg.CORBA.MARSHAL;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * The explicit command to close the connection.
+ *
+ *
+ * The close message consists from the message header only and
+ * is the same for GIOP 1.0, 1.1, 1.2 and 1.3. The CloseMessage
+ * uses the default value from the {@link MessageHeader}.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class CloseMessage
+ extends MessageHeader
+{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = 1;
+
+ /**
+ * The singleton close message is typically enough, despite new
+ * instances may be instantiated if the specific version field
+ * value is mandatory.
+ */
+ private static final CloseMessage Singleton = new CloseMessage();
+
+ /**
+ * Create a new error message, setting the message field
+ * to the {@link MESSAGE_CLOSE} and the version number to
+ * the given major and minor values.
+ */
+ public CloseMessage()
+ {
+ message_type = CLOSE_CONNECTION;
+ }
+
+ /**
+ * Send the close message to the given output stream. The method,
+ * however, does not close the socket itself, this must be done
+ * explicitly in the calling code.
+ *
+ * @param socketStream a stream, where the close message is
+ * written.
+ */
+ public static void close(OutputStream socketStream)
+ {
+ try
+ {
+ Singleton.write(socketStream);
+ socketStream.flush();
+ }
+ catch (IOException ex)
+ {
+ MARSHAL m = new MARSHAL("Unable to flush the stream");
+ m.minor = Minor.Header;
+ m.initCause(ex);
+ throw m;
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java b/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java
new file mode 100644
index 000000000..81412e029
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/CodeSetServiceContext.java
@@ -0,0 +1,222 @@
+/* CodeSet_sctx.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+import gnu.CORBA.IOR;
+import java.io.IOException;
+
+/**
+ * The code set service context. This context must be included in all
+ * messages that use wide characters.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class CodeSetServiceContext
+ extends ServiceContext
+{
+ /**
+ * The context code sets id.
+ */
+ public static final int ID = 1;
+
+ /**
+ * The standard component to include in the messages.
+ */
+ public static final CodeSetServiceContext STANDARD = new CodeSetServiceContext();
+
+ /**
+ * The encoding, used to transfer the narrow (1 byte) character data.
+ * The default value is taken from {@link CharSets_OSF#NATIVE_CHARACTER}.
+ */
+ public int char_data = CharSets_OSF.NATIVE_CHARACTER;
+
+ /**
+ * The encoding, used to transfer the wide character data.
+ * The default value is taken from
+ * {@link CharSets_OSF#NATIVE_WIDE_CHARACTER}.
+ */
+ public int wide_char_data = CharSets_OSF.NATIVE_WIDE_CHARACTER;
+
+ /**
+ * Find and return the code set service context in the give
+ * contexts array. Returns {@link #STANDARD} if no code set
+ * context is present.
+ *
+ * @param contexts the array of contexts, can be null.
+ */
+ public static CodeSetServiceContext find(ServiceContext[] contexts)
+ {
+ if (contexts != null)
+ for (int i = 0; i < contexts.length; i++)
+ {
+ if (contexts [ i ] instanceof CodeSetServiceContext)
+ return (CodeSetServiceContext) contexts [ i ];
+ }
+ return STANDARD;
+ }
+
+ /**
+ * Select the suitable encoding that is defined in the provided profile.
+ *
+ * TODO character encoding. Now the encoding can be set, but it is ignored.
+ * If you take this task, scan 'TODO character encoding' for
+ * relevant places.
+ */
+ public static CodeSetServiceContext negotiate(IOR.CodeSets_profile profile)
+ {
+ if (profile.negotiated != null)
+ return profile.negotiated;
+
+ CodeSetServiceContext use = new CodeSetServiceContext();
+
+ use.char_data =
+ negotiate(profile.narrow, STANDARD.char_data, CharSets_OSF.ISO8859_1);
+
+ use.wide_char_data =
+ negotiate(profile.wide, STANDARD.wide_char_data, CharSets_OSF.UTF16);
+
+ profile.negotiated = use;
+
+ return use;
+ }
+
+ /**
+ * Read the context from the given stream. Does not read the
+ * code sets id.
+ */
+ public void readContext(AbstractCdrInput input)
+ {
+ AbstractCdrInput encap = input.read_encapsulation();
+
+ char_data = encap.read_ulong();
+ wide_char_data = encap.read_ulong();
+ }
+
+ /**
+ * Return a string representation.
+ */
+ public String toString()
+ {
+ return " Encoding: narrow " + name(char_data) + ", wide " +
+ name(wide_char_data) + ". ";
+ }
+
+ /**
+ * Write the context to the given stream, including the code
+ * sets id.
+ */
+ public void write(AbstractCdrOutput output)
+ {
+ output.write_ulong(ID);
+
+ AbstractCdrOutput enout = output.createEncapsulation();
+
+ enout.write_long(char_data);
+ enout.write_ulong(wide_char_data);
+
+ try
+ {
+ enout.close();
+ }
+ catch (IOException ex)
+ {
+ InternalError t = new InternalError();
+ t.initCause(ex);
+ throw t;
+ }
+ }
+
+ /**
+ * Negotiate about the character encoding. Prefer our native encoding,
+ * if no, prefer IORs native encoding, if no, find any encoding,
+ * supported by both sides, if no, return the specified final decission.
+ *
+ * @param profile the component profile in IOR.
+ * @param our_native our native encoding
+ * @param final_decission the encoding that must be returned if no
+ * compromise is found.
+ *
+ * @return the resulted encoding.
+ */
+ protected static int negotiate(IOR.CodeSets_profile.CodeSet_component profile,
+ int our_native, int final_decission
+ )
+ {
+ // If our and IORs native sets match, use the native set.
+ if (profile.native_set == our_native)
+ return our_native;
+
+ // If the native sets do not match, but the IOR says it
+ // supports our native set, use our native set.
+ if (profile.conversion != null)
+ for (int i = 0; i < profile.conversion.length; i++)
+ {
+ if (our_native == profile.conversion [ i ])
+ return our_native;
+ }
+
+ // At this point, we suggest to use the IORs native set.
+ int[] allSupported = CharSets_OSF.getSupportedCharSets();
+
+ for (int s = 0; s < allSupported.length; s++)
+ if (allSupported [ s ] == profile.native_set)
+ return profile.native_set;
+
+ // Any compromise left?
+ if (profile.conversion != null)
+ for (int s = 0; s < allSupported.length; s++)
+ for (int i = 0; i < profile.conversion.length; i++)
+ if (allSupported [ s ] == profile.conversion [ i ])
+ return allSupported [ s ];
+
+ // Return the CORBA default char encoding.
+ return final_decission;
+ }
+
+ /**
+ * Conveniency method, used in toString()
+ */
+ private String name(int set)
+ {
+ return "0x" + Integer.toHexString(set) + " (" + CharSets_OSF.getName(set) +
+ ") ";
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java b/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java
new file mode 100644
index 000000000..77ea20e38
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/ContextHandler.java
@@ -0,0 +1,76 @@
+/* ContextHandler.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import org.omg.CORBA.BAD_INV_ORDER;
+
+/**
+ * A header, supporting the service contexts. Such header has a context field
+ * and methods for adding the new contexts.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class ContextHandler
+{
+
+ /**
+ * Empty array, indicating that no service context is available.
+ */
+ protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[0];
+
+ /**
+ * The context data.
+ */
+ public ServiceContext[] service_context = NO_CONTEXT;
+
+ /**
+ * Add service context to this header.
+ *
+ * @param context_to_add context to add.
+ * @param replace if true, the existing context with this ID is replaced.
+ * Otherwise, BAD_INV_ORDER is throwsn.
+ */
+ public void addContext(org.omg.IOP.ServiceContext context_to_add,
+ boolean replace)
+ throws BAD_INV_ORDER
+ {
+ service_context = ServiceContext.add(service_context, context_to_add,
+ replace);
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java
new file mode 100644
index 000000000..0bd48dea8
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java
@@ -0,0 +1,114 @@
+/* ErrorMessage.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.OrbFunctional;
+import gnu.CORBA.IOR;
+import gnu.CORBA.Minor;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import java.net.Socket;
+
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.ORB;
+
+/**
+ * The error message is sent in response to the message, encoded
+ * in the unsupported version of the format or otherwise invalid.
+ *
+ * The error message consists from the message header only and
+ * is the same for GIOP 1.0, 1.1, 1.2 and 1.3.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class ErrorMessage
+ extends MessageHeader
+{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Create a new error message, setting the message field
+ * to the {@link MESSAGE_ERROR} and the version number to
+ * the given major and minor values.
+ */
+ public ErrorMessage(gnu.CORBA.Version msg_version)
+ {
+ version = msg_version;
+ message_type = MESSAGE_ERROR;
+ }
+
+ /**
+ * Send the error message to the given IOR address.
+ *
+ * @param ior the IOR address (host and port, other fields
+ * are not used).
+ *
+ * @param orb the ORB, sending the error message.
+ */
+ public void send(IOR ior, ORB orb)
+ {
+ try
+ {
+ Socket socket;
+
+ if (orb instanceof OrbFunctional)
+ socket = ((OrbFunctional) orb).socketFactory.createClientSocket(
+ ior.Internet.host, ior.Internet.port);
+ else
+ socket = new Socket(ior.Internet.host, ior.Internet.port);
+
+ OutputStream socketOutput = socket.getOutputStream();
+ write(socketOutput);
+ socketOutput.close();
+ socket.close();
+ }
+ catch (IOException ex)
+ {
+ MARSHAL t = new MARSHAL();
+ t.minor = Minor.Header;
+ t.initCause(ex);
+ throw t;
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java b/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java
new file mode 100644
index 000000000..3137343ed
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java
@@ -0,0 +1,465 @@
+/* MessageHeader.java -- GIOP message header.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.Minor;
+import gnu.CORBA.Version;
+import gnu.CORBA.CDR.BigEndianInputStream;
+import gnu.CORBA.CDR.BigEndianOutputStream;
+import gnu.CORBA.CDR.LittleEndianInputStream;
+import gnu.CORBA.CDR.LittleEndianOutputStream;
+import gnu.CORBA.CDR.AbstractDataInput;
+import gnu.CORBA.CDR.AbstractDataOutput;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.portable.IDLEntity;
+
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.Arrays;
+
+/**
+ * The GIOP message header.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class MessageHeader
+ implements IDLEntity
+{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Request message.
+ */
+ public static final byte REQUEST = 0;
+
+ /**
+ * Reply message
+ */
+ public static final byte REPLY = 1;
+
+ /**
+ * Cancel request message.
+ */
+ public static final byte CANCEL_REQUEST = 2;
+
+ /**
+ * Locate request message, used to check the server ability to process
+ * requests for the object reference. This message is also used to get the
+ * address where the object reference should be sent.
+ */
+ public static final byte LOCATE_REQUEST = 3;
+
+ /**
+ * Locate reply message, sent in response to the {@link #LocateRequest}
+ * message.
+ */
+ public static final byte LOCATE_REPLY = 4;
+
+ /**
+ * Instruction to close the connection.
+ */
+ public static final byte CLOSE_CONNECTION = 5;
+
+ /**
+ * Error report.
+ */
+ public static final byte MESSAGE_ERROR = 6;
+
+ /**
+ * The fragment messge, following the previous message that has more fragments
+ * flag set. Added in GIOP 1.1
+ */
+ public static final byte FRAGMENT = 7;
+
+ /**
+ * This must always be "GIOP".
+ */
+ public static final byte[] MAGIC = new byte[] { 'G', 'I', 'O', 'P' };
+
+ /**
+ * The message type names.
+ */
+ protected static String[] types = new String[] { "Request", "Reply",
+ "Cancel", "Locate request", "Locate reply", "Close connection", "Error",
+ "Fragment" };
+
+ /**
+ * The GIOP version. Initialised to 1.0 .
+ */
+ public Version version;
+
+ /**
+ * The flags field, introduced since GIOP 1.1.
+ */
+ public byte flags = 0;
+
+ /**
+ * The message type.
+ */
+ public byte message_type = REQUEST;
+
+ /**
+ * The message size, excluding the message header.
+ */
+ public int message_size = 0;
+
+ /**
+ * Create an empty message header, corresponding version 1.0.
+ */
+ public MessageHeader()
+ {
+ version = new Version(1, 0);
+ }
+
+ /**
+ * Create an empty message header, corresponding the given version.
+ *
+ * @param major the major message header version.
+ * @param minor the minot message header version.
+ */
+ public MessageHeader(int major, int minor)
+ {
+ version = new Version(major, minor);
+ }
+
+ /**
+ * Checks if the message is encoded in the Big Endian, most significant byte
+ * first.
+ */
+ public boolean isBigEndian()
+ {
+ return (flags & 0x1) == 0;
+ }
+
+ /**
+ * Checks if the message is partial, and more subsequent fragments follow.
+ */
+ public boolean moreFragmentsFollow()
+ {
+ return (flags & 0x2) != 0;
+ }
+
+ /**
+ * Set the encoding to use.
+ *
+ * @param use_big_endian if true (default), the Big Endian encoding is used.
+ * If false, the Little Endian encoding is used.
+ */
+ public void setBigEndian(boolean use_big_endian)
+ {
+ if (use_big_endian)
+ flags = (byte) (flags & ~1);
+ else
+ flags = (byte) (flags | 1);
+ }
+
+ /**
+ * Get the size of the message header itself. So far, it is always 12 bytes.
+ */
+ public int getHeaderSize()
+ {
+ return 12;
+ }
+
+ /**
+ * Get the message type as string.
+ *
+ * @param type the message type as int (the field {@link message_type}).
+ *
+ * @return the message type as string.
+ */
+ public String getTypeString(int type)
+ {
+ try
+ {
+ return types[type];
+ }
+ catch (ArrayIndexOutOfBoundsException ex)
+ {
+ return "unknown type (" + type + ")";
+ }
+ }
+
+ /**
+ * Creates reply header, matching the message header version number.
+ *
+ * @return one of {@link gnu.CORBA.GIOP.v1_0.ReplyHeader},
+ * {@link gnu.CORBA.GIOP.v1_2.ReplyHeader}, etc - depending on the version
+ * number in this header.
+ */
+ public ReplyHeader create_reply_header()
+ {
+ if (version.since_inclusive(1, 2))
+ return new gnu.CORBA.GIOP.v1_2.ReplyHeader();
+ else
+ return new gnu.CORBA.GIOP.v1_0.ReplyHeader();
+ }
+
+ /**
+ * Creates request header, matching the message header version number.
+ *
+ * @return one of {@link gnu.CORBA.GIOP.v1_0.RequestHeader},
+ * {@link gnu.CORBA.GIOP.v1_2.RequestHeader}, etc - depending on the version
+ * number in this header.
+ */
+ public RequestHeader create_request_header()
+ {
+ if (version.since_inclusive(1, 2))
+ return new gnu.CORBA.GIOP.v1_2.RequestHeader();
+ else
+ return new gnu.CORBA.GIOP.v1_0.RequestHeader();
+ }
+
+ /**
+ * Create the cancel header, matching the message header version number.
+ */
+ public CancelHeader create_cancel_header()
+ {
+ return new gnu.CORBA.GIOP.v1_0.CancelHeader();
+ }
+
+ /**
+ * Create the error message.
+ */
+ public ErrorMessage create_error_message()
+ {
+ return new ErrorMessage(version);
+ }
+
+ /**
+ * Read the header from the stream.
+ *
+ * @param istream a stream to read from.
+ * @throws MARSHAL if this is not a GIOP 1.0 header.
+ */
+ public void read(java.io.InputStream istream)
+ throws MARSHAL, EOFException
+ {
+ try
+ {
+ byte[] xMagic = new byte[MAGIC.length];
+ int r = istream.read(xMagic);
+ int minor;
+ if (! Arrays.equals(xMagic, MAGIC))
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ if (r == - 1)
+ {
+ b.append("Immediate EOF");
+ minor = Minor.EOF;
+ }
+ else
+ {
+ minor = Minor.Giop;
+ b.append(r + " bytes: ");
+ for (int i = 0; i < xMagic.length; i++)
+ {
+ b.append(Integer.toHexString(xMagic[i] & 0xFF));
+ b.append(' ');
+ }
+ }
+ MARSHAL m = new MARSHAL("Not a GIOP message: " + b);
+ m.minor = minor;
+ throw m;
+ }
+
+ version = Version.read_version(istream);
+
+ AbstractDataInput din;
+
+ flags = (byte) istream.read();
+
+ // This checks the bit in the byte we have just received.
+ if (isBigEndian())
+ din = new BigEndianInputStream(istream);
+ else
+ din = new LittleEndianInputStream(istream);
+
+ message_type = (byte) din.read();
+
+ message_size = din.readInt();
+ }
+ catch (IOException ex)
+ {
+ MARSHAL t = new MARSHAL();
+ t.minor = Minor.Header;
+ t.initCause(ex);
+ throw t;
+ }
+ }
+
+ /**
+ * Get the short string summary of the message.
+ *
+ * @return a short message summary.
+ */
+ public String toString()
+ {
+ return "GIOP " + version + ", " + (isBigEndian() ? "Big" : "Little")
+ + " endian, " + getTypeString(message_type) + ", " + message_size
+ + " bytes. ";
+ }
+
+ /**
+ * Write the header to stream.
+ *
+ * @param out a stream to write into.
+ */
+ public void write(java.io.OutputStream out)
+ {
+ try
+ {
+ AbstractDataOutput dout;
+
+ if (isBigEndian())
+ dout = new BigEndianOutputStream(out);
+ else
+ dout = new LittleEndianOutputStream(out);
+
+ // Write magic sequence.
+ dout.write(MAGIC);
+
+ // Write version number.
+ version.write((OutputStream) dout);
+ dout.write(flags);
+ dout.write(message_type);
+ dout.writeInt(message_size);
+ }
+ catch (IOException ex)
+ {
+ MARSHAL t = new MARSHAL(ex.getMessage());
+ t.minor = Minor.Header;
+ t.initCause(ex);
+ throw t;
+ }
+ }
+
+ /**
+ * Read data, followed by the message header. Handle fragmented messages.
+ *
+ * @param source the data source to read from.
+ * @param service the socket on that the time outs are set. Can be null (no
+ * timeouts are set).
+ * @param to_read the timeout while reading the message.
+ * @param to_pause the timeout for pauses between the message parts.
+ */
+ public byte[] readMessage(InputStream source, Socket service, int to_read,
+ int to_pause)
+ {
+ try
+ {
+ byte[] r = new byte[message_size];
+
+ int n = 0;
+ if (service != null)
+ service.setSoTimeout(to_read);
+
+ while (n < r.length)
+ {
+ n += source.read(r, n, r.length - n);
+ }
+ if (service != null)
+ service.setSoTimeout(to_pause);
+
+ // Read the message remainder if the message is fragmented.
+ if (moreFragmentsFollow())
+ {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream(
+ 2 * r.length);
+ buffer.write(r);
+
+ if (r.length < 10)
+ // Increase the buffer size if the default value (size of the
+ // previous message) is really too small.
+ r = new byte[1024];
+
+ MessageHeader h2 = new MessageHeader();
+
+ do
+ {
+ h2.read(source);
+
+ int dn;
+
+ n = 0;
+ while (n < h2.message_size)
+ {
+ dn = source.read(r, 0, h2.message_size - n);
+
+ if (n == 0 && service != null)
+ service.setSoTimeout(to_read);
+
+ if (n == 0 && version.since_inclusive(1, 2))
+ {
+ // Skip the four byte request id.
+ buffer.write(r, 4, dn - 4);
+ }
+ else
+ buffer.write(r, 0, dn);
+ n = +dn;
+ }
+
+ if (service != null)
+ service.setSoTimeout(to_pause);
+ }
+ while (h2.moreFragmentsFollow());
+ return buffer.toByteArray();
+ }
+ else
+ return r;
+ }
+ catch (IOException ioex)
+ {
+ MARSHAL m = new MARSHAL("Unable to read the message continuation.");
+ m.minor = Minor.Header;
+ m.initCause(ioex);
+ throw m;
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java
new file mode 100644
index 000000000..d14482903
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java
@@ -0,0 +1,145 @@
+/* ReplyHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+
+/**
+ * The header of the standard reply.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public abstract class ReplyHeader
+ extends ContextHandler
+{
+ /**
+ * Reply status, if no exception occured.
+ */
+ public static final int NO_EXCEPTION = 0;
+
+ /**
+ * Reply status, user exception.
+ */
+ public static final int USER_EXCEPTION = 1;
+
+ /**
+ * Reply status, system exception.
+ */
+ public static final int SYSTEM_EXCEPTION = 2;
+
+ /**
+ * Reply status, if the client ORB must re - send the request to another
+ * destination. The body contains IOR.
+ */
+ public static final int LOCATION_FORWARD = 3;
+
+ /**
+ * Reply status, indicating that the target has permanently changed the
+ * address to the supplied IOR.
+ */
+ public static final int LOCATION_FORWARD_PERM = 4;
+
+ /**
+ * Reply status, indicating, that the ORB requires to resend the object
+ * address in the required addressing mode, contained as the reply body.
+ */
+ public static final int NEEDS_ADDRESSING_MODE = 5;
+
+ /**
+ * The status of this reply, holds one of the reply status constants.
+ */
+ public int reply_status;
+
+ /**
+ * The Id of request into response of which this reply has been sent.
+ */
+ public int request_id;
+
+ /**
+ * Return the message status as a string.
+ */
+ public String getStatusString()
+ {
+ switch (reply_status)
+ {
+ case NO_EXCEPTION:
+ return "ok";
+
+ case USER_EXCEPTION:
+ return "user exception";
+
+ case SYSTEM_EXCEPTION:
+ return "system exception";
+
+ case LOCATION_FORWARD:
+ return "moved";
+
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * Reads the header from the stream.
+ *
+ * @param in a stream to read from.
+ */
+ public abstract void read(AbstractCdrInput in);
+
+ /**
+ * Returns a short string representation.
+ *
+ * @return a string representation.
+ */
+ public String toString()
+ {
+ String status = getStatusString();
+ if (status == null)
+ status = "status " + reply_status;
+ return request_id + ", " + status;
+ }
+
+ /**
+ * Writes the header to the stream.
+ *
+ * @param out a stream to write into.
+ */
+ public abstract void write(AbstractCdrOutput out);
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java
new file mode 100644
index 000000000..45997ab3d
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java
@@ -0,0 +1,156 @@
+/* RequestHeader.java -- The GIOP 1.0 request message.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.omg.CORBA.portable.IDLEntity;
+
+/**
+ * The GIOP request message.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public abstract class RequestHeader
+ extends ContextHandler
+ implements IDLEntity
+{
+ /**
+ * The currently free request id. This field is incremented each time the new
+ * request header is constructed. To facilitate error detection, the first
+ * free id is equal to 0x01234567 (19088743).
+ */
+ private static int freeId = 0x01234567;
+
+ /**
+ * The operation being invoked (IDL scope name).
+ */
+ public String operation;
+
+ /**
+ * Identifies the object that is the target of the invocation.
+ */
+ public byte[] object_key;
+
+ /**
+ * A value identifying the requesting principal. Initialised into a single
+ * zero byte.
+ *
+ * @deprecated by CORBA 2.2.
+ */
+ public byte[] requesting_principal;
+
+ /**
+ * This is used to associate the reply message with the previous request
+ * message. Initialised each time by the different value, increasing form 1 to
+ * Integer.MAX_VALUE.
+ */
+ public int request_id = getNextId();
+
+ /**
+ * If true, the response from the server is expected.
+ */
+ protected boolean response_expected = true;
+
+ /**
+ * Get next free request id. The value of the free request id starts from
+ * 0x02345678, it is incremented each time this function is called and is
+ * reset to 1 after reaching Integer.MAX_VALUE.
+ *
+ * @return the next free request id.
+ */
+ public static synchronized int getNextId()
+ {
+ int f = freeId;
+ if (freeId == Integer.MAX_VALUE)
+ freeId = 1;
+ else
+ freeId++;
+
+ return f;
+ }
+
+ /**
+ * Set if the sender expects any response to this message.
+ */
+ public abstract void setResponseExpected(boolean expected);
+
+ /**
+ * Return true if response is expected.
+ */
+ public abstract boolean isResponseExpected();
+
+ /**
+ * Converts an byte array into hexadecimal string values. Used in various
+ * toString() methods.
+ */
+ public String bytes(byte[] array)
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ for (int i = 0; i < array.length; i++)
+ {
+ b.append(Integer.toHexString(array[i] & 0xFF));
+ b.append(" ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Reads the header from the stream.
+ *
+ * @param in a stream to read from.
+ */
+ public abstract void read(AbstractCdrInput in);
+
+ /**
+ * Return a string representation.
+ */
+ public abstract String toString();
+
+ /**
+ * Writes the header to the stream.
+ *
+ * @param out a stream to write into.
+ */
+ public abstract void write(AbstractCdrOutput out);
+
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java
new file mode 100644
index 000000000..673ae0ba9
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java
@@ -0,0 +1,301 @@
+/* ServiceContext.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+
+import org.omg.CORBA.BAD_INV_ORDER;
+import org.omg.CORBA.BAD_PARAM;
+import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.portable.IDLEntity;
+
+/**
+ * Contains the ORB service data being passed.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class ServiceContext
+ implements IDLEntity
+{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = 1;
+
+ /* Standard values for the context_id. */
+ public static final int TransactionService = 0;
+
+ /**
+ * Defines code sets, used to encode wide and narrow characters. Required for
+ * messages with data structures, involving wide characters.
+ */
+ public static final int CodeSets = 1;
+
+ public static final int ChainBypassCheck = 2;
+
+ public static final int ChainBypassInfo = 3;
+
+ public static final int LogicalThreadId = 4;
+
+ public static final int BI_DIR_IIOP = 5;
+
+ public static final int SendingContextRunTime = 6;
+
+ public static final int INVOCATION_POLICIES = 7;
+
+ public static final int FORWARDED_IDENTITY = 8;
+
+ /**
+ * Contains exception details if exception being transferred is other than
+ * System or User exception. javax.rmi uses this context to transfer arbitrary
+ * java exceptions as CORBA value types.
+ */
+ public static final int UnknownExceptionInfo = 9;
+
+ public static final int RTCorbaPriority = 10;
+
+ public static final int RTCorbaPriorityRange = 11;
+
+ public static final int FT_GROUP_VERSION = 12;
+
+ public static final int FT_REQUEST = 13;
+
+ public static final int ExceptionDetailMessage = 14;
+
+ public static final int SecurityAttributeService = 15;
+
+ public static final int ActivityService = 16;
+
+ /**
+ * The context id (for instance, 0x1 for code sets context). At the moment of
+ * writing, the OMG defines 16 standard values and provides rules to register
+ * the vendor specific context ids. The range 0-4095 is reserved for the
+ * future standard OMG contexts.
+ */
+ public int context_id;
+
+ /**
+ * The context_data.
+ */
+ public byte[] context_data;
+
+ /**
+ * Crete unitialised instance.
+ */
+ public ServiceContext()
+ {
+ }
+
+ /**
+ * Create from omg context.
+ */
+ public ServiceContext(org.omg.IOP.ServiceContext from)
+ {
+ context_id = from.context_id;
+ context_data = from.context_data;
+ }
+
+ /**
+ * Read the context values from the stream.
+ *
+ * @param istream a stream to read from.
+ */
+ public static ServiceContext read(AbstractCdrInput istream)
+ {
+ int id = istream.read_ulong();
+
+ switch (id)
+ {
+ case CodeSetServiceContext.ID:
+
+ CodeSetServiceContext codeset = new CodeSetServiceContext();
+ codeset.readContext(istream);
+ return codeset;
+
+ default:
+
+ ServiceContext ctx = new ServiceContext();
+ ctx.context_id = id;
+ ctx.context_data = istream.read_sequence();
+ return ctx;
+ }
+ }
+
+ /**
+ * Read a sequence of contexts from the input stream.
+ */
+ public static ServiceContext[] readSequence(AbstractCdrInput istream)
+ {
+ int size = istream.read_long();
+ ServiceContext[] value = new gnu.CORBA.GIOP.ServiceContext[size];
+ for (int i = 0; i < value.length; i++)
+ value[i] = read(istream);
+ return value;
+ }
+
+ /**
+ * Write the context values into the stream.
+ *
+ * @param ostream a stream to write the data to.
+ */
+ public void write(AbstractCdrOutput ostream)
+ {
+ ostream.write_ulong(context_id);
+ ostream.write_sequence(context_data);
+ }
+
+ /**
+ * Write the sequence of contexts into the input stream.
+ */
+ public static void writeSequence(AbstractCdrOutput ostream, ServiceContext[] value)
+ {
+ ostream.write_long(value.length);
+ for (int i = 0; i < value.length; i++)
+ value[i].write(ostream);
+ }
+
+ /**
+ * Add context to the given array of contexts.
+ */
+ public static void add(org.omg.IOP.ServiceContext[] cx,
+ org.omg.IOP.ServiceContext service_context, boolean replace)
+ {
+ int exists = -1;
+
+ for (int i = 0; i < cx.length; i++)
+ if (cx[i].context_id == service_context.context_id)
+ exists = i;
+
+ if (exists < 0)
+ {
+ // Add context.
+ org.omg.IOP.ServiceContext[] n = new org.omg.IOP.ServiceContext[cx.length + 1];
+ for (int i = 0; i < cx.length; i++)
+ n[i] = cx[i];
+ n[cx.length] = service_context;
+ }
+ else
+ {
+ // Replace context.
+ if (!replace)
+ throw new BAD_INV_ORDER("Repetetive setting of the context "
+ + service_context.context_id, 15, CompletionStatus.COMPLETED_NO);
+ else
+ cx[exists] = service_context;
+ }
+ }
+
+ /**
+ * Add context to the given array of contexts.
+ */
+ public static ServiceContext[] add(ServiceContext[] cx,
+ org.omg.IOP.ServiceContext service_context, boolean replace)
+ {
+ int exists = -1;
+
+ for (int i = 0; i < cx.length; i++)
+ if (cx[i].context_id == service_context.context_id)
+ exists = i;
+
+ if (exists < 0)
+ {
+ // Add context.
+ ServiceContext[] n = new ServiceContext[cx.length + 1];
+ for (int i = 0; i < cx.length; i++)
+ n[i] = cx[i];
+ n[cx.length] = new ServiceContext(service_context);
+ return n;
+ }
+ else
+ {
+ // Replace context.
+ if (!replace)
+ throw new BAD_INV_ORDER("Repetetive setting of the context "
+ + service_context.context_id, 15, CompletionStatus.COMPLETED_NO);
+ else
+ cx[exists] = new ServiceContext(service_context);
+ return cx;
+ }
+ }
+
+ /**
+ * Find context with the given name in the context array.
+ */
+ public static org.omg.IOP.ServiceContext findContext(int ctx_name,
+ org.omg.IOP.ServiceContext[] cx)
+ {
+ for (int i = 0; i < cx.length; i++)
+ if (cx[i].context_id == ctx_name)
+ return cx[i];
+ throw new BAD_PARAM("No context with id " + ctx_name);
+ }
+
+ /**
+ * Find context with the given name in the context array, converting into
+ * org.omg.IOP.ServiceContext.
+ */
+ public static org.omg.IOP.ServiceContext findContext(int ctx_name,
+ ServiceContext[] cx)
+ {
+ for (int i = 0; i < cx.length; i++)
+ if (cx[i].context_id == ctx_name)
+ return new org.omg.IOP.ServiceContext(ctx_name, cx[i].context_data);
+ throw new BAD_PARAM("No context with id " + ctx_name);
+ }
+
+ /**
+ * Find context with the given name in the context array without conversions.
+ */
+ public static ServiceContext find(int ctx_name, ServiceContext[] cx)
+ {
+ for (int i = 0; i < cx.length; i++)
+ if (cx[i].context_id == ctx_name)
+ return cx[i];
+ return null;
+ }
+
+ /**
+ * Return a string representation.
+ */
+ public String toString()
+ {
+ return "ctx " + context_id + ", size " + context_data.length;
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java
new file mode 100644
index 000000000..115849223
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java
@@ -0,0 +1,72 @@
+/* CancelHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP.v1_0;
+
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * The message header for cancelling the request.
+ *
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class CancelHeader
+ extends gnu.CORBA.GIOP.CancelHeader
+{
+ /**
+ * Read the header.
+ *
+ * @param input a stream to read from.
+ */
+ public void read(InputStream input)
+ {
+ request_id = input.read_ulong();
+ }
+
+ /**
+ * Write the header.
+ *
+ * @param output a stream to write to.
+ */
+ public void write(OutputStream output)
+ {
+ output.write_ulong(request_id);
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java
new file mode 100644
index 000000000..dcb00c0eb
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java
@@ -0,0 +1,141 @@
+/* ReplyHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP.v1_0;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+import gnu.CORBA.GIOP.ServiceContext;
+import gnu.CORBA.GIOP.CodeSetServiceContext;
+
+import gnu.java.lang.CPStringBuilder;
+
+/**
+ * The header of the standard reply.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class ReplyHeader
+ extends gnu.CORBA.GIOP.ReplyHeader
+{
+ /**
+ * Return the message status as a string.
+ */
+ public String getStatusString()
+ {
+ switch (reply_status)
+ {
+ case NO_EXCEPTION :
+ return "ok";
+
+ case USER_EXCEPTION :
+ return "user exception";
+
+ case SYSTEM_EXCEPTION :
+ return "system exception";
+
+ case LOCATION_FORWARD :
+ return "moved";
+
+ default :
+ return null;
+ }
+ }
+
+ /**
+ * Get the string representation of all included contexts.
+ */
+ public String contexts()
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ for (int i = 0; i < service_context.length; i++)
+ {
+ b.append(service_context [ i ].toString());
+ b.append(' ');
+ }
+ return b.toString();
+ }
+
+ /**
+ * Reads the header from the stream.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param in a stream to read from.
+ */
+
+ public void read(AbstractCdrInput in)
+ {
+ service_context = ServiceContext.readSequence(in);
+ request_id = in.read_ulong();
+ reply_status = in.read_ulong();
+
+ in.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+
+ /**
+ * Returns a short string representation.
+ *
+ * @return a string representation.
+ */
+ public String toString()
+ {
+ String status = getStatusString();
+ if (status == null)
+ status = "status " + reply_status;
+ return request_id + ", " + status + " " + contexts();
+ }
+
+ /**
+ * Writes the header to the stream.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param out a stream to write into.
+ */
+ public void write(AbstractCdrOutput out)
+ {
+ ServiceContext.writeSequence(out, service_context);
+ out.write_ulong(request_id);
+ out.write_ulong(reply_status);
+
+ out.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java
new file mode 100644
index 000000000..d2bea9d88
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java
@@ -0,0 +1,159 @@
+/* RequestHeader.java -- The GIOP 1.0 request message.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP.v1_0;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+import gnu.CORBA.GIOP.ServiceContext;
+import gnu.CORBA.GIOP.CodeSetServiceContext;
+
+import gnu.java.lang.CPStringBuilder;
+
+import org.omg.CORBA.portable.IDLEntity;
+
+/**
+ * The GIOP 1.0 request message.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class RequestHeader
+ extends gnu.CORBA.GIOP.RequestHeader
+ implements IDLEntity
+{
+ /**
+ * Creates an empty request header, setting requesting principal
+ * to byte[] { 'P' }.
+ */
+ public RequestHeader()
+ {
+ requesting_principal = new byte[] { 'P' };
+ }
+
+ /**
+ * Set if the sender expects any response to this message.
+ */
+ public void setResponseExpected(boolean expected)
+ {
+ response_expected = expected;
+ }
+
+ /**
+ * Return true if response is expected.
+ */
+ public boolean isResponseExpected()
+ {
+ return response_expected;
+ }
+
+ public String bytes(byte[] array)
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ for (int i = 0; i < array.length; i++)
+ {
+ b.append(Integer.toHexString(array [ i ] & 0xFF));
+ b.append(" ");
+ }
+ return b.toString();
+ }
+
+ /**
+ * Get the string representation of all included contexts.
+ */
+ public String contexts()
+ {
+ CPStringBuilder b = new CPStringBuilder();
+ for (int i = 0; i < service_context.length; i++)
+ {
+ b.append(service_context [ i ].toString());
+ b.append(' ');
+ }
+ return b.toString();
+ }
+
+ /**
+ * Reads the header from the stream.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param in a stream to read from.
+ */
+ public void read(AbstractCdrInput in)
+ {
+ service_context = ServiceContext.readSequence(in);
+ request_id = in.read_ulong();
+ response_expected = in.read_boolean();
+ object_key = in.read_sequence();
+ operation = in.read_string();
+ requesting_principal = in.read_sequence();
+
+ in.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+
+ /**
+ * Return a string representation.
+ */
+ public String toString()
+ {
+ return "Request " + request_id + ", call '" + operation + "' on " +
+ bytes(object_key) + ", " +
+ (response_expected ? "wait response" : "one way") + ", from " +
+ bytes(requesting_principal) + contexts();
+ }
+
+ /**
+ * Writes the header to the stream.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param out a stream to write into.
+ */
+ public void write(AbstractCdrOutput out)
+ {
+ ServiceContext.writeSequence(out, service_context);
+ out.write_ulong(request_id);
+ out.write_boolean(response_expected);
+ out.write_sequence(object_key);
+ out.write_string(operation);
+ out.write_sequence(requesting_principal);
+
+ out.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java
new file mode 100644
index 000000000..3fc1541d9
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java
@@ -0,0 +1,118 @@
+/* ReplyHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP.v1_2;
+
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+import gnu.CORBA.GIOP.ServiceContext;
+import gnu.CORBA.GIOP.CodeSetServiceContext;
+
+/**
+ * GIOP 1.2 reply header.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class ReplyHeader
+ extends gnu.CORBA.GIOP.v1_0.ReplyHeader
+{
+ /**
+ * Adds the standard encoding context.
+ */
+ public ReplyHeader()
+ {
+ service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD };
+ }
+
+ /**
+ * Return the message status as a string.
+ */
+ public String getStatusString()
+ {
+ String s = super.getStatusString();
+ if (s != null)
+ return s;
+ switch (reply_status)
+ {
+ case LOCATION_FORWARD_PERM :
+ return "moved permanently";
+
+ case NEEDS_ADDRESSING_MODE :
+ return "the alternative addressing mode required";
+
+ default :
+ return null;
+ }
+ }
+
+ /**
+ * Reads the header from the stream.
+ * The fields go in different order than in the previous GIOP versions.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param in a stream to read from.
+ */
+ public void read(AbstractCdrInput in)
+ {
+ request_id = in.read_ulong();
+ reply_status = in.read_ulong();
+ service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in);
+
+ in.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+
+ /**
+ * Writes the header to the stream.
+ * The fields go in different order than in the previous GIOP versions.
+ *
+ * Sets the code set of this stream to
+ * the code set, specfied in the header.
+ *
+ * @param out a stream to write into.
+ */
+ public void write(AbstractCdrOutput out)
+ {
+ out.write_ulong(request_id);
+ out.write_ulong(reply_status);
+ gnu.CORBA.GIOP.ServiceContext.writeSequence(out, service_context);
+
+ out.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+}
diff --git a/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java
new file mode 100644
index 000000000..d083536a7
--- /dev/null
+++ b/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java
@@ -0,0 +1,222 @@
+/* RequestHeader.java --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.CORBA.GIOP.v1_2;
+
+import gnu.CORBA.Minor;
+import gnu.CORBA.CDR.AbstractCdrInput;
+import gnu.CORBA.CDR.AbstractCdrOutput;
+import gnu.CORBA.GIOP.ServiceContext;
+import gnu.CORBA.GIOP.CodeSetServiceContext;
+
+import java.io.IOException;
+
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.NO_IMPLEMENT;
+
+/**
+ * The GIOP 1.2 request header. The GIOP 1.1 request header
+ * is the same as GIOP 1.0 request header, if taking the
+ * alignment into consideration.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class RequestHeader
+ extends gnu.CORBA.GIOP.v1_0.RequestHeader
+{
+ /**
+ * Use serialVersionUID for interoperability.
+ */
+ private static final long serialVersionUID = 1;
+
+ /**
+ * Indicates that the object is addressed by the object key.
+ */
+ public static final short KeyAddr = 0;
+
+ /**
+ * Indicates that the object is addressed by the IOP tagged profile.
+ */
+ public static final short ProfileAddr = 1;
+
+ /**
+ * Indicates that the objec is addressed by IOR addressing info.
+ */
+ public static final short ReferenceAddr = 2;
+
+ /**
+ * The response flags of the header. By default, the flags are initialised
+ * by value 0x3 (response expected).
+ */
+ public byte response_flags = 3;
+
+ /**
+ * The used addressing method.
+ */
+ public short AddressingDisposition;
+
+ /**
+ * Adds the standard encoding context.
+ */
+ public RequestHeader()
+ {
+ service_context = new ServiceContext[] { CodeSetServiceContext.STANDARD };
+ }
+
+ /**
+ * Set if the sender expects any response to this message.
+ * Clears or sets the 2 lower bits of flags
+ * (0 - not expected, 0x3 - expected).
+ */
+ public void setResponseExpected(boolean expected)
+ {
+ response_expected = expected;
+
+ if (expected)
+ response_flags = (byte) (response_flags | 0x3);
+ else
+ response_flags = (byte) (response_flags & (~0x3));
+ }
+
+ /**
+ * Return true if response is expected.
+ *
+ * @return true if the two lowest bits of the flags are set or
+ * the response expected is explicitly set to true.
+ */
+ public boolean isResponseExpected()
+ {
+ return response_expected || ((response_flags & 0x3) == 0x3);
+ }
+
+ /**
+ * Read the header from the given stream.
+ *
+ * @param in a stream to read from.
+ */
+ public void read(AbstractCdrInput in)
+ {
+ try
+ {
+ request_id = in.read_ulong();
+ response_flags = (byte) in.read();
+
+ // Skip 3 reserved octets:
+ in.skip(3);
+
+ // Read target address.
+ AddressingDisposition = in.read_ushort();
+
+ switch (AddressingDisposition)
+ {
+ case KeyAddr :
+ object_key = in.read_sequence();
+ break;
+
+ // TODO FIXME add other addressing methods.
+ case ProfileAddr :
+ throw new NO_IMPLEMENT("Object addressing by IOP tagged profile");
+
+ case ReferenceAddr :
+ throw new NO_IMPLEMENT("Object addressing by IOR addressing info");
+
+ default :
+ MARSHAL m = new MARSHAL("Unknow addressing method in request, " +
+ AddressingDisposition
+ );
+ m.minor = Minor.UnsupportedAddressing;
+ throw m;
+ }
+
+ operation = in.read_string();
+ service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in);
+
+ // No requesting principal in this new format.
+ in.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+ catch (IOException ex)
+ {
+ MARSHAL t = new MARSHAL();
+ t.minor = Minor.Header;
+ t.initCause(ex);
+ throw t;
+ }
+ }
+
+ /**
+ * Return a string representation.
+ */
+ public String toString()
+ {
+ return "Request " + request_id + ", call '" + operation + "' on " +
+ bytes(object_key) + ", " +
+ (response_expected ? "wait response" : "one way") +
+ " addressed by " + " method " + AddressingDisposition + "." +
+ contexts();
+ }
+
+ /**
+ * Write the header to the given stream.
+ *
+ * @param out a stream to write into.
+ */
+ public void write(AbstractCdrOutput out)
+ {
+ out.write_ulong(request_id);
+
+ out.write(response_flags);
+
+ // Skip 3 reserved octets:
+ out.write(0);
+ out.write(0);
+ out.write(0);
+
+ // Write addressing disposition from IOR.
+ // TODO FIXME add other addressing methods.
+ out.write_ushort(KeyAddr);
+
+ out.write_sequence(object_key);
+
+ out.write_string(operation);
+
+ ServiceContext.writeSequence(out, service_context);
+
+ // No requesting principal in this new format.
+ out.setCodeSet(CodeSetServiceContext.find(service_context));
+ }
+}