diff options
| author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 00:30:23 +0000 |
|---|---|---|
| committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-07-16 00:30:23 +0000 |
| commit | c8875fb97fc03779a5bba09872227b1d08e5d52a (patch) | |
| tree | a0b991cf5866ae1d616639b906ac001811d74508 /libjava/classpath/gnu/CORBA/GIOP | |
| parent | c40c1730800ed292b6db39a83d592476fa59623c (diff) | |
| download | ppe42-gcc-c8875fb97fc03779a5bba09872227b1d08e5d52a.tar.gz ppe42-gcc-c8875fb97fc03779a5bba09872227b1d08e5d52a.zip | |
Initial revision
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@102074 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/gnu/CORBA/GIOP')
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java | 70 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java | 235 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java | 102 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java | 97 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java | 350 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java | 156 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java | 161 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java | 131 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java | 224 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java | 72 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java | 139 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java | 157 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/v1_2/ReplyHeader.java | 118 | ||||
| -rw-r--r-- | libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java | 213 |
14 files changed, 2225 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 00000000000..9f4de0d87d9 --- /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; + + /** + * Write the header. + * + * @param out a stream to write to. + */ + public abstract void read(InputStream input); + + /** + * Write the header. + * + * @param out 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 00000000000..f3f35dbaa21 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/CharSets_OSF.java @@ -0,0 +1,235 @@ +/* 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 + * + * @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 00000000000..d884329c440 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/CloseMessage.java @@ -0,0 +1,102 @@ +/* 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.IOR; + +import org.omg.CORBA.MARSHAL; + +import java.io.IOException; +import java.io.OutputStream; + +import java.net.Socket; + +/** + * 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 +{ + /** + * 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.initCause(ex); + throw m; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java new file mode 100644 index 00000000000..8d3b3539be5 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/ErrorMessage.java @@ -0,0 +1,97 @@ +/* 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.IOR; + +import java.io.IOException; +import java.io.OutputStream; + +import java.net.Socket; + +import org.omg.CORBA.MARSHAL; + +/** + * 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 +{ + /** + * 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 to the IOR address (host and port, other fields + * are not used). + */ + public void send(IOR ior) + { + try + { + Socket 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.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 00000000000..61c46e11ea4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/MessageHeader.java @@ -0,0 +1,350 @@ +/* MessageHeader.java -- GIOP 1.0 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.CDR.BigEndianOutputStream; +import gnu.CORBA.CDR.LittleEndianInputStream; +import gnu.CORBA.CDR.LittleEndianOutputStream; +import gnu.CORBA.CDR.abstractDataOutputStream; +import gnu.CORBA.Version; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.portable.IDLEntity; + +import java.io.DataInputStream; +import java.io.IOException; +import java.io.OutputStream; + +import java.util.Arrays; +import gnu.CORBA.CDR.BigEndianInputStream; +import gnu.CORBA.CDR.abstractDataInputStream; +import java.io.InputStream; + +/** + * The GIOP message header. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class MessageHeader + implements IDLEntity +{ + /** + * 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; + } + + /** + * 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 + { + try + { + byte[] xMagic = new byte[ MAGIC.length ]; + istream.read(xMagic); + if (!Arrays.equals(xMagic, MAGIC)) + throw new MARSHAL("Not a GIOP message"); + + version = Version.read_version(istream); + + abstractDataInputStream 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.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 + { + abstractDataOutputStream 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(); + t.initCause(ex); + throw t; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java new file mode 100644 index 00000000000..1e0e154f80d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/ReplyHeader.java @@ -0,0 +1,156 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; + + +/** + * The header of the standard reply. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class ReplyHeader +{ + /** + * 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; + + /** + * Empty array, indicating that no service context is available. + */ + protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[ 0 ]; + + /** + * The ORB service data. + */ + public ServiceContext[] service_context = NO_CONTEXT; + + /** + * 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(cdrInput 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(cdrOutput out); +} diff --git a/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java new file mode 100644 index 00000000000..f2de4e2715b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/RequestHeader.java @@ -0,0 +1,161 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; + + +import org.omg.CORBA.portable.IDLEntity; + +/** + * The GIOP request message. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class RequestHeader + 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; + + /** + * Contains the ORB service data being passed. Initialised as the + * zero size array by default. + */ + public ServiceContext[] service_context = new ServiceContext[ 0 ]; + + /** + * 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) + { + StringBuffer b = new StringBuffer(); + 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(cdrInput 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(cdrOutput out); +} diff --git a/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java new file mode 100644 index 00000000000..7e44bdcea77 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/ServiceContext.java @@ -0,0 +1,131 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; + + +import org.omg.CORBA.portable.IDLEntity; + +/** + * Contains the ORB service data being passed. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ServiceContext + implements IDLEntity +{ + /** + * The context data. + */ + public byte[] context_data; + + /** + * The context id. + */ + public int context_id; + + /** + * Read the context values from the stream. + * + * @param istream a stream to read from. + */ + public static ServiceContext read(cdrInput istream) + { + int id = istream.read_ulong(); + + switch (id) + { + case cxCodeSet.ID : + + cxCodeSet codeset = new cxCodeSet(); + 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(cdrInput 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(cdrOutput ostream) + { + ostream.write_ulong(context_id); + ostream.write_sequence(context_data); + } + + /** + * Write the sequence of contexts into the input stream. + */ + public static void writeSequence(cdrOutput ostream, ServiceContext[] value) + { + ostream.write_long(value.length); + for (int i = 0; i < value.length; i++) + value [ i ].write(ostream); + } + + /** + * Return a string representation. + */ + public String toString() + { + return "ctx "+context_id+", size "+context_data.length; + } +} diff --git a/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java b/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java new file mode 100644 index 00000000000..7f42c07f236 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/cxCodeSet.java @@ -0,0 +1,224 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.IOR; +import gnu.CORBA.IOR.CodeSets_profile; + +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 cxCodeSet + extends ServiceContext +{ + /** + * The context code sets id. + */ + public static final int ID = 1; + + /** + * The standard component to include in the messages. + */ + public static final cxCodeSet STANDARD = new cxCodeSet(); + + /** + * 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 cxCodeSet find(ServiceContext[] contexts) + { + if (contexts != null) + for (int i = 0; i < contexts.length; i++) + { + if (contexts [ i ] instanceof cxCodeSet) + return (cxCodeSet) 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 cxCodeSet negotiate(IOR.CodeSets_profile profile) + { + if (profile.negotiated != null) + return profile.negotiated; + + cxCodeSet use = new cxCodeSet(); + + 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(cdrInput input) + { + cdrInput 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(cdrOutput output) + { + output.write_ulong(ID); + + cdrOutput 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/v1_0/CancelHeader.java b/libjava/classpath/gnu/CORBA/GIOP/v1_0/CancelHeader.java new file mode 100644 index 00000000000..6e3650c4ba9 --- /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 +{ + /** + * Write the header. + * + * @param out a stream to write to. + */ + public void read(InputStream input) + { + request_id = input.read_ulong(); + } + + /** + * Write the header. + * + * @param out 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 00000000000..27181ca6347 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/ReplyHeader.java @@ -0,0 +1,139 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.GIOP.ServiceContext; +import gnu.CORBA.GIOP.cxCodeSet; + +/** + * 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() + { + StringBuffer b = new StringBuffer(); + 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(cdrInput in) + { + service_context = ServiceContext.readSequence(in); + request_id = in.read_ulong(); + reply_status = in.read_ulong(); + + in.setCodeSet(cxCodeSet.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(cdrOutput out) + { + ServiceContext.writeSequence(out, service_context); + out.write_ulong(request_id); + out.write_ulong(reply_status); + + out.setCodeSet(cxCodeSet.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 00000000000..ffa45c37bc0 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_0/RequestHeader.java @@ -0,0 +1,157 @@ +/* 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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; + +import org.omg.CORBA.portable.IDLEntity; +import gnu.CORBA.GIOP.ServiceContext; +import gnu.CORBA.GIOP.cxCodeSet; + +/** + * 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) + { + StringBuffer b = new StringBuffer(); + 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() + { + StringBuffer b = new StringBuffer(); + 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(cdrInput 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(cxCodeSet.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(cdrOutput 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(cxCodeSet.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 00000000000..c3f51a37b91 --- /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.cdrInput; +import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.GIOP.ServiceContext; +import gnu.CORBA.GIOP.cxCodeSet; + +/** + * 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[] { cxCodeSet.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(cdrInput in) + { + request_id = in.read_ulong(); + reply_status = in.read_ulong(); + service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in); + + in.setCodeSet(cxCodeSet.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(cdrOutput out) + { + out.write_ulong(request_id); + out.write_ulong(reply_status); + gnu.CORBA.GIOP.ServiceContext.writeSequence(out, service_context); + + out.setCodeSet(cxCodeSet.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 00000000000..d294d006723 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/v1_2/RequestHeader.java @@ -0,0 +1,213 @@ +/* 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.CDR.cdrInput; +import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.GIOP.ServiceContext; +import gnu.CORBA.GIOP.cxCodeSet; + +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 +{ + /** + * 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[] { cxCodeSet.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(cdrInput 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 by IOR addressing info"); + + default : + throw new MARSHAL("Unknow addressing method in request, " + + AddressingDisposition + ); + } + + operation = in.read_string(); + service_context = gnu.CORBA.GIOP.ServiceContext.readSequence(in); + + // No requesting principal in this new format. + in.setCodeSet(cxCodeSet.find(service_context)); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + 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(cdrOutput 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(cxCodeSet.find(service_context)); + } +} |

