diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2005-07-16 00:30:23 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2005-07-16 00:30:23 +0000 |
commit | f911ba985aa7fe0096c386c5be385ac5825ea527 (patch) | |
tree | a0b991cf5866ae1d616639b906ac001811d74508 /libjava/classpath/gnu/CORBA | |
parent | 6f4434b39b261de5317dc81ddfdd94d2e1d62b11 (diff) | |
download | gcc-f911ba985aa7fe0096c386c5be385ac5825ea527.zip gcc-f911ba985aa7fe0096c386c5be385ac5825ea527.tar.gz gcc-f911ba985aa7fe0096c386c5be385ac5825ea527.tar.bz2 |
Initial revision
From-SVN: r102074
Diffstat (limited to 'libjava/classpath/gnu/CORBA')
91 files changed, 21580 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/CORBA/Asynchron.java b/libjava/classpath/gnu/CORBA/Asynchron.java new file mode 100644 index 0000000..275b570 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Asynchron.java @@ -0,0 +1,185 @@ +/* Asynchron.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; + +import org.omg.CORBA.Request; +import org.omg.CORBA.WrongTransaction; + +import java.util.Iterator; +import java.util.LinkedList; + +/** + * Handles the asynchronous dynamic invocations. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class Asynchron +{ + LinkedList sent = new LinkedList(); + + /** + * Send multiple prepared requests one way, do not caring about the answer. + * The messages, containing requests, will be marked, indicating that + * the sender is not expecting to get a reply. + * + * @param requests the prepared array of requests. + * + * @see Request#send_oneway() + */ + public void send_multiple_requests_oneway(Request[] requests) + { + for (int i = 0; i < requests.length; i++) + { + requests [ i ].send_oneway(); + } + } + + /** + * Send multiple prepared requests expecting to get a reply. All requests + * are send in parallel, each in its own separate thread. When the + * reply arrives, it is stored in the agreed fields of the corresponing + * request data structure. If this method is called repeatedly, + * the new requests are added to the set of the currently sent requests, + * but the old set is not discarded. + * + * @param requests the prepared array of requests. + * + * @see #poll_next_response() + * @see #get_next_response() + * @see Request#send_deferred() + */ + public void send_multiple_requests_deferred(Request[] requests) + { + synchronized (sent) + { + for (int i = 0; i < requests.length; i++) + { + sent.add(requests [ i ]); + + // TODO Reuse threads that are instantiated in the method below, + // one thread per call. + requests [ i ].send_deferred(); + } + } + } + + /** + * Find if any of the requests that have been previously sent with + * {@link #send_multiple_requests_deferred}, have a response yet. + * + * @return true if there is at least one response to the previously + * sent request, false otherwise. + */ + public boolean poll_next_response() + { + synchronized (sent) + { + Iterator iter = sent.iterator(); + Request r; + while (iter.hasNext()) + { + r = (Request) iter.next(); + if (r.poll_response()) + return true; + } + } + return false; + } + + /** + * Get the next instance with a response being received. If all currently + * sent responses not yet processed, this method pauses till at least one of + * them is complete. If there are no requests currently sent, the method + * pauses till some request is submitted and the response is received. + * This strategy is identical to the one accepted by Suns 1.4 ORB + * implementation. + * + * The returned response is removed from the list of the currently + * submitted responses and is never returned again. + * + * @return the previously sent request that now contains the received + * response. + * + * @throws WrongTransaction If the method was called from the transaction + * scope different than the one, used to send the request. The exception + * can be raised only if the request is implicitly associated with some + * particular transaction. + */ + public Request get_next_response() + throws WrongTransaction + { + // The hard-coded waiting times for the incremental waiter. + // TODO it is possible to write more tricky system where the + // requests notify the Asynchron when they are complete. + // Wait for 5 ms intially. + int wait = 8; + + // Double the waiting time + int INC = 2; + + // Do not increase if the waiting time is already over 500 ms. + int MAX = 500; + while (true) + { + synchronized (sent) + { + Iterator iter = sent.iterator(); + Request r; + while (iter.hasNext()) + { + r = (Request) iter.next(); + if (r.poll_response()) + { + sent.remove(r); + return r; + } + } + } + try + { + Thread.sleep(wait); + if (wait < MAX) + wait = wait * INC; + } + catch (InterruptedException ex) + { + } + } + } +} diff --git a/libjava/classpath/gnu/CORBA/BigDecimalHelper.java b/libjava/classpath/gnu/CORBA/BigDecimalHelper.java new file mode 100644 index 0000000..f1e1dd6 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/BigDecimalHelper.java @@ -0,0 +1,193 @@ +/* BigDecimalHelper.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; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * Reads and writes BigDecimal as CORBA <code>fixed</code>. + * The format, described in CORBA specification, requires to store + * data in hexadecimal format, two digits per byte (oceted), most + * significant digit first. The last half-byte in the representation + * stores the sign, being 0xD for negative numbers and 0xC for + * zero and positive numbers. To have the even number of half bytes, + * 0x0 is appended to the beginning, if required. The position of the + * decimal point is not stored. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class BigDecimalHelper +{ + { + } + + /** + * @todo remove from the release version. + */ + public static void main(String[] args) + { + try + { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + BigDecimal d = new BigDecimal("12234.54689"); + + write(b, d); + + byte[] a = b.toByteArray(); + + for (int i = 0; i < a.length; i++) + { + int k = a [ i ] & 0xFF; + System.out.print(Integer.toHexString(k) + " "); + } + + System.out.println("Now reading"); + + ByteArrayInputStream bin = new ByteArrayInputStream(a); + + BigDecimal r = read(bin, d.scale()); + + System.out.println(r); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * Read the CORBA fixed, autodetecting the number of bytes + * and assuming the given scale. + */ + public static BigDecimal read(java.io.InputStream in, int scale) + throws IOException + { + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + int f; + + do + { + f = in.read(); + if (f >= 0) + bout.write(f); + } + // The last byte has 0xC or 0xD in the last halfbyte. + while ((f & 0xF) <= 0x9); + + return createFixed(scale, bout.toByteArray()); + } + + /** + * Write the big decimal as CORBA <code>fixed<.code>. + * The scale will not be stored. + * + * @param out a stream to write into. + * @param x a big decimal to write. + * @param digits a number of the decimal digits in the record + * being written. For the smaller + * numbers, zeroes are added to the left. + * + * @throws IOException if the stream write method throws one. + * @throws BadKind if this BigDecimal has more digits than + * specified. + */ + public static void write(java.io.OutputStream out, BigDecimal x) + throws IOException, BadKind + { + StringBuffer v = new StringBuffer(x.unscaledValue().toString()); + + boolean negative = v.charAt(0) == '-'; + + if (negative) + v = v.deleteCharAt(0); + + if ( (v.length() & 1) == 0) + v.insert(0, '0'); + + int c; + + for (int i = 0; i < v.length() - 1; i = i + 2) + { + c = ((v.charAt(i) - '0') << 4) | (v.charAt(i + 1) - '0'); + out.write(c); + } + + c = ((v.charAt(v.length() - 1) - '0') << 4) | (negative ? 0xD : 0xC); + + out.write(c); + } + + /** + * Convert the loaded byte array, representing + * CORBA <code>fixed</code>, into an instance of + * the {@link BigDecimal} + */ + private static BigDecimal createFixed(int scale, byte[] d) + { + StringBuffer s = new StringBuffer(2 * d.length); + + int last = d.length - 1; + + if ((d [ last ] & 0xF) == 0xD) + s.append('-'); + + if (last > 0) + for (int i = 0; i < last; i++) + { + s.append((char) (((d [ i ] >> 4) & 0xF) + '0')); + s.append((char) (((d [ i ]) & 0xF) + '0')); + } + + s.append((char) (((d [ last ] >> 4) & 0xF) + '0')); + + BigInteger b = new BigInteger(s.toString()); + BigDecimal dec = new BigDecimal(b, scale); + + return dec; + } +} diff --git a/libjava/classpath/gnu/CORBA/ByteArrayComparator.java b/libjava/classpath/gnu/CORBA/ByteArrayComparator.java new file mode 100644 index 0000000..8491154 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ByteArrayComparator.java @@ -0,0 +1,91 @@ +/* ByteArrayComparator.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; + +import java.util.Arrays; +import java.util.Comparator; + +/** + * A byte array comparator for mapping with CORBA object keys. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ByteArrayComparator + implements Comparator +{ + /** + * Compare arrays first by absolute equality, then by length + * and then (byte to byte) by content. + * + * @return 0 if arrays are equal, some comparison value otherwise. + */ + public int compare(Object an_a, Object a_b) + { + if (an_a == a_b) + return 0; + + byte[] a = null; + byte[] b = null; + try + { + a = (byte[]) an_a; + b = (byte[]) a_b; + } + catch (Exception ex) + { + throw new InternalError(an_a.getClass().getName() + "," + + a_b.getClass().getName() + ); + } + + if (a.length != b.length) + return a.length - b.length; + else + { + // The array sizes must be equal. + for (int i = 0; i < b.length; i++) + { + if (a [ i ] != b [ i ]) + return a [ i ] - b [ i ]; + } + } + + return 0; + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java b/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java new file mode 100644 index 0000000..bc01939 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/BigEndianInputStream.java @@ -0,0 +1,61 @@ +/* BigEndianInputStream.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.CDR; + +import java.io.DataInputStream; +import java.io.InputStream; + +/** + * As java uses Big Endian by default, this class is directly derived + * form DataInputStream. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class BigEndianInputStream + extends DataInputStream + implements abstractDataInputStream +{ + /** + * Delegates to the parent constructor. + */ + public BigEndianInputStream(InputStream in) + { + super(in); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java new file mode 100644 index 0000000..e0aa7da --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/BigEndianOutputStream.java @@ -0,0 +1,62 @@ +/* BigEndianOutputStream.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.CDR; + +import java.io.DataOutputStream; +import java.io.OutputStream; + +/** + * A stream to read the data in Big Endian format. This class is + * directly derived from DataOutputStream that uses the Big + * Endian. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class BigEndianOutputStream + extends DataOutputStream + implements abstractDataOutputStream +{ + /** + * Delegate functionality to the parent constructor. + */ + public BigEndianOutputStream(OutputStream out) + { + super(out); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java b/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java new file mode 100644 index 0000000..b71a9a4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/LittleEndianInputStream.java @@ -0,0 +1,633 @@ +/* LittleEndianInputStream.java -- + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2005 Free Software Foundation + +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.CDR; + +import java.io.DataInput; +import java.io.EOFException; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PushbackInputStream; + +/** + * This class reads data in the Little Endian format. It reuses + * code from GNU Classpath DataInputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public class LittleEndianInputStream + extends FilterInputStream + implements abstractDataInputStream +{ + // Byte buffer, used to make primitive read calls more efficient. + byte[] buf = new byte[ 8 ]; + + /** + * This constructor initializes a new <code>DataInputStream</code> + * to read from the specified subordinate stream. + * + * @param in The subordinate <code>InputStream</code> to read from + */ + public LittleEndianInputStream(InputStream in) + { + super(in); + } + + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to fill the buffer completely, but + * may return a short count if there is insufficient data remaining to be + * read to fill the buffer. + * + * @param b The buffer into which bytes will be read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + public int read(byte[] b) + throws IOException + { + return in.read(b, 0, b.length); + } + + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to read <code>len</code> bytes and + * will start storing them at position <code>off</code> into the buffer. + * This method can return a short count if there is insufficient data + * remaining to be read to complete the desired read length. + * + * @param b The buffer into which bytes will be read. + * @param off The offset into the buffer to start storing bytes. + * @param len The requested number of bytes to read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + public int read(byte[] b, int off, int len) + throws IOException + { + return in.read(b, off, len); + } + + /** + * This method reads a Java boolean value from an input stream. It does + * so by reading a single byte of data. If that byte is zero, then the + * value returned is <code>false</code>. If the byte is non-zero, then + * the value returned is <code>true</code>. + * <p> + * This method can read a <code>boolean</code> written by an object + * implementing the <code>writeBoolean()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>boolean</code> value read + * + * @exception EOFException If end of file is reached before reading + * the boolean + * @exception IOException If any other error occurs + * + * @see DataOutput#writeBoolean + */ + public boolean readBoolean() + throws IOException + { + return convertToBoolean(in.read()); + } + + /** + * This method reads a Java byte value from an input stream. The value + * is in the range of -128 to 127. + * <p> + * This method can read a <code>byte</code> written by an object + * implementing the <code>writeByte()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>byte</code> value read + * + * @exception EOFException If end of file is reached before reading the byte + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + public byte readByte() + throws IOException + { + return convertToByte(in.read()); + } + + /** + * This method reads a Java <code>char</code> value from an input stream. + * It operates by reading two bytes from the stream and converting them to + * a single 16-bit Java <code>char</code>. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to a <code>char</code> in + * the following manner: + * <p> + * <code>(char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)</code> + * <p> + * This method can read a <code>char</code> written by an object + * implementing the <code>writeChar()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>char</code> value read + * + * @exception EOFException If end of file is reached before reading the char + * @exception IOException If any other error occurs + * + * @see DataOutput#writeChar + */ + public char readChar() + throws IOException + { + readFully(buf, 0, 2); + return convertToChar(buf); + } + + /** + * This method reads a Java double value from an input stream. It operates + * by first reading a <code>long</code> value from the stream by calling the + * <code>readLong()</code> method in this interface, then converts + * that <code>long</code> to a <code>double</code> using the + * <code>longBitsToDouble</code> method in the class + * <code>java.lang.Double</code> + * <p> + * This method can read a <code>double</code> written by an object + * implementing the <code>writeDouble()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>double</code> value read + * + * @exception EOFException If end of file is reached before reading + * the double + * @exception IOException If any other error occurs + * + * @see DataOutput#writeDouble + * @see java.lang.Double#longBitsToDouble + */ + public double readDouble() + throws IOException + { + return Double.longBitsToDouble(readLong()); + } + + /** + * This method reads a Java float value from an input stream. It + * operates by first reading an <code>int</code> value from the + * stream by calling the <code>readInt()</code> method in this + * interface, then converts that <code>int</code> to a + * <code>float</code> using the <code>intBitsToFloat</code> method + * in the class <code>java.lang.Float</code> + * <p> + * This method can read a <code>float</code> written by an object + * implementing the <code>writeFloat()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>float</code> value read + * + * @exception EOFException If end of file is reached before reading the float + * @exception IOException If any other error occurs + * + * @see DataOutput#writeFloat + * @see java.lang.Float#intBitsToFloat + */ + public float readFloat() + throws IOException + { + return Float.intBitsToFloat(readInt()); + } + + /** + * This method reads raw bytes into the passed array until the array is + * full. Note that this method blocks until the data is available and + * throws an exception if there is not enough data left in the stream to + * fill the buffer. Note also that zero length buffers are permitted. + * In this case, the method will return immediately without reading any + * bytes from the stream. + * + * @param b The buffer into which to read the data + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + public void readFully(byte[] b) + throws IOException + { + readFully(b, 0, b.length); + } + + /** + * This method reads raw bytes into the passed array <code>buf</code> + * starting + * <code>offset</code> bytes into the buffer. The number of bytes read + * will be + * exactly <code>len</code>. Note that this method blocks until the data is + * available and throws an exception if there is not enough data left in + * the stream to read <code>len</code> bytes. Note also that zero length + * buffers are permitted. In this case, the method will return immediately + * without reading any bytes from the stream. + * + * @param buf The buffer into which to read the data + * @param offset The offset into the buffer to start storing data + * @param len The number of bytes to read into the buffer + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + public void readFully(byte[] buf, int offset, int len) + throws IOException + { + if (len < 0) + throw new IndexOutOfBoundsException("Negative length: " + len); + + while (len > 0) + { + // in.read will block until some data is available. + int numread = in.read(buf, offset, len); + if (numread < 0) + throw new EOFException(); + len -= numread; + offset += numread; + } + } + + /** + * This method reads a Java <code>int</code> value from an input stream + * It operates by reading four bytes from the stream and converting them to + * a single Java <code>int</code>. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> through <code>byte4</code> represent + * the first four bytes read from the stream, they will be + * transformed to an <code>int</code> in the following manner: + * <p> + * <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + + * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code> + * <p> + * The value returned is in the range of -2147483648 to 2147483647. + * <p> + * This method can read an <code>int</code> written by an object + * implementing the <code>writeInt()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>int</code> value read + * + * @exception EOFException If end of file is reached before reading the int + * @exception IOException If any other error occurs + * + * @see DataOutput#writeInt + */ + public int readInt() + throws IOException + { + readFully(buf, 0, 4); + return convertToInt(buf); + } + + /** + * This method reads the next line of text data from an input + * stream. It operates by reading bytes and converting those bytes + * to <code>char</code> values by treating the byte read as the low + * eight bits of the <code>char</code> and using 0 as the high eight + * bits. Because of this, it does not support the full 16-bit + * Unicode character set. + * <p> + * The reading of bytes ends when either the end of file or a line + * terminator is encountered. The bytes read are then returned as a + * <code>String</code> A line terminator is a byte sequence + * consisting of either <code>\r</code>, <code>\n</code> or + * <code>\r\n</code>. These termination charaters are discarded and + * are not returned as part of the string. + * <p> + * This method can read data that was written by an object implementing the + * <code>writeLine()</code> method in <code>DataOutput</code>. + * + * @return The line read as a <code>String</code> + * + * @exception IOException If an error occurs + * + * @see DataOutput + * + * @deprecated + */ + public String readLine() + throws IOException + { + StringBuffer strb = new StringBuffer(); + + while (true) + { + int c = in.read(); + if (c == -1) // got an EOF + return strb.length() > 0 ? strb.toString() : null; + if (c == '\r') + { + int next_c = in.read(); + if (next_c != '\n' && next_c != -1) + { + if (!(in instanceof PushbackInputStream)) + in = new PushbackInputStream(in); + ((PushbackInputStream) in).unread(next_c); + } + break; + } + if (c == '\n') + break; + strb.append((char) c); + } + + return strb.length() > 0 ? strb.toString() : ""; + } + + /** + * This method reads a Java <code>long</code> value from an input stream + * It operates by reading eight bytes from the stream and converting them to + * a single Java <code>long</code>. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> through <code>byte8</code> represent + * the first eight bytes read from the stream, they will be + * transformed to an <code>long</code> in the following manner: + * <p> + * <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + + * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + + * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + + * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) + * </code> + * <p> + * The value returned is in the range of -9223372036854775808 to + * 9223372036854775807. + * <p> + * This method can read an <code>long</code> written by an object + * implementing the <code>writeLong()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>long</code> value read + * + * @exception EOFException If end of file is reached before reading the long + * @exception IOException If any other error occurs + * + * @see DataOutput#writeLong + */ + public long readLong() + throws IOException + { + readFully(buf, 0, 8); + return convertToLong(buf); + } + + /** + * This method reads a signed 16-bit value into a Java in from the + * stream. It operates by reading two bytes from the stream and + * converting them to a single 16-bit Java <code>short</code>. The + * two bytes are stored most significant byte first (i.e., "big + * endian") regardless of the native host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to a <code>short</code>. in + * the following manner: + * <p> + * <code>(short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF))</code> + * <p> + * The value returned is in the range of -32768 to 32767. + * <p> + * This method can read a <code>short</code> written by an object + * implementing the <code>writeShort()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>short</code> value read + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + public short readShort() + throws IOException + { + readFully(buf, 0, 2); + return convertToShort(buf); + } + + /** + * This method reads 8 unsigned bits into a Java <code>int</code> + * value from the stream. The value returned is in the range of 0 to + * 255. + * <p> + * This method can read an unsigned byte written by an object + * implementing the <code>writeUnsignedByte()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The unsigned bytes value read as a Java <code>int</code>. + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + public int readUnsignedByte() + throws IOException + { + return convertToUnsignedByte(in.read()); + } + + /** + * This method reads 16 unsigned bits into a Java int value from the stream. + * It operates by reading two bytes from the stream and converting them to + * a single Java <code>int</code> The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to an <code>int</code> in + * the following manner: + * <p> + * <code>(int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code> + * <p> + * The value returned is in the range of 0 to 65535. + * <p> + * This method can read an unsigned short written by an object + * implementing the <code>writeUnsignedShort()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The unsigned short value read as a Java <code>int</code> + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + public int readUnsignedShort() + throws IOException + { + readFully(buf, 0, 2); + return convertToUnsignedShort(buf); + } + + /** + * This method attempts to skip and discard the specified number of bytes + * in the input stream. It may actually skip fewer bytes than requested. + * This method will not skip any bytes if passed a negative number of bytes + * to skip. + * + * @param n The requested number of bytes to skip. + * + * @return The requested number of bytes to skip. + * + * @exception IOException If an error occurs. + * @specnote The JDK docs claim that this returns the number of bytes + * actually skipped. The JCL claims that this method can throw an + * EOFException. Neither of these appear to be true in the JDK 1.3's + * implementation. This tries to implement the actual JDK behaviour. + */ + public int skipBytes(int n) + throws IOException + { + if (n <= 0) + return 0; + try + { + return (int) in.skip(n); + } + catch (EOFException x) + { + // do nothing. + } + return n; + } + + protected boolean convertToBoolean(int b) + throws EOFException + { + if (b < 0) + throw new EOFException(); + + return (b != 0); + } + + protected byte convertToByte(int i) + throws EOFException + { + if (i < 0) + throw new EOFException(); + + return (byte) i; + } + + protected int convertToUnsignedByte(int i) + throws EOFException + { + if (i < 0) + throw new EOFException(); + + return (i & 0xFF); + } + + /** + * Less significant byte first. + */ + protected char convertToChar(byte[] buf) + { + return (char) ((buf [ 1 ] << 8) | (buf [ 0 ] & 0xff)); + } + + /** + * Less significant byte first. + */ + protected short convertToShort(byte[] buf) + { + return (short) ((buf [ 1 ] << 8) | (buf [ 0 ] & 0xff)); + } + + /** + * Less significant byte first. + */ + protected int convertToUnsignedShort(byte[] buf) + { + return (((buf [ 1 ] & 0xff) << 8) | (buf [ 0 ] & 0xff)); + } + + /** + * Less significant byte first. + */ + protected int convertToInt(byte[] buf) + { + return (((buf [ 3 ] & 0xff) << 24) | ((buf [ 2 ] & 0xff) << 16) | + ((buf [ 1 ] & 0xff) << 8) | (buf [ 0 ] & 0xff)); + } + + /** + * Less significant byte first. + */ + protected long convertToLong(byte[] buf) + { + return (((long) (buf [ 7 ] & 0xff) << 56) | + ((long) (buf [ 6 ] & 0xff) << 48) | + ((long) (buf [ 5 ] & 0xff) << 40) | + ((long) (buf [ 4 ] & 0xff) << 32) | + ((long) (buf [ 3 ] & 0xff) << 24) | + ((long) (buf [ 2 ] & 0xff) << 16) | + ((long) (buf [ 1 ] & 0xff) << 8) | ((long) (buf [ 0 ] & 0xff))); + } + + /** + * This should never be called. + * + * @throws InternalError, always. + */ + public String readUTF() + { + throw new InternalError(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java new file mode 100644 index 0000000..a6d56cf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/LittleEndianOutputStream.java @@ -0,0 +1,253 @@ +/* LittleEndianOutputStream.java -- + Copyright (C) 1998, 2001, 2003, 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.CDR; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * This stream writes data in the Little Endian format + * (less significant byte first). This is opposite to the + * usual data presentation in java platform. + * + * This class reuses code from DataOutputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Aaron M. Renn (arenn@urbanophile.com) + * @author Tom Tromey (tromey@cygnus.com) + */ +public class LittleEndianOutputStream + extends FilterOutputStream + implements abstractDataOutputStream +{ + /** + * This method initializes an instance of <code>DataOutputStream</code> to + * write its data to the specified underlying <code>OutputStream</code> + * + * @param out The subordinate <code>OutputStream</code> to which this + * object will write + */ + public LittleEndianOutputStream(OutputStream out) + { + super(out); + } + + /** + * This method flushes any unwritten bytes to the underlying stream. + * + * @exception IOException If an error occurs. + */ + public void flush() + throws IOException + { + out.flush(); + } + + /** + * This method writes the specified byte (passed as an <code>int</code>) + * to the underlying output stream. + * + * @param value The <code>byte</code> to write, passed as an <code>int</code>. + * + * @exception IOException If an error occurs. + */ + public synchronized void write(int value) + throws IOException + { + out.write(value); + } + + /** + * This method writes <code>len</code> bytes from the specified byte array + * <code>buf</code> starting at position <code>offset</code> into the + * buffer to the underlying output stream. + * + * @param buf The byte array to write from. + * @param offset The index into the byte array to start writing from. + * @param len The number of bytes to write. + * + * @exception IOException If an error occurs. + */ + public synchronized void write(byte[] buf, int offset, int len) + throws IOException + { + out.write(buf, offset, len); + } + + /** + * This method writes a Java boolean value to an output stream. If + * <code>value</code> is <code>true</code>, a byte with the value of + * 1 will be written, otherwise a byte with the value of 0 will be + * written. + * + * The value written can be read using the <code>readBoolean</code> + * method in <code>DataInput</code>. + * + * @param value The <code>boolean</code> value to write to the stream + * + * @exception IOException If an error occurs + * + * @see DataInput#readBoolean + */ + public void writeBoolean(boolean value) + throws IOException + { + write(value ? 1 : 0); + } + + /** + * This method writes a Java byte value to an output stream. The + * byte to be written will be in the lowest 8 bits of the + * <code>int</code> value passed. + * + * The value written can be read using the <code>readByte</code> or + * <code>readUnsignedByte</code> methods in <code>DataInput</code>. + * + * @param value The <code>byte</code> to write to the stream, passed as + * the low eight bits of an <code>int</code>. + * + * @exception IOException If an error occurs + * + * @see DataInput#readByte + * @see DataInput#readUnsignedByte + */ + public void writeByte(int value) + throws IOException + { + write(value & 0xff); + } + + /** + * This method writes a Java short value to an output stream. + * + * @param value The <code>short</code> value to write to the stream, + * passed as an <code>int</code>. + * + * @exception IOException If an error occurs + */ + public synchronized void writeShort(int value) + throws IOException + { + write((byte) (0xff & value)); + write((byte) (0xff & (value >> 8))); + } + + /** + * Writes char in Little Endian. + */ + public synchronized void writeChar(int value) + throws IOException + { + write((byte) (0xff & value)); + write((byte) (0xff & (value >> 8))); + } + + /** + * Writes int in Little Endian. + */ + public synchronized void writeInt(int value) + throws IOException + { + write((byte) (0xff & value)); + write((byte) (0xff & (value >> 8))); + write((byte) (0xff & (value >> 16))); + write((byte) (0xff & (value >> 24))); + } + + /** + * Writes long in Little Endian. + */ + public synchronized void writeLong(long value) + throws IOException + { + write((byte) (0xff & value)); + write((byte) (0xff & (value >> 8))); + write((byte) (0xff & (value >> 16))); + write((byte) (0xff & (value >> 24))); + write((byte) (0xff & (value >> 32))); + write((byte) (0xff & (value >> 40))); + write((byte) (0xff & (value >> 48))); + write((byte) (0xff & (value >> 56))); + } + + /** + * This method writes a Java <code>float</code> value to the stream. This + * value is written by first calling the method + * <code>Float.floatToIntBits</code> + * to retrieve an <code>int</code> representing the floating point number, + * then writing this <code>int</code> value to the stream exactly the same + * as the <code>writeInt()</code> method does. + * + * @param value The <code>float</code> value to write to the stream + * + * @exception IOException If an error occurs + * + * @see writeInt + * @see DataInput#readFloat + * @see Float#floatToIntBits + */ + public void writeFloat(float value) + throws IOException + { + writeInt(Float.floatToIntBits(value)); + } + + /** + * This method writes a Java <code>double</code> value to the stream. This + * value is written by first calling the method + * <code>Double.doubleToLongBits</code> + * to retrieve an <code>long</code> representing the floating point number, + * then writing this <code>long</code> value to the stream exactly the same + * as the <code>writeLong()</code> method does. + * + * @param value The <code>double</code> value to write to the stream + * + * @exception IOException If an error occurs + * + * @see writeLong + * @see DataInput#readDouble + * @see Double#doubleToLongBits + */ + public void writeDouble(double value) + throws IOException + { + writeLong(Double.doubleToLongBits(value)); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/Vio.java b/libjava/classpath/gnu/CORBA/CDR/Vio.java new file mode 100644 index 0000000..8f17bd2 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/Vio.java @@ -0,0 +1,638 @@ +/* gnuValueBaseHelper.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.CDR; + +import gnu.CORBA.ObjectCreator; + +import org.omg.CORBA.CustomMarshal; +import org.omg.CORBA.DataInputStream; +import org.omg.CORBA.DataOutputStream; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.StringSeqHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.portable.ValueFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.Serializable; + +/** + * A specialised class for reading and writing the value types. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class Vio +{ + /** + * If true, wrap value type data into chunks. This decrease the + * performance, but is required for the interoperability with + * Sun's CORBA implementation. Chunking may increase the security, + * as there is more control on the number of bytes being transferred. + * + * The current implementation would accept both single chunk or multiple + * chunks, but will always send a single chunk. + */ + public static boolean USE_CHUNKING = true; + + /** + * The first field in the value record. The last octet may contain + * additional flags (vf_CODEBASE, vf_ID and vf_MULTIPLE_IDS). The tag + * value is different for the indirections (vt_INDIRECTION) and + * nulls (vt_NULL). + */ + public static final int vt_VALUE_TAG = 0x7fffff00; + + /** + * The value tag flag, indicating that the codebase URL is present + * in the value tag record. + */ + public static final int vf_CODEBASE = 0x1; + + /** + * The value tag flag, indicating that a single repository id is present + * in the value tag record. + */ + public static final int vf_ID = 0x2; + + /** + * The value tag flag, indicating, that there are multiple repository + * ids present in the record. If this flag is set, the flag vf_ID must + * also be set, resulting the value of the least significant byte 0x6. + */ + public static final int vf_MULTIPLE_IDS = 0x4; + + /** + * The value tag flag, indicating the presence of chunking. Each chunk is + * preceeded by a positive int, indicating the number of bytes in the chunk. + * A sequence of chunks is terminated by a non positive int. + */ + public static final int vf_CHUNKING = 0x8; + + /** + * The indirection tag value. Such tag must be followed by the CORBA long, + * indicating the offset in the CORBA message, where the indirected + * information is present. This offset is assumed zero at the position + * where the mentioned CORBA long starts and can refer both forward + * (positive values) and backward (negative values). + */ + public static final int vt_INDIRECTION = 0xffffffff; + + /** + * This tag value means that the value object being transferred is equal + * to null. + */ + public static final int vt_NULL = 0x0; + + /** + * Read the value base from the given input stream. Determines the + * required class from the repository id. This includes operations + * that are not required when an unitialised instance or at least + * class of the value type is known. Hence it may be faster to use + * the alternative methods, read(InputStream, Class) or + * read(InputStream, Serializable). + * + * @param input a stream to read from. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + // We may need to jump back if the value is read via value factory. + input.mark(512); + + int value_tag = input.read_long(); + checkTag(value_tag); + + String codebase = null; + String[] ids = null; + String id = null; + + // The existing implementing object. + java.lang.Object ox = null; + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present. The codebase is a space + // separated list of URLs from where the implementing + // code can be downloaded. + codebase = input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present. + ids = StringSeqHelper.read(input); + for (int i = 0; (i < ids.length) && (ox == null); i++) + { + ox = ObjectCreator.Idl2Object(ids [ i ]); + + if (ox == null) + { + // Try to find the value factory. + ValueFactory f = + ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(ids [ i ]); + + if (f != null) + { + // Reset, as the value factory reads from beginning. + input.reset(); + return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); + } + } + } + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present. + id = input.read_string(); + ox = ObjectCreator.Idl2Object(id); + + if (ox == null) + { + // Try to find the value factory. + ValueFactory f = + ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(id); + + if (f != null) + { + input.reset(); + return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); + } + } + } + } + + if (ox == null) + throw new MARSHAL("Unable to instantiate the value type"); + else + { + read_instance(input, ox, value_tag); + return (Serializable) ox; + } + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Read the value base from the given input stream when + * the value base class is available. Hence there is no need + * to guess it from the repository id. + * + * @param input a stream to read from. + * @param value_class the class of the value being read. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input, Class value_class) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + int value_tag = input.read_long(); + checkTag(value_tag); + + // The existing implementing object. + java.lang.Object ox = value_class.newInstance(); + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present, but skip it. + input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present, but skip them. + StringSeqHelper.read(input); + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present, but skip it. + input.read_string(); + } + } + + read_instance(input, ox, value_tag); + return (Serializable) ox; + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Read the value base from the given input stream when + * the unitialised instance is available. Hence there is no need + * to guess the class from the repository id and then to instantiate + * an instance. + * + * @param input a stream to read from. + * @param value_instance an instance of the value. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input, Serializable value_instance) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + int value_tag = input.read_long(); + checkTag(value_tag); + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present, but skip it. + input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present, but skip them. + StringSeqHelper.read(input); + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present, but skip it. + input.read_string(); + } + } + + read_instance(input, value_instance, value_tag); + return (Serializable) value_instance; + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Fill in the instance fields by the data from the input stream. + * The method assumes that the value header, if any, is already + * behind. The information from the stream is stored into the + * passed ox parameter. + * + * @param input an input stream to read from. + * @param value a value type object, must be either Streamable or + * CustomMarshal. + */ + public static void read_instance(InputStream input, Object value, + int value_tag + ) + { + try + { + if ((value_tag & vf_CHUNKING) != 0) + { + ByteArrayOutputStream bout = null; + int n = -1; + + // Read all chunks. + int chunk_size = input.read_long(); + if (chunk_size <= 0) + throw new MARSHAL("Invalid first chunk size " + chunk_size); + + byte[] r = new byte[ chunk_size ]; + + while (chunk_size > 0) + { + if (r.length < chunk_size) + r = new byte[ chunk_size + 256 ]; + + n = 0; + reading: + while (n < chunk_size) + n += input.read(r, n, r.length - n); + + // Read the size of the next chunk. + chunk_size = input.read_long(); + + // If the value is non negative, there is more than one chunk. + // Accumulate chunks in the buffer. + // The last chunk (or the only chunk, if only one chunk is + // present) is not written in the buffer. It is stored in the + // array r, avoiding unnecessary buffer operations. + if (chunk_size > 0) + { + bout = new ByteArrayOutputStream(2 * chunk_size); + bout.write(r, 0, chunk_size); + } + } + + if (bout != null) + { + // More than one chunk was present. + // Add the last chunk. + bout.write(r, 0, n); + input = new cdrBufInput(bout.toByteArray()); + } + else + { + // Only one chunk was present. + input = new cdrBufInput(r); + } + } + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL("Unable to read chunks"); + m.initCause(ex); + throw m; + } + + // The user-defines io operations are implemented. + if (value instanceof CustomMarshal) + { + CustomMarshal marsh = (CustomMarshal) value; + try + { + marsh.unmarshal((DataInputStream) input); + } + catch (ClassCastException ex) + { + incorrect_plug_in(ex); + } + } + else + // The IDL-generated io operations are implemented. + if (value instanceof Streamable) + { + ((Streamable) value)._read(input); + } + else + + // Stating the interfaces that the USER should use. + throw new MARSHAL("The " + value.getClass().getName() + + " must implement either StreamableValue or CustomValue." + ); + + // The negative end of state marker is expected from OMG standard. + // If the chunking is used, this marker is already extracted. + if ((value_tag & vf_CHUNKING) == 0) + { + int eor = input.read_long(); + if (eor >= 0) + throw new MARSHAL("End of state marker has an invalid value " + eor); + } + } + + /** + * Write the value base into the given stream. + * + * @param output a stream to write to. + * + * @param value a value type object, must be either Streamable or + * CustomMarshal. + * + * @throws MARSHAL if the writing failed due any reason. + */ + public static void write(OutputStream output, Serializable value) + { + // Write null if this is a null value. + if (value == null) + output.write_long(vt_NULL); + else + write(output, value, ObjectCreator.toIDL(value.getClass().getName())); + } + + /** + * Write the value base into the given stream, stating that it is an + * instance of the given class. The written record has no repository + * id and requires to supply a class or initialised instance for reading + * rather than an actual class it is. + * + * This results writing a different repository id. + * + * If the passed value implements the {@link CustomMarshal}, + * the helper uses {@link CustomMarshal#marshal} + * to write the content in a user defined way. Otherwise, + * this implementation initialises the {@link ObjectOutputStream} + * and writes through it. + * + * @param output a stream to write to. + * + * @param value a value to write. + * + * @throws MARSHAL if the writing failed due any reason. + */ + public static void write(OutputStream output, Serializable value, + Class substitute + ) + { + // Write null if this is a null value. + if (value == null) + output.write_long(vt_NULL); + + else + write(output, value, ObjectCreator.toIDL(substitute.getName())); + } + + /** + * Write value when its repository Id is explicitly given. + * + * @param output an output stream to write into. + * @param value a value to write. + * @param id a value repository id. + */ + public static void write(OutputStream output, Serializable value, String id) + { + if (value == null) + output.write_long(vt_NULL); + else + write_instance(output, value, id); + } + + /** + * Write value when its repository Id is explicitly given. + * Does not handle null. + * + * @param output an output stream to write into. + * @param value a value to write. + * @param id a value repository id. + */ + private static void write_instance(OutputStream output, Serializable value, + String id + ) + { + // This implementation always writes a single repository id. + // It never writes multiple repository ids and currently does not use + // a codebase. + int value_tag = vt_VALUE_TAG | vf_ID; + + OutputStream outObj; + cdrBufOutput out = null; + + if (USE_CHUNKING) + { + out = new cdrBufOutput(); + out.setOrb(output.orb()); + outObj = out; + value_tag |= vf_CHUNKING; + } + else + outObj = output; + + output.write_long(value_tag); + output.write_string(id); + + // User defince write method is present. + if (value instanceof CustomMarshal) + { + try + { + ((CustomMarshal) value).marshal((DataOutputStream) outObj); + } + catch (ClassCastException ex) + { + incorrect_plug_in(ex); + } + } + else if (value instanceof Streamable) + { + ((Streamable) value)._write(outObj); + } + else + + // Stating the interfaces that the USER should use. + throw new MARSHAL("The " + value.getClass().getName() + + " must implement either StreamableValue or CustomValue." + ); + + if (USE_CHUNKING) + { + output.write_long(out.buffer.size()); + try + { + out.buffer.writeTo(output); + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + } + + // The end of record marker, required by OMG standard. + output.write_long(-1); + } + + /** + * This can be called if the alternative CORBA implementation + * is incorrectly plugged in. + * + * @throws NO_IMPLEMENT, always. + */ + private static void incorrect_plug_in(Throwable ex) + throws NO_IMPLEMENT + { + NO_IMPLEMENT no = new NO_IMPLEMENT("Incorrect CORBA plug-in"); + no.initCause(ex); + throw no; + } + + /** + * Check the passed value tag for correctness. + * + * @param value_tag a tag to check, must be between 0x7fffff00 and 0x7fffffff + * + * @throws MARSHAL if the tag is outside this interval. + */ + private static final void checkTag(int value_tag) + { + if ((value_tag < 0x7fffff00 || value_tag > 0x7fffffff) && + value_tag != vt_NULL && value_tag != vt_INDIRECTION + ) + throw new MARSHAL("Invalid value record, unsupported header tag: " + + value_tag + ); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java b/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java new file mode 100644 index 0000000..be92625 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/abstractDataInputStream.java @@ -0,0 +1,392 @@ +/* abstractDataInputStream.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.CDR; + +import java.io.IOException; + +/** + * Some data input stream that can be either Big or + * Little Endian. + * + * This class reuses code from GNU Classpath DataInputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface abstractDataInputStream +{ + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to fill the buffer completely, but + * may return a short count if there is insufficient data remaining to be + * read to fill the buffer. + * + * @param b The buffer into which bytes will be read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + int read(byte[] b) + throws IOException; + + /** + * This method reads bytes from the underlying stream into the specified + * byte array buffer. It will attempt to read <code>len</code> bytes and + * will start storing them at position <code>off</code> into the buffer. + * This method can return a short count if there is insufficient data + * remaining to be read to complete the desired read length. + * + * @param b The buffer into which bytes will be read. + * @param off The offset into the buffer to start storing bytes. + * @param len The requested number of bytes to read. + * + * @return The actual number of bytes read, or -1 if end of stream reached + * before reading any bytes. + * + * @exception IOException If an error occurs. + */ + int read(byte[] b, int off, int len) + throws IOException; + + /** + * This method reads a Java boolean value from an input stream. It does + * so by reading a single byte of data. If that byte is zero, then the + * value returned is <code>false</code>. If the byte is non-zero, then + * the value returned is <code>true</code>. + * <p> + * This method can read a <code>boolean</code> written by an object + * implementing the <code>writeBoolean()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>boolean</code> value read + * + * @exception EOFException If end of file is reached before reading + * the boolean + * @exception IOException If any other error occurs + * + * @see DataOutput#writeBoolean + */ + boolean readBoolean() + throws IOException; + + /** + * This method reads a Java byte value from an input stream. The value + * is in the range of -128 to 127. + * <p> + * This method can read a <code>byte</code> written by an object + * implementing the <code>writeByte()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>byte</code> value read + * + * @exception EOFException If end of file is reached before reading the byte + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + byte readByte() + throws IOException; + + /** + * This method reads a Java <code>char</code> value from an input stream. + * It operates by reading two bytes from the stream and converting them to + * a single 16-bit Java <code>char</code>. The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to a <code>char</code> in + * the following manner: + * <p> + * <code>(char)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF)</code> + * <p> + * This method can read a <code>char</code> written by an object + * implementing the <code>writeChar()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>char</code> value read + * + * @exception EOFException If end of file is reached before reading the char + * @exception IOException If any other error occurs + * + * @see DataOutput#writeChar + */ + char readChar() + throws IOException; + + /** + * This method reads a Java double value from an input stream. It operates + * by first reading a <code>long</code> value from the stream by calling the + * <code>readLong()</code> method in this interface, then converts + * that <code>long</code> to a <code>double</code> using the + * <code>longBitsToDouble</code> method in the class + * <code>java.lang.Double</code> + * <p> + * This method can read a <code>double</code> written by an object + * implementing the <code>writeDouble()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>double</code> value read + * + * @exception EOFException If end of file is reached before reading + * the double + * @exception IOException If any other error occurs + * + * @see DataOutput#writeDouble + * @see java.lang.Double#longBitsToDouble + */ + double readDouble() + throws IOException; + + /** + * This method reads a Java float value from an input stream. It + * operates by first reading an <code>int</code> value from the + * stream by calling the <code>readInt()</code> method in this + * interface, then converts that <code>int</code> to a + * <code>float</code> using the <code>intBitsToFloat</code> method + * in the class <code>java.lang.Float</code> + * <p> + * This method can read a <code>float</code> written by an object + * implementing the <code>writeFloat()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>float</code> value read + * + * @exception EOFException If end of file is reached before reading the float + * @exception IOException If any other error occurs + * + * @see DataOutput#writeFloat + * @see java.lang.Float#intBitsToFloat + */ + float readFloat() + throws IOException; + + /** + * This method reads raw bytes into the passed array until the array is + * full. Note that this method blocks until the data is available and + * throws an exception if there is not enough data left in the stream to + * fill the buffer. Note also that zero length buffers are permitted. + * In this case, the method will return immediately without reading any + * bytes from the stream. + * + * @param b The buffer into which to read the data + * + * @exception EOFException If end of file is reached before filling the + * buffer + * @exception IOException If any other error occurs + */ + void readFully(byte[] b) + throws IOException; + + /** + * This method reads a Java <code>int</code> value from an input stream + * It operates by reading four bytes from the stream and converting them to + * a single Java <code>int</code>. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> through <code>byte4</code> represent + * the first four bytes read from the stream, they will be + * transformed to an <code>int</code> in the following manner: + * <p> + * <code>(int)(((byte1 & 0xFF) << 24) + ((byte2 & 0xFF) << 16) + + * ((byte3 & 0xFF)<< 8) + (byte4 & 0xFF)))</code> + * <p> + * The value returned is in the range of -2147483648 to 2147483647. + * <p> + * This method can read an <code>int</code> written by an object + * implementing the <code>writeInt()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>int</code> value read + * + * @exception EOFException If end of file is reached before reading the int + * @exception IOException If any other error occurs + * + * @see DataOutput#writeInt + */ + int readInt() + throws IOException; + + /** + * This method reads a Java <code>long</code> value from an input stream + * It operates by reading eight bytes from the stream and converting them to + * a single Java <code>long</code>. The bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> through <code>byte8</code> represent + * the first eight bytes read from the stream, they will be + * transformed to an <code>long</code> in the following manner: + * <p> + * <code>(long)(((byte1 & 0xFF) << 56) + ((byte2 & 0xFF) << 48) + + * ((byte3 & 0xFF) << 40) + ((byte4 & 0xFF) << 32) + + * ((byte5 & 0xFF) << 24) + ((byte6 & 0xFF) << 16) + + * ((byte7 & 0xFF) << 8) + (byte8 & 0xFF))) + * </code> + * <p> + * The value returned is in the range of -9223372036854775808 to + * 9223372036854775807. + * <p> + * This method can read an <code>long</code> written by an object + * implementing the <code>writeLong()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>long</code> value read + * + * @exception EOFException If end of file is reached before reading the long + * @exception IOException If any other error occurs + * + * @see DataOutput#writeLong + */ + long readLong() + throws IOException; + + /** + * This method reads a signed 16-bit value into a Java in from the + * stream. It operates by reading two bytes from the stream and + * converting them to a single 16-bit Java <code>short</code>. The + * two bytes are stored most significant byte first (i.e., "big + * endian") regardless of the native host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to a <code>short</code>. in + * the following manner: + * <p> + * <code>(short)(((byte1 & 0xFF) << 8) | (byte2 & 0xFF))</code> + * <p> + * The value returned is in the range of -32768 to 32767. + * <p> + * This method can read a <code>short</code> written by an object + * implementing the <code>writeShort()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The <code>short</code> value read + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + short readShort() + throws IOException; + + /** + * This method reads 8 unsigned bits into a Java <code>int</code> + * value from the stream. The value returned is in the range of 0 to + * 255. + * <p> + * This method can read an unsigned byte written by an object + * implementing the <code>writeUnsignedByte()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The unsigned bytes value read as a Java <code>int</code>. + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeByte + */ + int readUnsignedByte() + throws IOException; + + /** + * This method reads 16 unsigned bits into a Java int value from the stream. + * It operates by reading two bytes from the stream and converting them to + * a single Java <code>int</code> The two bytes are stored most + * significant byte first (i.e., "big endian") regardless of the native + * host byte ordering. + * <p> + * As an example, if <code>byte1</code> and <code>byte2</code> + * represent the first and second byte read from the stream + * respectively, they will be transformed to an <code>int</code> in + * the following manner: + * <p> + * <code>(int)(((byte1 & 0xFF) << 8) + (byte2 & 0xFF))</code> + * <p> + * The value returned is in the range of 0 to 65535. + * <p> + * This method can read an unsigned short written by an object + * implementing the <code>writeUnsignedShort()</code> method in the + * <code>DataOutput</code> interface. + * + * @return The unsigned short value read as a Java <code>int</code> + * + * @exception EOFException If end of file is reached before reading the value + * @exception IOException If any other error occurs + * + * @see DataOutput#writeShort + */ + int readUnsignedShort() + throws IOException; + + /** + * Read a single byte. + * + * @return a byte, extracted from the stream or -1 if + * EOF has been reached. + * @throws IOException + */ + public int read() + throws IOException; + + /** + * This method attempts to skip and discard the specified number of bytes + * in the input stream. It may actually skip fewer bytes than requested. + * This method will not skip any bytes if passed a negative number of bytes + * to skip. + * + * @param n The requested number of bytes to skip. + * + * @return The requested number of bytes to skip. + * + * @exception IOException If an error occurs. + * @specnote The JDK docs claim that this returns the number of bytes + * actually skipped. The JCL claims that this method can throw an + * EOFException. Neither of these appear to be true in the JDK 1.3's + * implementation. This tries to implement the actual JDK behaviour. + */ + int skipBytes(int n) + throws IOException; +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java new file mode 100644 index 0000000..2f9b8c4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/abstractDataOutputStream.java @@ -0,0 +1,185 @@ +/* abstractDataOutputStream.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.CDR; + +import java.io.IOException; + +/** + * An abstract data output stream that could write data in either + * Big Endian or Little Endian format. + * + * This class reuses code from GNU Classpath DataOutputStream. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Warren Levy (warrenl@cygnus.com) + * @author Aaron M. Renn (arenn@urbanophile.com) + */ +public interface abstractDataOutputStream +{ + /** + * This method flushes any unwritten bytes to the underlying stream. + * + * @exception IOException If an error occurs. + */ + void flush() + throws IOException; + + /** + * This method writes the specified byte (passed as an <code>int</code>) + * to the underlying output stream. + * + * @param value The <code>byte</code> to write, passed as an <code>int</code>. + * + * @exception IOException If an error occurs. + */ + void write(int value) + throws IOException; + + /** + * This method writes <code>len</code> bytes from the specified byte array + * <code>buf</code> starting at position <code>offset</code> into the + * buffer to the underlying output stream. + * + * @param buf The byte array to write from. + * @param offset The index into the byte array to start writing from. + * @param len The number of bytes to write. + * + * @exception IOException If an error occurs. + */ + void write(byte[] buf, int offset, int len) + throws IOException; + + /** + * Write the complete byte array. + * @throws IOException + */ + void write(byte[] buf) + throws IOException; + + /** + * This method writes a Java boolean value to an output stream. If + * <code>value</code> is <code>true</code>, a byte with the value of + * 1 will be written, otherwise a byte with the value of 0 will be + * written. + * + * The value written can be read using the <code>readBoolean</code> + * method in <code>DataInput</code>. + * + * @param value The <code>boolean</code> value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeBoolean(boolean value) + throws IOException; + + /** + * This method writes a Java byte value to an output stream. The + * byte to be written will be in the lowest 8 bits of the + * <code>int</code> value passed. + * + * The value written can be read using the <code>readByte</code> or + * <code>readUnsignedByte</code> methods in <code>DataInput</code>. + * + * @param value The <code>byte</code> to write to the stream, passed as + * the low eight bits of an <code>int</code>. + * + * @exception IOException If an error occurs + */ + void writeByte(int value) + throws IOException; + + /** + * This method writes a Java short value to an output stream. The + * char to be written will be in the lowest 16 bits of the <code>int</code> + * value passed. + * + * @exception IOException If an error occurs + */ + void writeShort(int value) + throws IOException; + + /** + * This method writes a Java char value to an output stream. The + * char to be written will be in the lowest 16 bits of the <code>int</code> + * value passed. + * + * @exception IOException If an error occurs + */ + void writeChar(int value) + throws IOException; + + /** + * This method writes a Java int value to an output stream. + * + * @param value The <code>int</code> value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeInt(int value) + throws IOException; + + /** + * This method writes a Java long value to an output stream. + * + * @param value The <code>long</code> value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeLong(long value) + throws IOException; + + /** + * This method writes a Java <code>float</code> value to the stream. + * @param value The <code>float</code> value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeFloat(float value) + throws IOException; + + /** + * This method writes a Java <code>double</code> value to the stream. + * + * @param value The <code>double</code> value to write to the stream + * + * @exception IOException If an error occurs + */ + void writeDouble(double value) + throws IOException; +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java b/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java new file mode 100644 index 0000000..a719b32 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/aligningInputStream.java @@ -0,0 +1,122 @@ +/* aligningInputStream.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.CDR; + +import java.io.ByteArrayInputStream; + +import org.omg.CORBA.BAD_PARAM; + +/** + * The input stream with the possibility to align on the + * word (arbitrary size) boundary. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class aligningInputStream + extends ByteArrayInputStream +{ + /** + * The alignment offset. + */ + private int offset = 0; + + /** + * Create a stream, reading form the given buffer. + * + * @param a_buffer a buffer to read from. + */ + public aligningInputStream(byte[] a_buffer) + { + super(a_buffer); + } + + /** + * Create a stream, reading from the given buffer region. + * + * @param a_buffer a buffer to read from. + * @param offset the offset of the region. + * @param length thr length of the region. + */ + public aligningInputStream(byte[] a_buffer, int offset, int length) + { + super(a_buffer, offset, length); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + offset = an_offset; + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + * + * @throws BAD_PARAM, minor code 0, the alignment is not possible, + * usually due the wrong parameter value. + */ + public void align(int alignment) + { + try + { + int d = (pos + offset) % alignment; + if (d > 0) + { + skip(alignment - d); + } + } + catch (Exception ex) + { + BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); + p.initCause(ex); + throw p; + } + } + + /** + * Get the byte buffer, from where the data are read. + */ + public byte[] getBuffer() + { + return buf; + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java b/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java new file mode 100644 index 0000000..8a682c1 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/aligningOutputStream.java @@ -0,0 +1,121 @@ +/* aligningOutputStream.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.CDR; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.omg.CORBA.BAD_PARAM; + +/** + * The input stream with the possibility to align on the + * word (arbitrary size) boundary. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class aligningOutputStream + extends ByteArrayOutputStream +{ + /** + * The alignment offset. + */ + private int offset = 0; + + /** + * Create a stream with the default intial buffer size. + */ + public aligningOutputStream() + { + } + + /** + * Create a stream with the given intial buffer size. + */ + public aligningOutputStream(int initial_size) + { + super(initial_size); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + offset = an_offset; + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + * + * @throws BAD_PARAM, minor code 0, the alignment is not possible, + * usually due the wrong parameter value. + */ + public void align(int alignment) + { + try + { + int d = (count + offset) % alignment; + if (d > 0) + { + skip(alignment - d); + } + } + catch (Exception ex) + { + BAD_PARAM p = new BAD_PARAM("Unable to align at " + alignment); + p.initCause(ex); + throw p; + } + } + + /** + * Write the specified number of zero bytes. + * + * @param bytes the number of zero bytes to write. + */ + public void skip(int bytes) + { + for (int i = 0; i < bytes; i++) + { + write(0); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java b/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java new file mode 100644 index 0000000..3cab721 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/cdrBufInput.java @@ -0,0 +1,115 @@ +/* cdrBufInput.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.CDR; + + +/** + * The CDR input stream that reads data from the byte buffer. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * + * 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 class cdrBufInput + extends cdrInput +{ + /** + * The byte array input stream to read data from. + */ + public final aligningInputStream buffer; + + /** + * Creates the CDR input stream that reads from the given buffer + * array. + * + * @param a_buffer an array to read from. + */ + public cdrBufInput(byte[] a_buffer) + { + buffer = new aligningInputStream(a_buffer); + setInputStream(buffer); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int offset) + { + buffer.setOffset(offset); + } + + /** + * Skip several bytes, aligning the internal pointer on the + * selected boundary. + */ + public void align(int alignment) + { + buffer.align(alignment); + } + + /** + * Mark the current position. + * @param ahead + */ + public synchronized void mark(int ahead) + { + buffer.mark(ahead); + } + + /** + * Checks if marking is supported. + * @return + */ + public boolean markSupported() + { + return buffer.markSupported(); + } + + /** + * Resets the stream to the previously marked position. + */ + public void reset() + { + buffer.reset(); + setInputStream(buffer); + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java b/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java new file mode 100644 index 0000000..47f5f17 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/cdrBufOutput.java @@ -0,0 +1,115 @@ +/* cdrBufOutput.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.CDR; + +import java.io.ByteArrayOutputStream; + +/** + * A CORBA output stream, writing data into the internal + * buffer ({@link ByteArrayOutputStream}). + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class cdrBufOutput + extends cdrOutput +{ + /** + * The byte buffer. + */ + public final aligningOutputStream buffer; + + /** + * Creates the instance with the given initial buffer size. + * @param bufSize the buffer size. + */ + public cdrBufOutput(int bufSize) + { + buffer = new aligningOutputStream(bufSize); + setOutputStream(buffer); + } + + /** + * Creates the instance with the default buffer size. + */ + public cdrBufOutput() + { + buffer = new aligningOutputStream(); + setOutputStream(buffer); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + buffer.setOffset(an_offset); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public void align(int boundary) + { + buffer.align(boundary); + } + + /** + * Return the input stream that reads the previously written values. + */ + public org.omg.CORBA.portable.InputStream create_input_stream() + { + cdrBufInput in = new cdrBufInput(buffer.toByteArray()); + in.setOrb(orb); + + in.setVersion(giop); + in.setCodeSet(getCodeSet()); + + return in; + } + + /** + * Resets (clears) the buffer. + */ + public void reset() + { + buffer.reset(); + setOutputStream(buffer); + } +} diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrInput.java b/libjava/classpath/gnu/CORBA/CDR/cdrInput.java new file mode 100644 index 0000000..859f93a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/cdrInput.java @@ -0,0 +1,1671 @@ +/* cdrInput.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.CDR; + +import gnu.CORBA.BigDecimalHelper; +import gnu.CORBA.Functional_ORB; +import gnu.CORBA.GIOP.CharSets_OSF; +import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.IOR; +import gnu.CORBA.IOR_Delegate; +import gnu.CORBA.TypeCodeHelper; +import gnu.CORBA.Unexpected; +import gnu.CORBA.Version; +import gnu.CORBA.gnuAny; +import gnu.CORBA.stubFinder; + +import org.omg.CORBA.Any; +import org.omg.CORBA.AnySeqHolder; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.ShortSeqHolder; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.ObjectImpl; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Serializable; + +import java.math.BigDecimal; + +/** + * A simple CORBA CDR (common data representation) + * input stream, reading data from the + * given {@link java.io.InputStream}. The primitive types + * are aligned on they natural boundaries by implementing the + * abstract method {@link #align(int boundary)}. + * + * The same class also implements {@link org.omg.CORBA.DataInputStream} to + * read the object content in a user defined way. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class cdrInput + extends org.omg.CORBA_2_3.portable.InputStream + implements org.omg.CORBA.DataInputStream +{ + /** + * The message, explaining that the exception has been thrown due + * unexpected end of the input stream. This usually happens the + * server and client disagree on communication or data representation + * rules. + */ + protected static final String UNEXP_EOF = "Unexpected end of stream"; + + /** + * This instance is used to convert primitive data types into the + * byte sequences. + */ + protected abstractDataInputStream b; + + /** + * The input stream, from where the data are actually + * being read. + */ + protected java.io.InputStream actual_stream; + + /** + * The associated orb, if any. + */ + protected ORB orb; + + /** + * The GIOP version. + */ + protected Version giop = new Version(1, 2); + + /** + * The code set information. + */ + protected cxCodeSet codeset = cxCodeSet.STANDARD; + + /** + * The name of the currently used narrow charset, null if + * the native narrow charset is used. + */ + private String narrow_charset = null; + + /** + * The name of the currently used wide charset, null if + * the native wide charset is used. + */ + private String wide_charset = null; + + /** + * True if the native code set is used for narrow characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean narrow_native; + + /** + * True if the native code set is used for wide characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean wide_native; + + /** + * If true, the stream expect + * the multi-byte data in the form "less significant byte + * first" (Little Endian). This is the opposite to the + * java standard (Big Endian). + */ + private boolean little_endian; + + /** + * Creates the stream. The stream reads Big Endian by + * default. + * + * @param readFrom a stream to read CORBA input from. + */ + public cdrInput(java.io.InputStream readFrom) + { + setInputStream(readFrom); + setCodeSet(cxCodeSet.STANDARD); + } + + /** + * Creates the stream, requiring the subsequent call + * of {@link #setInputStream(java.io.InputStream)}. + */ + public cdrInput() + { + setCodeSet(cxCodeSet.STANDARD); + } + + /** + * Set the Big Endian or Little Endian encoding. + * The stream reads Big Endian by default. + * + * @param use_little_endian if true, the stream expect + * the multi-byte data in the form "less significant byte + * first" (Little Endian). This is the opposite to the + * java standard (Big Endian). + */ + public void setBigEndian(boolean use_big_endian) + { + little_endian = !use_big_endian; + setInputStream(actual_stream); + } + + /** + * Set the input stream that receives the CORBA input. + * + * @param readFrom the stream. + */ + public void setInputStream(java.io.InputStream readFrom) + { + if (little_endian) + b = new LittleEndianInputStream(readFrom); + else + b = new BigEndianInputStream(readFrom); + + actual_stream = readFrom; + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public abstract void setOffset(int offset); + + /** + * Set the orb, associated with this stream. + * @param an_orb + */ + public void setOrb(ORB an_orb) + { + orb = an_orb; + } + + /** + * Set the GIOP version. Some data types are written differently + * for the different versions. The default version is 1.0 . + */ + public void setVersion(Version giop_version) + { + giop = giop_version; + } + + /** + * Align the curretn position at the given natural boundary. + */ + public abstract void align(int boundary); + + /** + * Reads the CORBA unsigned long (java int), returning the + * value in the sufficiently large java long. + */ + public long gnu_read_ulong() + { + try + { + long l = b.readInt(); + l &= 0xFFFFFFF; + return l; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the unsigned short integer value and return it as java + * int, sufficiently large to hold all values. + */ + public int gnu_read_ushort() + { + try + { + align(2); + return b.readUnsignedShort(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Return the associated {@link ORB}. + * @return the associated {@link ORB} or null is no such is set. + */ + public ORB orb() + { + return orb; + } + + /** + * Read a single byte directly from the buffer. + */ + public int read() + throws java.io.IOException + { + try + { + return b.read(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + } + + /** + * Read bytes directly from the buffer. + */ + public int read(byte[] x, int ofs, int len) + throws java.io.IOException + { + try + { + return b.read(x, ofs, len); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + } + + /** + * Read bytes directly from the buffer. + */ + public int read(byte[] x) + throws java.io.IOException + { + try + { + return b.read(x); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + } + + /** + * Read the CORBA object. The object to read is represented in the + * form of the plain (not a string-encoded) IOR profile without the + * heading endian indicator. The responsible method for reading such + * data is {@link IOR.read_no_endian}. + * + * The returned object is usually casted into the given type using + * the .narrow method of its helper, despite in some cases the direct + * cast would also work. + * + * The null objects are recognised from the empty profile set. + * For such objects, null is returned. + * + * @return the loaded and constructed object. + */ + public org.omg.CORBA.Object read_Object() + { + try + { + IOR ior = new IOR(); + ior._read_no_endian(this); + + if (ior.Id == null) + return null; + + // Check maybe this is a remote reference to the local object. + // This is only possible if we access the repository of the + // connected object. + if (orb instanceof Functional_ORB) + { + Functional_ORB forb = (Functional_ORB) orb; + org.omg.CORBA.Object local = forb.find_local_object(ior); + if (local != null) + return local; + } + + // Search for the available stubs. + ObjectImpl impl = stubFinder.search(orb, ior); + try + { + if (impl._get_delegate() == null) + impl._set_delegate(new IOR_Delegate(orb, ior)); + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception + // in response to the attempt to get the unset delegate. + impl._set_delegate(new IOR_Delegate(orb, ior)); + } + + return impl; + } + catch (IOException ex) + { + BAD_OPERATION bad = new BAD_OPERATION(); + bad.initCause(ex); + throw bad; + } + } + + /** + * Read the type code. The type code format is defined in the + * CORBA documenation. + */ + public TypeCode read_TypeCode() + { + try + { + return TypeCodeHelper.read(this); + } + + catch (Bounds ex) + { + throw new Unexpected(); + } + catch (BadKind ex) + { + throw new Unexpected(); + } + } + + /** + * Read the CORBA {@link Any}. This method first reads the + * type code, then delegates the functionality + * to {@link Any#read_value}. + */ + public Any read_any() + { + TypeCode ty = read_TypeCode(); + gnuAny any = new gnuAny(); + any.read_value(this, ty); + return any; + } + + /** + * Read the boolean, treating any non zero byte as true, + * zero byte as false. + */ + public boolean read_boolean() + { + try + { + return b.read() == 0 ? false : true; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the array of boolean. + */ + public void read_boolean_array(boolean[] x, int offs, int len) + { + try + { + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.read() == 0 ? false : true; + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a character using narrow charset encoding. Depending form + * which encoding is set, this still can be Unicode or ever wider. + */ + public char read_char() + { + try + { + if (narrow_native) + return (char) b.read(); + else + return (char) new InputStreamReader((InputStream) b, narrow_charset).read(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a character array, using narrow charset encoding. + */ + public void read_char_array(char[] x, int offset, int length) + { + try + { + if (narrow_native) + { + for (int i = offset; i < offset + length; i++) + x [ i ] = (char) b.read(); + } + else + { + InputStreamReader reader = + new InputStreamReader((InputStream) b, narrow_charset); + reader.read(x, offset, length); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the double value, IEEE 754 format. + */ + public double read_double() + { + try + { + align(8); + return b.readDouble(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(); + } + } + + /** + * Read the array of double values, IEEE 754 format. + */ + public void read_double_array(double[] x, int offs, int len) + { + try + { + align(8); + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.readDouble(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the encapsulated stream. + * If the encapsulated sequence appears to be in the + * Little endian format, the flag of the returned stream + * is set to read Little endian. + */ + public cdrBufInput read_encapsulation() + { + try + { + int l = read_long(); + + byte[] r = new byte[ l ]; + int n = 0; + reading: + while (n < r.length) + { + n += read(r, n, r.length - n); + } + + cdrBufInput capsule = new cdrBufInput(r); + capsule.setOrb(orb); + + int endian = capsule.read_octet(); + + if (endian != 0) + { + capsule.setBigEndian(false); + } + + return capsule; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA fixed (the end of the <code>fixed</code> + * can be determined by its last byte). The scale is always + * assumed to be zero. + */ + public BigDecimal read_fixed() + { + try + { + return BigDecimalHelper.read(this, 0); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the float value, IEEE 754 format. + */ + public float read_float() + { + try + { + align(4); + return b.readFloat(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of float values, IEEE 754 format. + */ + public void read_float_array(float[] x, int offs, int len) + { + try + { + align(4); + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.readFloat(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA long (java int), high byte first. + */ + public int read_long() + { + try + { + align(4); + return b.readInt(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of CORBA longs (java ints). + */ + public void read_long_array(int[] x, int offs, int len) + { + try + { + align(4); + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.readInt(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA long long (java long). + */ + public long read_longlong() + { + try + { + align(8); + return b.readLong(); + } + catch (EOFException ex) + { + throw new MARSHAL(UNEXP_EOF); + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read an array of CORBA long longs (java longs). + */ + public void read_longlong_array(long[] x, int offs, int len) + { + try + { + align(8); + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.readLong(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a single byte. + */ + public byte read_octet() + { + try + { + return b.readByte(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the byte array. + */ + public void read_octet_array(byte[] x, int offs, int len) + { + try + { + b.read(x, offs, len); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the length of the byte array as CORBA long and then + * the array itseld. + */ + public byte[] read_sequence() + { + try + { + int l = read_long(); + byte[] b = new byte[ l ]; + if (l > 0) + { + read(b); + } + return b; + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the CORBA short integer. + */ + public short read_short() + { + try + { + align(2); + return b.readShort(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read the array of CORBA short integer values. + */ + public void read_short_array(short[] x, int offs, int len) + { + try + { + align(2); + for (int i = offs; i < offs + len; i++) + { + x [ i ] = b.readShort(); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Read a singe byte string. The method firs reads the + * byte array and then calls a constructor to create a + * string from this array. The character encoding, if + * previously set, is taken into consideration. + * + * @return a loaded string. + */ + public String read_string() + { + try + { + align(4); + + int n = b.readInt(); + byte[] s = new byte[ n ]; + b.read(s); + + // Discard the null terminator. + if (narrow_charset == null) + return new String(s, 0, n - 1); + else + return new String(s, 0, n - 1, narrow_charset); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(); + } + } + + /** + * Reads the CORBA unsigned long (java int), delegating + * functionality to {@link #read_long}. + */ + public int read_ulong() + { + return read_long(); + } + + /** + * Reads the array of CORBA unsigned long (java integer) values, + * delegating functionality to + * {@link #real_long_array}. + */ + public void read_ulong_array(int[] x, int offs, int len) + { + read_long_array(x, offs, len); + } + + /** + * Read the CORBA unsigned long long value, + * delegating functionality to {@link #read_longlong}. + * There is no way to return values over the limit of + * the java signed long in other way than returning + * the negative value. + */ + public long read_ulonglong() + { + return read_longlong(); + } + + /** + * Reads the array of CORBA long long (java long) values, + * delegating functionality to + * {@link #real_longlong_array}. + */ + public void read_ulonglong_array(long[] x, int offs, int len) + { + read_longlong_array(x, offs, len); + } + + /** + * Read the unsigned short integer value. Due strange specification, + * the returned value must be the short type as well, so the + * the best solution seems just to delegete functionality to + * read_short. + */ + public short read_ushort() + { + return read_short(); + } + + /** + * Read an array of unsigned short values, delegating the + * functionality to {@link read_short_array}. + */ + public void read_ushort_array(short[] x, int offs, int len) + { + read_short_array(x, offs, len); + } + + /** + * Reads the wide character using the encoding, specified in the + * wide_charset. + */ + public char read_wchar() + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + return (char) b.readShort(); + else + return (char) new InputStreamReader((InputStream) b, wide_charset).read(); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + catch (IOException ex) + { + throw new Unexpected(); + } + } + + /** + * Read an array of "wide chars", each representing a two byte + * Unicode character, high byte first. + */ + public void read_wchar_array(char[] x, int offset, int length) + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + { + for (int i = offset; i < offset + length; i++) + x [ i ] = (char) b.readShort(); + } + else + { + InputStreamReader reader = + new InputStreamReader((InputStream) b, wide_charset); + reader.read(x, offset, length); + } + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Reads the string in wide character format + * (ussually UTF-16, Unicode). Takes the currently set charset + * into consideration. + * + * If the native (UTF-16) encoding is used + * of the GIOP protocol is before 1.2, delegates functionality + * to "plain" {@link #read_wstring_UTF_16}. + */ + public String read_wstring() + { + // Native encoding or word oriented data. + if (wide_native || giop.until_inclusive(1, 1)) + return read_wstring_UTF_16(); + try + { + align(4); + + int n = b.readInt(); + byte[] s = new byte[ n ]; + b.read(s); + + return new String(s, 0, n, wide_charset); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Reads first length of the string and the all characters as an + * Unicode (UTF-16) characters. Mind that GIOP 1.1 has the extra + * null character at the end that must be discarded. + */ + public String read_wstring_UTF_16() + { + try + { + int p = 0; + int n = read_long(); + + // The null terminator that is no longer present since 1.2 . + int nt = giop.since_inclusive(1, 2) ? 0 : 1; + + // Convert bytes to shorts. + n = n / 2; + + char[] s = new char[ n ]; + + for (int i = 0; i < s.length; i++) + s [ i ] = (char) b.readShort(); + + // Check for the byte order marker here. + if (s [ 0 ] == 0xFEFF) + { + // Big endian encoding - do nothing, but move the pointer + // one position forward. + p = 1; + } + else if (s [ 0 ] == 0xFFFE) + { + // Little endian encoding, swap the bytes and move one + // position forward. + p = 1; + + for (int i = p; i < s.length; i++) + s [ i ] = swap(s [ i ]); + } + + // Discard the null terminator and, if needed, the endian marker. + return new String(s, p, n - nt - p); + } + catch (EOFException ex) + { + MARSHAL t = new MARSHAL(UNEXP_EOF); + t.initCause(ex); + throw t; + } + + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Swap bytes in the character. + */ + public static char swap(char x) + { + int hi; + int lo; + + lo = x & 0xFF; + hi = (x >> 8) & 0xFF; + + return (char) ((lo << 8) | hi); + } + + /** + * Set the current code set context. + */ + public void setCodeSet(cxCodeSet a_codeset) + { + this.codeset = a_codeset; + narrow_charset = CharSets_OSF.getName(codeset.char_data); + wide_charset = CharSets_OSF.getName(codeset.wide_char_data); + + narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; + wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; + } + + /** + * Get the current code set context. + */ + public cxCodeSet getCodeSet() + { + return codeset; + } + + /** + * Read the object that is an instance of the given class. The current + * implementation delegates functionality to the parameterless + * {@link readObject()}. + * + * @param klass a class of that this object the instance is. + * + * @return the returned object. + */ + public org.omg.CORBA.Object read_Object(Class klass) + { + return read_Object(); + } + + /** + * Read a value type structure from the stream. + * + * OMG specification states the writing format is outside the scope + * of GIOP definition. This implementation uses java serialization + * mechanism, calling {@link ObjectInputStream#readObject} + * + * @return an value type structure, unmarshaled from the stream + */ + public Serializable read_Value() + { + return read_value(); + } + + /** + * Read the abstract interface. An abstract interface can be either + * CORBA value type or CORBA object and is returned as an abstract + * java.lang.Object. + * + * As specified in OMG specification, this reads a single + * boolean and then delegates either to {@link #read_Object()} (for false) + * or to {@link #read_Value()} (for true). + * + * @return an abstract interface, unmarshaled from the stream + */ + public java.lang.Object read_Abstract() + { + return read_abstract_interface(); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_char_array(CharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_char_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_wchar_array(WCharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_wchar_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the char array to fit the newly + * read values. + * + * @param holder_value the existing char array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private char[] ensureArray(char[] holder_value, int offset, int length) + { + if (holder_value == null) + return new char[ offset + length ]; + else if (holder_value.length < offset + length) + { + char[] value = new char[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_ulong_array(ULongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_long_array(LongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the int array to fit the newly + * read values. + * + * @param holder_value the existing int array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private int[] ensureArray(int[] holder_value, int offset, int length) + { + if (holder_value == null) + return new int[ offset + length ]; + else if (holder_value.length < offset + length) + { + int[] value = new int[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_float_array(FloatSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_float_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the float array to fit the newly + * read values. + * + * @param holder_value the existing float array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private float[] ensureArray(float[] holder_value, int offset, int length) + { + if (holder_value == null) + return new float[ offset + length ]; + else if (holder_value.length < offset + length) + { + float[] value = new float[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_double_array(DoubleSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_double_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the double array to fit the newly + * read values. + * + * @param holder_value the existing double array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private double[] ensureArray(double[] holder_value, int offset, int length) + { + if (holder_value == null) + return new double[ offset + length ]; + else if (holder_value.length < offset + length) + { + double[] value = new double[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_short_array(ShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_short_array(holder.value, offset, length); + } + + /** {@inheritDoc} */ + public void read_ushort_array(UShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ushort_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the short array to fit the newly + * read values. + * + * @param holder_value the existing short array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private short[] ensureArray(short[] holder_value, int offset, int length) + { + if (holder_value == null) + return new short[ offset + length ]; + else if (holder_value.length < offset + length) + { + short[] value = new short[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_octet_array(OctetSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_octet_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the byte array to fit the newly + * read values. + * + * @param holder_value the existing byte array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private byte[] ensureArray(byte[] holder_value, int offset, int length) + { + if (holder_value == null) + return new byte[ offset + length ]; + else if (holder_value.length < offset + length) + { + byte[] value = new byte[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_longlong_array(LongLongSeqHolder holder, int offset, + int length + ) + { + holder.value = ensureArray(holder.value, offset, length); + read_longlong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_ulonglong_array(ULongLongSeqHolder holder, int offset, + int length + ) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulonglong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of longs to fit the newly + * read values. + * + * @param holder_value the existing array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private long[] ensureArray(long[] holder_value, int offset, int length) + { + if (holder_value == null) + return new long[ offset + length ]; + else if (holder_value.length < offset + length) + { + long[] value = new long[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_boolean_array(BooleanSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_boolean_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of booleans to fit the newly + * read values. + * + * @param holder_value the existing array of booleans, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private boolean[] ensureArray(boolean[] holder_value, int offset, int length) + { + if (holder_value == null) + return new boolean[ offset + length ]; + else if (holder_value.length < offset + length) + { + boolean[] value = new boolean[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_any_array(AnySeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + for (int i = offset; i < offset + length; i++) + { + holder.value [ i ] = read_any(); + } + } + + /** + * If required, allocate or resize the array of Anys to fit the newly + * read values. + * + * @param holder_value the existing array of Anys, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private Any[] ensureArray(Any[] holder_value, int offset, int length) + { + if (holder_value == null) + return new Any[ offset + length ]; + else if (holder_value.length < offset + length) + { + Any[] value = new Any[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * This method is required to represent the DataInputStream as a value + * type object. + * + * @return a single entity "IDL:omg.org/CORBA/DataInputStream:1.0", + * always. + */ + public String[] _truncatable_ids() + { + return new String[] { "IDL:omg.org/CORBA/DataInputStream:1.0" }; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java b/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java new file mode 100644 index 0000000..86ca3b1 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/cdrOutput.java @@ -0,0 +1,999 @@ +/* cdrOutput.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.CDR; + +import gnu.CORBA.BigDecimalHelper; +import gnu.CORBA.GIOP.CharSets_OSF; +import gnu.CORBA.GIOP.cxCodeSet; +import gnu.CORBA.IOR; +import gnu.CORBA.Simple_delegate; +import gnu.CORBA.TypeCodeHelper; +import gnu.CORBA.Unexpected; +import gnu.CORBA.Version; +import gnu.CORBA.primitiveTypeCode; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Serializable; + +import java.math.BigDecimal; + +/** + * A simple CORBA CDR (common data representation) + * output stream, writing data into the + * given {@link java.io.OutputStream}. + * + * The same class also implements the {@link DataInputStream}, + * providing support for writing the value type objects + * in a user defined way. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public abstract class cdrOutput + extends org.omg.CORBA_2_3.portable.OutputStream + implements org.omg.CORBA.DataOutputStream +{ + /** + * This instance is used to convert primitive data types into the + * byte sequences. + */ + protected abstractDataOutputStream b; + + /** + * The associated orb, if any. + */ + protected ORB orb; + + /** + * The GIOP version. + */ + protected Version giop = new Version(1, 0); + + /** + * The code set information. + */ + protected cxCodeSet codeset; + + /** + * The name of the currently used narrow charset. + */ + private String narrow_charset; + + /** + * The name of the currently used wide charset, null if + * the native wide charset is used. + */ + private String wide_charset; + + /** + * True if the native code set is used for narrow characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean narrow_native; + + /** + * True if the native code set is used for wide characters. + * If the set is native, no the intermediate Reader object + * is instantiated when writing characters. + */ + private boolean wide_native; + + /** + * If true, the Little Endian encoding is used to write the + * data. Otherwise, the Big Endian encoding is used. + */ + private boolean little_endian; + + /** + * The stream whre the data are actually written. + */ + private java.io.OutputStream actual_stream; + + /** + * Creates the stream. + * + * @param writeTo a stream to write CORBA output to. + */ + public cdrOutput(java.io.OutputStream writeTo) + { + setOutputStream(writeTo); + setCodeSet(cxCodeSet.STANDARD); + } + + /** + * Creates the stream, requiring the subsequent call + * of {@link #setOutputStream(java.io.OutputStream)}. + */ + public cdrOutput() + { + setCodeSet(cxCodeSet.STANDARD); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public abstract void setOffset(int an_offset); + + /** + * Set the current code set context. + */ + public void setCodeSet(cxCodeSet a_codeset) + { + this.codeset = a_codeset; + narrow_charset = CharSets_OSF.getName(codeset.char_data); + wide_charset = CharSets_OSF.getName(codeset.wide_char_data); + + narrow_native = CharSets_OSF.NATIVE_CHARACTER == codeset.char_data; + wide_native = CharSets_OSF.NATIVE_WIDE_CHARACTER == codeset.wide_char_data; + } + + /** + * Get the current code set context. + */ + public cxCodeSet getCodeSet() + { + return codeset; + } + + /** + * Set the orb, associated with this stream. + * @param an_orb + */ + public void setOrb(ORB an_orb) + { + orb = an_orb; + } + + /** + * Set the output stream that receives the CORBA output. + * + * @param writeTo the stream. + */ + public void setOutputStream(java.io.OutputStream writeTo) + { + if (little_endian) + b = new LittleEndianOutputStream(writeTo); + else + b = new BigEndianOutputStream(writeTo); + + actual_stream = writeTo; + } + + /** + * Set the GIOP version. Some data types are written differently + * for the different versions. The default version is 1.0 . + */ + public void setVersion(Version giop_version) + { + giop = giop_version; + } + + /** + * Specify if the stream should use the Big Endian (usual for java) + * or Little Encoding. The default is Big Endian. + * + * @param use_big_endian if true, use Big Endian, if false, + * use Little Endian. + */ + public void setBigEndian(boolean use_big_endian) + { + little_endian = !use_big_endian; + setOutputStream(actual_stream); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public abstract void align(int boundary); + + /** + * Create the encapsulation stream, associated with the current + * stream. The encapsulated stream must be closed. When being + * closed, the encapsulation stream writes its buffer into + * this stream using the CORBA CDR encapsulation rules. + * + * It is not allowed to write to the current stream directly + * before the encapsulation stream is closed. + * + * The encoding (Big/Little Endian) inside the encapsulated + * sequence is the same as used into the parent stream. + * + * @return the encapsulated stream. + */ + public cdrOutput createEncapsulation() + { + return new encapsulatedOutput(this, !little_endian); + } + + /** + * Return the associated {@link ORB}. + * @return the associated {@link ORB} or null is no such is set. + */ + public ORB orb() + { + return orb; + } + + /** + * Write a single byte. + * @param a byte to write (low 8 bits are written). + */ + public void write(int n) + { + try + { + b.write(n); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Write bytes directly into the underlying stream. + */ + public void write(byte[] x) + throws java.io.IOException + { + b.write(x); + } + + /** + * Write bytes directly into the underlying stream. + */ + public void write(byte[] x, int ofs, int len) + throws java.io.IOException + { + b.write(x, ofs, len); + } + + /** + * Following the specification, this is not implemented. + * Override to get the functionality. + */ + public void write_Context(Context context, ContextList contexts) + { + throw new NO_IMPLEMENT(); + } + + /** + * Read the CORBA object. The object is written + * form of the plain (not a string-encoded) IOR profile without the + * heading endian indicator. The responsible method for reading such + * data is {@link IOR.write_no_endian}. + * + * The null value is written as defined in OMG specification + * (zero length string, followed by an empty set of profiles). + */ + public void write_Object(org.omg.CORBA.Object x) + { + if (x == null) + { + IOR.write_null(this); + return; + } + else if (x instanceof ObjectImpl) + { + Delegate d = ((ObjectImpl) x)._get_delegate(); + + if (d instanceof Simple_delegate) + { + Simple_delegate ido = (Simple_delegate) d; + ido.getIor()._write_no_endian(this); + return; + } + } + + // Either this is not an ObjectImpl or it has the + // unexpected delegate. Try to convert via ORBs + // object_to_string(). + if (orb != null) + { + IOR ior = IOR.parse(orb.object_to_string(x)); + ior._write_no_endian(this); + return; + } + else + throw new BAD_OPERATION("Please set the ORB for this stream."); + } + + /** + * Write the TypeCode. This implementation delegates functionality + * to {@link cdrTypeCode}. + * + * @param x a TypeCode to write. + */ + public void write_TypeCode(TypeCode x) + { + try + { + TypeCodeHelper.write(this, x); + } + catch (UserException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes an instance of the CORBA {@link Any}. + * This method writes the typecode, followed + * by value itself. In Any contains null + * (value not set), the {@link TCKind#tk_null} + * is written. + * + * @param x the {@link Any} to write. + */ + public void write_any(Any x) + { + Streamable value = x.extract_Streamable(); + if (value != null) + { + write_TypeCode(x.type()); + value._write(this); + } + else + { + primitiveTypeCode p = new primitiveTypeCode(TCKind.tk_null); + write_TypeCode(p); + } + } + + /** + * Writes a single byte, 0 for <code>false</code>, + * 1 for <code>true</code>. + * + * @param x the value to write + */ + public void write_boolean(boolean x) + { + try + { + b.write(x ? 1 : 0); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the boolean array. + * + * @param x array + * @param ofs offset + * @param len length. + */ + public void write_boolean_array(boolean[] x, int ofs, int len) + { + try + { + for (int i = ofs; i < ofs + len; i++) + { + b.write(x [ i ] ? 1 : 0); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the lower byte of the passed parameter. + * @param x the char to write + * + * It is effective to write more characters at once. + */ + public void write_char(char x) + { + try + { + if (narrow_native) + b.write(x); + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, narrow_charset); + ow.write(x); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the lower bytes of the passed array members. + * + * @param chars an array + * @param offsets offset + * @param length length + */ + public void write_char_array(char[] chars, int offset, int length) + { + try + { + if (narrow_native) + { + for (int i = offset; i < offset + length; i++) + { + b.write(chars [ i ]); + } + } + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, narrow_charset); + ow.write(chars, offset, length); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the double value (IEEE 754 format). + */ + public void write_double(double x) + { + try + { + align(8); + b.writeDouble(x); + } + catch (Exception ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of double values. + */ + public void write_double_array(double[] x, int ofs, int len) + { + try + { + align(8); + for (int i = ofs; i < ofs + len; i++) + { + b.writeDouble(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes CORBA fixed, storing all digits but not the scale. + * The end of the record on <code>fixed</code> can + * be determined from its last byte. + */ + public void write_fixed(BigDecimal fixed) + { + try + { + BigDecimalHelper.write(this, fixed); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + catch (BadKind ex) + { + Unexpected.error(ex); + } + } + + /** + * Write the float value (IEEE 754 format). + */ + public void write_float(float x) + { + try + { + align(4); + b.writeFloat(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes an array of the float values. + */ + public void write_float_array(float[] x, int ofs, int len) + { + try + { + align(4); + for (int i = ofs; i < ofs + len; i++) + { + b.writeFloat(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the integer value (CORBA long, four bytes, high byte first). + * @param x the value to write. + */ + public void write_long(int x) + { + try + { + align(4); + b.writeInt(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of integer (CORBA long) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_long_array(int[] x, int ofs, int len) + { + try + { + align(4); + for (int i = ofs; i < ofs + len; i++) + { + b.writeInt(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the long (CORBA long long) value, 8 bytes, + * high byte first. + * + * @param x the value to write. + */ + public void write_longlong(long x) + { + try + { + align(8); + b.writeLong(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of longs (CORBA long longs) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_longlong_array(long[] x, int ofs, int len) + { + try + { + align(8); + for (int i = ofs; i < ofs + len; i++) + { + b.writeLong(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes this byte. + * @param x + */ + public void write_octet(byte x) + { + try + { + b.writeByte(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of bytes (CORBA octets) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_octet_array(byte[] x, int ofs, int len) + { + try + { + b.write(x, ofs, len); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes first the size of array, and then the byte array using + * the {@link java.io.OutputStream#write(byte[]) }. The sequence + * being written is preceeded by the int, representing the array + * length. + */ + public void write_sequence(byte[] buf) + { + try + { + write_long(buf.length); + write(buf); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.initCause(ex); + throw t; + } + } + + /** + * Writes the contents of the provided stream. + * The sequence being written is preceeded by the int, + * representing the stream buffer length (the number of + * bytes being subsequently written). + */ + public void write_sequence(cdrBufOutput from) + { + try + { + write_long(from.buffer.size()); + from.buffer.writeTo(this); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.initCause(ex); + throw t; + } + } + + /** + * Writes the two byte integer (short), high byte first. + * + * @param x the integer to write. + */ + public void write_short(short x) + { + try + { + align(2); + b.writeShort(x); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the array of short (two byte integer) values. + * + * @param x value + * @param ofs offset + * @param len length + */ + public void write_short_array(short[] x, int ofs, int len) + { + try + { + align(2); + for (int i = ofs; i < ofs + len; i++) + { + b.writeShort(x [ i ]); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the string. This implementation first calls + * String.getBytes() and then writes the length of the returned + * array (as CORBA ulong) and the returned array itself. + * + * The encoding information, if previously set, is taken + * into consideration. + * + * @param x the string to write. + */ + public void write_string(String x) + { + try + { + byte[] ab = x.getBytes(narrow_charset); + write_long(ab.length + 1); + write(ab); + + // write null terminator. + write(0); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the CORBA unsigned long in the same way as CORBA long. + */ + public void write_ulong(int x) + { + write_long(x); + } + + /** + * Writes the array of CORBA unsigned longs in the same way as + * array of ordinary longs. + */ + public void write_ulong_array(int[] x, int ofs, int len) + { + write_long_array(x, ofs, len); + } + + /** + * Write the unsigned long long in the same way as an ordinary long long. + * + * @param x a value to write. + */ + public void write_ulonglong(long x) + { + write_longlong(x); + } + + /** + * Write the array of unsingel long longs in the same way + * an an array of the ordinary long longs. + */ + public void write_ulonglong_array(long[] x, int ofs, int len) + { + write_longlong_array(x, ofs, len); + } + + /** + * Write the unsigned short in the same way as an ordinary short. + */ + public void write_ushort(short x) + { + write_short(x); + } + + /** + * Write an array of unsigned short integersin the same way + * as an array of ordinary short integers. + */ + public void write_ushort_array(short[] x, int ofs, int len) + { + write_short_array(x, ofs, len); + } + + /** + * Writes the character as two byte short integer (Unicode value), + * high byte first. Writes in Big Endian, but never writes the + * endian indicator. + * + * The character is always written using the native UTF-16BE charset + * because its size under arbitrary encoding is not evident. + */ + public void write_wchar(char x) + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + b.writeShort(x); + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, wide_charset); + ow.write(x); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Write the array of wide chars. + * + * @param chars the array of wide chars + * @param offset offset + * @param length length + * + * The char array is always written using the native UTF-16BE charset + * because the character size under arbitrary encoding is not evident. + */ + public void write_wchar_array(char[] chars, int offset, int length) + { + try + { + if (giop.until_inclusive(1, 1)) + align(2); + + if (wide_native) + { + for (int i = offset; i < offset + length; i++) + { + b.writeShort(chars [ i ]); + } + } + else + { + OutputStreamWriter ow = + new OutputStreamWriter((OutputStream) b, wide_charset); + ow.write(chars, offset, length); + ow.flush(); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Writes the length of the string in bytes (not characters) and + * then all characters as two byte unicode chars. Adds the + * Big Endian indicator, 0xFFFE, at the beginning and null wide char at + * the end. + * + * @param x the string to write. + */ + public void write_wstring(String x) + { + try + { + if (giop.since_inclusive(1, 2)) + { + byte[] bytes = x.getBytes(wide_charset); + write_sequence(bytes); + } + else + { + // Encoding with null terminator always in UTF-16. + // The wide null terminator needs extra two bytes. + write_long(2 * x.length() + 2); + + for (int i = 0; i < x.length(); i++) + { + b.writeShort(x.charAt(i)); + } + + // Write null terminator. + b.writeShort(0); + } + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** {@inheritDoc} */ + public void write_any_array(Any[] anys, int offset, int length) + { + for (int i = offset; i < offset + length; i++) + { + write_any(anys [ i ]); + } + } + + public String[] _truncatable_ids() + { + /**@todo Implement this org.omg.CORBA.portable.ValueBase abstract method*/ + throw new java.lang.UnsupportedOperationException("Method _truncatable_ids() not yet implemented."); + } + + /** {@inheritDoc} */ + public void write_Abstract(java.lang.Object value) + { + write_Abstract(value); + } + + /** {@inheritDoc} */ + public void write_Value(Serializable value) + { + write_Value(value); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java b/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java new file mode 100644 index 0000000..3350291 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/encapsulatedOutput.java @@ -0,0 +1,146 @@ +/* EncapsulationOutput.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.CDR; + +import java.io.IOException; + +/** + * The encapsulated data, as they are defined by CORBA specification. + * This includes the extra 0 byte (Big endian) in the beginning. + * When written to the parent steam, the encapsulated data are preceeded + * by the data length in bytes. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class encapsulatedOutput + extends cdrOutput +{ + /** + * The Big Endian (most siginificant byte first flag). + */ + public static final byte BIG_ENDIAN = 0; + + /** + * The Little Endian (least siginificant byte first flag). + */ + public static final byte LITTLE_ENDIAN = 1; + + /** + * The byte buffer. + */ + public final aligningOutputStream buffer; + + /** + * The stream, where the data are being encapsulated. + */ + public final org.omg.CORBA.portable.OutputStream parent; + + /** + * Create the EncapsulationOutput with the given parent stream + * and the specified encoding. + */ + public encapsulatedOutput(org.omg.CORBA.portable.OutputStream _parent, + boolean use_big_endian) + { + super(); + buffer = new aligningOutputStream(); + setOutputStream(buffer); + parent = _parent; + write(use_big_endian?BIG_ENDIAN:LITTLE_ENDIAN); + } + + /** + * Set the alignment offset, if the index of the first byte in the + * stream is different from 0. + */ + public void setOffset(int an_offset) + { + buffer.setOffset(an_offset); + } + + /** + * Align the curretn position at the given natural boundary. + */ + public void align(int boundary) + { + buffer.align(boundary); + } + + /** + * Writes the content of the encapsulated output into the parent + * buffer. + */ + public void close() + { + try + { + parent.write_long(buffer.size()); + buffer.writeTo(parent); + } + catch (IOException ex) + { + InternalError err = new InternalError(); + err.initCause(ex); + throw err; + } + } + + /** + * Return the input stream that reads the previously written values. + */ + public org.omg.CORBA.portable.InputStream create_input_stream() + { + cdrBufInput in = new cdrBufInput(buffer.toByteArray()); + in.setOrb(orb); + + in.setVersion(giop); + in.setCodeSet(getCodeSet()); + + return in; + } + + /** + * Resets (clears) the buffer. + */ + public void reset() + { + buffer.reset(); + setOutputStream(buffer); + } +} diff --git a/libjava/classpath/gnu/CORBA/Connected_objects.java b/libjava/classpath/gnu/CORBA/Connected_objects.java new file mode 100644 index 0000000..30d15e7 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Connected_objects.java @@ -0,0 +1,231 @@ +/* Connected_objects.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; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * The repository of objects, that have been connected to the + * {@link FunctionalORB} by the method + * {@link ORB.connect(org.omg.CORBA.Object)}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Connected_objects +{ + /** + * The reference data about the connected object. + */ + public class cObject + { + /** + * Create an initialised instance. + */ + cObject(org.omg.CORBA.Object _object, int _port, byte[] _key) + { + object = _object; + port = _port; + key = _key; + } + + /** + * The object. + */ + public final org.omg.CORBA.Object object; + + /** + * The port on that the object is connected. + */ + public final int port; + + /** + * The object key. + */ + public final byte[] key; + + public boolean equals(java.lang.Object other) + { + if (other instanceof cObject) + { + cObject o = (cObject) other; + return o.object.equals(object) && o.port == port; + } + else + return false; + } + } + + /** + * The free number to give for the next instance. + * This field is incremented each time the + * new collection of the connected objects is created. + * Each collection has its own unique instance number. + */ + private static long free_object_number; + + /** + * The map of the all connected objects, maps the object key to the + * object. + */ + private Map objects = new TreeMap(new ByteArrayComparator()); + + /** + * Get the record of the stored object. + * + * @param object the stored object + * + * @return the record about the stored object, null if + * this object is not stored here. + */ + public cObject getKey(org.omg.CORBA.Object stored_object) + { + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + cObject ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (cObject) item.getValue(); + if (stored_object.equals(ref.object)) + return ref; + } + return null; + } + + /** + * Add the new object to the repository. The object key is + * generated automatically. + * + * @param object the object to add. + * @param port, on that the ORB will be listening to the remote + * invocations. + * + * @return the newly created object record. + */ + public cObject add(org.omg.CORBA.Object object, int port) + { + return add(generateObjectKey(object), object, port); + } + + /** + * Add the new object to the repository. + * + * @param key the object key. + * @param object the object to add. + * @param port the port, on that the ORB will be listening on the + * remote invocations. + */ + public cObject add(byte[] key, org.omg.CORBA.Object object, int port) + { + cObject rec = new cObject(object, port, key); + objects.put(key, rec); + return rec; + } + + /** + * Get the stored object. + * + * @param key the key (in the byte array form). + * + * @return the matching object, null if none is matching. + */ + public cObject get(byte[] key) + { + return (cObject) objects.get(key); + } + + /** + * Get the map entry set. + * @return + */ + public Set entrySet() + { + return objects.entrySet(); + } + + /** + * Remove the given object. + * + * @param object the object to remove. + */ + public void remove(org.omg.CORBA.Object object) + { + cObject ref = getKey(object); + if (ref != null) + objects.remove(ref.key); + } + + /** + * Remove the given object, indiciating it by the key. + * + * @param object the object to remove. + */ + public void remove(byte[] key) + { + objects.remove(key); + } + + /** + * Generate the object key, unique in the currently + * running java virtual machine. + * + * The generated key includes the object class name + * and the absolute instance number. + * + * @return the generated key. + */ + protected byte[] generateObjectKey(org.omg.CORBA.Object object) + { + return (object.getClass().getName() + ":" + getFreeInstanceNumber()).getBytes(); + } + + /** + * Get next free instance number. + */ + private static synchronized long getFreeInstanceNumber() + { + long instance_number = free_object_number; + free_object_number++; + return instance_number; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DefinitionKindHolder.java b/libjava/classpath/gnu/CORBA/DefinitionKindHolder.java new file mode 100644 index 0000000..1ef7350 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DefinitionKindHolder.java @@ -0,0 +1,91 @@ +/* DefinitionKindHolder.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; + +import org.omg.CORBA.DefinitionKind; +import org.omg.CORBA.DefinitionKindHelper; + + +/** + * The definition kind holder. This class is not included in the original + * API specification, so we place it outside the org.omg namespace. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class DefinitionKindHolder + implements org.omg.CORBA.portable.Streamable +{ + /** + * The stored value. + */ + public DefinitionKind value; + + /** + * Create the initialised instance. + * @param initialValue + */ + public DefinitionKindHolder(DefinitionKind initialValue) + { + value = initialValue; + } + + /** + * Read from the CDR stream. + */ + public void _read(org.omg.CORBA.portable.InputStream in) + { + value = DefinitionKindHelper.read(in); + } + + /** + * Get the typecode. + */ + public org.omg.CORBA.TypeCode _type() + { + return DefinitionKindHelper.type(); + } + + /** + * Write into the CDR stream. + */ + public void _write(org.omg.CORBA.portable.OutputStream out) + { + DefinitionKindHelper.write(out, value); + } +} diff --git a/libjava/classpath/gnu/CORBA/DuplicateNameHolder.java b/libjava/classpath/gnu/CORBA/DuplicateNameHolder.java new file mode 100644 index 0000000..ad004bc --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DuplicateNameHolder.java @@ -0,0 +1,106 @@ +/* DuplicateNameHolder.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; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName; +import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateNameHelper; + +/** +* A holder for the exception {@link DuplicateName}. + +* @author Audrius Meskauskas, Lithiania (AudriusA@Bioinformatics.org) +*/ +public class DuplicateNameHolder + implements Streamable +{ + /** + * The stored DuplicateName value. + */ + public DuplicateName value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public DuplicateNameHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public DuplicateNameHolder(DuplicateName initialValue) + { + value = initialValue; + } + + /** + * Fill in the {@link value} by data from the CDR stream. + * + * @param input the org.omg.CORBA.portable stream to read. + */ + public void _read(InputStream input) + { + value = DuplicateNameHelper.read(input); + } + + /** + * Write the stored value into the CDR stream. + * + * @param output the org.omg.CORBA.portable stream to write. + */ + public void _write(OutputStream output) + { + DuplicateNameHelper.write(output, value); + } + + /** + * Get the typecode of the DuplicateName. + */ + public TypeCode _type() + { + return DuplicateNameHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/NameValuePairHolder.java b/libjava/classpath/gnu/CORBA/DynAn/NameValuePairHolder.java new file mode 100644 index 0000000..7afc81c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/NameValuePairHolder.java @@ -0,0 +1,95 @@ +/* NameValuePairHolder.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.DynAn; + +import org.omg.CORBA.NameValuePair; +import org.omg.CORBA.NameValuePairHelper; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +/** + * The name-value pair holder. The {@link NameValuePair} has no standard + * holder defined, but it is needed to store the {@link NameValuePair} into + * {@link Any}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameValuePairHolder + implements Streamable +{ + /** + * The stored value of the name value pair. + */ + public NameValuePair value; + + public NameValuePairHolder() + { + } + + public NameValuePairHolder(NameValuePair a_value) + { + value = a_value; + } + + /** + * Read the name value pair. + */ + public void _read(InputStream input) + { + value = NameValuePairHelper.read(input); + } + + /** + * Return the typecode of the name value pair. + */ + public TypeCode _type() + { + return NameValuePairHelper.type(); + } + + /** + * Write the name value pair. + */ + public void _write(OutputStream output) + { + NameValuePairHelper.write(output, value); + } +} diff --git a/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java b/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java new file mode 100644 index 0000000..890ca5f --- /dev/null +++ b/libjava/classpath/gnu/CORBA/EmptyExceptionHolder.java @@ -0,0 +1,132 @@ +/* EmptyStructHolder.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; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +/** + * This holder can store any CORBA exception that has no user defined fields. + * Only the repository ID is written when the method {@link #_write} is called. + * The _read method is not supported for this holder. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class EmptyExceptionHolder + implements Streamable +{ + /** + * The wrapped exception. + */ + public Throwable value; + + /** + * The typecode of the wrapped exception. + */ + public TypeCode typecode; + + /** + * Create the exception holder, initialised to the given values. + * + * @param an_exception the wrapped exception. + * @param an_id the exception repository id. + */ + public EmptyExceptionHolder(Throwable an_exception, TypeCode a_typecode) + { + value = an_exception; + typecode = a_typecode; + } + + /** + * Reads the exception from the input stream. + * + * The value field obtains the value of either the read exception or + * the UNKNOWN if the repository ID does not match + * the exception from the reachable code. + */ + public void _read(InputStream input) + { + String id = input.read_string(); + Object ex = ObjectCreator.Idl2Object(id); + if (ex == null) + value = new UNKNOWN(id); + else + value = (Throwable) ex; + } + + /** + * Return the typecode of the stored exception. + * + * @return the value, passed as a_typecode in constructor. + */ + public TypeCode _type() + { + return typecode; + } + + /** + * Write the exception into the give output stream. Writes the + * repository id that is taken from the typecode. This method also + * works when no helper class is available. + * + * @param output a stream to write into. + * + * @throws BAD_OPERATION if the value for the holder is not set or + * the typecode cannot provide repository id. + */ + public void _write(OutputStream output) + { + try + { + output.write_string(typecode.id()); + } + catch (Exception ex) + { + BAD_OPERATION bad = new BAD_OPERATION(); + bad.initCause(ex); + throw bad; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/ExceptionCreator.java b/libjava/classpath/gnu/CORBA/ExceptionCreator.java new file mode 100644 index 0000000..536053c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ExceptionCreator.java @@ -0,0 +1,248 @@ +/* ExceptionCreator.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; + +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.CompletionStatusHelper; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * Creates the objects from the agreed IDL names. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ExceptionCreator +{ + /** + * The standard OMG prefix. + */ + public static final String OMG_PREFIX = "omg.org/"; + + /** + * The standard java prefix. + */ + public static final String JAVA_PREFIX = "org.omg."; + + /** + * Create the system exception with the given idl name. + * + * @param idl the exception IDL name, must match the syntax + * "IDL:<class/name>:1.0". + * @param minor the exception minor code. + * @param completed the exception completion status. + * + * @return the created exception. + */ + public static SystemException createSystemException(String idl, int minor, + CompletionStatus completed + ) + { + try + { + String cl = toClassName(idl); + Class exClass = Class.forName(cl); + + Constructor constructor = + exClass.getConstructor(new Class[] + { + String.class, int.class, + CompletionStatus.class + } + ); + + Object exception = + constructor.newInstance(new Object[] + { + " Remote exception " + idl + ", minor " + + minor + ", " + completed + ".", + new Integer(minor), completed + } + ); + + return (SystemException) exception; + } + catch (Exception ex) + { + ex.printStackTrace(); + return new UNKNOWN("Unsupported system exception", minor, completed); + } + } + + /** + * Read the system exception from the given stream. + * @param input the CDR stream to read from. + * @return the exception that has been stored in the stream + * (IDL name, minor code and completion status). + */ + public static SystemException readSystemException(InputStream input) + { + String idl = input.read_string(); + int minor = input.read_ulong(); + CompletionStatus status = CompletionStatusHelper.read(input); + + SystemException exception = + ExceptionCreator.createSystemException(idl, minor, status); + + return exception; + } + + /** + * Reads the user exception, having the given Id, from the + * input stream. The id is expected to be in the form like + * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' + * + * @param idl the exception idl name. + * @param input the stream to read from. + * + * @return the loaded exception. + * @return null if the helper class cannot be found. + */ + public static UserException readUserException(String idl, InputStream input) + { + try + { + String holder = toHelperName(idl); + + System.out.println("Helper " + holder); + + Class holderClass = Class.forName(holder); + + Method read = + holderClass.getMethod("read", + new Class[] + { + org.omg.CORBA.portable.InputStream.class + } + ); + + return (UserException) read.invoke(null, new Object[] { input }); + } + catch (MARSHAL mex) + { + // This one is ok to throw + throw mex; + } + catch (Exception ex) + { + ex.printStackTrace(); + return null; + } + } + + /** + * Writes the system exception data to CDR output stream. + * + * @param output a stream to write data to. + * @param ex an exception to write. + */ + public static void writeSystemException(OutputStream output, + SystemException ex + ) + { + String exIDL = toIDL(ex.getClass().getName()); + output.write_string(exIDL); + output.write_ulong(ex.minor); + CompletionStatusHelper.write(output, ex.completed); + } + + /** + * Converts teh given IDL name to class name. + * + * @param IDL the idl name. + * + */ + protected static String toClassName(String IDL) + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); + + return s.replace('/', '.'); + } + + /** + * Gets the helper class name from the string like + * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' + * + * @param IDL the idl name. + */ + protected static String toHelperName(String IDL) + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); + + return s.replace('/', '.') + "Helper"; + } + + /** + * Convert the class name to IDL name. + * + * @param cn the class name. + * + * @return the idl name. + */ + protected static String toIDL(String cn) + { + if (cn.startsWith(JAVA_PREFIX)) + cn = cn.substring(JAVA_PREFIX.length()); + + cn = cn.replace('.', '/'); + + return "IDL:" + OMG_PREFIX + cn + ":1.0"; + } +} diff --git a/libjava/classpath/gnu/CORBA/Functional_ORB.java b/libjava/classpath/gnu/CORBA/Functional_ORB.java new file mode 100644 index 0000000..7395f31 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Functional_ORB.java @@ -0,0 +1,1438 @@ +/* FunctionalORB.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.GIOP.ErrorMessage; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.RequestHeader; +import gnu.CORBA.GIOP.CloseMessage; +import gnu.CORBA.NamingService.NamingServiceTransient; + +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_RESOURCES; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.Request; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CosNaming.NamingContextExt; +import org.omg.CosNaming.NamingContextExtHelper; + +import java.applet.Applet; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.UnknownHostException; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.TreeMap; + +/** + * The ORB implementation, capable to handle remote invocations on the + * registered object. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Functional_ORB + extends Restricted_ORB +{ + /** + * A server, responsible for listening on requests on some + * local port. The ORB may listen on multiple ports and process + * the requests in separate threads. Normally the server takes + * one port per object being served. + */ + class portServer + extends Thread + { + /** + * The number of the currently running parallel threads. + */ + private int running_threads; + + /** + * The port on that this portServer is listening for requests. + */ + int s_port; + + /** + * The server socket of this portServer. + */ + ServerSocket service; + + /** + * True if the serving node must shutdown due + * call of the close_now(). + */ + boolean terminated; + + /** + * Create a new portServer, serving on specific port. + */ + portServer(int _port) + { + s_port = _port; + } + + /** + * Enter the serving loop (get request/process it). + * All portServer normally terminate thy threads when + * the Functional_ORB.running is set to false. + */ + public void run() + { + try + { + service = new ServerSocket(s_port); + } + catch (IOException ex) + { + BAD_OPERATION bad = + new BAD_OPERATION("Unable to open the server socket."); + bad.initCause(ex); + throw bad; + } + + while (running) + { + try + { + serve(this, service); + } + catch (SocketException ex) + { + // May be thrown when the service is closed by + // the close_now(). + if (terminated) + return; + } + catch (Exception iex) + { + // Wait 5 seconds. Do not terminate the + // service due potentially transient error. + try + { + Thread.sleep(5000); + } + catch (InterruptedException ex) + { + } + } + } + } + + /** + * Forcibly close the server socket and mark this port as free. + */ + public void close_now() + { + try + { + terminated = true; + service.close(); + } + catch (Exception ex) + { + // This may happen if the service has not been opened or + // cannot be closed. Return without action. + } + } + + /** + * If the thread is no longer in use, close the socket (if opened). + */ + protected void finalize() + { + close_now(); + } + } + + /** + * The default value where the first instance of this ORB will start + * looking for a free port. + */ + public static int DEFAULT_INITIAL_PORT = 1126; + + /** + * The property of port, on that this ORB is listening for requests from clients. + * This class supports one port per ORB only. + */ + public static final String LISTEN_ON = "gnu.classpath.CORBA.ListenOn"; + + /** + * The property, defining the IOR of the intial reference to resolve. + */ + public static final String REFERENCE = "org.omg.CORBA.ORBInitRef"; + + /** + * The property, defining the port on that the default name service is running. + */ + public static final String NS_PORT = "org.omg.CORBA.ORBInitialPort"; + + /** + * The property, defining the host on that the default name service is running. + */ + public static final String NS_HOST = "org.omg.CORBA.ORBInitialHost"; + + /** + * The string, defining the naming service initial reference. + */ + public static final String NAME_SERVICE = "NameService"; + + /** + * The if the client has once opened a socket, it should start sending + * the message header in a given time. Otherwise the server will close the + * socket. This prevents server hang when the client opens the socket, + * but does not send any message, usually due crash on the client side. + */ + public static String START_READING_MESSAGE = + "gnu.classpath.CORBA.TOUT_START_READING_MESSAGE"; + + /** + * If the client has started to send the request message, the socket time + * out changes to the specified value. + */ + public static String WHILE_READING = "gnu.classpath.CORBA.TOUT_WHILE_READING"; + + /** + * If the message body is received, the time out changes to the + * specifice value. This must be longer, as includes time, required to + * process the received task. We make it 40 minutes. + */ + public static String AFTER_RECEIVING = + "gnu.classpath.CORBA.TOUT_AFTER_RECEIVING"; + + /** + * The address of the local host. + */ + public final String LOCAL_HOST; + + /** + * The if the client has once opened a socket, it should start sending + * the message header in a given time. Otherwise the server will close the + * socket. This prevents server hang when the client opens the socket, + * but does not send any message, usually due crash on the client side. + */ + private int TOUT_START_READING_MESSAGE = 20 * 1000; + + // (Here and below, we use * to make the meaning of the constant clearler). + + /** + * If the client has started to send the request message, the socket time + * out changes to the specified value. + */ + private int TOUT_WHILE_READING = 2 * 60 * 1000; + + /** + * If the message body is received, the time out changes to the + * specifice value. This must be longer, as includes time, required to + * process the received task. We make it 40 minutes. + */ + private int TOUT_AFTER_RECEIVING = 40 * 60 * 1000; + + /** + * Some clients tend to submit multiple requests over the + * same socket. The server waits for the next request on + * the same socket for the duration, specified + * below. In additions, the request of this implementation also + * waits for the same duration before closing the socket. + * The default time is seven seconds. + */ + public static int TANDEM_REQUESTS = 7000; + + /** + * The map of the already conncted objects. + */ + protected final Connected_objects connected_objects = new Connected_objects(); + + /** + * The maximal CORBA version, supported by this ORB. The default value + * 0 means that the ORB will not check the request version while trying + * to respond. + */ + protected Version max_version; + + /** + * Setting this value to false causes the ORB to shutdown after the + * latest serving operation is complete. + */ + protected boolean running; + + /** + * The map of the initial references. + */ + private Map initial_references = new TreeMap(); + + /** + * The currently active portServers. + */ + private ArrayList portServers = new ArrayList(); + + /** + * The host, on that the name service is expected to be running. + */ + private String ns_host; + + /** + * Probably free port, under that the ORB will try listening for + * remote requests first. When the new object is connected, this + * port is used first, then it is incremented by 1, etc. If the given + * port is not available, up to 20 subsequent values are tried and then + * the parameterless server socket contructor is called. The constant is + * shared between multiple instances of this ORB. + */ + private static int Port = DEFAULT_INITIAL_PORT; + + /** + * The port, on that the name service is expected to be running. + */ + private int ns_port = 900; + + /** + * The instance, stored in this field, handles the asynchronous dynamic + * invocations. + */ + protected Asynchron asynchron = new Asynchron(); + + /** + * The list of the freed ports. The ORB reuses ports, when possible. + */ + protected LinkedList freed_ports = new LinkedList(); + + /** + * The maximal allowed number of the currently running parallel + * threads per object. For security reasons, this is made private and + * unchangeable. After exceeding this limit, the NO_RESOURCES + * is thrown back to the client. + */ + private int MAX_RUNNING_THREADS = 256; + + /** + * Create the instance of the Functional ORB. + */ + public Functional_ORB() + { + try + { + LOCAL_HOST = ns_host = InetAddress.getLocalHost().getHostAddress(); + initial_references.put("CodecFactory", new gnuCodecFactory(this)); + } + catch (UnknownHostException ex) + { + BAD_OPERATION bad = + new BAD_OPERATION("Unable to open the server socket."); + bad.initCause(ex); + throw bad; + } + } + + /** + * If the max version is assigned, the orb replies with the error + * message if the request version is above the supported 1.2 version. + * This behavior is recommended by OMG, but not all implementations + * respond that error message by re-sending the request, encoded in the older + * version. + */ + public void setMaxVersion(Version max_supported) + { + max_version = max_supported; + } + + /** + * Get the maximal supported GIOP version or null if the version is + * not checked. + */ + public Version getMaxVersion() + { + return max_version; + } + + /** + * Get the currently free port, starting from the initially set port + * and going up max 20 steps, then trying to bind into any free + * address. + * + * @return the currently available free port. + * + * @throws NO_RESOURCES if the server socked cannot be opened on the + * local host. + */ + public int getFreePort() + throws BAD_OPERATION + { + ServerSocket s; + int a_port; + + try + { + // If there are some previously freed ports, use them first. + if (!freed_ports.isEmpty()) + { + Integer free = (Integer) freed_ports.getLast(); + freed_ports.removeLast(); + s = new ServerSocket(free.intValue()); + s.close(); + return free.intValue(); + } + } + catch (Exception ex) + { + // This may be thrown if the request for the new port has arrived + // before the current service is completly shutdown. + // OK then, use a new port. + } + + for (a_port = Port; a_port < Port + 20; a_port++) + { + try + { + s = new ServerSocket(a_port); + s.close(); + Port = a_port + 1; + return a_port; + } + catch (IOException ex) + { + // Repeat the loop if this exception has been thrown. + } + } + + try + { + // Try any port. + s = new ServerSocket(); + a_port = s.getLocalPort(); + s.close(); + return a_port; + } + catch (IOException ex) + { + NO_RESOURCES bad = + new NO_RESOURCES("Unable to open the server socket."); + bad.initCause(ex); + throw bad; + } + } + + /** + * Set the port, on that the server is listening for the client requests. + * If only one object is connected to the orb, the server will be + * try listening on this port first. It the port is busy, or if more + * objects are connected, the subsequent object will receive a larger + * port values, skipping unavailable ports, if required. The change + * applies globally. + * + * @param a_Port a port, on that the server is listening for requests. + */ + public static void setPort(int a_Port) + { + Port = a_Port; + } + + /** + * Connect the given CORBA object to this ORB. After the object is + * connected, it starts receiving remote invocations via this ORB. + * + * The ORB tries to connect the object to the port, that has been + * previously set by {@link setPort(int)}. On failure, it tries + * 20 subsequent larger values and then calls the parameterless + * server socked constructor to get any free local port. + * If this fails, the {@link NO_RESOURCES} is thrown. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect(org.omg.CORBA.Object object) + { + int a_port = getFreePort(); + + Connected_objects.cObject ref = connected_objects.add(object, a_port); + IOR ior = createIOR(ref); + prepareObject(object, ior); + if (running) + startService(ior); + } + + /** + * Connect the given CORBA object to this ORB, explicitly specifying + * the object key. + * + * The ORB tries to connect the object to the port, that has been + * previously set by {@link setPort(int)}. On failure, it tries + * 20 subsequent larger values and then calls the parameterless + * server socked constructor to get any free local port. + * If this fails, the {@link NO_RESOURCES} is thrown. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * @param key the object key, usually used to identify the object from + * remote side. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect(org.omg.CORBA.Object object, byte[] key) + { + int a_port = getFreePort(); + + Connected_objects.cObject ref = connected_objects.add(key, object, a_port); + IOR ior = createIOR(ref); + prepareObject(object, ior); + if (running) + startService(ior); + } + + /** + * Start the service on the given port of this IOR. + * + * @param ior the ior (only Internet.port is used). + */ + private void startService(IOR ior) + { + portServer p = new portServer(ior.Internet.port); + portServers.add(p); + p.start(); + } + + /** + * Destroy this server, releasing the occupied resources. + */ + public void destroy() + { + super.destroy(); + + portServer p; + for (int i = 0; i < portServers.size(); i++) + { + p = (portServer) portServers.get(i); + p.close_now(); + } + } + + /** + * Disconnect the given CORBA object from this ORB. The object will be + * no longer receiving the remote invocations. In response to the + * remote invocation on this object, the ORB will send the + * exception {@link OBJECT_NOT_EXIST}. The object, however, is not + * destroyed and can receive the local invocations. + + * @param object the object to disconnect. + */ + public void disconnect(org.omg.CORBA.Object object) + { + Connected_objects.cObject rmKey = null; + + // Handle the case when it is possible to get the object key. + // Handle the case when the object is known, but not local. + if (object instanceof ObjectImpl) + { + Delegate delegate = ((ObjectImpl) object)._get_delegate(); + if (delegate instanceof Simple_delegate) + { + byte[] key = ((Simple_delegate) delegate).getIor().key; + rmKey = connected_objects.get(key); + } + } + + // Try to find and disconned the object that is not an instance of the + // object implementation. + if (rmKey == null) + rmKey = connected_objects.getKey(object); + + // Disconnect the object on any success. + if (rmKey != null) + { + // Find and stop the corresponding portServer. + portServer p; + StopService: + for (int i = 0; i < portServers.size(); i++) + { + p = (portServer) portServers.get(i); + if (p.s_port == rmKey.port) + { + p.close_now(); + freed_ports.addFirst(new Integer(rmKey.port)); + break StopService; + } + connected_objects.remove(rmKey.key); + } + } + } + + /** + * Find the local object, connected to this ORB. + * + * @param ior the ior of the potentially local object. + * + * @return the local object, represented by the given IOR, + * or null if this is not a local connected object. + */ + public org.omg.CORBA.Object find_local_object(IOR ior) + { + // Must be the same host. + if (!ior.Internet.host.equals(LOCAL_HOST)) + return null; + + // Must be the same port. + if (ior.Internet.port != Port) + return null; + + return find_connected_object(ior.key); + } + + /** + * List the initially available CORBA objects (services). + * + * @return a list of services. + * + * @see resolve_initial_references(String) + */ + public String[] list_initial_services() + { + String[] refs = new String[ initial_references.size() ]; + int p = 0; + + Iterator iter = initial_references.keySet().iterator(); + while (iter.hasNext()) + refs [ p++ ] = (String) iter.next(); + + return refs; + } + + /** + * Get the IOR reference string for the given object. + * The string embeds information about the object + * repository Id, its access key and the server internet + * address and port. With this information, the object + * can be found by another ORB, possibly located on remote + * computer. + * + * @param the CORBA object + * @return the object IOR representation. + * + * @throws BAD_PARAM if the object has not been previously + * connected to this ORB. + * @throws BAD_OPERATION in the unlikely case if the local host + * address cannot be resolved. + * + * @see string_to_object(String) + */ + public String object_to_string(org.omg.CORBA.Object forObject) + { + // Handle the case when the object is known, but not local. + if (forObject instanceof ObjectImpl) + { + Delegate delegate = ((ObjectImpl) forObject)._get_delegate(); + if (delegate instanceof Simple_delegate) + return ((Simple_delegate) delegate).getIor().toStringifiedReference(); + } + + // Handle the case when the object is local. + Connected_objects.cObject rec = connected_objects.getKey(forObject); + + if (rec == null) + throw new BAD_PARAM("The object " + forObject + + " has not been previously connected to this ORB" + ); + + IOR ior = createIOR(rec); + + return ior.toStringifiedReference(); + } + + /** + * Find and return the easily accessible CORBA object, addressed + * by name. + * + * @param name the object name. + * @return the object + * + * @throws org.omg.CORBA.ORBPackage.InvalidName if the given name + * is not associated with the known object. + */ + public org.omg.CORBA.Object resolve_initial_references(String name) + throws InvalidName + { + org.omg.CORBA.Object object = null; + try + { + object = (org.omg.CORBA.Object) initial_references.get(name); + if (object == null && name.equals(NAME_SERVICE)) + { + object = getDefaultNameService(); + if (object != null) + initial_references.put(NAME_SERVICE, object); + } + } + catch (Exception ex) + { + InvalidName err = new InvalidName(name); + err.initCause(ex); + throw err; + } + if (object != null) + return object; + else + throw new InvalidName("Not found: '" + name + "'"); + } + + /** + * Start the ORBs main working cycle + * (receive invocation - invoke on the local object - send response - + * wait for another invocation). + * + * The method only returns after calling {@link #shutdown(boolean)}. + */ + public void run() + { + running = true; + + // Instantiate the port server for each socket. + Iterator iter = connected_objects.entrySet().iterator(); + Map.Entry m; + Connected_objects.cObject obj; + + while (iter.hasNext()) + { + m = (Map.Entry) iter.next(); + obj = (Connected_objects.cObject) m.getValue(); + + portServer subserver = new portServer(obj.port); + portServers.add(subserver); + + // Reuse the current thread for the last portServer. + if (!iter.hasNext()) + { + // Discard the iterator, eliminating lock checks. + iter = null; + subserver.run(); + return; + } + else + subserver.start(); + } + } + + /** + * Shutdown the ORB server. + * + * @param wait_for_completion if true, the current thread is + * suspended until the shutdown process is complete. + */ + public void shutdown(boolean wait_for_completion) + { + super.shutdown(wait_for_completion); + running = false; + + if (!wait_for_completion) + { + for (int i = 0; i < portServers.size(); i++) + { + portServer p = (portServer) portServers.get(i); + p.close_now(); + } + } + } + + /** + * Find and return the CORBA object, addressed by the given + * IOR string representation. The object can (an usually is) + * located on a remote computer, possibly running a different + * (not necessary java) CORBA implementation. + * + * @param ior the object IOR representation string. + * + * @return the found CORBA object. + * @see object_to_string(org.omg.CORBA.Object) + */ + public org.omg.CORBA.Object string_to_object(String an_ior) + { + IOR ior = IOR.parse(an_ior); + org.omg.CORBA.Object object = find_local_object(ior); + if (object == null) + { + ObjectImpl impl = stubFinder.search(this, ior); + try + { + if (impl._get_delegate() == null) + { + impl._set_delegate(new IOR_Delegate(this, ior)); + } + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception + // in response to the attempt to get the unset delegate. + impl._set_delegate(new IOR_Delegate(this, ior)); + } + + object = impl; + connected_objects.add(ior.key, impl, ior.Internet.port); + } + return object; + } + + /** + * Get the default naming service for the case when there no + * NameService entries. + */ + protected org.omg.CORBA.Object getDefaultNameService() + { + if (initial_references.containsKey(NAME_SERVICE)) + { + return (org.omg.CORBA.Object) initial_references.get(NAME_SERVICE); + } + + IOR ior = new IOR(); + ior.Id = NamingContextExtHelper.id(); + ior.Internet.host = ns_host; + ior.Internet.port = ns_port; + ior.key = NamingServiceTransient.getDefaultKey(); + + IOR_contructed_object iorc = new IOR_contructed_object(this, ior); + NamingContextExt namer = NamingContextExtHelper.narrow(iorc); + initial_references.put(NAME_SERVICE, namer); + return namer; + } + + /** + * Find and return the object, that must be previously connected + * to this ORB. Return null if no such object is available. + * + * @param key the object key. + * + * @return the connected object, null if none. + */ + protected org.omg.CORBA.Object find_connected_object(byte[] key) + { + Connected_objects.cObject ref = connected_objects.get(key); + return ref == null ? null : ref.object; + } + + /** + * Set the ORB parameters. This method is normally called from + * {@link #init(Applet, Properties)}. + * + * @param app the current applet. + * + * @param props application specific properties, passed as the second + * parameter in {@link #init(Applet, Properties)}. + * Can be <code>null</code>. + */ + protected void set_parameters(Applet app, Properties props) + { + useProperties(props); + + String[][] para = app.getParameterInfo(); + if (para != null) + { + for (int i = 0; i < para.length; i++) + { + if (para [ i ] [ 0 ].equals(LISTEN_ON)) + Port = Integer.parseInt(para [ i ] [ 1 ]); + + if (para [ i ] [ 0 ].equals(REFERENCE)) + { + StringTokenizer st = new StringTokenizer(para [ i ] [ 1 ], "="); + initial_references.put(st.nextToken(), + string_to_object(st.nextToken()) + ); + } + + if (para [ i ] [ 0 ].equals(NS_HOST)) + ns_host = para [ i ] [ 1 ]; + + if (para [ i ] [ 0 ].equals(START_READING_MESSAGE)) + TOUT_START_READING_MESSAGE = Integer.parseInt(para [ i ] [ 1 ]); + + if (para [ i ] [ 0 ].equals(WHILE_READING)) + TOUT_WHILE_READING = Integer.parseInt(para [ i ] [ 1 ]); + + if (para [ i ] [ 0 ].equals(AFTER_RECEIVING)) + TOUT_AFTER_RECEIVING = Integer.parseInt(para [ i ] [ 1 ]); + + try + { + if (para [ i ] [ 0 ].equals(NS_PORT)) + ns_port = Integer.parseInt(para [ i ] [ 1 ]); + } + catch (NumberFormatException ex) + { + BAD_PARAM bad = + new BAD_PARAM("Invalid " + NS_PORT + + "property, unable to parse '" + + props.getProperty(NS_PORT) + "'" + ); + bad.initCause(ex); + throw bad; + } + } + } + } + + /** + * Set the ORB parameters. This method is normally called from + * {@link #init(String[], Properties)}. + * + * @param para the parameters, that were passed as the parameters + * to the <code>main(String[] args)</code> method of the current standalone + * application. + * + * @param props application specific properties that were passed + * as a second parameter in {@link init(String[], Properties)}). + * Can be <code>null</code>. + */ + protected void set_parameters(String[] para, Properties props) + { + if (para.length > 1) + for (int i = 0; i < para.length - 1; i++) + { + if (para [ i ].endsWith("ListenOn")) + Port = Integer.parseInt(para [ i + 1 ]); + + if (para [ i ].endsWith("ORBInitRef")) + { + StringTokenizer st = new StringTokenizer(para [ i + 1 ], "="); + initial_references.put(st.nextToken(), + string_to_object(st.nextToken()) + ); + } + + if (para [ i ].endsWith("ORBInitialHost")) + ns_host = para [ i + 1 ]; + + try + { + if (para [ i ].endsWith("ORBInitialPort")) + ns_port = Integer.parseInt(para [ i + 1 ]); + } + catch (NumberFormatException ex) + { + throw new BAD_PARAM("Invalid " + para [ i ] + + "parameter, unable to parse '" + + props.getProperty(para [ i + 1 ]) + "'" + ); + } + } + + useProperties(props); + } + + private IOR createIOR(Connected_objects.cObject ref) + throws BAD_OPERATION + { + IOR ior = new IOR(); + ior.key = ref.key; + ior.Internet.port = ref.port; + + if (ref.object instanceof ObjectImpl) + { + ObjectImpl imp = (ObjectImpl) ref.object; + if (imp._ids().length > 0) + ior.Id = imp._ids() [ 0 ]; + } + if (ior.Id == null) + ior.Id = ref.object.getClass().getName(); + + try + { + ior.Internet.host = InetAddress.getLocalHost().getHostAddress(); + ior.Internet.port = ref.port; + } + catch (UnknownHostException ex) + { + throw new BAD_OPERATION("Cannot resolve the local host address"); + } + return ior; + } + + /** + * Prepare object for connecting it to this ORB. + * + * @param object the object being connected. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + private void prepareObject(org.omg.CORBA.Object object, IOR ior) + throws BAD_PARAM + { + if (!(object instanceof InvokeHandler)) + throw new BAD_PARAM(object.getClass().getName() + + " does not implement InvokeHandler. " + ); + + // If no delegate is set, set the default delegate. + if (object instanceof ObjectImpl) + { + ObjectImpl impl = (ObjectImpl) object; + try + { + if (impl._get_delegate() == null) + { + impl._set_delegate(new Simple_delegate(this, ior)); + } + } + catch (BAD_OPERATION ex) + { + // Some colaborants may throw this exception. + impl._set_delegate(new Simple_delegate(this, ior)); + } + } + } + + /** + * Write the response message. + * + * @param net_out the stream to write response into + * @param msh_request the request message header + * @param rh_request the request header + * @param handler the invocation handler that has been used to + * invoke the operation + * @param sysEx the system exception, thrown during the invocation, + * null if none. + * + * @throws IOException + */ + private void respond_to_client(OutputStream net_out, + MessageHeader msh_request, + RequestHeader rh_request, + bufferedResponseHandler handler, + SystemException sysEx + ) + throws IOException + { + // Set the reply header properties. + ReplyHeader reply = handler.reply_header; + + if (sysEx != null) + reply.reply_status = ReplyHeader.SYSTEM_EXCEPTION; + else if (handler.isExceptionReply()) + reply.reply_status = ReplyHeader.USER_EXCEPTION; + else + reply.reply_status = ReplyHeader.NO_EXCEPTION; + + reply.request_id = rh_request.request_id; + + cdrBufOutput out = new cdrBufOutput(50 + handler.getBuffer().buffer.size()); + out.setOrb(this); + + out.setOffset(msh_request.getHeaderSize()); + + reply.write(out); + + // Write the reply data from the handler. + handler.getBuffer().buffer.writeTo(out); + + MessageHeader msh_reply = new MessageHeader(); + + msh_reply.version = msh_request.version; + msh_reply.message_type = MessageHeader.REPLY; + msh_reply.message_size = out.buffer.size(); + + // Write the reply. + msh_reply.write(net_out); + out.buffer.writeTo(net_out); + net_out.flush(); + } + + /** + * Contains a single servicing task. + * + * Normally, each task matches a single remote invocation. + * However under frequent tandem submissions the same + * task may span over several invocations. + * + * @param serverSocket the ORB server socket. + * + * @throws MARSHAL + * @throws IOException + */ + private void serve(final portServer p, ServerSocket serverSocket) + throws MARSHAL, IOException + { + final Socket service; + service = serverSocket.accept(); + + // Tell the server there are no more resources. + if (p.running_threads >= MAX_RUNNING_THREADS) + { + serveStep(service, true); + return; + } + + new Thread() + { + public void run() + { + try + { + synchronized (p) + { + p.running_threads++; + } + serveStep(service, false); + } + finally + { + synchronized (p) + { + p.running_threads--; + } + } + } + }.start(); + } + + /** + * A single servicing step, when the client socket is alrady open. + * + * Normally, each task matches a single remote invocation. + * However under frequent tandem submissions the same + * task may span over several invocations. + * + * @param service the opened client socket. + * @param no_resources if true, the "NO RESOURCES" exception + * is thrown to the client. + */ + private void serveStep(Socket service, boolean no_resources) + { + try + { + Serving: + while (true) + { + InputStream in = service.getInputStream(); + service.setSoTimeout(TOUT_START_READING_MESSAGE); + + MessageHeader msh_request = new MessageHeader(); + + try + { + msh_request.read(in); + } + catch (MARSHAL ex) + { + // This exception may be thrown due closing the connection. + return; + } + + if (max_version != null) + if (!msh_request.version.until_inclusive(max_version.major, + max_version.minor + ) + ) + { + OutputStream out = service.getOutputStream(); + new ErrorMessage(max_version).write(out); + return; + } + + byte[] r = new byte[ msh_request.message_size ]; + + int n = 0; + + service.setSoTimeout(TOUT_WHILE_READING); + + reading: + while (n < r.length) + { + n += in.read(r, n, r.length - n); + } + + service.setSoTimeout(TOUT_AFTER_RECEIVING); + + if (msh_request.message_type == MessageHeader.REQUEST) + { + RequestHeader rh_request; + + cdrBufInput cin = new cdrBufInput(r); + cin.setOrb(this); + cin.setVersion(msh_request.version); + cin.setOffset(msh_request.getHeaderSize()); + cin.setBigEndian(msh_request.isBigEndian()); + + rh_request = msh_request.create_request_header(); + + // Read header and auto set the charset. + rh_request.read(cin); + + // in 1.2 and higher, align the current position at + // 8 octet boundary. + if (msh_request.version.since_inclusive(1, 2)) + cin.align(8); + + // find the target object. + InvokeHandler target = + (InvokeHandler) find_connected_object(rh_request.object_key); + + // Prepare the reply header. This must be done in advance, + // as the size must be known for handler to set alignments + // correctly. + ReplyHeader rh_reply = msh_request.create_reply_header(); + + // TODO log errors about not existing objects and methods. + bufferedResponseHandler handler = + new bufferedResponseHandler(this, msh_request, rh_reply); + + SystemException sysEx = null; + + try + { + if (no_resources) + throw new NO_RESOURCES(); + if (target == null) + throw new OBJECT_NOT_EXIST(); + target._invoke(rh_request.operation, cin, handler); + } + catch (SystemException ex) + { + sysEx = ex; + + org.omg.CORBA.portable.OutputStream ech = + handler.createExceptionReply(); + ObjectCreator.writeSystemException(ech, ex); + } + catch (Exception except) + { + sysEx = + new UNKNOWN("Unknown", 2, CompletionStatus.COMPLETED_MAYBE); + + org.omg.CORBA.portable.OutputStream ech = + handler.createExceptionReply(); + + ObjectCreator.writeSystemException(ech, sysEx); + } + + // Write the response. + if (rh_request.isResponseExpected()) + { + OutputStream sou = service.getOutputStream(); + respond_to_client(sou, msh_request, rh_request, handler, + sysEx + ); + } + } + else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION || + msh_request.message_type == MessageHeader.MESSAGE_ERROR + ) + { + CloseMessage.close(service.getOutputStream()); + service.close(); + return; + } + else + ; + + // TODO log error: "Not a request message." + if (service != null && !service.isClosed()) + { + // Wait for the subsequent invocations on the + // same socket for the TANDEM_REQUEST duration. + service.setSoTimeout(TANDEM_REQUESTS); + } + else + return; + } + } + catch (SocketException ex) + { + // OK. + return; + } + catch (IOException ioex) + { + // Network error, probably transient. + // TODO log it. + return; + } + } + + private void useProperties(Properties props) + { + if (props != null) + { + if (props.containsKey(LISTEN_ON)) + Port = Integer.parseInt(props.getProperty(LISTEN_ON)); + + if (props.containsKey(NS_HOST)) + ns_host = props.getProperty(NS_HOST); + + try + { + if (props.containsKey(NS_PORT)) + ns_port = Integer.parseInt(props.getProperty(NS_PORT)); + + if (props.containsKey(START_READING_MESSAGE)) + TOUT_START_READING_MESSAGE = + Integer.parseInt(props.getProperty(START_READING_MESSAGE)); + + if (props.containsKey(WHILE_READING)) + TOUT_WHILE_READING = + Integer.parseInt(props.getProperty(WHILE_READING)); + + if (props.containsKey(AFTER_RECEIVING)) + TOUT_AFTER_RECEIVING = + Integer.parseInt(props.getProperty(AFTER_RECEIVING)); + } + catch (NumberFormatException ex) + { + throw new BAD_PARAM("Invalid " + NS_PORT + + "property, unable to parse '" + + props.getProperty(NS_PORT) + "'" + ); + } + + Enumeration en = props.elements(); + while (en.hasMoreElements()) + { + String item = (String) en.nextElement(); + if (item.equals(REFERENCE)) + initial_references.put(item, + string_to_object(props.getProperty(item)) + ); + } + } + } + + /** + * Get the next instance with a response being received. If all currently + * sent responses not yet processed, this method pauses till at least one of + * them is complete. If there are no requests currently sent, the method + * pauses till some request is submitted and the response is received. + * This strategy is identical to the one accepted by Suns 1.4 ORB + * implementation. + * + * The returned response is removed from the list of the currently + * submitted responses and is never returned again. + * + * @return the previously sent request that now contains the received + * response. + * + * @throws WrongTransaction If the method was called from the transaction + * scope different than the one, used to send the request. The exception + * can be raised only if the request is implicitly associated with some + * particular transaction. + */ + public Request get_next_response() + throws org.omg.CORBA.WrongTransaction + { + return asynchron.get_next_response(); + } + + /** + * Find if any of the requests that have been previously sent with + * {@link #send_multiple_requests_deferred}, have a response yet. + * + * @return true if there is at least one response to the previously + * sent request, false otherwise. + */ + public boolean poll_next_response() + { + return asynchron.poll_next_response(); + } + + /** + * Send multiple prepared requests expecting to get a reply. All requests + * are send in parallel, each in its own separate thread. When the + * reply arrives, it is stored in the agreed fields of the corresponing + * request data structure. If this method is called repeatedly, + * the new requests are added to the set of the currently sent requests, + * but the old set is not discarded. + * + * @param requests the prepared array of requests. + * + * @see #poll_next_response() + * @see #get_next_response() + * @see Request#send_deferred() + */ + public void send_multiple_requests_deferred(Request[] requests) + { + asynchron.send_multiple_requests_deferred(requests); + } + + /** + * Send multiple prepared requests one way, do not caring about the answer. + * The messages, containing requests, will be marked, indicating that + * the sender is not expecting to get a reply. + * + * @param requests the prepared array of requests. + * + * @see Request#send_oneway() + */ + public void send_multiple_requests_oneway(Request[] requests) + { + asynchron.send_multiple_requests_oneway(requests); + } + + /** + * Set the flag, forcing all server threads to terminate. + */ + protected void finalize() + throws java.lang.Throwable + { + running = false; + super.finalize(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java b/libjava/classpath/gnu/CORBA/GIOP/CancelHeader.java new file mode 100644 index 0000000..9f4de0d --- /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 0000000..f3f35db --- /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 0000000..d884329 --- /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 0000000..8d3b353 --- /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 0000000..61c46e1 --- /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 0000000..1e0e154 --- /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 0000000..f2de4e2 --- /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 0000000..7e44bdce --- /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 0000000..7f42c07 --- /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 0000000..6e3650c --- /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 0000000..27181ca --- /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 0000000..ffa45c3 --- /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 0000000..c3f51a3 --- /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 0000000..d294d00 --- /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)); + } +} diff --git a/libjava/classpath/gnu/CORBA/IOR.java b/libjava/classpath/gnu/CORBA/IOR.java new file mode 100644 index 0000000..cedbce4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IOR.java @@ -0,0 +1,563 @@ +/* IOR.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.cdrInput; +import gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.GIOP.CharSets_OSF; +import gnu.CORBA.GIOP.cxCodeSet; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.ULongSeqHelper; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * The implementaton of the Interoperable Object Reference (IOR). + * IOR can be compared with the Internet address for a web page, + * it provides means to locate the CORBA service on the web. + * IOR contains the host address, port number, the object identifier + * (key) inside the server, the communication protocol version, + * supported charsets and so on. + * + * Ths class provides method for encoding and + * decoding the IOR information from/to the stringified references, + * usually returned by {@link org.omg.CORBA.ORB#String object_to_string()}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * + * @see org.mog.CORBA.Object.object_to_string(Object forObject) + * @see string_to_object(String IOR) + */ +public class IOR +{ + /** + * The code sets profile. + */ + public static class CodeSets_profile + { + /** + * The code set component. + */ + public static class CodeSet_component + { + /** + * The conversion code sets. + */ + public int[] conversion; + + /** + * The native code set. + */ + public int native_set; + + /** + * Read from the CDR stream. + */ + public void read(org.omg.CORBA.portable.InputStream in) + { + native_set = in.read_ulong(); + conversion = ULongSeqHelper.read(in); + } + + /** + * Get a string representation. + */ + public String toString() + { + StringBuffer b = new StringBuffer(); + b.append("native " + name(native_set)); + if (conversion != null && conversion.length > 0) + { + b.append(" conversion "); + for (int i = 0; i < conversion.length; i++) + { + b.append(name(conversion [ i ])); + b.append(' '); + } + } + b.append(' '); + return b.toString(); + } + + /** + * Write into CDR stream. + */ + public void write(org.omg.CORBA.portable.OutputStream out) + { + out.write_long(native_set); + ULongSeqHelper.write(out, conversion); + } + + private String name(int set) + { + return "0x" + Integer.toHexString(set) + " (" + + CharSets_OSF.getName(set) + ") "; + } + } + + /** + * The agreed tag for the Codesets profile. + */ + public static final int TAG_CODE_SETS = 1; + + /** + * Information about narrow character encoding (TCS-C). + */ + public CodeSet_component narrow = new CodeSet_component(); + + /** + * About wide character encoding (TCS-W). + */ + public CodeSet_component wide = new CodeSet_component(); + + /** + * The negotiated coding result for this IOR. Saves time, requred for + * negotiation computations. + */ + public cxCodeSet negotiated; + + /** + * Read the code set profile information from the given input stream. + * + * @param profile a stream to read from. + */ + public void read(cdrInput profile) + { + cdrBufInput encapsulation = profile.read_encapsulation(); + narrow.read(encapsulation); + wide.read(encapsulation); + } + + /** + * Returns a string representation. + */ + public String toString() + { + return "Narrow char: " + narrow + ", Wide char: " + wide; + } + + /** + * Write the code set profile information into the given input stream. + * + * @param profile a stream to write into. + */ + public void write(cdrOutput profile) + { + cdrOutput encapsulation = profile.createEncapsulation(); + narrow.write(encapsulation); + wide.write(encapsulation); + try + { + encapsulation.close(); + } + catch (IOException ex) + { + throw new InternalError(); + } + } + } + + /** + * The internet profile. + */ + public static class Internet_profile + { + /** + * The agreed tag for the Internet profile. + */ + public static final int TAG_INTERNET_IOP = 0; + + /** + * The host. + */ + public String host; + + /** + * The IIOP version (initialised to 1.2 by default). + */ + public Version version = new Version(1, 2); + + /** + * The port. + */ + public int port; + + /** + * Return the human readable representation. + */ + public String toString() + { + StringBuffer b = new StringBuffer(); + b.append(host); + b.append(":"); + b.append(port); + b.append(" (v"); + b.append(version); + b.append(")"); + return b.toString(); + } + } + + /** + * The standard minor code, indicating that the string to object + * converstio has failed due non specific reasons. + */ + public static final int FAILED = 10; + + /** + * The code sets profile of this IOR. + */ + public CodeSets_profile CodeSets = new CodeSets_profile(); + + /** + * The internet profile of this IOR. + */ + public Internet_profile Internet = new Internet_profile(); + + /** + * The object repository Id. + */ + public String Id; + + /** + * The additional tagged components, encapsulated in + * the byte arrays. They are only supported by the + * later versions, than currently implemented. + */ + public byte[][] extra; + + /** + * The object key. + */ + public byte[] key; + + /** + * True if the profile was encoded using the Big Endian or + * the encoding is not known. + * + * false if it was encoded using the Little Endian. + */ + public boolean Big_Endian = true; + + /** + * Create an empty instance, initialising the code sets to default + * values. + */ + public IOR() + { + int[] supported = CharSets_OSF.getSupportedCharSets(); + + CodeSets.narrow.native_set = CharSets_OSF.NATIVE_CHARACTER; + CodeSets.narrow.conversion = supported; + + CodeSets.wide.native_set = CharSets_OSF.NATIVE_WIDE_CHARACTER; + CodeSets.wide.conversion = supported; + } + + /** + * Parse the provided stringifed reference. + * + * @param stringified_reference, in the form of + * IOR:nnnnnn..... + * + * @return the parsed IOR + * + * @throws BAD_PARAM, minor code 10, if the IOR cannot be parsed. + * + * TODO corballoc and other alternative formats. + */ + public static IOR parse(String stringified_reference) + throws BAD_PARAM + { + try + { + if (!stringified_reference.startsWith("IOR:")) + throw new BAD_PARAM("The string refernce must start with IOR:", + FAILED, CompletionStatus.COMPLETED_NO + ); + + IOR r = new IOR(); + + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + String x = stringified_reference; + x = x.substring(x.indexOf(":") + 1); + + char cx; + + for (int i = 0; i < x.length(); i = i + 2) + { + cx = (char) Integer.parseInt(x.substring(i, i + 2), 16); + buf.write(cx); + } + + cdrBufInput cdr = new cdrBufInput(buf.toByteArray()); + + r._read(cdr); + return r; + } + catch (Exception ex) + { + ex.printStackTrace(); + throw new BAD_PARAM(ex + " while parsing " + stringified_reference, + FAILED, CompletionStatus.COMPLETED_NO + ); + } + } + + /** + * Read the IOR from the provided input stream. + * + * @param c a stream to read from. + * @throws IOException if the stream throws it. + */ + public void _read(cdrInput c) + throws IOException, BAD_PARAM + { + int endian; + + endian = c.read_long(); + if (endian != 0) + { + Big_Endian = false; + c.setBigEndian(false); + } + _read_no_endian(c); + } + + /** + * Read the IOR from the provided input stream, not reading + * the endian data at the beginning of the stream. The IOR is + * thansferred in this form in + * {@link write_Object(org.omg.CORBA.Object)}. + * + * If the stream contains a null value, the Id and Internet fields become + * equal to null. Otherwise Id contains some string (possibly + * empty). + * + * Id is checked for null in cdrInput that then returns + * null instead of object. + * + * @param c a stream to read from. + * @throws IOException if the stream throws it. + */ + public void _read_no_endian(cdrInput c) + throws IOException, BAD_PARAM + { + Id = c.read_string(); + + int n_profiles = c.read_long(); + + if (n_profiles == 0) + { + Id = null; + Internet = null; + return; + } + + for (int i = 0; i < n_profiles; i++) + { + int tag = c.read_long(); + cdrBufInput profile = c.read_encapsulation(); + + if (tag == Internet_profile.TAG_INTERNET_IOP) + { + Internet = new Internet_profile(); + Internet.version = Version.read_version(profile); + Internet.host = profile.read_string(); + Internet.port = profile.gnu_read_ushort(); + + int lk = profile.read_long(); + key = new byte[ lk ]; + profile.read(key); + + // Read tagged components. + int n_components = 0; + + try + { + if (Internet.version.since_inclusive(1, 1)) + n_components = profile.read_long(); + + for (int t = 0; t < n_components; t++) + { + int ctag = profile.read_long(); + + if (ctag == CodeSets_profile.TAG_CODE_SETS) + { + CodeSets.read(profile); + } + } + } + catch (Unexpected ex) + { + ex.printStackTrace(); + } + } + } + } + + /** + * Write this IOR record to the provided CDR stream. + * This procedure writes the zero (Big Endian) marker first. + */ + public void _write(cdrOutput out) + { + // Always use Big Endian. + out.write(0); + _write_no_endian(out); + } + + /** + * Write a null value to the CDR output stream. + * + * The null value is written as defined in OMG specification + * (zero length string, followed by an empty set of profiles). + */ + public static void write_null(cdrOutput out) + { + // Empty Id string. + out.write_string(""); + + // Empty set of profiles. + out.write_long(0); + } + + /** + * Write this IOR record to the provided CDR stream. The procedure + * writed data in Big Endian, but does NOT add any endian marker + * to the beginning. + */ + public void _write_no_endian(cdrOutput out) + { + try + { + // Write repository id. + out.write_string(Id); + + // Always one profile. + out.write_long(1); + + // It is the Internet profile. + out.write_long(Internet_profile.TAG_INTERNET_IOP); + + // Need to write the Internet profile into the separate + // stream as we must know the size in advance. + cdrOutput b = out.createEncapsulation(); + + Internet.version.write(b); + b.write_string(Internet.host); + + b.write_ushort((short) (Internet.port & 0xFFFF)); + + // Write the object key. + b.write_long(key.length); + b.write(key); + + // One tagged component. + b.write_long(1); + + b.write_long(CodeSets_profile.TAG_CODE_SETS); + CodeSets.write(b); + + b.close(); + } + catch (IOException ex) + { + Unexpected.error(ex); + } + } + + /** + * Returns a human readable string representation of this IOR object. + */ + public String toString() + { + StringBuffer b = new StringBuffer(); + b.append(Id); + b.append(" at "); + b.append(Internet); + + if (!Big_Endian) + b.append(" (Little endian) "); + + b.append(" Key "); + + for (int i = 0; i < key.length; i++) + { + b.append(Integer.toHexString(key [ i ] & 0xFF)); + } + + b.append(" "); + b.append(CodeSets); + + return b.toString(); + } + + /** + * Returs a stringified reference. + * + * @return a newly constructed stringified reference. + */ + public String toStringifiedReference() + { + cdrBufOutput out = new cdrBufOutput(); + + _write(out); + + StringBuffer b = new StringBuffer("IOR:"); + + byte[] binary = out.buffer.toByteArray(); + String s; + + for (int i = 0; i < binary.length; i++) + { + s = Integer.toHexString(binary [ i ] & 0xFF); + if (s.length() == 1) + b.append('0'); + b.append(s); + } + + return b.toString(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IOR_Delegate.java b/libjava/classpath/gnu/CORBA/IOR_Delegate.java new file mode 100644 index 0000000..b06f630 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IOR_Delegate.java @@ -0,0 +1,311 @@ +/* gnuDelegate.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.GIOP.ReplyHeader; + +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.RemarshalException; + +import java.io.IOException; + +import java.net.Socket; + +/** + * The Classpath implementation of the {@link Delegate} functionality in the + * case, when the object was constructed from an IOR object. The IOR can be + * constructed from the stringified object reference. + * + * There is an different instance of this delegate for each CORBA object. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class IOR_Delegate + extends Simple_delegate +{ + /** + * Contructs an instance of object using the given IOR. + */ + public IOR_Delegate(ORB an_orb, IOR an_ior) + { + super(an_orb, an_ior); + } + + /** + * Creates the request to invoke the method on this object. + * + * @param target the object, for that the operation must be invoked. + * @param context context (null allowed) + * @param operation the method name + * @param parameters the method parameters + * @param returns the return value holder + * @param exceptions the exceptions that can be thrown by the method + * @param ctx_list the context list (null allowed) + * + * @return the created request. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns + ) + { + gnuRequest request = new gnuRequest(); + + request.setIor(getIor()); + request.set_target(target); + + request.setOperation(operation); + request.set_args(parameters); + request.m_context = context; + request.set_result(returns); + request.setORB(orb); + + return request; + } + + /** + * Creates the request to invoke the method on this object. + * + * @param target the object, for that the operation must be invoked. + * @param context context (null allowed) + * @param operation the method name + * @param parameters the method parameters + * @param returns the return value holder + * + * @return the created request. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns, ExceptionList exceptions, + ContextList ctx_list + ) + { + gnuRequest request = new gnuRequest(); + + request.setIor(ior); + request.set_target(target); + + request.setOperation(operation); + request.set_args(parameters); + request.m_context = context; + request.set_result(returns); + request.set_exceptions(exceptions); + request.set_context_list(ctx_list); + request.setORB(orb); + + return request; + } + + /** + * Invoke operation on the given object, writing parameters to the given + * output stream. + * + * @param target the target object. + * @param output the output stream, previously returned by + * {@link #request(org.omg.CORBA.Object, String, boolean)}. + * + * @return the input stream, to read the response from or null for a + * one-way request. + * + * @throws SystemException if the SystemException has been thrown on the + * remote side (the exact type and the minor code matches the data of + * the remote exception that has been thrown). + * + * @throws org.omg.CORBA.portable.ApplicationException as specified. + * @throws org.omg.CORBA.portable.RemarshalException as specified. + */ + public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) + throws ApplicationException, RemarshalException + { + streamRequest request = (streamRequest) output; + if (request.response_expected) + { + binaryReply response = request.request.submit(); + + // Read reply header. + ReplyHeader rh = response.header.create_reply_header(); + cdrBufInput input = response.getStream(); + input.setOrb(orb); + rh.read(input); + + boolean moved_permanently = false; + + switch (rh.reply_status) + { + case ReplyHeader.NO_EXCEPTION : + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + return input; + + case ReplyHeader.SYSTEM_EXCEPTION : + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + throw ObjectCreator.readSystemException(input); + + case ReplyHeader.USER_EXCEPTION : + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + input.mark(2000); + + String uxId = input.read_string(); + input.reset(); + + throw new ApplicationException(uxId, input); + + case ReplyHeader.LOCATION_FORWARD_PERM : + moved_permanently = true; + + case ReplyHeader.LOCATION_FORWARD : + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + + IOR forwarded = new IOR(); + try + { + forwarded._read_no_endian(input); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL("Cant read forwarding info"); + t.initCause(ex); + throw t; + } + + request.request.setIor(forwarded); + + // If the object has moved permanently, its IOR is replaced. + if (moved_permanently) + setIor(forwarded); + + return invoke(target, request); + + default : + throw new MARSHAL("Unknow reply status: " + rh.reply_status); + } + } + else + { + request.request.send_oneway(); + return null; + } + } + + /** + * Create a request to invoke the method of this CORBA object. + * + * @param target the CORBA object, to that this operation must be applied. + * @param operation the name of the method to invoke. + * + * @return the request. + */ + public Request request(org.omg.CORBA.Object target, String operation) + { + gnuRequest request = new gnuRequest(); + + request.setIor(ior); + request.set_target(target); + + request.setOperation(operation); + request.setORB(orb); + + return request; + } + + /** + * Create a request to invoke the method of this CORBA object. + * + * @param target the CORBA object, to that this operation must be applied. + * @param operation the name of the method to invoke. + * @param response_expected specifies if this is one way message or the + * response to the message is expected. + * + * @return the stream where the method arguments should be written. + */ + public OutputStream request(org.omg.CORBA.Object target, String operation, + boolean response_expected + ) + { + gnuRequest request = new gnuRequest(); + + request.setIor(ior); + request.set_target(target); + request.setOperation(operation); + + request.getParameterStream().response_expected = response_expected; + request.setORB(orb); + + return request.getParameterStream(); + } + + /** + * If there is an opened cache socket to access this object, close + * that socket. + * + * @param target The target is not used, this delegate requires a + * single instance per object. + */ + public void release(org.omg.CORBA.Object target) + { + String key = ior.Internet.host + ":" + ior.Internet.port; + + Socket socket = SocketRepository.get_socket(key); + try + { + if (socket != null) + { + socket.close(); + } + } + catch (IOException ex) + { + // do nothing, then. + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/IOR_contructed_object.java b/libjava/classpath/gnu/CORBA/IOR_contructed_object.java new file mode 100644 index 0000000..2fab707 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/IOR_contructed_object.java @@ -0,0 +1,109 @@ +/* IOR_contructed_object.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; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * Implements an object, constructed from an IOR reference. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class IOR_contructed_object + extends ObjectImpl +{ + /** + * The IOR, from which the object was constructed. + */ + protected final IOR ior; + + /** + * The object id, as defined in IOR. + */ + protected final String[] id; + + /** + * Create the object from the given IOR. + * + * @param an_ior the IOR. + */ + public IOR_contructed_object(ORB orb, IOR an_ior) + { + ior = an_ior; + _set_delegate(new IOR_Delegate(orb, ior)); + id = new String[] { ior.Id }; + } + + /** + * Create the object from the given string IOR representation. + * + * @param an_ior the IOR in the string form. + */ + public IOR_contructed_object(Functional_ORB orb, String an_ior) + { + ior = IOR.parse(an_ior); + _set_delegate(new IOR_Delegate(orb, ior)); + id = new String[] { ior.Id }; + } + + public String[] _ids() + { + return id; + } + + /** + * Get a string reference for this object. + * + * @return the class name:IOR profile + */ + public String toString() + { + return getClass().getName() + ":IOR:" + ior; + } + + /** + * Calls realease on the delegate. + */ + protected void finalize() + throws java.lang.Throwable + { + _get_delegate().release(this); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NamingService/Binding_iterator_impl.java b/libjava/classpath/gnu/CORBA/NamingService/Binding_iterator_impl.java new file mode 100644 index 0000000..79d7870 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/Binding_iterator_impl.java @@ -0,0 +1,139 @@ +/* Binding_iterator.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.NamingService; + +import org.omg.CosNaming.Binding; +import org.omg.CosNaming.BindingHolder; +import org.omg.CosNaming.BindingListHolder; +import org.omg.CosNaming.BindingType; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming._BindingIteratorImplBase; + +/** + * The implementation of the {@link BindingIterator}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class Binding_iterator_impl + extends _BindingIteratorImplBase +{ + /** + * The value, returned by the {@link #next_one} when there + * are no bindings available. + */ + private static final Binding no_more_bindings = + new Binding(new NameComponent[ 0 ], BindingType.nobject); + + /** + * The collection of the available bindings. + */ + private final Binding[] bindings; + + /** + * The position of the internal iterator pointer. + */ + private int p; + + public Binding_iterator_impl(Binding[] a_bindings) + { + bindings = a_bindings; + } + + /** + * Disconnect the iterator from its ORB. The iterator will + * no longer be accessible and will be a subject of the + * garbage collection. + */ + public void destroy() + { + _orb().disconnect(this); + } + + /** + * Return the desired amount of bindings. + * + * @param amount the maximal number of bindings to return. + * @param a_list a holder to store the returned bindings. + * + * @return false if there are no more bindings available, + * true otherwise. + */ + public boolean next_n(int amount, BindingListHolder a_list) + { + if (p < bindings.length) + { + int n = bindings.length - p; + if (n > amount) + n = amount; + + a_list.value = new Binding[ n ]; + for (int i = 0; i < n; i++) + a_list.value [ i ] = bindings [ p++ ]; + + return true; + } + else + { + a_list.value = new Binding[ 0 ]; + return false; + } + } + + /** + * Return the next binding. + * + * @param a_binding a holder, where the next binding will be stored. + * + * @return false if there are no more bindings available, true + * otherwise. + */ + public boolean next_one(BindingHolder a_binding) + { + if (p < bindings.length) + { + a_binding.value = (Binding) bindings [ p++ ]; + return true; + } + else + { + a_binding.value = no_more_bindings; + return false; + } + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/Ext.java b/libjava/classpath/gnu/CORBA/NamingService/Ext.java new file mode 100644 index 0000000..fb7406c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/Ext.java @@ -0,0 +1,230 @@ +/* TransientContextExt.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.NamingService; + +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.Object; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CosNaming.BindingIteratorHolder; +import org.omg.CosNaming.BindingListHolder; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContext; +import org.omg.CosNaming.NamingContextPackage.AlreadyBound; +import org.omg.CosNaming.NamingContextPackage.CannotProceed; +import org.omg.CosNaming.NamingContextPackage.InvalidName; +import org.omg.CosNaming.NamingContextPackage.NotEmpty; +import org.omg.CosNaming.NamingContextPackage.NotFound; +import org.omg.CosNaming._NamingContextExtImplBase; + +/** + * This naming context that adds the the string based extensions, + * defined by {@link NamingContextExt}. The basic functionality + * is handled by the enclosed instance of the {@link NamingContext}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class Ext + extends _NamingContextExtImplBase +{ + /** + * The older version of the naming context, where all relevant calls + * are forwarded. + */ + private final NamingContext classic; + + /** + * The converter class converts between string and array form of the + * name. + */ + private snConverter converter = new snConverter(); + + /** + * Create the extensions for the given instance of the context. + * + * @param previous_version the previous version of the naming context. + */ + public Ext(NamingContext previous_version) + { + classic = previous_version; + } + + /** + * Sets a delegate to this context and, if appropriated, also + * sets the same delegate to the enclosing 'classic' context. + * + * @param a_delegate a delegate to set. + */ + public void _set_delegate(Delegate a_delegate) + { + super._set_delegate(a_delegate); + if (classic instanceof ObjectImpl) + ((ObjectImpl) classic)._set_delegate(a_delegate); + } + + /** {@inheritDoc} */ + public void bind(NameComponent[] a_name, Object an_object) + throws NotFound, CannotProceed, InvalidName, AlreadyBound + { + classic.bind(a_name, an_object); + } + + /** {@inheritDoc} */ + public void bind_context(NameComponent[] a_name, NamingContext context) + throws NotFound, CannotProceed, InvalidName, AlreadyBound + { + classic.bind_context(a_name, context); + } + + /** {@inheritDoc} */ + public NamingContext bind_new_context(NameComponent[] a_name) + throws NotFound, AlreadyBound, CannotProceed, + InvalidName + { + return classic.bind_new_context(a_name); + } + + /** {@inheritDoc} */ + public void destroy() + throws NotEmpty + { + classic.destroy(); + } + + /** {@inheritDoc} */ + public void list(int amount, BindingListHolder a_list, + BindingIteratorHolder an_iter + ) + { + classic.list(amount, a_list, an_iter); + } + + /** {@inheritDoc} */ + public NamingContext new_context() + { + return classic.new_context(); + } + + /** {@inheritDoc} */ + public void rebind(NameComponent[] a_name, Object an_object) + throws NotFound, CannotProceed, InvalidName + { + classic.rebind(a_name, an_object); + } + + /** {@inheritDoc} */ + public void rebind_context(NameComponent[] a_name, NamingContext context) + throws NotFound, CannotProceed, InvalidName + { + classic.rebind_context(a_name, context); + } + + /** {@inheritDoc} */ + public Object resolve(NameComponent[] a_name) + throws NotFound, CannotProceed, InvalidName + { + return classic.resolve(a_name); + } + + /** + * Resolves the name, represented in the form of the string. The name + * is first parsed into an array representation, then the call + * is forwarded to the {@link resolve(NameComponent[])}. + * + * @param a_name_string a name to resolve. + * + * @return the resolved object. + * + * @throws NotFound if the name cannot be resolved. + * @throws InvalidName if the name is invalid. + * @throws CannotProceed on unexpected circumstances. + */ + public Object resolve_str(String a_name_string) + throws NotFound, CannotProceed, InvalidName + { + return resolve(to_name(a_name_string)); + } + + /** + * Convert the name string representation into array representation. + * + * @param a_name_string a string to convert. + * @return a converted array of the name components + * + * @throws InvalidName on parsing error. + */ + public NameComponent[] to_name(String a_name_string) + throws InvalidName + { + return converter.toName(a_name_string); + } + + /** + * Convert a name component array representation into string representation. + * + * @param a_name a name to convert. + * + * @return a string form. + * + * @throws InvalidName if the passed name is invalid. + */ + public String to_string(NameComponent[] a_name) + throws InvalidName + { + return converter.toString(a_name); + } + + /** + * This method is not yet implemented. + * FIXME TODO implement it. + */ + public String to_url(String an_address, String a_name_string) + throws org.omg.CosNaming.NamingContextExtPackage.InvalidAddress, + InvalidName + { + throw new NO_IMPLEMENT("Method to_url() not yet implemented."); + } + + /** {@inheritDoc} */ + public void unbind(NameComponent[] a_name) + throws NotFound, CannotProceed, InvalidName + { + classic.unbind(a_name); + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/NameValidator.java b/libjava/classpath/gnu/CORBA/NamingService/NameValidator.java new file mode 100644 index 0000000..d7d5a14 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NameValidator.java @@ -0,0 +1,79 @@ +/* NameValidator.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.NamingService; + + +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContextPackage.InvalidName; + +/** + * Checks the given name for validity. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameValidator +{ + /** + * Check the given name. This method must be package level, as it is + * not defined in the API. + * + * @param name the name to check. + * + * @throws InvalidName if the given name is not valid. + */ + public static void check(NameComponent[] name) + throws InvalidName + { + if (name == null) + throw new InvalidName("name=null"); + + if (name.length == 0) + throw new InvalidName("name.length=0"); + + for (int i = 0; i < name.length; i++) + { + if (name [ i ] == null) + throw new InvalidName("name[" + i + "]=null"); + if (name [ i ].id == null) + throw new InvalidName("name[" + i + "].id=null"); + if (name [ i ].kind == null) + throw new InvalidName("name[" + i + "].kind=null"); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java b/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java new file mode 100644 index 0000000..a69b061 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NamingMap.java @@ -0,0 +1,187 @@ +/* NamingMap.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.NamingService; + +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContextPackage.AlreadyBound; +import org.omg.CosNaming.NamingContextPackage.InvalidName; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * The Naming Map maps the single names components into associated objects or + * naming contexts. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NamingMap +{ + /** + * The actual map. + */ + private final TreeMap map; + + /** + * Creates an instance of the naming map, intialising the comparator + * to the {@link cmpNameComparator}. + */ + public NamingMap() + { + map = new TreeMap(cmpNameComponent.singleton); + } + + /** + * Put the given CORBA object, specifying the given name as a key. + * If the entry with the given name already exists, or if the given + * object is already mapped under another name, the + * {@link AlreadyBound} exception will be thrown. + * + * @param name the name + * @param object the object + */ + public void bind(NameComponent name, org.omg.CORBA.Object object) + throws AlreadyBound, InvalidName + { + if (containsKey(name)) + { + Object x = get(name); + + // Do not throw an exception if the same object is named by + // the same name. + if (x.equals(object)) + throw new AlreadyBound("The name is in use for another object"); + } + else + { + if (containsValue(object)) + throw new AlreadyBound("Tha object has another name"); + } + } + + /** + * Checks if this map contains the definition of the given name. + * + * @param key the name to check. + */ + public boolean containsKey(NameComponent key) + { + return map.containsKey(key); + } + + /** + * Checks if this map contains the definition of the given object. + * + * @param object the object to check. + */ + public boolean containsValue(org.omg.CORBA.Object object) + { + return map.containsValue(object); + } + + /** + * Returns the map entry set. + * + * @return the map entry set, containing the instances of the + * Map.Entry. + */ + public Set entries() + { + return map.entrySet(); + } + + /** + * Get the CORBA object, associated with the given name. + * + * @param name the name. + * + * @return the associated object, null if none. + */ + public org.omg.CORBA.Object get(NameComponent name) + { + return (org.omg.CORBA.Object) map.get(name); + } + + /** + * Put the given CORBA object, specifying the given name as a key. + * Remove all pre - existing mappings for the given name and object. + * + * @param name the name. + * @param object + */ + public void rebind(NameComponent name, org.omg.CORBA.Object object) + throws InvalidName + { + // Remove the existing mapping for the given name, if present. + remove(name); + + Iterator iter = entries().iterator(); + Map.Entry item; + + // Remove the existing mapping for the given object, if present. + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + if (item.getValue().equals(object)) + iter.remove(); + } + + map.put(name, object); + } + + /** + * Removes the given name, if present. + * + * @param name a name to remove. + */ + public void remove(NameComponent name) + { + map.remove(name); + } + + /** + * Get the size of the map. + */ + public int size() + { + return map.size(); + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java b/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java new file mode 100644 index 0000000..fda46ad --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NamingServiceTransient.java @@ -0,0 +1,160 @@ +/* Server.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.NamingService; + +import gnu.CORBA.Functional_ORB; + +import org.omg.CosNaming.NamingContextExt; + +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; + +/** + * The server for the gnu classpath naming service. This is an executable + * class that must be started to launch the GNU Classpath CORBA + * transient naming service. + * + * GNU Classpath currently works with this naming service and is also + * interoperable with the Sun Microsystems naming services from + * releases 1.3 and 1.4, both transient <i>tnameserv</i> and persistent + * <i>orbd</i>. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NamingServiceTransient +{ + /** + * The default port (900), on that the naming service starts if no + * -ORBInitialPort is specified in the command line. + */ + public static final int PORT = 900; + + /** + * Get the object key for the naming service. The default + * key is the string "NameService" in ASCII. + * + * @return the byte array. + */ + public static byte[] getDefaultKey() + { + try + { // NameService + return "NameService".getBytes("UTF-8"); + } + catch (UnsupportedEncodingException ex) + { + throw new InternalError("UTF-8 unsupported"); + } + } + + /** + * Start the naming service on the current host at the given port. + * The parameter -org.omg.CORBA.ORBInitialPort NNN or + * -ORBInitialPort NNN, if present, specifies the port, on that + * the service must be started. If this key is not specified, + * the service starts at the port 900. + * + * The parameter -ior FILE_NAME, if present, forces to store the ior string + * of this naming service to the specified file. + * + * @param args the parameter string. + */ + public static void main(String[] args) + { + int port = PORT; + String iorf = null; + try + { + // Create and initialize the ORB + final Functional_ORB orb = new Functional_ORB(); + + if (args.length > 1) + for (int i = 0; i < args.length - 1; i++) + { + if (args [ i ].endsWith("ORBInitialPort")) + port = Integer.parseInt(args [ i + 1 ]); + + if (args [ i ].equals("-ior")) + iorf = args [ i + 1 ]; + } + + Functional_ORB.setPort(port); + + // Create the servant and register it with the ORB + NamingContextExt namer = new Ext(new TransientContext()); + orb.connect(namer, getDefaultKey()); + + // Storing the IOR reference. + String ior = orb.object_to_string(namer); + if (iorf != null) + { + FileOutputStream f = new FileOutputStream(iorf); + PrintStream p = new PrintStream(f); + p.print(ior); + p.close(); + } + + System.out.println("GNU Classpath, transient naming service. " + + "Copyright (C) 2005 Free Software Foundation\n" + + "This tool comes with ABSOLUTELY NO WARRANTY. " + + "This is free software, and you are\nwelcome to " + + "redistribute it under conditions, defined in " + + "GNU Classpath license.\n\n" + ior + ); + + new Thread() + { + public void run() + { + // Wait for invocations from clients. + orb.run(); + } + }.start(); + } + catch (Exception e) + { + System.err.println("ERROR: " + e); + e.printStackTrace(System.out); + } + + // Restore the default value for allocating ports for the subsequent objects. + Functional_ORB.setPort(Functional_ORB.DEFAULT_INITIAL_PORT); + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/TransientContext.java b/libjava/classpath/gnu/CORBA/NamingService/TransientContext.java new file mode 100644 index 0000000..4b7c193 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/TransientContext.java @@ -0,0 +1,416 @@ +/* nContext.java -- implementation of NamingContext + 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.NamingService; + +import org.omg.CORBA.Object; +import org.omg.CosNaming.Binding; +import org.omg.CosNaming.BindingIteratorHolder; +import org.omg.CosNaming.BindingListHolder; +import org.omg.CosNaming.BindingType; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContext; +import org.omg.CosNaming.NamingContextOperations; +import org.omg.CosNaming.NamingContextPackage.AlreadyBound; +import org.omg.CosNaming.NamingContextPackage.CannotProceed; +import org.omg.CosNaming.NamingContextPackage.InvalidName; +import org.omg.CosNaming.NamingContextPackage.NotEmpty; +import org.omg.CosNaming.NamingContextPackage.NotFound; +import org.omg.CosNaming.NamingContextPackage.NotFoundReason; +import org.omg.CosNaming._NamingContextImplBase; + +import java.util.Iterator; +import java.util.Map; + +/** + * This class implements the transient naming service, defined by + * {@link NamingContex}. The 'transient' means that the service does + * not store its state into the persistent memory. If the service is + * restarted, the named objects must be re-registered again. + * + * TODO Write the persistent naming service. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class TransientContext + extends _NamingContextImplBase + implements NamingContext, NamingContextOperations +{ + /** + * The already named contexts. + */ + protected final NamingMap named_contexts = new NamingMap(); + + /** + * The already named objects. + */ + protected final NamingMap named_objects = new NamingMap(); + + /** + * Gives the object a name, valid in this context. + * + * @param a_name the name, being given to the object. + * @param an_object the object, being named. + * + * @throws AlreadyBound if the object is already named in this context. + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public void bind(NameComponent[] a_name, Object an_object) + throws NotFound, CannotProceed, InvalidName, AlreadyBound + { + if (a_name.length == 1) + named_objects.bind(a_name [ 0 ], an_object); + else + { + NamingContext context = + (NamingContext) named_contexts.get(a_name [ 0 ]); + context.bind(getSuffix(a_name), an_object); + } + } + + /** + * Gives a child context name, valid in this context. + * + * @param a_name the name, being given to the child context. + * @param a_context the child context being named. + * + * @throws AlreadyBound if the child context is already named in + * the current context. + */ + public void bind_context(NameComponent[] a_name, NamingContext a_context) + throws NotFound, CannotProceed, InvalidName, AlreadyBound + { + if (a_name.length == 1) + named_contexts.bind(a_name [ 0 ], a_context); + else + { + NamingContext context = + (NamingContext) named_contexts.get(a_name [ 0 ]); + context.bind_context(getSuffix(a_name), a_context); + } + } + + /** + * Create a new context and give it a given name (bound it) + * in the current context. + * + * The context being created is returned by calling + * {@link #new_context()}. + * + * @param a_name the name being given to the new context. + * + * @return the newly created context. + * + * @throws AlreadyBound if the name is already in use. + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public NamingContext bind_new_context(NameComponent[] a_name) + throws NotFound, AlreadyBound, CannotProceed, + InvalidName + { + if (named_contexts.containsKey(a_name [ 0 ]) || + named_objects.containsKey(a_name [ 0 ]) + ) + throw new AlreadyBound(); + + NamingContext child = new_context(); + bind_context(a_name, child); + return child; + } + + /** + * Destroy this context (must be empty). + * @throws NotEmpty if the context being destroyed is not empty. + */ + public void destroy() + throws NotEmpty + { + if (named_contexts.size() > 0 || named_objects.size() > 0) + throw new NotEmpty(); + } + + /** + * Iterate over all bindings, defined in this namind context. + * + * @param amount the maximal number of context to return in the + * holder a_list. The remaining bindings are accessible via iterator + * an_iter. If the parameter amount is zero, all bindings are accessed only + * via this iterator. + * + * This implementation list contexts first, then objects. + * + * @param a_list the holder, where the returned bindigs are stored. + * @param an_iter the iterator that can be used to access the remaining + * bindings. + */ + public void list(int amount, BindingListHolder a_list, + BindingIteratorHolder an_iter + ) + { + int nb = named_contexts.size() + named_objects.size(); + int nl = nb; + if (nl > amount) + nl = amount; + + a_list.value = new Binding[ nl ]; + + Iterator contexts = named_contexts.entries().iterator(); + Iterator objects = named_objects.entries().iterator(); + + // Create a binding list. + for (int i = 0; i < nl; i++) + { + if (contexts.hasNext()) + a_list.value [ i ] = mkBinding(contexts.next(), BindingType.ncontext); + else if (objects.hasNext()) + a_list.value [ i ] = mkBinding(objects.next(), BindingType.nobject); + else + throw new InternalError(); + } + + // Create an iterator. + Binding[] remainder = new Binding[ nb - nl ]; + int p = 0; + + while (contexts.hasNext()) + remainder [ p++ ] = mkBinding(contexts.next(), BindingType.ncontext); + + while (objects.hasNext()) + remainder [ p++ ] = mkBinding(objects.next(), BindingType.nobject); + + Binding_iterator_impl bit = new Binding_iterator_impl(remainder); + _orb().connect(bit); + an_iter.value = bit; + } + + /** + * Creates a new naming context, not bound to any name. + */ + public NamingContext new_context() + { + Ext context = new Ext(new TransientContext()); + + // Connect the context to the current ORB: + _orb().connect(context); + return context; + } + + /** + * Names or renames the object. + * + * @param a_name the new name, being given to the object + * in the scope of the current context. If the object is already + * named in this context, it is renamed. + * + * @param an_object the object, being named. + * + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public void rebind(NameComponent[] a_name, Object an_object) + throws NotFound, CannotProceed, InvalidName + { + if (a_name.length == 1) + named_objects.rebind(a_name [ 0 ], an_object); + else + { + NamingContext context = + (NamingContext) named_contexts.get(a_name [ 0 ]); + context.rebind(getSuffix(a_name), an_object); + } + } + + /** + * Names or renames the child context. + * If the child context is already named in + * the current context, it is renamed. The the name being given is in + * use, the old meaning of the name is discarded. + * + * @param a_name the name, being given to the child context in the scope + * of the current context. + * + * @param a_context the child context being named. + * + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public void rebind_context(NameComponent[] a_name, NamingContext a_context) + throws NotFound, CannotProceed, InvalidName + { + if (a_name.length == 1) + named_contexts.rebind(a_name [ 0 ], a_context); + else + { + NamingContext context = + (NamingContext) named_contexts.get(a_name [ 0 ]); + context.rebind_context(getSuffix(a_name), a_context); + } + } + + /** + * Get the object, bound to the specified name in this + * context. The given object must match the bound + * name. + * + * This implementation resolves the names as defined in specification + * of the CORBA naming service. This means, if the beginning of the + * name can be resolved to some naming context, the request is + * forwarded to this context, passing the unresolved name part as a + * parameter. In this way, it is possible to have a hierarchy of the + * naming services. The central services resolve the the beginning + * of the name. The local services resolve the remaining nodes of the + * name that may be relevant to some local details. It can be three or + * more ranks of the naming services. + * + * @param a_name the object name. + * + * @return the object, matching this name. The client + * usually casts or narrows (using the helper) the returned value + * to the more specific type. + * + * @throws NotFound if the name cannot be resolved. + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public Object resolve(NameComponent[] a_name) + throws NotFound, CannotProceed, InvalidName + { + NameValidator.check(a_name); + + if (a_name.length > 1) + return resolveSubContext(a_name); + else + { + // A single node name. + org.omg.CORBA.Object object; + + object = named_objects.get(a_name [ 0 ]); + if (object != null) + return object; + + object = named_contexts.get(a_name [ 0 ]); + if (object != null) + return object; + } + + throw new NotFound(NotFoundReason.missing_node, a_name); + } + + /** + * Removes the name from the binding context. + * + * @param a_name a name to remove. + * + * @throws InvalidName if the name has zero length or otherwise invalid. + */ + public void unbind(NameComponent[] a_name) + throws NotFound, CannotProceed, InvalidName + { + NameValidator.check(a_name); + + // Single node name - handle it. + if (a_name.length == 1) + { + if (named_objects.containsKey(a_name [ 0 ])) + named_objects.remove(a_name [ 0 ]); + else if (named_contexts.containsKey(a_name [ 0 ])) + named_contexts.remove(a_name [ 0 ]); + else + throw new NotFound(NotFoundReason.missing_node, a_name); + } + else + { + // Handle the first node and forward the command. + NamingContext subcontext = + (NamingContext) named_contexts.get(a_name [ 0 ]); + + if (subcontext == null) + throw new NotFound(NotFoundReason.missing_node, a_name); + + subcontext.unbind(getSuffix(a_name)); + } + } + + /** + * Get the name suffix, discarding the first member. + */ + private NameComponent[] getSuffix(NameComponent[] a_name) + { + NameComponent[] suffix = new NameComponent[ a_name.length - 1 ]; + System.arraycopy(a_name, 1, suffix, 0, suffix.length); + return suffix; + } + + /** + * Create a binding. + * + * @param entry the entry, defining the bound object. + * @param type the binding type. + * @return the created binding. + */ + private Binding mkBinding(java.lang.Object an_entry, BindingType type) + { + Map.Entry entry = (Map.Entry) an_entry; + Binding b = new Binding(); + + // The name component has always only one node (the current context) + b.binding_name = new NameComponent[] { (NameComponent) entry.getKey() }; + b.binding_type = type; + return b; + } + + /** + * Find the context, bound to the first name of the given + * name, and pass the remainder (without the first node) + * of the name for that context to resolve. + * + * @param name the name to resolve. + * + * @return the resolved context + */ + private Object resolveSubContext(NameComponent[] a_name) + throws NotFound, CannotProceed, InvalidName + { + // A multiple node name. + // This context resolves the first node only. + NamingContext context = (NamingContext) named_contexts.get(a_name [ 0 ]); + if (context == null) + throw new NotFound(NotFoundReason.missing_node, a_name); + + NameComponent[] suffix = getSuffix(a_name); + + return context.resolve(suffix); + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java b/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java new file mode 100644 index 0000000..1e06fb8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/cmpNameComponent.java @@ -0,0 +1,98 @@ +/* cmpNameComponent.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.NamingService; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CosNaming.NameComponent; + +import java.util.Comparator; + +/** + * This class implements the name component comparator, needed to + * sort and compare the name components in maps and sorted sets. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public final class cmpNameComponent + implements Comparator +{ + /** + * The singleton instance of the name comparator. + */ + public static final cmpNameComponent singleton = new cmpNameComponent(); + + /** + * It is enough to have a singleton. + */ + private cmpNameComponent() + { + } + + /** + * Compare the two names components. + * + * @param nc_a the first name component. + * @param nc_b the second name component. + * + * @return 0 if the name components are equal, non zero value + * as result of comparison otherwise. + * + * @throws BAD_PARAM if one of the components is empty or + * has {@link NameComponent#id} or {@link NameComponent#kind} + * field intialised to null. + */ + public final int compare(Object nc_a, Object nc_b) + { + NameComponent a = (NameComponent) nc_a; + NameComponent b = (NameComponent) nc_b; + + int cn = a.id.compareTo(b.id); + if (cn != 0) + return cn; + return a.kind.compareTo(b.kind); + } + + /** + * All instances of this class are equal. + */ + public boolean equals(Object x) + { + return x instanceof cmpNameComponent; + } +} diff --git a/libjava/classpath/gnu/CORBA/NamingService/snConverter.java b/libjava/classpath/gnu/CORBA/NamingService/snConverter.java new file mode 100644 index 0000000..a9b9219 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/snConverter.java @@ -0,0 +1,328 @@ +/* snConverter.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.NamingService; + +import org.omg.CORBA.IntHolder; +import org.omg.CosNaming.NameComponent; +import org.omg.CosNaming.NamingContextPackage.InvalidName; + +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * This class converts between string and array representations of the + * multi component object names. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class snConverter +{ + /** + * A string, indicating the escape character. + */ + public static final String ESCAPE = "\\"; + + /** + * Convert the string name representation into the array name + * representation. See {@link #toString(NameComponent)} for the + * description of this format. + * + * @param name the string form of the name. + * + * @return the array form of the name. + * + * @throws InvalidName if the name cannot be parsed. + */ + public NameComponent[] toName(String a_name) + throws InvalidName + { + ArrayList components = new ArrayList(); + StringTokenizer st = new StringTokenizer(a_name, "./\\", true); + + String id; + String kind; + String next; + + // Create the buffer array, reserving the last element for null. + String[] n = new String[ st.countTokens() + 1 ]; + + int pp = 0; + while (st.hasMoreTokens()) + n [ pp++ ] = st.nextToken(); + + IntHolder p = new IntHolder(); + + NameComponent node = readNode(p, n); + + while (node != null) + { + components.add(node); + node = readNode(p, n); + } + + NameComponent[] name = new NameComponent[ components.size() ]; + for (int i = 0; i < name.length; i++) + { + name [ i ] = (NameComponent) components.get(i); + } + + NameValidator.check(name); + + return name; + } + + /** + * Converts the name into its string representation, as defined in + * the specification CORBA naming service. + * + * A string representation for the name consists of the name components, + * separated by a slash '/' character (for example, 'a/b/c'). If the + * {@link NameComponent#kind} field is not empty, it is given after + * period ('.'), for example 'a.b/c.d/.' . + * The period alone represents node where part where both + * {@link NameComponent#kind} and {@link NameComponent#id} are empty strings. + * + * If slash or dot are part of the name, they are escaped by backslash ('\'). + * If the backslash itself is part of the name, it is doubled. + * + * @param a_name a name to convert. + * @return a string representation. + */ + public String toString(NameComponent[] a_name) + throws InvalidName + { + NameValidator.check(a_name); + + StringBuffer b = new StringBuffer(); + + NameComponent n; + + for (int ni = 0; ni < a_name.length; ni++) + { + n = a_name [ ni ]; + appEscaping(b, n.id); + if (n.kind.length() > 0) + { + b.append('.'); + appEscaping(b, n.kind); + } + + if (ni < a_name.length - 1) + b.append('/'); + } + return b.toString(); + } + + /** + * Append the contents of the string to this + * string buffer, inserting the escape sequences, where required. + * + * @param b a buffer to append the contents to. + * @param s a string to append. + */ + private void appEscaping(StringBuffer b, String s) + { + char c; + for (int i = 0; i < s.length(); i++) + { + c = s.charAt(i); + switch (c) + { + case '.' : + case '/' : + case '\\' : + b.append('\\'); + b.append(c); + break; + + default : + b.append(c); + break; + } + } + } + + /** + * Assert the end of the current name component. + */ + private void assertEndOfNode(IntHolder p, String[] t) + throws InvalidName + { + if (t [ p.value ] != null) + if (!t [ p.value ].equals("/")) + throw new InvalidName("End of node expected at token " + p.value); + } + + /** + * Read the named component node. After reading the current positon + * advances to the beginning of the next node in an array. + * + * @param p the current position being wrapped inside the passed + * IntHolder. + * + * @param t the text buffer. + * + * @return the created node. + */ + private NameComponent readNode(IntHolder p, String[] t) + throws InvalidName + { + // End of stream has been reached. + if (t [ p.value ] == null) + return null; + + NameComponent n = new NameComponent(); + + if (t [ p.value ].equals(".")) + { + // The 'id' is missing, but the 'kind' may follow. + n.id = ""; + p.value++; + n.kind = readPart(p, t); + assertEndOfNode(p, t); + if (t [ p.value ] != null) + p.value++; + } + else if (t [ p.value ].equals("/")) + { + // This is not allowed here and may happen only + // on two subsequent slashes. + throw new InvalidName("Unexpected '/' token " + p.value); + } + else + { + n.id = readPart(p, t); + + // If some chars follow the id. + if (t [ p.value ] != null) + { + // Dot means that the kind part follows + if (t [ p.value ].equals(".")) + { + p.value++; + n.kind = readPart(p, t); + assertEndOfNode(p, t); + if (t [ p.value ] != null) + p.value++; + } + + // The next name component follows - advance to + // the beginning of the next name component. + else if (t [ p.value ].equals("/")) + { + n.kind = ""; + p.value++; + } + else + throw new InvalidName("Unexpected '" + t [ p.value ] + + "' at token " + p.value + ); + } + else + + // Id, and then end of sequence. + n.kind = ""; + } + + return n; + } + + /** + * Read the name part (id or kind). + * + * @param p the current position. After reading, advances + * to the beginning of the next name fragment. + * + * @param t the string buffer. + * + * @return the name part with resolved escape sequences. + */ + private String readPart(IntHolder p, String[] t) + { + StringBuffer part = new StringBuffer(); + + while (t [ p.value ] != null && !t [ p.value ].equals(".") && + !t [ p.value ].equals("/") + ) + { + if (t [ p.value ].equals(ESCAPE)) + { + p.value++; + part.append(t [ p.value ]); + } + else + part.append(t [ p.value ]); + + p.value++; + } + + return part.toString(); + } + + public static void main(String[] args) + { + NameComponent a = new NameComponent("a", "ak"); + NameComponent b = new NameComponent("b/z", "b.k"); + NameComponent c = new NameComponent("c", ""); + + snConverter sn = new snConverter(); + + try + { + String s = sn.toString(new NameComponent[] { a, b, c }); + System.out.println(s); + + //NameComponent[] k = toName("a.k/b.k2/c/d/."); + //NameComponent[] k = toName("a.bc/.b/c.x"); + + NameComponent[] k = sn.toName(s); + System.out.println("ToString"); + + for (int i = 0; i < k.length; i++) + { + System.out.println(k [ i ].id + ":" + k [ i ].kind); + } + } + catch (InvalidName ex) + { + ex.printStackTrace(); + } + } + +} diff --git a/libjava/classpath/gnu/CORBA/ObjectCreator.java b/libjava/classpath/gnu/CORBA/ObjectCreator.java new file mode 100644 index 0000000..b99c46b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ObjectCreator.java @@ -0,0 +1,348 @@ +/* ExceptionCreator.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; + +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.CompletionStatusHelper; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** + * Creates java objects from the agreed IDL names for the simple + * case when the CORBA object is directly mapped into the locally + * defined java class. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ObjectCreator +{ + /** + * The standard OMG prefix. + */ + public static final String OMG_PREFIX = "omg.org/"; + + /** + * The standard java prefix. + */ + public static final String JAVA_PREFIX = "org.omg."; + + /** + * The prefix for classes that are placed instide the + * gnu.CORBA namespace. + */ + public static final String CLASSPATH_PREFIX = "gnu.CORBA."; + + /** + * Try to instantiate an object with the given IDL name. + * The object must be mapped to the local java class. + * The omg.org domain must be mapped into the object in either + * org/omg or gnu/CORBA namespace. + * + * @param IDL name + * @return instantiated object instance or null if no such + * available. + */ + public static java.lang.Object createObject(String idl, String suffix) + { + try + { + return Class.forName(toClassName(JAVA_PREFIX, idl) + suffix) + .newInstance(); + } + catch (Exception ex) + { + try + { + return Class.forName(toClassName(CLASSPATH_PREFIX, idl) + suffix) + .newInstance(); + } + catch (Exception exex) + { + return null; + } + } + } + + /** + * Create the system exception with the given idl name. + * + * @param idl the exception IDL name, must match the syntax + * "IDL:<class/name>:1.0". + * @param minor the exception minor code. + * @param completed the exception completion status. + * + * @return the created exception. + */ + public static SystemException createSystemException(String idl, int minor, + CompletionStatus completed + ) + { + try + { + String cl = toClassName(JAVA_PREFIX, idl); + Class exClass = Class.forName(cl); + + Constructor constructor = + exClass.getConstructor(new Class[] + { + String.class, int.class, + CompletionStatus.class + } + ); + + Object exception = + constructor.newInstance(new Object[] + { + " Remote exception " + idl + ", minor " + + minor + ", " + completed + ".", + new Integer(minor), completed + } + ); + + return (SystemException) exception; + } + catch (Exception ex) + { + ex.printStackTrace(); + return new UNKNOWN("Unsupported system exception", minor, completed); + } + } + + /** + * Read the system exception from the given stream. + * @param input the CDR stream to read from. + * @return the exception that has been stored in the stream + * (IDL name, minor code and completion status). + */ + public static SystemException readSystemException(InputStream input) + { + String idl = input.read_string(); + int minor = input.read_ulong(); + CompletionStatus status = CompletionStatusHelper.read(input); + + SystemException exception = + ObjectCreator.createSystemException(idl, minor, status); + + return exception; + } + + /** + * Reads the user exception, having the given Id, from the + * input stream. The id is expected to be in the form like + * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' + * + * @param idl the exception idl name. + * @param input the stream to read from. + * + * @return the loaded exception. + * @return null if the helper class cannot be found. + */ + public static UserException readUserException(String idl, InputStream input) + { + try + { + String helper = toHelperName(idl); + Class helperClass = Class.forName(helper); + + Method read = + helperClass.getMethod("read", + new Class[] + { + org.omg.CORBA.portable.InputStream.class + } + ); + + return (UserException) read.invoke(null, new Object[] { input }); + } + catch (MARSHAL mex) + { + // This one is ok to throw + throw mex; + } + catch (Exception ex) + { + ex.printStackTrace(); + return null; + } + } + + /** + * Gets the helper class name from the string like + * 'IDL:test/org/omg/CORBA/ORB/communication/ourUserException:1.0' + * + * @param IDL the idl name. + */ + public static String toHelperName(String IDL) + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); + + return s.replace('/', '.') + "Helper"; + } + + /** + * Writes the system exception data to CDR output stream. + * + * @param output a stream to write data to. + * @param ex an exception to write. + */ + public static void writeSystemException(OutputStream output, + SystemException ex + ) + { + String exIDL = toIDL(ex.getClass().getName()); + output.write_string(exIDL); + output.write_ulong(ex.minor); + CompletionStatusHelper.write(output, ex.completed); + } + + /** + * Converts the given IDL name to class name. + * + * @param IDL the idl name. + * + */ + protected static String toClassName(String prefix, String IDL) + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = prefix + s.substring(OMG_PREFIX.length()); + + return s.replace('/', '.'); + } + + /** + * Converts the given IDL name to class name and tries to load the + * matching class. The OMG prefix (omg.org) is replaced by + * the java prefix org.omg. No other prefixes are added. + * + * @param IDL the idl name. + * + * TODO Cache the returned classes, avoiding these string manipulations + * each time the conversion is required. + * + * @return the matching class or null if no such is available. + */ + public static Class Idl2class(String IDL) + { + String s = IDL; + int a = s.indexOf(':') + 1; + int b = s.lastIndexOf(':'); + + s = IDL.substring(a, b); + + if (s.startsWith(OMG_PREFIX)) + s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); + + String cn = s.replace('/', '.'); + + try + { + return Class.forName(cn); + } + catch (ClassNotFoundException ex) + { + return null; + } + } + + /** + * Converts the given IDL name to class name, tries to load the + * matching class and create an object instance with parameterless + * constructor. The OMG prefix (omg.org) is replaced by + * the java prefix org.omg. No other prefixes are added. + * + * @param IDL the idl name. + * + * @return instantiated object instance or null if such attempt was not + * successful. + */ + public static java.lang.Object Idl2Object(String IDL) + { + Class cx = Idl2class(IDL); + + try + { + if (cx != null) + return cx.newInstance(); + else + return null; + } + catch (Exception ex) + { + return null; + } + } + + /** + * Convert the class name to IDL name. + * + * @param cn the class name. + * + * @return the idl name. + */ + public static String toIDL(String cn) + { + if (cn.startsWith(JAVA_PREFIX)) + cn = OMG_PREFIX + cn.substring(JAVA_PREFIX.length()).replace('.', '/'); + else if (cn.startsWith(CLASSPATH_PREFIX)) + cn = + OMG_PREFIX + cn.substring(CLASSPATH_PREFIX.length()).replace('.', '/'); + + return "IDL:" + cn + ":1.0"; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/OctetHolder.java b/libjava/classpath/gnu/CORBA/OctetHolder.java new file mode 100644 index 0000000..02fd9a4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/OctetHolder.java @@ -0,0 +1,129 @@ +/* OctetHolder.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; + +import gnu.CORBA.primitiveTypeCode; + +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; + +/** + * A holder for CORBA <code>octet</code> that is mapped into + * java <code>long</code>. + * + * The holders have several application areas. The end user usually + * sees them implementing CORBA methods where the primitive type + * is passed by reference. While CORBA (or, for example, C) supports + * this, the java does not and a wrapper class is required. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public final class OctetHolder + implements Streamable +{ + /** + * The default type code for this holder. + */ + private static final TypeCode t_octet = + new primitiveTypeCode(TCKind.tk_octet); + + /** + * The <code>long</code> (CORBA <code>octet</code>) value, + * held by this OctetHolder. + */ + public byte value; + + /** + * Constructs an instance of OctetHolder, + * initializing {@link #value} to <code>0 </code>. + */ + public OctetHolder() + { + } + + /** + * Constructs an instance of OctetHolder, + * initializing {@link #value} to the given <code>octed</code> (byte). + * + * @param initial_value a value that will be assigned to the + * {@link #value} field. + */ + public OctetHolder(byte initial_value) + { + value = initial_value; + } + + /** + * Fill in the {@link value } field by reading the required data + * from the given stream. For <code>octet</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.InputStream#read_octet}. + * + * @param input the input stream to read from. + */ + public void _read(InputStream input) + { + value = input.read_octet(); + } + + /** + * Returns the TypeCode, corresponding the CORBA type that is stored + * using this holder. + */ + public TypeCode _type() + { + return t_octet; + } + + /** + * Write the {@link value } field to the given stream. + * For <code>octet</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.OutputStream#write_octet(long) }. + * + * @param output the output stream to write into. + */ + public void _write(OutputStream output) + { + output.write_octet(value); + } +} diff --git a/libjava/classpath/gnu/CORBA/Poa/InvalidPolicyHolder.java b/libjava/classpath/gnu/CORBA/Poa/InvalidPolicyHolder.java new file mode 100644 index 0000000..154762a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/InvalidPolicyHolder.java @@ -0,0 +1,106 @@ +/* InvalidPolicyHolder.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.Poa; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import org.omg.PortableServer.POAPackage.InvalidPolicyHelper; + +/** +* A holder for the exception {@link InvalidPolicy}. + +* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) +*/ +public class InvalidPolicyHolder + implements Streamable +{ + /** + * The stored InvalidPolicy value. + */ + public InvalidPolicy value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public InvalidPolicyHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public InvalidPolicyHolder(InvalidPolicy initialValue) + { + value = initialValue; + } + + /** + * Fill in the {@link value} by data from the CDR stream. + * + * @param input the org.omg.CORBA.portable stream to read. + */ + public void _read(InputStream input) + { + value = InvalidPolicyHelper.read(input); + } + + /** + * Write the stored value into the CDR stream. + * + * @param output the org.omg.CORBA.portable stream to write. + */ + public void _write(OutputStream output) + { + InvalidPolicyHelper.write(output, value); + } + + /** + * Get the typecode of the InvalidPolicy. + */ + public TypeCode _type() + { + return InvalidPolicyHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Restricted_ORB.java b/libjava/classpath/gnu/CORBA/Restricted_ORB.java new file mode 100644 index 0000000..801154e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Restricted_ORB.java @@ -0,0 +1,463 @@ +/* RestrictedORB.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; + +import gnu.CORBA.CDR.cdrBufOutput; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.Environment; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.Request; +import org.omg.CORBA.StructMember; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.UnionMember; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ValueFactory; + +import java.applet.Applet; + +import java.util.Hashtable; +import java.util.Properties; + +/** + * This class implements so-called Singleton ORB, a highly restricted version + * that cannot communicate over network. This ORB is provided + * for the potentially malicious applets with heavy security restrictions. + * It, however, supports some basic features that might be needed even + * when the network access is not granted. + * + * This ORB can only create typecodes, + * {@link Any}, {@link ContextList}, {@link NVList} and + * {@link org.omg.CORBA.portable.OutputStream} that writes to an + * internal buffer. + * + * All other methods throw the {@link NO_IMPLEMENT} exception. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Restricted_ORB + extends org.omg.CORBA_2_3.ORB +{ + /** + * The singleton instance of this ORB. + */ + public static final ORB Singleton = new Restricted_ORB(); + + /** + * The value factories. + */ + protected Hashtable factories = new Hashtable(); + + /** + * Create a new instance of the RestrictedORB. This is used + * in derived classes only. + */ + protected Restricted_ORB() + { + } + + /** {@inheritDoc} */ + public TypeCode create_alias_tc(String id, String name, TypeCode typecode) + { + return new aliasTypeCode(typecode, id, name); + } + + /** {@inheritDoc} */ + public Any create_any() + { + gnuAny any = new gnuAny(); + any.setOrb(this); + return any; + } + + /** {@inheritDoc} */ + public TypeCode create_array_tc(int length, TypeCode element_type) + { + primitiveArrayTypeCode p = + new primitiveArrayTypeCode(TCKind.tk_array, element_type); + p.setLength(length); + return p; + } + + /** {@inheritDoc} */ + public ContextList create_context_list() + { + return new gnuContextList(); + } + + /** {@inheritDoc} */ + public TypeCode create_enum_tc(String id, String name, String[] values) + { + recordTypeCode r = new recordTypeCode(TCKind.tk_enum); + for (int i = 0; i < values.length; i++) + { + r.field().name = values [ i ]; + } + + r.setId(id); + r.setName(name); + + return r; + } + + /** {@inheritDoc} */ + public Environment create_environment() + { + return new gnuEnvironment(); + } + + /** {@inheritDoc} */ + public ExceptionList create_exception_list() + { + return new gnuExceptionList(); + } + + /** {@inheritDoc} */ + public TypeCode create_exception_tc(String id, String name, + StructMember[] members + ) + { + recordTypeCode r = new recordTypeCode(TCKind.tk_except); + r.setId(id); + r.setName(name); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public TypeCode create_interface_tc(String id, String name) + { + no(); + return null; + } + + /** {@inheritDoc} */ + public NVList create_list(int count) + { + return new gnuNVList(count); + } + + /** {@inheritDoc} */ + public NamedValue create_named_value(String s, Any any, int flags) + { + return new gnuNamedValue(); + } + + /** {@inheritDoc} */ + public OutputStream create_output_stream() + { + cdrBufOutput stream = new cdrBufOutput(); + stream.setOrb(this); + return stream; + } + + /** {@inheritDoc} */ + public TypeCode create_sequence_tc(int bound, TypeCode element_type) + { + primitiveArrayTypeCode p = + new primitiveArrayTypeCode(TCKind.tk_sequence, element_type); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode create_string_tc(int bound) + { + stringTypeCode p = new stringTypeCode(TCKind.tk_string); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode create_struct_tc(String id, String name, + StructMember[] members + ) + { + recordTypeCode r = new recordTypeCode(TCKind.tk_struct); + r.setId(id); + r.setName(name); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** {@inheritDoc} */ + public TypeCode create_union_tc(String id, String name, TypeCode type, + UnionMember[] members + ) + { + recordTypeCode r = new recordTypeCode(TCKind.tk_union); + r.setId(id); + r.setName(name); + + for (int i = 0; i < members.length; i++) + { + r.add(members [ i ]); + } + + return r; + } + + /** {@inheritDoc} */ + public TypeCode create_wstring_tc(int bound) + { + stringTypeCode p = new stringTypeCode(TCKind.tk_wstring); + p.setLength(bound); + return p; + } + + /** {@inheritDoc} */ + public TypeCode get_primitive_tc(TCKind tcKind) + { + try + { + return typeNamer.getPrimitveTC(tcKind); + } + catch (BadKind ex) + { + throw new BAD_PARAM("This is not a primitive type code: " + + tcKind.value() + ); + } + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public String[] list_initial_services() + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public String object_to_string(org.omg.CORBA.Object forObject) + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws InvalidName never in this class, but it is thrown + * in the derived classes. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object resolve_initial_references(String name) + throws InvalidName + { + no(); + throw new InternalError(); + } + + /** + * Shutdown the ORB server. + * + * For RestrictedORB, returns witout action. + */ + public void run() + { + } + + /** + * Shutdown the ORB server. + * + * For RestrictedORB, returns witout action. + */ + public void shutdown(boolean wait_for_completion) + { + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object string_to_object(String IOR) + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + protected void set_parameters(Applet app, Properties props) + { + no(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + protected void set_parameters(String[] args, Properties props) + { + no(); + } + + /** + * Throws an exception, stating that the given method is not supported + * by the Restricted ORB. + */ + private final void no() + { + // Apart the programming errors, this can only happen if the + // malicious code is trying to do that it is not allowed. + throw new NO_IMPLEMENT("Use init(args, props) for the functional version."); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public Request get_next_response() + throws org.omg.CORBA.WrongTransaction + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public boolean poll_next_response() + { + no(); + throw new InternalError(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public void send_multiple_requests_deferred(Request[] requests) + { + no(); + } + + /** + * This method is not allowed for a RestrictedORB. + * + * @throws NO_IMPLEMENT, always. + */ + public void send_multiple_requests_oneway(Request[] requests) + { + no(); + } + + /** + * Register the value factory under the given repository id. + */ + public ValueFactory register_value_factory(String repository_id, + ValueFactory factory + ) + { + factories.put(repository_id, factory); + return factory; + } + + /** + * Unregister the value factroy. + */ + public void unregister_value_factory(String id) + { + factories.remove(id); + } + + /** + * Look for the value factory for the value, having the given repository id. + * The implementation checks for the registered value factories first. + * If none found, it tries to load and instantiate the class, mathing the + * given naming convention. If this faild, null is returned. + * + * @param repository_id a repository id. + * + * @return a found value factory, null if none. + */ + public ValueFactory lookup_value_factory(String repository_id) + { + ValueFactory f = (ValueFactory) factories.get(repository_id); + if (f != null) + return f; + + f = (ValueFactory) ObjectCreator.createObject(repository_id, "DefaultFactory"); + if (f != null) + factories.put(repository_id, f); + + return f; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/ServiceDetailHolder.java b/libjava/classpath/gnu/CORBA/ServiceDetailHolder.java new file mode 100644 index 0000000..e878637 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ServiceDetailHolder.java @@ -0,0 +1,91 @@ +/* ServiceDetailHolder.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; + +import org.omg.CORBA.ServiceDetail; +import org.omg.CORBA.ServiceDetailHelper; + + +/** + * The service detail holder. This class is not included in the original + * API specification, so we place it outside the org.omg namespace. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ServiceDetailHolder + implements org.omg.CORBA.portable.Streamable +{ + /** + * The stored value. + */ + public ServiceDetail value; + + /** + * Create the initialised instance. + * @param initialValue + */ + public ServiceDetailHolder(ServiceDetail initialValue) + { + value = initialValue; + } + + /** + * Read from the CDR stream. + */ + public void _read(org.omg.CORBA.portable.InputStream in) + { + value = ServiceDetailHelper.read(in); + } + + /** + * Get the typecode. + */ + public org.omg.CORBA.TypeCode _type() + { + return ServiceDetailHelper.type(); + } + + /** + * Write into the CDR stream. + */ + public void _write(org.omg.CORBA.portable.OutputStream out) + { + ServiceDetailHelper.write(out, value); + } +} diff --git a/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java b/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java new file mode 100644 index 0000000..0b69881 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/ServiceRequestAdapter.java @@ -0,0 +1,159 @@ +/* ServiceRequestConverter.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; + +import gnu.CORBA.CDR.cdrBufOutput; + +import org.omg.CORBA.ARG_IN; +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.ServerRequest; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.Streamable; + +/** + * This class exists to handle obsolete invocation style using + * ServerRequest. + * + * @deprecated The method {@link ObjectImpl#_invoke} is much faster. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ServiceRequestAdapter + implements ResponseHandler +{ + /** + * A buffer for writing the response. + */ + cdrBufOutput reply = new cdrBufOutput(); + + /** + * If set to true, an exception has been thrown during the invocation. + */ + boolean isException; + + public OutputStream createExceptionReply() + { + isException = true; + return reply; + } + + public OutputStream createReply() + { + isException = false; + return reply; + } + + /** + * The old style invocation using the currently deprecated server + * request class. + * + * @param request a server request, containg the invocation information. + * @param target the invocation target + * @param result the result holder with the set suitable streamable to read + * the result or null for void. + */ + public static void invoke(ServerRequest request, InvokeHandler target, + Streamable result + ) + { + try + { + int IN = ARG_IN.value; + int OUT = ARG_OUT.value; + + // Write all arguments to the buffer output stream. + cdrBufOutput buffer = new cdrBufOutput(); + gnuNVList args = new gnuNVList(); + request.arguments(args); + + for (int i = 0; i < args.count(); i++) + { + if ((args.item(i).flags() & IN) != 0) + { + args.item(i).value().write_value(buffer); + } + } + + ServiceRequestAdapter h = new ServiceRequestAdapter(); + + target._invoke(request.operation(), buffer.create_input_stream(), h); + + InputStream in = h.reply.create_input_stream(); + + if (h.isException) + { + // Write the exception information + gnuAny exc = new gnuAny(); + universalHolder uku = new universalHolder(h.reply); + exc.insert_Streamable(uku); + request.set_exception(exc); + } + else + { + if (result != null) + { + result._read(in); + gnuAny r = new gnuAny(); + r.insert_Streamable(result); + request.set_result(r); + }; + + // Unpack the arguments + for (int i = 0; i < args.count(); i++) + { + if ((args.item(i).flags() & OUT) != 0) + { + Any a = args.item(i).value(); + a.read_value(in, a.type()); + } + } + } + } + catch (Bounds ex) + { + throw new InternalError(); + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/SetOverrideTypeHolder.java b/libjava/classpath/gnu/CORBA/SetOverrideTypeHolder.java new file mode 100644 index 0000000..12b4b9f --- /dev/null +++ b/libjava/classpath/gnu/CORBA/SetOverrideTypeHolder.java @@ -0,0 +1,90 @@ +/* SetOverrideTypeHolder.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; + +import org.omg.CORBA.SetOverrideType; +import org.omg.CORBA.SetOverrideTypeHelper; + +/** + * The holder for SetOverrideType. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class SetOverrideTypeHolder + implements org.omg.CORBA.portable.Streamable +{ + /** + * The stored SetOverrideType value. + */ + public SetOverrideType value; + + /** + * Create the initialised instance. + * + * @param initialValue the initial value. + */ + public SetOverrideTypeHolder(SetOverrideType initialValue) + { + value = initialValue; + } + + /** + * Fill in the {@link value} by data from the CDR stream. + */ + public void _read(org.omg.CORBA.portable.InputStream in) + { + value = SetOverrideTypeHelper.read(in); + } + + /** + * Get the typecode of the SetOverrideType. + */ + public org.omg.CORBA.TypeCode _type() + { + return SetOverrideTypeHelper.type(); + } + + /** + * Write the stored value into the CDR stream. + */ + public void _write(org.omg.CORBA.portable.OutputStream out) + { + SetOverrideTypeHelper.write(out, value); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Simple_delegate.java b/libjava/classpath/gnu/CORBA/Simple_delegate.java new file mode 100644 index 0000000..d0b2ad2 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Simple_delegate.java @@ -0,0 +1,249 @@ +/* Local_delegate.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; + +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * The delegate, implementing the basic functionality only. This delegate + * is set in {@link ORG.connect(org.omg.CORBA.Object)} if ORB + * determines that the object is an instance of the + * {@link org.omg.CORBA.portable.ObjectImpl} and no other delegate is set. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Simple_delegate + extends Delegate +{ + /** + * The orb. + */ + protected final ORB orb; + + /** + * The ior. + */ + protected IOR ior; + + public Simple_delegate(ORB an_orb, IOR an_ior) + { + orb = an_orb; + ior = an_ior; + } + + /** + * Set the IOR of this object. The IOR must be newly set if + * the server reports that the object has permanently moved to a new + * location. + * + * @param an_ior the new IOR. + */ + public void setIor(IOR an_ior) + { + this.ior = an_ior; + } + + /** + * Get the IOR of this object. + */ + public IOR getIor() + { + return ior; + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns + ) + { + throw new NO_IMPLEMENT(); + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String operation, NVList parameters, + NamedValue returns, ExceptionList exceptions, + ContextList ctx_list + ) + { + throw new NO_IMPLEMENT(); + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target) + { + throw new NO_IMPLEMENT(); + } + + /** + * Performs direct comparison ('=='). + */ + public boolean equals(org.omg.CORBA.Object self, org.omg.CORBA.Object other) + { + return self == other; + } + + /** + * Not implemented. + * + * @throws NO_IMPLEMENT, always. + */ + public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target) + { + throw new NO_IMPLEMENT(); + } + + /** + * Return the hashcode (0 <= hashcode < maximum). + */ + public int hash(org.omg.CORBA.Object target, int maximum) + { + return target == null ? 0 : target.hashCode() % maximum; + } + + /** + * Delegates functionality to java.lang.Object.hashCode(); + */ + public int hashCode(org.omg.CORBA.Object target) + { + return target == null ? 0 : target.hashCode(); + } + + /** + * Check if this object can be referenced by the given repository id. + * + * @param target the CORBA object, must be an instance of + * {@link org.omg.CORBA.portable.ObjectImpl}. + * + * @param repositoryIdentifer the repository id. + * + * @return true if the passed parameter is a repository id of this + * CORBA object. + */ + public boolean is_a(org.omg.CORBA.Object target, String repositoryIdentifer) + { + if (!(target instanceof ObjectImpl)) + throw new NO_IMPLEMENT("Supported only for org.omg.CORBA.portable.ObjectImpl"); + + ObjectImpl imp = (ObjectImpl) target; + String[] ids = imp._ids(); + + for (int i = 0; i < ids.length; i++) + { + if (ids [ i ].equals(repositoryIdentifer)) + return true; + } + return false; + } + + /** + * Only returns true if the objects are equal ('=='). + */ + public boolean is_equivalent(org.omg.CORBA.Object target, + org.omg.CORBA.Object other + ) + { + return target == other; + } + + /** + * Returns true by default. + */ + public boolean is_local(org.omg.CORBA.Object self) + { + return true; + } + + /** + * Returns true if the target is null. + */ + public boolean non_existent(org.omg.CORBA.Object target) + { + return target == null; + } + + /** + * Returns the ORB, passed in constructor, + * regardless of the argument. This class requires a single instance + * per each object. + */ + public ORB orb(org.omg.CORBA.Object target) + { + return orb; + } + + /** + * Returns without action. + */ + public void release(org.omg.CORBA.Object target) + { + } + + /** + * This should never be called this type delegate. + * + * @throws InternalError, always. + */ + public Request request(org.omg.CORBA.Object target, String operation) + { + throw new InternalError(); + } +} diff --git a/libjava/classpath/gnu/CORBA/SocketRepository.java b/libjava/classpath/gnu/CORBA/SocketRepository.java new file mode 100644 index 0000000..70bcead --- /dev/null +++ b/libjava/classpath/gnu/CORBA/SocketRepository.java @@ -0,0 +1,93 @@ +/* SocketRepository.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; + +import java.net.Socket; + +import java.util.HashMap; + +/** + * This class caches the opened sockets that are reused during the + * frequent calls. Otherwise, some CORBA applications may spend + * up to 90 % of the working time just for closing and opening the sockets. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class SocketRepository +{ + /** + * The socket map. + */ + private static HashMap sockets = new HashMap(); + + /** + * Put a socket. + * + * @param key as socket key. + * + * @param s a socket. + */ + public static void put_socket(Object key, Socket s) + { + sockets.put(key, s); + } + + /** + * Get a socket. + * + * @param key a socket key. + * + * @return an opened socket for reuse, null if no such + * available or it is closed. + */ + public static Socket get_socket(Object key) + { + Socket s = (Socket) sockets.get(key); + if (s != null && s.isClosed()) + { + sockets.remove(key); + return null; + } + else + { + sockets.remove(key); + return s; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/TypeCodeHelper.java b/libjava/classpath/gnu/CORBA/TypeCodeHelper.java new file mode 100644 index 0000000..c742275 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/TypeCodeHelper.java @@ -0,0 +1,297 @@ +/* TypeCodeHelper.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; + +/** + * Reads and writes the TypeCodes usind common data representation. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class TypeCodeHelper +{ + /** + * Read the CORBA {@link TypeCode}. First, the TypeCode kind + * is read as four byte long. Then, if needed, the additional + * parameters are loaded following CORBA specification. + * + * @param in a stream to read from. + */ + public static TypeCode read(org.omg.CORBA.portable.InputStream in) + throws BadKind, Bounds + { + TCKind kind = TCKind.from_int(in.read_long()); + TypeCode rt; + generalTypeCode g; + recordTypeCode r; + recordTypeCode.Field f; + stringTypeCode s; + int n; + + switch (kind.value()) + { + case TCKind._tk_sequence : + case TCKind._tk_array : + + primitiveArrayTypeCode p = new primitiveArrayTypeCode(kind); + p.setLength(in.read_long()); + rt = p; + break; + + case TCKind._tk_string : + case TCKind._tk_wstring : + s = new stringTypeCode(kind); + s.setLength(in.read_long()); + rt = s; + break; + + case TCKind._tk_fixed : + + fixedTypeCode fx = new fixedTypeCode(); + fx.setDigits(in.read_short()); + fx.setScale(in.read_short()); + rt = fx; + break; + + case TCKind._tk_objref : + case TCKind._tk_native : + case TCKind._tk_abstract_interface : + g = new generalTypeCode(kind); + g.setId(in.read_string()); + g.setName(in.read_string()); + rt = g; + break; + + case TCKind._tk_alias : + case TCKind._tk_value_box : + g = new generalTypeCode(kind); + g.setId(in.read_string()); + g.setName(in.read_string()); + g.setContentType(in.read_TypeCode()); + rt = g; + break; + + case TCKind._tk_struct : + case TCKind._tk_except : + r = new recordTypeCode(kind); + r.setId(in.read_string()); + r.setName(in.read_string()); + + n = in.read_long(); + + for (int i = 0; i < n; i++) + { + f = r.field(); + f.name = in.read_string(); + f.type = in.read_TypeCode(); + } + rt = r; + break; + + case TCKind._tk_enum : + r = new recordTypeCode(kind); + r.setId(in.read_string()); + r.setName(in.read_string()); + + n = in.read_long(); + + for (int i = 0; i < n; i++) + { + f = r.field(); + f.name = in.read_string(); + } + rt = r; + break; + + case TCKind._tk_union : + r = new recordTypeCode(kind); + r.setId(in.read_string()); + r.setName(in.read_string()); + r.setDiscriminator_type(in.read_TypeCode()); + r.setDefaultIndex(in.read_long()); + + n = in.read_long(); + + for (int i = 0; i < n; i++) + { + f = r.field(); + f.label = in.read_any(); + f.name = in.read_string(); + f.type = in.read_TypeCode(); + } + rt = r; + + break; + + case TCKind._tk_value : + r = new recordTypeCode(kind); + r.setId(in.read_string()); + r.setName(in.read_string()); + r.setTypeModifier(in.read_short()); + r.setConcreteBase_type(in.read_TypeCode()); + + n = in.read_long(); + + for (int i = 0; i < n; i++) + { + f = r.field(); + f.name = in.read_string(); + f.type = in.read_TypeCode(); + f.visibility = in.read_short(); + } + rt = r; + break; + + default : + rt = new primitiveTypeCode(kind); + } + return rt; + } + + /** + * Write the CORBA {@link TypeCode}. First, the TypeCode kind + * is written as four byte long. Then, if needed, the additional + * parameters are stored following CORBA specification. + * + * @param out a stream to write into. + * @param x a {@link TypeCode} to write. + */ + public static void write(org.omg.CORBA.portable.OutputStream out, TypeCode x) + throws BadKind, Bounds + { + out.write_long(x.kind().value()); + + switch (x.kind().value()) + { + case TCKind._tk_string : + case TCKind._tk_wstring : + out.write_long(x.length()); + break; + + case TCKind._tk_sequence : + case TCKind._tk_array : + write(out, x.content_type()); + out.write_long(x.length()); + break; + + case TCKind._tk_fixed : + out.write_short(x.fixed_digits()); + out.write_short(x.fixed_scale()); + break; + + case TCKind._tk_objref : + case TCKind._tk_native : + case TCKind._tk_abstract_interface : + out.write_string(x.id()); + out.write_string(x.name()); + break; + + case TCKind._tk_alias : + case TCKind._tk_value_box : + out.write_string(x.id()); + out.write_string(x.name()); + write(out, x.content_type()); + break; + + case TCKind._tk_struct : + case TCKind._tk_except : + out.write_string(x.id()); + out.write_string(x.name()); + + out.write_long(x.member_count()); + + for (int i = 0; i < x.member_count(); i++) + { + out.write_string(x.member_name(i)); + write(out, x.member_type(i)); + } + break; + + case TCKind._tk_enum : + out.write_string(x.id()); + out.write_string(x.name()); + + out.write_long(x.member_count()); + + for (int i = 0; i < x.member_count(); i++) + { + out.write_string(x.member_name(i)); + } + break; + + case TCKind._tk_union : + out.write_string(x.id()); + out.write_string(x.name()); + + write(out, x.discriminator_type()); + out.write_long(x.default_index()); + + out.write_long(x.member_count()); + + for (int i = 0; i < x.member_count(); i++) + { + out.write_any(x.member_label(i)); + out.write_string(x.member_name(i)); + write(out, x.member_type(i)); + } + break; + + case TCKind._tk_value : + out.write_string(x.id()); + out.write_string(x.name()); + out.write_short(x.type_modifier()); + write(out, x.concrete_base_type()); + + out.write_long(x.member_count()); + + for (int i = 0; i < x.member_count(); i++) + { + out.write_string(x.member_name(i)); + write(out, x.member_type(i)); + out.write_short(x.member_visibility(i)); + } + break; + + default :} + } +} diff --git a/libjava/classpath/gnu/CORBA/Unexpected.java b/libjava/classpath/gnu/CORBA/Unexpected.java new file mode 100644 index 0000000..89fb7e7 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Unexpected.java @@ -0,0 +1,128 @@ +/* DNW.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; + + +/** + * Contains the static method to throw an error in the case + * when the execution should never get into the current point. + * + * The error message contains the text, suggesting to check + * the user code first and then report a bug. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Unexpected + extends InternalError +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The default message for the CORBA assertion error. + */ + public static final String SHARED_MESSAGE = + "CORBA assertion error. Please check your code. " + + "If you think it is Classpath problem, please report " + + "this bug providing as much information as possible."; + + /** + * Create an instance with explaining message and enclosing + * exception. + */ + public Unexpected(String msg, Exception why) + { + super(msg + ". " + SHARED_MESSAGE); + if (why != null) + initCause(why); + } + + /** + * Create an instance with enclosing exception. + */ + public Unexpected(Exception why) + { + super(SHARED_MESSAGE); + if (why != null) + initCause(why); + } + + /** + * Create an instance. + */ + public Unexpected() + { + super(SHARED_MESSAGE); + } + + /** + * Throws an error with the custom explaining message and + * the appended share message. + * + * @param msg the error message + * @param why the enclosing exception. + */ + public static void error(String msg, Exception why) + { + throw new Unexpected(msg, why); + } + + /** + * Throws an error with the shared explaining message. + * + * @param why the enclosing exception. + * @throws Error, always. + */ + public static void error(Exception why) + { + throw new Unexpected(why); + } + + /** + * Throws an error with the shared explaining message. + * + * @throws Error, always. + */ + public static void error() + { + throw new Unexpected(); + } +} diff --git a/libjava/classpath/gnu/CORBA/Version.java b/libjava/classpath/gnu/CORBA/Version.java new file mode 100644 index 0000000..84f40bf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Version.java @@ -0,0 +1,206 @@ +/* Version.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; + +import java.io.IOException; +import java.io.Serializable; + +import org.omg.CORBA.MARSHAL; + +/** + * A version number, represented by the major version number + * and the minor version number. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Version + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Major number (0..256, so the byte cannot be used). + */ + public final int major; + + /** + * Minor number. + */ + public final int minor; + + /** + * Create the version with the given version numbers. + * + * @param major major number (0..255) + * @param minor minor number (0..255) + */ + public Version(int _major, int _minor) + { + major = (byte) _major; + minor = (byte) _minor; + } + + /** + * Returns true if the versions are equal. + * @param other the other version to compare. + * + * @return true if the versions are equal + */ + public boolean equals(java.lang.Object other) + { + if (other == this) + { + return true; + } + if (!(other instanceof Version)) + { + return false; + } + + Version that = (Version) other; + return same(that); + } + + /** + * Read from the input stream, major number first. + * @param in a stream to read from. + */ + public static Version read_version(java.io.InputStream in) + { + try + { + int major = in.read() & 0xFF; + int minor = in.read() & 0xFF; + return new Version(major, minor); + } + catch (IOException ex) + { + throw new MARSHAL("IOException while reading message header"); + } + } + + /** + * Returns true if the versions are the same. + * + * @param that the other version to compare. + * + * @return true if the versions are the same. + */ + public boolean same(Version that) + { + return major == that.major && minor == that.minor; + } + + /** + * Returns true if the given version is higher than + * or equals to the version, supplied as parameter + * in the form of two integers. + * + * @param a_major major number of the version to compare. + * @param a_minor minor number of the version to compare. + * + * @return true if this version is higher than or equals to + * the version v. + */ + public boolean since_inclusive(int a_major, int a_minor) + { + if (major > a_major) + return true; + else if (major < a_major) + return false; + else + + // Major numbers are equal. + return minor >= a_minor; + } + + /** + * Return the string representation, in the form + * major.minor. + */ + public String toString() + { + return major + "." + minor; + } + + /** + * Returs true if the given version is lower or equal to the + * version, specified by the provided minor and major version + * number. This means, the version, specified by these two numbers, + * should be supported by teh current version. + * + * @param a_major a major version number. + * @param a_minor a minor version number. + * + * @return true if the current version should be supported by the + * version, specified by the two passed numbers. + */ + public boolean until_inclusive(int a_major, int a_minor) + { + if (major < a_major) + return true; + else if (major > a_major) + return false; + else + + // Major numbers are equal. + return minor <= a_minor; + } + + /** + * Write into the output stream, major number first. + * + * @param out a stream to write into. + */ + public void write(java.io.OutputStream out) + { + try + { + out.write(major & 0xFF); + out.write(minor & 0xFF); + } + catch (IOException ex) + { + throw new MARSHAL("IOException while writing message header"); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/WCharHolder.java b/libjava/classpath/gnu/CORBA/WCharHolder.java new file mode 100644 index 0000000..23f0ad1 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/WCharHolder.java @@ -0,0 +1,126 @@ +/* WCharHolder.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +/** + * A holder for CORBA <code>char</code> that is mapped into + * java <code>char</code>. + * + * The holders have several application areas. The end user usually + * sees them implementing CORBA methods where the primitive type + * is passed by reference. While CORBA (or, for example, C) supports + * this, the java does not and a wrapper class is required. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public final class WCharHolder + implements Streamable +{ + /** + * The default type code for this holder. + */ + private static final TypeCode t_char = new primitiveTypeCode(TCKind.tk_wchar); + + /** + * The <code>char</code> (CORBA <code>wchar</code>) value, + * held by this WCharHolder. + */ + public char value; + + /** + * Constructs an instance of WCharHolder, + * initializing {@link #value} to <code>0 </code>. + */ + public WCharHolder() + { + } + + /** + * Constructs an instance of WCharHolder, + * initializing {@link #value} to the given <code>char</code>. + * + * @param initial_value a value that will be assigned to the + * {@link #value} field. + */ + public WCharHolder(char initial_value) + { + value = initial_value; + } + + /** + * Fill in the {@link value } field by reading the required data + * from the given stream. For <code>char</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.InputStream#read_wchar}. + * + * @param input the input stream to read from. + */ + public void _read(InputStream input) + { + value = input.read_wchar(); + } + + /** + * Returns the TypeCode, corresponding the CORBA type that is stored + * using this holder. + */ + public TypeCode _type() + { + return t_char; + } + + /** + * Write the {@link value } field to the given stream. + * For <code>char</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.OutputStream#write_wchar(char) }. + * + * @param output the output stream to write into. + */ + public void _write(OutputStream output) + { + output.write_wchar(value); + } +} diff --git a/libjava/classpath/gnu/CORBA/WStringHolder.java b/libjava/classpath/gnu/CORBA/WStringHolder.java new file mode 100644 index 0000000..c9e8e33 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/WStringHolder.java @@ -0,0 +1,129 @@ +/* WStringHolder.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +/** + * A holder for CORBA <code>wstring</code> that is mapped into + * java <code>String</code>. This holder writes and reads differently + * from the StringHolder. + * + * The holders have several application areas. The end user usually + * sees them implementing CORBA methods where the primitive type + * is passed by reference. While CORBA (or, for example, C) supports + * this, the java does not and a wrapper class is required. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class WStringHolder + implements Streamable +{ + /** + * The default type code for this holder. + */ + private static final stringTypeCode t_string = + new stringTypeCode(TCKind.tk_wstring); + + /** + * The <code>String</code> (CORBA <code>string</code>) value, + * held by this WStringHolder. + */ + public String value; + + /** + * Constructs an instance of WStringHolder, + * initializing {@link #value} to <code>null</code>. + */ + public WStringHolder() + { + } + + /** + * Constructs an instance of WStringHolder, + * initializing {@link #value} to the given <code>String</code>. + * + * @param initial_value a value that will be assigned to the + * {@link #value} field. + */ + public WStringHolder(String initial_value) + { + value = initial_value; + } + + /** + * Fill in the {@link #value } field by reading the required data + * from the given stream. For <code>string</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.InputStream#read_wstring}. + * + * @param input the input stream to read from. + */ + public void _read(InputStream input) + { + value = input.read_wstring(); + } + + /** + * Returns the TypeCode, corresponding the CORBA type that is stored + * using this holder. The {@link TypeCode#length()} method of the + * returned typecode always returns 0. + */ + public TypeCode _type() + { + return t_string; + } + + /** + * Write the {@link #value } field to the given stream. + * For <code>string</code>, the functionality + * is delegated to + * {@link org.omg.CORBA.portable.OutputStream#write_wstring(String) }. + * + * @param output the output stream to write into. + */ + public void _write(OutputStream output) + { + output.write_wstring(value); + } +} diff --git a/libjava/classpath/gnu/CORBA/_PolicyImplBase.java b/libjava/classpath/gnu/CORBA/_PolicyImplBase.java new file mode 100644 index 0000000..d9ff9d6 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/_PolicyImplBase.java @@ -0,0 +1,231 @@ +/* _PolicyImplBase.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; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.Policy; +import org.omg.CORBA.PolicyHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; + +/** + * The server side implementation base for the {@link Policy}. + * + * @specnote The java 1.4 API does not define the server side policy + * implementation base, but it defines the policy client side stub. + * As these two classes always work together, and even no separate testing is + * possible, the required implementation base is provided in gnu.CORBA + * namespace. Sun will probably include they base in the future java APIs. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class _PolicyImplBase + extends ObjectImpl + implements Policy, InvokeHandler +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The policy repository ids. + */ + private final String[] ids; + + /** + * The type of this policy. + */ + private final int type; + + /** + * The value of this policy. The value object is never the same + * for different policies. + */ + private final java.lang.Object value; + + /** + * The policy integer code, written in request to write + * the policy value. + */ + private final int policyCode; + + /** + * Create the new policy of the given type, having the given value. + * For security reasons, the method is kept package private. + * + * @param p_type the type of this policy. + * @param p_value the value of this policy. + * @param p_code the integer code of this policy. + * @param p_idl the policy IDL type string. The {@link #_ids()} + * will return array, first line being this string and another + * being PolicyHelper.id(). + */ + public _PolicyImplBase(int p_type, java.lang.Object p_value, int p_code, + String p_idl + ) + { + type = p_type; + value = p_value; + policyCode = p_code; + ids = new String[] { p_idl, PolicyHelper.id() }; + } + + /** + * Get the integer code of the type of this policy. + */ + public final int policy_type() + { + return type; + } + + /** + * Return the list of repository ids. + */ + public final String[] _ids() + { + return ids; + } + + /** + * Call the required method. + */ + public final OutputStream _invoke(String method, InputStream input, + ResponseHandler rh + ) + { + OutputStream output = null; + + if (method.equals("destroy")) + { + // The "destroy" has been invoked. + destroy(); + output = rh.createReply(); + } + else if (method.equals("copy")) + { + // The "copy" has been invoked. + org.omg.CORBA.Object returns = copy(); + output = rh.createReply(); + output.write_Object(this); + } + else if (method.equals("policy_type")) + { + // The "policy_type" has been invoked. + int returns = policy_type(); + output = rh.createReply(); + output.write_long(returns); + } + else if (method.equals("value")) + { + // The "value" can be invoked on the children types + // and must return an integer, representing the policy value + // (CORBA enumeration). + output = rh.createReply(); + output.write_long(policyCode); + } + else + throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE); + + return output; + } + + /** + * Get the value of this policy + */ + public final java.lang.Object getValue() + { + return value; + } + + /** + * Get the integer code of this policy value. + */ + public final int getCode() + { + return policyCode; + } + + /** + * Returns without action. It is a work of garbage collector + * to remove the unused objects. + */ + public final void destroy() + { + } + + /** + * Returns the string representation of the given policy. + */ + public final String toString() + { + return value.toString(); + } + + /** + * Create a copy of this policy. The object is not mutable, so + * <code>this</code> can be returned. + * + * @return <code>this</code> + */ + public Policy copy() + { + return this; + } + + /** + * Use the value to get a hash code. + */ + public int hashCode() + { + return getValue().hashCode(); + } + + /** + * Check the values for equality. + */ + public boolean equals(Object x) + { + return x == null ? false : getValue().equals(x); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/aliasTypeCode.java b/libjava/classpath/gnu/CORBA/aliasTypeCode.java new file mode 100644 index 0000000..8846631 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/aliasTypeCode.java @@ -0,0 +1,142 @@ +/* aliasTypeCode.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * The type code that is an alias of another type code. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class aliasTypeCode + extends primitiveTypeCode +{ + /** + * The typecode repository id. + */ + protected final String id; + + /** + * The typecode name. + */ + protected final String name; + + /** + * The type code for that this typecode is an alias. + */ + protected final TypeCode aliasFor; + + /** + * Create the typecode, specifying for that typecode it is an + * alias and the id and name of the newly created typecode. + * + * @param an_aliasFor the typecode, for that this typecode is an + * alias. + * + * @param an_id the repository id fo the newly created typecode. + * + * @param a_name the name of the newly created typecode. + */ + public aliasTypeCode(TypeCode an_aliasFor, String an_id, String a_name) + { + super(TCKind.tk_alias); + aliasFor = an_aliasFor; + id = an_id; + name = a_name; + } + + /** + * Get the typecode, for that this typecode is an alias. + */ + public TypeCode content_type() + { + return aliasFor; + } + + /** + * The objects are assumed to be equal if they repository + * ids are both equal or both unavailable and the + * kind values are equal. + * + * @param other the other typecode to compare. + */ + public boolean equal(TypeCode other) + { + if (super.equal(other)) + return true; + try + { + return id.equals(other.id()); + } + catch (BadKind ex) + { + return false; + } + } + + /** + * Return true if the given typecode is equal for + * either this typecode of the alias typecode. + * + * @param other the typecode to compare. + */ + public boolean equivalent(TypeCode other) + { + return other.equal(this) || other.equal(aliasFor); + } + + /** + * Get the repository id of this typecode. + */ + public String id() + { + return id; + } + + /** + * Get the name of this typecode. + */ + public String name() + { + return name; + } +} diff --git a/libjava/classpath/gnu/CORBA/binaryReply.java b/libjava/classpath/gnu/CORBA/binaryReply.java new file mode 100644 index 0000000..71afa37 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/binaryReply.java @@ -0,0 +1,95 @@ +/* binaryReply.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.GIOP.MessageHeader; + +import org.omg.CORBA.ORB; + +/** + * The remote object reply in the binary form, holding + * the message header and the following binary data. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +class binaryReply +{ + /** + * The message header. + */ + final MessageHeader header; + + /** + * The associated orb. + */ + final ORB orb; + + /** + * The message data. + */ + final byte[] data; + + /** + * Create the binary reply. + * + * @param an_header the message header + * @param a_data the message data. + */ + binaryReply(ORB an_orb, MessageHeader an_header, byte[] a_data) + { + orb = an_orb; + header = an_header; + data = a_data; + } + + /** + * Get the CDR input stream with the correctly set alignment. + * + * @return the CDR stream to read the message data. + */ + cdrBufInput getStream() + { + cdrBufInput in = new cdrBufInput(data); + in.setOffset(header.getHeaderSize()); + in.setVersion(header.version); + in.setOrb(orb); + in.setBigEndian(header.isBigEndian()); + return in; + } +} diff --git a/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java b/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java new file mode 100644 index 0000000..e7f00ba --- /dev/null +++ b/libjava/classpath/gnu/CORBA/bufferedResponseHandler.java @@ -0,0 +1,187 @@ +/* bufferedResponseHandler.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; + +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.cxCodeSet; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; + +/** + * Provides the CDR output streams for writing the response to the given + * buffer. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +class bufferedResponseHandler + implements ResponseHandler +{ + /** + * The message header. + * This field is used to compute the size and alignments. + * It is, however, never directly written to the buffer stream. + */ + final MessageHeader message_header; + + /** + * The associated orb. + */ + final ORB orb; + + /** + * The reply header. This field is used to compute the size and alignments. + * It is, however, never directly written to the buffer stream. + */ + final ReplyHeader reply_header; + + /** + * True if the stream was obtained by invoking {@link #createExceptionReply()}, + * false otherwise. + */ + private boolean exceptionReply; + + /** + * The buffer to write into. + */ + private cdrBufOutput buffer; + + /** + * Create a new buffered response handler that uses the given message + * headers. The headers are used to compute sizes and check the versions. + * They are not written into a stream inside this class. + * + * @param m_header a message header. + * @param r_header a reply header. + */ + bufferedResponseHandler(ORB an_orb, MessageHeader m_header, + ReplyHeader r_header + ) + { + message_header = m_header; + reply_header = r_header; + orb = an_orb; + prepareStream(); + } + + /** + * Get an output stream for providing details about the exception. + * Before returning the stream, the handler automatically writes + * the message header and the reply about exception header, + * but not the message header. + * + * @return the stream to write exception details into. + */ + public OutputStream createExceptionReply() + { + exceptionReply = true; + prepareStream(); + return buffer; + } + + /** + * Get an output stream for writing a regular reply (not an exception). + * + * Before returning the stream, the handler automatically writes + * the regular reply header, but not the message header. + * + * @return the output stream for writing a regular reply. + */ + public OutputStream createReply() + { + exceptionReply = false; + prepareStream(); + reply_header.reply_status = ReplyHeader.NO_EXCEPTION; + return buffer; + } + + /** + * Get the buffer, normally containing the written reply. + * The reply includes the reply header (or the exception header) + * but does not include the message header. + * + * The stream buffer can also be empty if no data have been written + * into streams, returned by {@link #createReply()} or + * {@link #createExceptionReply()}. + * + * @return the CDR output stream, containing the written output. + */ + cdrBufOutput getBuffer() + { + return buffer; + } + + /** + * True if the stream was obtained by invoking + * {@link #createExceptionReply()}, false otherwise + * (usually no-exception reply). + */ + boolean isExceptionReply() + { + return exceptionReply; + } + + /** + * Compute the header offset, set the correct version number and codeset. + */ + private void prepareStream() + { + buffer = new cdrBufOutput(); + buffer.setOrb(orb); + buffer.setOffset(message_header.getHeaderSize()); + + // Get the position after the reply header would be written. + reply_header.write(buffer); + + int new_offset = message_header.getHeaderSize() + buffer.buffer.size(); + + buffer.buffer.reset(); + buffer.setOffset(new_offset); + + if (message_header.version.since_inclusive(1, 2)) + buffer.align(8); + + buffer.setVersion(message_header.version); + + buffer.setCodeSet(cxCodeSet.find(reply_header.service_context)); + } +} diff --git a/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java b/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java new file mode 100644 index 0000000..699c6f7 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/cdrEncapsCodec.java @@ -0,0 +1,356 @@ +/* cdrEncapsCodec.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.cdrOutput; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UserException; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecPackage.FormatMismatch; +import org.omg.IOP.CodecPackage.InvalidTypeForEncoding; +import org.omg.IOP.CodecPackage.TypeMismatch; + +/** + * The local {@link Codec} implementation for ENCODING_CDR_ENCAPS + * encoding. This is a local implementation; the remote side should + * have its own Codec of this kind. + * + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class cdrEncapsCodec + extends LocalObject + implements Codec +{ + /** + * The default version of encoding, used in parameterless constructor. + */ + private static final Version DEFAULT_VERSION = new Version(1, 2); + + /** + * If set to true, no wide string or wide character is allowed (GIOP 1.0). + */ + private final boolean noWide; + + /** + * The version of this encoding. + */ + private final Version version; + + /** + * The associated ORB. + */ + protected final ORB orb; + + /** + * If true, this Codec writes the record length (as int) in the beginning + * of the record. This indicator is part of the formal OMG standard, but it is + * missing in Sun's implementation. Both Suns's and this Codec detects + * the indicator, if present, but can also decode data where this information + * is missing. If the length indicator is missing, the first four bytes in + * Suns encoding are equal to 0 (Big Endian marker). + */ + private boolean lengthIndicator = true; + + /** + * Create an instance of this Codec, encoding following the given version. + */ + public cdrEncapsCodec(ORB _orb, Version _version) + { + orb = _orb; + version = _version; + noWide = version.until_inclusive(1, 0); + } + + /** + * Return the array of repository ids for this object. + * + * @return { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }, always. + */ + public String[] _ids() + { + return new String[] { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }; + } + + /** + * Decode the contents of the byte array into Any. + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode(byte[] them) + throws FormatMismatch + { + cdrBufInput input = createInput(them); + cdrBufInput encapsulation = createEncapsulation(them, input); + + TypeCode type = encapsulation.read_TypeCode(); + + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new FormatMismatch(ex.getMessage()); + } + + return readAny(type, encapsulation); + } + + private cdrBufInput createEncapsulation(byte[] them, cdrBufInput input) + { + cdrBufInput encapsulation; + + if ((them [ 0 ] | them [ 1 ] | them [ 2 ] | them [ 3 ]) == 0) + { + // Skip that appears to be the always present Big Endian marker. + encapsulation = input; + input.read_short(); + } + else + encapsulation = input.read_encapsulation(); + return encapsulation; + } + + /** {@inheritDoc} */ + public byte[] encode(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + cdrBufOutput output = createOutput(that); + + // cdrBufOutput has internal support for this encoding. + cdrOutput encapsulation = output.createEncapsulation(); + + try + { + TypeCodeHelper.write(encapsulation, that.type()); + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Decode the value, stored in the byte array, into Any, assuming, + * that the byte array holds the data structure, defined by the + * given typecode. + * + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode_value(byte[] them, TypeCode type) + throws FormatMismatch, TypeMismatch + { + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new TypeMismatch(ex.getMessage()); + } + + cdrBufInput input = createInput(them); + cdrBufInput encapsulation = createEncapsulation(them, input); + return readAny(type, encapsulation); + } + + /** + * Read an Any from the given stream. + * + * @param type a type of the Any to read. + * @param input the encapsulation stream. + */ + private Any readAny(TypeCode type, cdrBufInput encapsulation) + throws MARSHAL + { + gnuAny a = new gnuAny(); + a.setOrb(orb); + + // cdrBufInput has internal support for this encoding. + a.read_value(encapsulation, type); + return a; + } + + /** {@inheritDoc} */ + public byte[] encode_value(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + cdrBufOutput output = createOutput(that); + + cdrOutput encapsulation = output.createEncapsulation(); + + try + { + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Create the CDR output stream for writing the given Any. + * The cdrBufOutput has internal support for encapsulation encodings. + * + * @param that the Any that will be written. + * + * @return the stream. + * + * @throws InvalidTypeForEncoding if that Any cannot be written under the + * given version. + */ + private cdrBufOutput createOutput(Any that) + throws InvalidTypeForEncoding + { + cdrBufOutput output = new cdrBufOutput(); + output.setOrb(orb); + output.setVersion(version); + return output; + } + + /** + * Checks if the given type can be encoded. Currently only checks for wide + * strings and wide chars for GIOP 1.0. + * + * @param t a typecode to chek. + * + * @throws InvalidTypeForEncoding if the typecode is not valid for the given + * version. + */ + private void checkTypePossibility(String name, TypeCode t) + throws InvalidTypeForEncoding + { + if (noWide) + { + try + { + int kind = t.kind().value(); + + if (kind == TCKind._tk_wchar || kind == TCKind._tk_wstring) + throw new InvalidTypeForEncoding(name + " wide char in " + + version + ); + else if (kind == TCKind._tk_alias || kind == TCKind._tk_array || + kind == TCKind._tk_sequence + ) + checkTypePossibility("Array member", t.content_type()); + + else if (kind == TCKind._tk_struct || kind == TCKind._tk_union) + { + for (int i = 0; i < t.member_count(); i++) + { + checkTypePossibility(t.member_name(i), t.member_type(i)); + } + } + } + catch (UserException ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + } + } + + /** + * Create the CDR input stream for reading the given byte array. + * + * @param them a byte array to read. + * + * @return the stream. + */ + private cdrBufInput createInput(byte[] them) + { + cdrBufInput input = new cdrBufInput(them); + input.setOrb(orb); + input.setVersion(version); + return input; + } + + /** + * Check if the Codec writes the length indicator. + */ + public boolean hasLengthIndicator() + { + return lengthIndicator; + } + + /** + * Sets if the Codec must write the record length in the beginning of the + * array. Encodings both with and without that indicator are understood + * both by Suns and this codec, but the OMG specification seems requiring + * it. The default behavior is to use the length indicator. + * + * @param use_lengthIndicator + */ + public void setUseLengthIndicator(boolean use_lengthIndicator) + { + lengthIndicator = use_lengthIndicator; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/corbaArrayList.java b/libjava/classpath/gnu/CORBA/corbaArrayList.java new file mode 100644 index 0000000..1690f05 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/corbaArrayList.java @@ -0,0 +1,115 @@ +/* corbaArrayList.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; + +import java.io.Serializable; + +import java.util.ArrayList; + +import org.omg.CORBA.Bounds; + +/** + * This class is used to store array lists. Differently from + * the java.util lists, + * it throws {@link org.omg.CORBA.Bounds} rather than + * {@link IndexOutOfBoundsException}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class corbaArrayList + extends ArrayList + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Creates the list with the given initial size. + */ + public corbaArrayList(int initial_size) + { + super(initial_size); + } + + /** + * Creates the list with the default size. + */ + public corbaArrayList() + { + } + + /** + * Remove the item at the given index. + * @param at the index + * @throws org.omg.CORBA.Bounds if the index is out of bounds. + */ + public void drop(int at) + throws Bounds + { + try + { + super.remove(at); + } + catch (IndexOutOfBoundsException ex) + { + throw new Bounds("[" + at + "], valid [0.." + size() + "]"); + } + } + + /** + * Get the item at the given index. + * @param at the index + * @return the item at the index + * @throws org.omg.CORBA.Bounds if the index is out of bounds. + */ + public Object item(int at) + throws Bounds + { + try + { + return super.get(at); + } + catch (IndexOutOfBoundsException ex) + { + throw new Bounds("[" + at + "], valid [0.." + size() + "]"); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/fixedTypeCode.java b/libjava/classpath/gnu/CORBA/fixedTypeCode.java new file mode 100644 index 0000000..ec88c22 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/fixedTypeCode.java @@ -0,0 +1,149 @@ +/* fixedTypeCode.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; + +import java.math.BigDecimal; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A typecode for CORBA <code>fixed</code> + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class fixedTypeCode + extends primitiveTypeCode +{ + /** + * The number of the used digits. + */ + private short digits; + + /** + * The number of the digits after the decimal point. + */ + private short scale; + + /** + * Creates the instance of the fixed type code. + */ + public fixedTypeCode() + { + super(TCKind.tk_fixed); + } + + /** + * Creates the instance of the fixed type code, + * setting the digits and scale by example. + */ + public fixedTypeCode(BigDecimal example) + { + super(TCKind.tk_fixed); + if (example != null) + { + setScale(example.scale()); + setDigits(countDigits(example)); + } + } + + /** + * Set the number of digits. + */ + public void setDigits(int a_digits) + { + this.digits = (short) a_digits; + } + + /** + * Set the number of digits after the decimal point. + */ + public void setScale(int a_scale) + { + this.scale = (short) a_scale; + } + + /** + * Get the number of digits in thid BigDecimal + * + * @param x a BigDecimal to check. + */ + public static int countDigits(BigDecimal number) + { + return number.unscaledValue().abs().toString().length(); + } + + public boolean equals(Object other) + { + if (other == this) + { + return true; + } + if (!(other instanceof TypeCode)) + { + return false; + } + try + { + TypeCode that = (TypeCode) other; + return kind() == that.kind() && digits == that.fixed_digits() && + scale == that.fixed_scale(); + } + catch (BadKind ex) + { + return false; + } + } + + /** + * Get the number of digits. + */ + public short fixed_digits() + { + return digits; + } + + /** + * Get the number of digits after the decimal point. + */ + public short fixed_scale() + { + return scale; + } +} diff --git a/libjava/classpath/gnu/CORBA/generalTypeCode.java b/libjava/classpath/gnu/CORBA/generalTypeCode.java new file mode 100644 index 0000000..3b79148 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/generalTypeCode.java @@ -0,0 +1,243 @@ +/* generalTypeCode.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; + +import gnu.CORBA.CDR.cdrBufOutput; + +import java.util.Arrays; +import java.util.BitSet; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A typecode for types, requiring to provide various additional + * properties but still not requiring to store the + * members of the structure. The property can be retrieved + * by the corresponding method if it has been previously assigned. + * Otherwise, a {@link BadKind} is thrown. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class generalTypeCode + extends primitiveTypeCode +{ + /** + * Indicates that the field value has not been previously set. + */ + protected static int UNSET = Integer.MIN_VALUE; + + /** + * The kinds for that the length() must return 0 even if it + * has not been previously set. + */ + private static final BitSet lengthAllowed = new BitSet(); + + static + { + lengthAllowed.set(TCKind._tk_array); + lengthAllowed.set(TCKind._tk_sequence); + lengthAllowed.set(TCKind._tk_string); + lengthAllowed.set(TCKind._tk_wstring); + } + + private String id; + private String name; + private TypeCode concrete_base_type; + private TypeCode content_type; + private int len; + private int type_modifier = UNSET; + + /** + * Create a new instance, setting kind to the given kind. + * @param kind + */ + public generalTypeCode(TCKind kind) + { + super(kind); + if (!lengthAllowed.get(kind.value())) + len = UNSET; + } + + /** + * Set this property. + */ + public void setConcreteBase_type(TypeCode concrete_base_type) + { + this.concrete_base_type = concrete_base_type; + } + + /** + * Set the component content type. + */ + public void setContentType(TypeCode a_content_type) + { + this.content_type = a_content_type; + } + + /** + * Set this property. + */ + public void setId(String id) + { + this.id = id; + } + + /** + * Set the length property. + * @param l + */ + public void setLength(int l) + { + len = l; + } + + /** + * Set this property. + */ + public void setName(String name) + { + this.name = name; + } + + /** + * Set the type modifier. + */ + public void setTypeModifier(int a_type_modifier) + { + this.type_modifier = a_type_modifier; + } + + /** {@inheritDoc} */ + public TypeCode concrete_base_type() + throws BadKind + { + if (concrete_base_type != null) + return concrete_base_type; + throw new BadKind("concrete_base_type"); + } + + /** + * Returns the content type that must be explicitly set + * for this class. + * + * @throws BadKind if the content type has not been set. + */ + public TypeCode content_type() + throws BadKind + { + if (content_type != null) + return content_type; + throw new BadKind("content_type"); + } + + /** + * Returns true if both typecodes, if written into CDR + * stream, would result the same stream content. + */ + public boolean equal(TypeCode other) + { + if (this == other) + return true; + if (kind() != other.kind()) + return false; + + cdrBufOutput a = new cdrBufOutput(16); + cdrBufOutput b = new cdrBufOutput(16); + + a.write_TypeCode(this); + b.write_TypeCode(other); + + return Arrays.equals(a.buffer.toByteArray(), b.buffer.toByteArray()); + } + + /** + * Delegates functionality to {@link #equal}. + */ + public boolean equivalent(TypeCode other) + { + return equal(other); + } + + /** {@inheritDoc} */ + public String id() + throws BadKind + { + if (id != null) + return id; + throw new BadKind("id"); + } + + /** + * Get the length. For sequences, arrays, strings and wstrings + * this method returns 0 rather than throwing a BadKind even + * if {@link setLength(int)} has not been previously called. + * + * @return the length of string, array or sequence. + * + * @throws BadKind if the method cannot be invoked for the + * given kind of typecode. + */ + public int length() + throws BadKind + { + if (len != UNSET) + return len; + throw new BadKind("length"); + } + + /** {@inheritDoc} */ + public String name() + throws BadKind + { + if (name != null) + return name; + throw new BadKind("name"); + } + + /** {@inheritDoc} */ + public short type_modifier() + throws BadKind + { + if (type_modifier != UNSET) + return (short) type_modifier; + throw new BadKind("type_modifier"); + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuAny.java b/libjava/classpath/gnu/CORBA/gnuAny.java new file mode 100644 index 0000000..a48c50d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuAny.java @@ -0,0 +1,830 @@ +/* gnuAny.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; + +import org.omg.CORBA.Any; +import org.omg.CORBA.AnyHolder; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BooleanHolder; +import org.omg.CORBA.CharHolder; +import org.omg.CORBA.DoubleHolder; +import org.omg.CORBA.FixedHolder; +import org.omg.CORBA.FloatHolder; +import org.omg.CORBA.IntHolder; +import org.omg.CORBA.LongHolder; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ObjectHolder; +import org.omg.CORBA.Principal; +import org.omg.CORBA.PrincipalHolder; +import org.omg.CORBA.ShortHolder; +import org.omg.CORBA.StringHolder; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodeHolder; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.ValueBaseHolder; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; +import java.io.Serializable; + +import java.lang.reflect.Field; + +import java.math.BigDecimal; + +import java.util.Arrays; + +/** + * The implementation of {@link Any}. + * + * For performance reasonse, the inserted values are not cloned. + * If the value object allows modifications (like {@link Streamable}), + * these subsequent alterations are reflected by the instance of + * this gnuAny, and the gnuAny alterations are reflected by the + * returned value. If it is required to have the uncoupled value, + * it must be requested from the copy of the current instance. + * The {@link gnuAny} can be simply cloned by the provided + * {@link Clone()} method. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuAny + extends Any +{ + /** + * The value, returned by {@link #type()} if the value has been + * not intialized. + */ + protected static final TypeCode nullType = + new primitiveTypeCode(TCKind.tk_null); + + /** + * The Streamable, representing the value, held by this gnuAny. + */ + protected Streamable has; + + /** + * The complete typecode of the Streamable, if explicitly set. + */ + protected TypeCode typecode; + + /** + * The typecode kind of the Streamable, if explicitly set. + */ + protected int xKind = -1; + + /** + * The associated ORB. + */ + private ORB orb; + + /** + * Set the associated orb. + */ + public void setOrb(ORB an_orb) + { + orb = an_orb; + } + + /** + * Creates a deep copy of this gnuAny, writing to and subsequently + * reading from from the byte buffer. + * + * @return the uncoupled gnuAny with all fields set to identical + * values. + */ + public gnuAny Clone() + { + cdrBufOutput out = new cdrBufOutput(); + out.setOrb(orb); + out.write_any(this); + + cdrBufInput in = new cdrBufInput(out.buffer.toByteArray()); + in.setOrb(orb); + return (gnuAny) in.read_any(); + } + + /** + * Create the buffered CDR input stream, containing the + * value, stored inside of this {@link Any}. + */ + public org.omg.CORBA.portable.InputStream create_input_stream() + { + if (has instanceof universalHolder) + { + universalHolder u = (universalHolder) has; + return u.getInputStream(); + } + else + { + cdrBufOutput out = new cdrBufOutput(); + out.setOrb(orb); + write_value(out); + + cdrBufInput in = new cdrBufInput(out.buffer.toByteArray()); + in.setOrb(orb); + return in; + } + } + + /** + * Create the buffered CDR output stream (empty). + */ + public org.omg.CORBA.portable.OutputStream create_output_stream() + { + cdrBufOutput stream = new cdrBufOutput(); + stream.setOrb(orb); + return stream; + } + + /** + * Compare two Any's for equality. + * @param other the other Any to compare. + */ + public boolean equal(Any other) + { + if (other == this) + return true; + if (type().kind() != other.type().kind()) + return false; + + if (has != null && other instanceof gnuAny) + if (has.equals(((gnuAny) other).has)) + return true; + + cdrBufOutput a = new cdrBufOutput(); + a.setOrb(orb); + write_value(a); + + cdrBufOutput b = new cdrBufOutput(); + b.setOrb(orb); + other.write_value(b); + + byte[] ba = a.buffer.toByteArray(); + byte[] bb = b.buffer.toByteArray(); + + return Arrays.equals(ba, bb); + } + + /** + * Delegates functionality to {@link #equal(Any)}. + */ + public boolean equals(java.lang.Object other) + { + if (other == this) + return true; + if (!(other instanceof Any)) + return false; + + return equal((Any) other); + } + + /** + * Extract the previously stored object. + */ + public org.omg.CORBA.Object extract_Object() + { + try + { + return ((ObjectHolder) has).value; + } + catch (ClassCastException ex) + { + throw new BAD_OPERATION(); + } + } + + /** + * Extract the previously inserted CORBA <code>Principal</code>/ + * @return the previously inserted value. + * + * @throws org.omg.CORBA.BAD_OPERATION if the holder contains something + * else than Principal. + * + * @deprecated by CORBA 2.2. + */ + public Principal extract_Principal() + { + check(TCKind._tk_Principal); + return ((PrincipalHolder) has).value; + } + + /** + * Return the value, encapsulated in a suitable holder. + * This implementation returns the direct reference, + * so the alterations on the returned streamable are + * directly reflected to the content of this {@link Any}. + */ + public Streamable extract_Streamable() + { + return has; + } + + public TypeCode extract_TypeCode() + throws BAD_OPERATION + { + check(TCKind._tk_TypeCode); + return ((TypeCodeHolder) has).value; + } + + /** + * Extract the stored value type. + * + * @return the previously stored value type. + * + * @throws BAD_OPERATION if the Any contains something different. + * + * @see org.omg.CORBA.portable.ValueBase + */ + public Serializable extract_Value() + throws BAD_OPERATION + { + try + { + if (has instanceof ValueBaseHolder) + return ((ValueBaseHolder) has).value; + else + { + // Normally, ValueBase holder must be an instance of the + // ValueBaseHolder. However some IDL compilers probably + // have a bug, do not deriving this way. The the only + // way to access the wrapped value is via reflection. + Field f = has.getClass().getField("value"); + return (Serializable) f.get(has); + } + } + catch (Exception ex) + { + return new BAD_OPERATION("Value type expected"); + } + } + + /** {@inheritDoc} */ + public Any extract_any() + throws BAD_OPERATION + { + check(TCKind._tk_any); + return ((AnyHolder) has).value; + } + + /** {@inheritDoc} */ + public boolean extract_boolean() + throws BAD_OPERATION + { + check(TCKind._tk_boolean); + return ((BooleanHolder) has).value; + } + + /** {@inheritDoc} */ + public char extract_char() + throws BAD_OPERATION + { + check(TCKind._tk_char); + return ((CharHolder) has).value; + } + + /** {@inheritDoc} */ + public double extract_double() + throws BAD_OPERATION + { + check(TCKind._tk_double); + return ((DoubleHolder) has).value; + } + + /** + * Extract the previously inserted CORBA <code>fixed</code>/ + * @return the previously inserted value. + * + * @throws org.omg.CORBA.BAD_OPERATION if the holder contains something + * else than BigDecimal. + */ + public BigDecimal extract_fixed() + throws org.omg.CORBA.BAD_OPERATION + { + check(TCKind._tk_fixed); + return ((FixedHolder) has).value; + } + + /** {@inheritDoc} */ + public float extract_float() + throws BAD_OPERATION + { + check(TCKind._tk_float); + return ((FloatHolder) has).value; + } + + /** {@inheritDoc} */ + public int extract_long() + throws BAD_OPERATION + { + // CORBA long = java int. + check(TCKind._tk_long); + return ((IntHolder) has).value; + } + + /** {@inheritDoc} */ + public long extract_longlong() + throws BAD_OPERATION + { + check(TCKind._tk_longlong); + return ((LongHolder) has).value; + } + + /** {@inheritDoc} */ + public byte extract_octet() + throws BAD_OPERATION + { + // ShortHolder holds also octets. + check(TCKind._tk_octet); + return (byte) ((OctetHolder) has).value; + } + + /** {@inheritDoc} */ + public short extract_short() + throws BAD_OPERATION + { + check(TCKind._tk_short); + return ((ShortHolder) has).value; + } + + /** {@inheritDoc} */ + public String extract_string() + throws BAD_OPERATION + { + check(TCKind._tk_string); + return ((StringHolder) has).value; + } + + /** {@inheritDoc} */ + public int extract_ulong() + throws BAD_OPERATION + { + // IntHolder also holds ulongs. + check(TCKind._tk_ulong); + return ((IntHolder) has).value; + } + + /** {@inheritDoc} */ + public long extract_ulonglong() + throws BAD_OPERATION + { + // LongHolder also holds ulonglong + check(TCKind._tk_ulonglong); + return ((LongHolder) has).value; + } + + /** {@inheritDoc} */ + public short extract_ushort() + throws BAD_OPERATION + { + // ShortHolder also holds ushorts. + check(TCKind._tk_ushort); + return ((ShortHolder) has).value; + } + + /** {@inheritDoc} */ + public char extract_wchar() + throws BAD_OPERATION + { + check(TCKind._tk_wchar); + return ((WCharHolder) has).value; + } + + /** {@inheritDoc} */ + public String extract_wstring() + throws BAD_OPERATION + { + // StringHolder also holds wstrings. + check(TCKind._tk_wstring); + return ((WStringHolder) has).value; + } + + /** + * Inserts the CORBA object and sets the typecode to the given type. + */ + public void insert_Object(org.omg.CORBA.Object x, TypeCode typecode) + { + has = new ObjectHolder(x); + type(typecode); + } + + /** + * Inserts the CORBA object. + */ + public void insert_Object(org.omg.CORBA.Object x) + { + has = new ObjectHolder(x); + } + + /** + * Insert the CORBA Principal. + * This implementation uses direct assignment, so the later + * alterations of that BigDecimal are reflected on the + * content of this {@link Any}. + * + * @deprecated by CORBA 2.2. + */ + public void insert_Principal(Principal x) + { + resetTypes(); + if (has instanceof PrincipalHolder) + ((PrincipalHolder) has).value = x; + else + has = new PrincipalHolder(x); + } + + /** + * Sets the value to the value, encapsulated in this holder. + * This implementation uses direct assignment, so the later + * alterations of that streamable are reflected on the + * content of this {@link Any}. + */ + public void insert_Streamable(Streamable x) + { + resetTypes(); + has = x; + } + + /** + * Insert the typecode into this Any + * @param typecode the typecode to insert. + */ + public void insert_TypeCode(TypeCode typecode) + { + resetTypes(); + if (has instanceof TypeCodeHolder) + ((TypeCodeHolder) has).value = typecode; + else + has = new TypeCodeHolder(typecode); + } + + /** {@inheritDoc} */ + public void insert_Value(Serializable x, TypeCode typecode) + { + type(typecode); + insert_Value(x); + } + + /** {@inheritDoc} */ + public void insert_Value(Serializable x) + { + resetTypes(); + if (has instanceof ValueBaseHolder) + ((ValueBaseHolder) has).value = x; + else + has = new ValueBaseHolder(x); + } + + /** + * Insert another {@link Any} into this {@link Any}. + * This implementation uses direct assignment, so the later + * alterations of that {@link Any} are reflected on the + * content of this {@link Any}. + */ + public void insert_any(Any an_any) + { + resetTypes(); + if (has instanceof AnyHolder) + ((AnyHolder) has).value = an_any; + else + has = new AnyHolder(an_any); + } + + /** {@inheritDoc} */ + public void insert_boolean(boolean x) + { + resetTypes(); + if (has instanceof BooleanHolder) + ((BooleanHolder) has).value = x; + else + has = new BooleanHolder(x); + } + + /** {@inheritDoc} */ + public void insert_char(char x) + { + resetTypes(); + if (has instanceof CharHolder) + ((CharHolder) has).value = x; + else + has = new CharHolder(x); + } + + /** {@inheritDoc} */ + public void insert_double(double x) + { + resetTypes(); + if (has instanceof DoubleHolder) + ((DoubleHolder) has).value = x; + else + has = new DoubleHolder(x); + } + + /** + * Inserts the CORBA <code>fixed</code>, setting the typecode + * explicitly. + * This implementation uses direct assignment, so the later + * alterations of that BigDecimal are reflected on the + * content of this {@link Any}. + */ + public void insert_fixed(BigDecimal x, TypeCode x_typecode) + { + resetTypes(); + insert_fixed(x); + typecode = x_typecode; + } + + /** + * Inserts the CORBA <code>fixed</code>, setting the typecode + * by example of the currently passed value. + * This implementation uses direct assignment, so the later + * alterations of that BigDecimal are reflected on the + * content of this {@link Any}, including the typecode. + */ + public void insert_fixed(BigDecimal x) + { + resetTypes(); + if (has instanceof FixedHolder) + ((FixedHolder) has).value = x; + else + has = new FixedHolder(x); + } + + /** {@inheritDoc} */ + public void insert_float(float x) + { + resetTypes(); + if (has instanceof FloatHolder) + ((FloatHolder) has).value = x; + else + has = new FloatHolder(x); + } + + /** {@inheritDoc} */ + public void insert_long(int x) + { + resetTypes(); + if (has instanceof IntHolder) + ((IntHolder) has).value = x; + else + has = new IntHolder(x); + } + + /** {@inheritDoc} */ + public void insert_longlong(long x) + { + resetTypes(); + if (has instanceof LongHolder) + ((LongHolder) has).value = x; + else + has = new LongHolder(x); + } + + /** {@inheritDoc} */ + public void insert_octet(byte x) + { + resetTypes(); + if (has instanceof OctetHolder) + ((OctetHolder) has).value = x; + else + has = new OctetHolder(x); + } + + /** {@inheritDoc} */ + public void insert_short(short x) + { + resetTypes(); + if (has instanceof ShortHolder) + ((ShortHolder) has).value = x; + else + has = new ShortHolder(x); + } + + /** {@inheritDoc} */ + public void insert_string(String x) + { + resetTypes(); + if (has instanceof StringHolder) + ((StringHolder) has).value = x; + else + has = new StringHolder(x); + + typecode = new stringTypeCode(TCKind.tk_string); + } + + /** {@inheritDoc} */ + public void insert_ulong(int x) + { + resetTypes(); + if (has instanceof IntHolder) + ((IntHolder) has).value = x; + else + has = new IntHolder(x); + xKind = TCKind._tk_ulong; + } + + /** {@inheritDoc} */ + public void insert_ulonglong(long x) + { + resetTypes(); + if (has instanceof LongHolder) + ((LongHolder) has).value = x; + else + has = new LongHolder(x); + xKind = TCKind._tk_ulonglong; + } + + /** {@inheritDoc} */ + public void insert_ushort(short x) + { + resetTypes(); + if (has instanceof ShortHolder) + ((ShortHolder) has).value = x; + else + has = new ShortHolder(x); + xKind = TCKind._tk_ushort; + } + + /** {@inheritDoc} */ + public void insert_wchar(char x) + { + resetTypes(); + if (has instanceof WCharHolder) + ((WCharHolder) has).value = x; + else + has = new WCharHolder(x); + } + + /** {@inheritDoc} */ + public void insert_wstring(String x) + { + resetTypes(); + if (has instanceof WStringHolder) + ((WStringHolder) has).value = x; + else + has = new WStringHolder(x); + } + + /** + * Return the associated orb. + */ + public ORB orb() + { + return orb; + } + + /** + * Read the value of the given type from the given stream. + * + * @param input a stream to read from. + * @param a_type a typecode of the value to read. + */ + public void read_value(org.omg.CORBA.portable.InputStream input, + TypeCode a_type + ) + throws MARSHAL + { + try + { + int kind = a_type.kind().value(); + + // Fixed needs special handling. + if (kind == TCKind._tk_fixed) + { + BigDecimal dec = BigDecimalHelper.read(input, a_type.fixed_scale()); + has = new FixedHolder(dec); + } + else + { + has = holderFactory.createHolder(a_type); + if (has == null) + { + // Use the Universal Holder that reads till the end of stream. + // This works with the extract/insert pair of the typical + // Helper. + cdrBufOutput buffer = new cdrBufOutput(); + buffer.setOrb(orb); + has = new universalHolder(buffer); + } + } + type(a_type); + has._read(input); + } + catch (BadKind ex) + { + throw new MARSHAL("Bad kind: " + ex.getMessage()); + } + catch (IOException ex) + { + throw new MARSHAL("IO exception: " + ex.getMessage()); + } + } + + /** {@inheritDoc} */ + public TypeCode type() + { + if (typecode != null) + return typecode; + else if (xKind >= 0) + { + typecode = new primitiveTypeCode(TCKind.from_int(xKind)); + return typecode; + } + else + return has != null ? has._type() : nullType; + } + + /** + * Explicitly set the typecode of the value to the given type. + * + * @param valueTypeCode the typecode of the value. + */ + public void type(TypeCode valueTypeCode) + { + xKind = valueTypeCode.kind().value(); + typecode = valueTypeCode; + } + + /** {@inheritDoc} */ + public void write_value(org.omg.CORBA.portable.OutputStream output) + { + if (has != null) + has._write(output); + } + + /** + * Check if the current value if the value of the given kind. + * @param kind a kind to check. + * @throws BAD_OPERATION if the value is not set of is different kind. + */ + protected void check(int kind) + throws BAD_OPERATION + { + if (has == null) + throw new BAD_OPERATION("value not set"); + + if (xKind >= 0) + { + if (xKind != kind) + throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + + " when stored " + typeNamer.nameIt(xKind) + ); + } + else + { + if (type().kind().value() != kind) + throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + + " stored " + typeNamer.nameIt(type()) + ); + } + } + + /** + * Clear the additional type information before reusing this instance. + */ + private final void resetTypes() + { + typecode = null; + xKind = -1; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/gnuCodecFactory.java b/libjava/classpath/gnu/CORBA/gnuCodecFactory.java new file mode 100644 index 0000000..8b71baf --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuCodecFactory.java @@ -0,0 +1,95 @@ +/* gnuCodecFactory.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; + +import org.omg.CORBA.*; +import org.omg.CORBA.LocalObject; +import org.omg.IOP.*; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecFactory; +import org.omg.IOP.CodecFactoryPackage.UnknownEncoding; +import org.omg.IOP.Encoding; + +/** + * A simple implementation of the Codec factory, able to return the + * standard Codec's. Only ENCODING_CDR_ENCAPS encoding is supported. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuCodecFactory + extends LocalObject + implements CodecFactory +{ + /** + * The associated ORB. + */ + private final ORB orb; + + /** + * Create a new instance of the this factory, associated with the given ORB. + */ + public gnuCodecFactory(ORB an_orb) + { + orb = an_orb; + } + + /** + * Creates the Codec for the given encoding. + * + * @param for_encoding the encoding for that the Codec must be created. + * + * @return the suitable Codec. + * + * @throws UnknownEncoding if the encoding is not a ENCODING_CDR_ENCAPS. + */ + public Codec create_codec(Encoding for_encoding) + throws UnknownEncoding + { + if (for_encoding.format != ENCODING_CDR_ENCAPS.value) + throw new UnknownEncoding("Only ENCODING_CDR_ENCAPS is " + + "supported by this factory." + ); + + return new cdrEncapsCodec(orb, + new Version(for_encoding.major_version, + for_encoding.minor_version + ) + ); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/gnuContext.java b/libjava/classpath/gnu/CORBA/gnuContext.java new file mode 100644 index 0000000..baa9fc8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuContext.java @@ -0,0 +1,202 @@ +/* gnuContext.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; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.omg.CORBA.Any; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.CTX_RESTRICT_SCOPE; +import org.omg.CORBA.Context; +import org.omg.CORBA.NVList; + +/** + * The working implementation of the {@link org.omg.CORBA.Context}. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuContext + extends Context +{ + /** + * The parent context. + */ + Context parent; + + /** + * The collection to store the context properties. + */ + Map properties = new Hashtable(); + + /** + * The name of this context. + */ + String name; + + /** + * Creates the new context with the given name and parent. + * + * @param a_name a name of the new context. + * @param a_parent a parent, used to resolve the missing references. + */ + public gnuContext(String a_name, Context a_parent) + { + name = a_name; + parent = a_parent; + } + + /** {@inheritDoc} */ + public String context_name() + { + return name; + } + + /** {@inheritDoc} */ + public Context create_child(String child) + { + return new gnuContext(child, this); + } + + /** {@inheritDoc} */ + public void delete_values(String property) + { + boolean starts = false; + if (property.endsWith("*")) + { + starts = true; + property = property.substring(0, property.length() - 1); + } + + Set keys = properties.keySet(); + + Iterator iter = keys.iterator(); + while (iter.hasNext()) + { + String key = (String) iter.next(); + if ((starts && key.startsWith(property)) || + (!starts && key.equals(property)) + ) + iter.remove(); + } + } + + /** {@inheritDoc} */ + public NVList get_values(String start_scope, int flags, String pattern) + { + if (start_scope != null) + { + Context c = this; + while (c != null && !c.context_name().equals(start_scope)) + c = c.parent(); + if (c == null) + return new gnuNVList(); + } + + try + { + gnuNVList rt = new gnuNVList(); + + boolean starts = false; + if (pattern.endsWith("*")) + { + starts = true; + pattern = pattern.substring(0, pattern.length() - 1); + } + + Set keys = properties.keySet(); + + Iterator iter = keys.iterator(); + while (iter.hasNext()) + { + String key = (String) iter.next(); + if ((starts && key.startsWith(pattern)) || + (!starts && key.equals(pattern)) + ) + { + rt.add_value(key, (Any) properties.get(key), 0); + } + } + + if ((flags & CTX_RESTRICT_SCOPE.value) == 0 && parent != null) + { + NVList par = parent.get_values(start_scope, flags, pattern); + for (int i = 0; i < par.count(); i++) + { + rt.list.add(par.item(i)); + } + } + + return rt; + } + catch (Bounds ex) + { + throw new Error("Report this bug."); + } + } + + /** {@inheritDoc} */ + public Context parent() + { + return parent; + } + + /** {@inheritDoc} */ + public void set_one_value(String name, Any value) + { + properties.put(name, value); + } + + /** {@inheritDoc} */ + public void set_values(NVList values) + { + try + { + for (int i = 0; i < values.count(); i++) + { + properties.put(values.item(i).name(), values.item(i).value()); + } + } + catch (Bounds ex) + { + throw new Error("Please report this bug."); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuContextList.java b/libjava/classpath/gnu/CORBA/gnuContextList.java new file mode 100644 index 0000000..2a26437 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuContextList.java @@ -0,0 +1,83 @@ +/* gnuContextList.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; + +import java.util.ArrayList; + +import org.omg.CORBA.Bounds; +import org.omg.CORBA.ContextList; + +/** + * The working implementation of the {@link org.omg.CORBA.ContextList}. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuContextList + extends ContextList +{ + /** + * The collection, holding the actual list of strings. + */ + corbaArrayList strings = new corbaArrayList(); + + /** {@inheritDoc} */ + public void add(String name) + { + strings.add(name); + } + + /** {@inheritDoc} */ + public int count() + { + return strings.size(); + } + + /** {@inheritDoc} */ + public String item(int at) + throws Bounds + { + return (String) strings.item(at); + } + + /** {@inheritDoc} */ + public void remove(int at) + throws Bounds + { + strings.drop(at); + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuEnvironment.java b/libjava/classpath/gnu/CORBA/gnuEnvironment.java new file mode 100644 index 0000000..ba02e3b --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuEnvironment.java @@ -0,0 +1,72 @@ +/* gnuEnvironment.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; + +import org.omg.CORBA.Environment; + +/** + * The implementation of the exception container ("Environment"). + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuEnvironment + extends Environment +{ + /** + * The stored exception. + */ + protected Exception exception; + + /** {@inheritDoc} */ + public void clear() + { + exception = null; + } + + /** {@inheritDoc} */ + public void exception(Exception except) + { + exception = except; + } + + /** {@inheritDoc} */ + public Exception exception() + { + return exception; + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuExceptionList.java b/libjava/classpath/gnu/CORBA/gnuExceptionList.java new file mode 100644 index 0000000..b684ec9 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuExceptionList.java @@ -0,0 +1,84 @@ +/* gnuExceptionList.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; + +import java.util.ArrayList; + +import org.omg.CORBA.Bounds; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.TypeCode; + +/** + * The implementation of the list of type codes for exceptions. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org). + */ +public class gnuExceptionList + extends ExceptionList +{ + /** + * A list to store the objects. + */ + protected corbaArrayList list = new corbaArrayList(); + + /** {@inheritDoc} */ + public void add(TypeCode an_exception) + { + list.add(an_exception); + } + + /** {@inheritDoc} */ + public int count() + { + return list.size(); + } + + /** {@inheritDoc} */ + public TypeCode item(int at) + throws Bounds + { + return (TypeCode) list.item(at); + } + + /** {@inheritDoc} */ + public void remove(int at) + throws Bounds + { + list.drop(at); + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuNVList.java b/libjava/classpath/gnu/CORBA/gnuNVList.java new file mode 100644 index 0000000..e436c33 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuNVList.java @@ -0,0 +1,127 @@ +/* gnuNVList.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; + +import org.omg.CORBA.Any; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; + +/** + * The implementation of {@link NVList}. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuNVList + extends NVList +{ + /** + * The list of the named values. + */ + protected corbaArrayList list; + + /** + * Creates the list with the default initial size. + */ + public gnuNVList() + { + list = new corbaArrayList(); + } + + /** + * Creates the list with the given initial size. + */ + public gnuNVList(int initial_size) + { + list = new corbaArrayList(initial_size); + } + + /** {@inheritDoc} */ + public NamedValue add(int a_flags) + { + return add_value(null, new gnuAny(), a_flags); + } + + /** {@inheritDoc} */ + public NamedValue add_item(String a_name, int a_flags) + { + return add_value(a_name, new gnuAny(), a_flags); + } + + /** {@inheritDoc} */ + public NamedValue add_value(String a_name, Any a_value, int a_flags) + { + gnuNamedValue n = new gnuNamedValue(); + n.setName(a_name); + n.setValue(a_value); + n.setFlags(a_flags); + list.add(n); + return n; + } + + /** + * Add the given named value to the list directly. + * + * @param value the named vaue to add. + */ + public void add(NamedValue value) + { + list.add(value); + } + + + /** {@inheritDoc} */ + public int count() + { + return list.size(); + } + + /** {@inheritDoc} */ + public NamedValue item(int at) + throws Bounds + { + return (NamedValue) list.item(at); + } + + /** {@inheritDoc} */ + public void remove(int at) + throws Bounds + { + list.drop(at); + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuNamedValue.java b/libjava/classpath/gnu/CORBA/gnuNamedValue.java new file mode 100644 index 0000000..6e3c271 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuNamedValue.java @@ -0,0 +1,112 @@ +/* gnuNamedValue.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; + +import org.omg.CORBA.Any; +import org.omg.CORBA.NamedValue; + +/** + * The implementation of the named value. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuNamedValue + extends NamedValue +{ + /** + * The named value value. + */ + private Any m_value = new gnuAny(); + + /** + * The named value name. + */ + private String m_name; + + /** + * The named value flags. + */ + private int m_flags; + + /** + * Set the flags, the normally expected values are + * {@link org.omg.CORBA.ARG_IN#value}, + * {@link org.omg.CORBA.ARG_OUT#value} and + * {@link org.omg.CORBA.ARG_INOUT#value}. + */ + public void setFlags(int flags) + { + m_flags = flags; + } + + /** + * Set the name of the value. + * @param name the name of this value + */ + public void setName(String name) + { + m_name = name; + } + + /** + * Set the value of the value. + * @param value the value of this object. + */ + public void setValue(Any value) + { + m_value = value; + } + + /** {@inheritDoc} */ + public int flags() + { + return m_flags; + } + + /** {@inheritDoc} */ + public String name() + { + return m_name; + } + + /** {@inheritDoc} */ + public Any value() + { + return m_value; + } +} diff --git a/libjava/classpath/gnu/CORBA/gnuRequest.java b/libjava/classpath/gnu/CORBA/gnuRequest.java new file mode 100644 index 0000000..a47410e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuRequest.java @@ -0,0 +1,1008 @@ +/* gnuRequest.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.GIOP.CloseMessage; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.RequestHeader; +import gnu.CORBA.GIOP.cxCodeSet; + +import org.omg.CORBA.ARG_IN; +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.Context; +import org.omg.CORBA.ContextList; +import org.omg.CORBA.Environment; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_RESOURCES; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.UserException; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.net.BindException; +import java.net.Socket; + +/** + * The implementation of the CORBA request. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class gnuRequest + extends Request + implements Cloneable +{ + /** + * The maximal supported GIOP version. + */ + public static Version MAX_SUPPORTED = new Version(1, 2); + + /** + * The initial pause that the Request makes when + * the required port is not available. + */ + public static int PAUSE_INITIAL = 50; + + /** + * The number of repretetive attempts to get a required + * port, if it is not immediately available. + */ + public static int PAUSE_STEPS = 12; + + /** + * The maximal pausing interval between two repetetive attempts. + * The interval doubles after each unsuccessful attempt, but + * will not exceed this value. + */ + public static int PAUSE_MAX = 1000; + + /** + * The empty byte array. + */ + private static final binaryReply EMPTY = + new binaryReply(null, new MessageHeader(), new byte[ 0 ]); + + /** + * The context holder for methods ctx(Context) and ctx(). + */ + protected Context m_context; + + /** + * The context list for method contexts(). + */ + protected ContextList m_context_list; + + /** + * The request environment for holding the exception + * the has possibly been thrown by the method being invoked. + */ + protected Environment m_environment = new gnuEnvironment(); + + /** + * The list of all exceptions that can be thrown by the + * method being invoked. + */ + protected ExceptionList m_exceptions = new gnuExceptionList(); + + /** + * The result, returned by the invoked method (function). + */ + protected NamedValue m_result = new gnuNamedValue(); + + /** + * The invocation target. + */ + protected org.omg.CORBA.Object m_target; + + /** + * The name of the method being invoked. + */ + protected String m_operation; + + /** + * The flag, indicating that the request has been sent + * and the result is already received. + */ + protected boolean complete; + + /** + * The flag, indicating that the response to this request must be + * ignored (used with {@link #send_oneway()}). + */ + protected boolean oneWay; + + /** + * The flag, indicating that the request has been sent + * and no result is yet received. + */ + protected boolean running; + + /** + * The request arguments. + */ + protected gnuNVList m_args = new gnuNVList(); + + /** + * The request arguments in the case when they are directly written into + * the parameter buffer. + */ + protected streamRequest m_parameter_buffer; + + /** + * The IOR of the target. + */ + private IOR ior; + + /** + * The ORB of the target. + */ + private ORB orb; + + /** + * The encoding, used to send the message. + * + * The default encoding is inherited from the set IOR + * (that string reference can be encoded in either Big or + * Little endian). If the IOR encoding is not known + * (for example, by obtaining the reference from the naming + * service), the Big Endian is used. + */ + private boolean Big_endian = true; + + /** + * Set the IOR data, sufficient to find the invocation target. + * This also sets default endian encoding for invocations. + * + * @see IOR.parse(String) + */ + public void setIor(IOR an_ior) + { + ior = an_ior; + setBigEndian(ior.Big_Endian); + } + + /** + * Get the IOR data, sufficient to find the invocation target. + * + * @return the IOR data. + */ + public IOR getIor() + { + return ior; + } + + /** + * Set the ORB, related to the invocation target. + */ + public void setORB(ORB an_orb) + { + orb = an_orb; + } + + /** + * Set the encoding that will be used to send the message. + * The default encoding is inherited from the set IOR + * (that string reference can be encoded in either Big or + * Little endian). If the IOR encoding is not known + * (for example, by obtaining the reference from the naming + * service), the Big Endian is used. + * + * @param use_big_endian true to use the Big Endian, false + * to use the Little Endian encoding. + */ + public void setBigEndian(boolean use_big_endian) + { + Big_endian = use_big_endian; + } + + /** + * The the method name to invoke. + * + * @param operation the method name. + */ + public void setOperation(String operation) + { + m_operation = operation; + } + + /** + * Get the parameter stream, where the invocation arguments should + * be written if they are written into the stream directly. + */ + public streamRequest getParameterStream() + { + m_parameter_buffer = new streamRequest(); + m_parameter_buffer.request = this; + m_parameter_buffer.setVersion(ior.Internet.version); + m_parameter_buffer.setCodeSet(cxCodeSet.negotiate(ior.CodeSets)); + m_parameter_buffer.setOrb(orb); + m_parameter_buffer.setBigEndian(Big_endian); + return m_parameter_buffer; + } + + /** + * Creates a shallow copy of this request. + */ + public gnuRequest Clone() + { + try + { + return (gnuRequest) clone(); + } + catch (CloneNotSupportedException ex) + { + throw new Unexpected(ex); + } + } + + /** {@inheritDoc} */ + public Any add_in_arg() + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_IN.value); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public Any add_inout_arg() + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_INOUT.value); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public Any add_named_in_arg(String name) + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_IN.value); + v.setName(name); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public Any add_named_inout_arg(String name) + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_INOUT.value); + v.setName(name); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public Any add_named_out_arg(String name) + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_OUT.value); + v.setName(name); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public Any add_out_arg() + { + gnuNamedValue v = new gnuNamedValue(); + v.setFlags(ARG_OUT.value); + m_args.add(v); + return v.value(); + } + + /** {@inheritDoc} */ + public NVList arguments() + { + return m_args; + } + + /** {@inheritDoc} */ + public ContextList contexts() + { + return m_context_list; + } + + /** {@inheritDoc} */ + public Context ctx() + { + return m_context; + } + + /** {@inheritDoc} */ + public void ctx(Context a_context) + { + m_context = a_context; + } + + /** {@inheritDoc} */ + public Environment env() + { + return m_environment; + } + + /** {@inheritDoc} */ + public ExceptionList exceptions() + { + return m_exceptions; + } + + /** {@inheritDoc} */ + public void get_response() + throws org.omg.CORBA.WrongTransaction + { + /** + * The response is ready after it is received. + * FIXME implement context checks and any other functionality, + * if required. + */ + } + + /** + * Submit the request, suspending the current thread until the + * answer is received. + * + * This implementation requires to set the IOR property + * ({@link #setIOR(IOR)} before calling this method. + * + * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been + * previously set. + * + * @throws SystemException if this exception has been thrown on + * remote side. The exact exception type and the minor code are + * the same as they have been for the exception, thrown on remoted + * side. + */ + public synchronized void invoke() + throws BAD_INV_ORDER + { + waitWhileBusy(); + complete = false; + running = true; + + if (ior == null) + throw new BAD_INV_ORDER("Set IOR property first"); + + try + { + p_invoke(); + } + finally + { + running = false; + complete = true; + } + } + + /** {@inheritDoc} */ + public String operation() + { + return m_operation; + } + + /** + * Get the orb, related to the invocation target. + */ + public ORB orb() + { + return orb; + } + + /** {@inheritDoc} */ + public boolean poll_response() + { + return complete && !running; + } + + /** {@inheritDoc} */ + public NamedValue result() + { + return m_result; + } + + /** {@inheritDoc} + * + */ + public Any return_value() + { + return m_result.value(); + } + + /** {@inheritDoc} */ + public synchronized void send_deferred() + { + waitWhileBusy(); + new Thread() + { + public void run() + { + invoke(); + } + }.start(); + } + + /** + * Send a request and forget about it, not waiting for a response. + * This can be done also for methods that normally are expected + * to return some values. + * + * TODO It is generally recommended to reuse the threads. Reuse? + */ + public void send_oneway() + { + final gnuRequest cloned = Clone(); + cloned.oneWay = true; + + new Thread() + { + public void run() + { + cloned.invoke(); + } + }.start(); + } + + /** + * Set the argument list. + * This field is initialised as empty non null instance by default, + * so the method is only used in cases when the direct replacement + * is desired. + * + * @param a_args the argument list. + */ + public void set_args(NVList a_args) + { + if (a_args instanceof gnuNVList) + m_args = (gnuNVList) a_args; + else + { + try + { + // In case if this is another implementation of the NVList. + m_args.list.clear(); + for (int i = 0; i < a_args.count(); i++) + { + m_args.add(a_args.item(i)); + } + } + catch (Bounds ex) + { + Unexpected.error(ex); + } + } + } + + /** + * Set the context list that is later returned by the + * method {@link #contexts()}. + * + * @param a_context_list a new context list. + */ + public void set_context_list(ContextList a_context_list) + { + m_context_list = a_context_list; + } + + /** + * Set the exception container. + * This field is initialised as empty non null instance by default, + * so the method is only used in cases when the direct replacement + * is desired. + * + * @param a_environment the new exception container. + */ + public void set_environment(Environment a_environment) + { + m_environment = a_environment; + } + + /** + * Set the list of exceptions. + * This field is initialised as empty non null instance by default, + * so the method is only used in cases when the direct replacement + * is desired. + * + * @param a_exceptions a list of exceptions. + */ + public void set_exceptions(ExceptionList a_exceptions) + { + m_exceptions = a_exceptions; + } + + /** + * Set the operation name. + * + * @param a_operation the operation name. + */ + public void set_operation(String a_operation) + { + m_operation = a_operation; + } + + /** + * Set the named value, returned as result. + * This field is initialised as empty non null instance by default, + * so the method is only used in cases when the direct replacement + * is desired. + * + * @param a_result the result keeper. + */ + public void set_result(NamedValue a_result) + { + m_result = a_result; + } + + /** + * Set the type of the named value, returned as a result. + * Instantiates a new instance of the result value. + */ + public void set_return_type(TypeCode returns) + { + if (m_result == null || !returns.equal(m_result.value().type())) + { + m_result = new gnuNamedValue(); + m_result.value().type(returns); + } + } + + /** + * Set the invocation target. + * + * @param a_target the CORBA object for that the method will be invoked. + */ + public void set_target(org.omg.CORBA.Object a_target) + { + m_target = a_target; + } + + /** + * Do the actual invocation. + * This implementation requires to set the IOR property + * ({@link #setIOR(IOR)} before calling this method. + * + * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been + * previously set or if the direct argument addition is mixed with + * the direct argument writing into the output stream. + * + * @return the server response in binary form. + */ + public synchronized binaryReply submit() + { + gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader(); + + header.setBigEndian(Big_endian); + + // The byte order will be Big Endian by default. + header.message_type = gnu.CORBA.GIOP.MessageHeader.REQUEST; + header.version = useVersion(ior.Internet.version); + + RequestHeader rh = header.create_request_header(); + + rh.object_key = ior.key; + rh.operation = m_operation; + + // Prepare the submission. + cdrBufOutput request_part = new cdrBufOutput(); + + request_part.setOffset(header.getHeaderSize()); + request_part.setVersion(header.version); + request_part.setCodeSet(cxCodeSet.negotiate(ior.CodeSets)); + request_part.setOrb(orb); + request_part.setBigEndian(header.isBigEndian()); + + // This also sets the stream encoding to the encoding, specified + // in the header. + rh.write(request_part); + + if (m_args != null && m_args.count() > 0) + { + write_parameters(header, request_part); + + if (m_parameter_buffer != null) + throw new BAD_INV_ORDER("Please either add parameters or " + + "write them into stream, but not both " + + "at once." + ); + } + + if (m_parameter_buffer != null) + { + write_parameter_buffer(header, request_part); + } + + // Now the message size is available. + header.message_size = request_part.buffer.size(); + + Socket socket = null; + + java.lang.Object key = ior.Internet.host + ":" + ior.Internet.port; + + synchronized (SocketRepository.class) + { + socket = SocketRepository.get_socket(key); + } + + try + { + long pause = PAUSE_INITIAL; + + if (socket == null) + { + // The BindException may be thrown under very heavy parallel + // load. For some time, just wait, exceptiong the socket to free. + Open: + for (int i = 0; i < PAUSE_STEPS; i++) + { + try + { + socket = new Socket(ior.Internet.host, ior.Internet.port); + break Open; + } + catch (BindException ex) + { + try + { + // Expecting to free a socket via finaliser. + System.gc(); + Thread.sleep(pause); + pause = pause * 2; + if (pause > PAUSE_MAX) + pause = PAUSE_MAX; + } + catch (InterruptedException iex) + { + } + } + } + } + + if (socket == null) + throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port + + " in use" + ); + socket.setKeepAlive(true); + + OutputStream socketOutput = socket.getOutputStream(); + + // Write the message header. + header.write(socketOutput); + + // Write the request header and parameters (if present). + request_part.buffer.writeTo(socketOutput); + + socketOutput.flush(); + if (!socket.isClosed()) + { + MessageHeader response_header = new MessageHeader(); + InputStream socketInput = socket.getInputStream(); + response_header.read(socketInput); + + byte[] r = new byte[ response_header.message_size ]; + int n = 0; + reading: + while (n < r.length) + { + n += socketInput.read(r, n, r.length - n); + } + return new binaryReply(orb, response_header, r); + } + else + return EMPTY; + } + catch (IOException io_ex) + { + MARSHAL m = + new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" + + ior.Internet.port + ); + m.initCause(io_ex); + throw m; + } + finally + { + try + { + if (socket != null && !socket.isClosed()) + { + socket.setSoTimeout(Functional_ORB.TANDEM_REQUESTS); + SocketRepository.put_socket(key, socket); + } + } + catch (IOException scx) + { + InternalError ierr = new InternalError(); + ierr.initCause(scx); + throw ierr; + } + } + } + + /** {@inheritDoc} */ + public org.omg.CORBA.Object target() + { + return m_target; + } + + /** + * Get the used version. Normally, it is better to respond using the + * same version as it is specified in IOR, but not above the maximal + * supported version. + */ + public Version useVersion(Version desired) + { + if (desired.until_inclusive(MAX_SUPPORTED.major, MAX_SUPPORTED.minor)) + return desired; + else + return MAX_SUPPORTED; + } + + /** + * Wait while the response to request, submitted using + * {@link #send_deferred()} or {@link #invoke()} (from other thread) + * is returned. + * + * FIXME It is possible to rewrite this using + * Object.wait() and Object.notify(), but be sure to prepare the test + * as well. + */ + public synchronized void waitWhileBusy() + { + // Waiting constants. + long wait = 10; + long increment = 2; + long max = 5000; + + while (running) + { + try + { + Thread.sleep(wait); + if (wait < max) + wait = wait * increment; + } + catch (InterruptedException ex) + { + } + } + } + + /** + * Do actual invocation. This method recursively calls itself if + * the redirection is detected. + */ + private void p_invoke() + throws SystemException + { + binaryReply response = submit(); + + ReplyHeader rh = response.header.create_reply_header(); + cdrBufInput input = response.getStream(); + input.setOrb(orb); + + rh.read(input); + + // The stream must be aligned sinve v1.2, but only once. + boolean align = response.header.version.since_inclusive(1, 2); + + boolean moved_permanently = false; + + switch (rh.reply_status) + { + case ReplyHeader.NO_EXCEPTION : + + NamedValue arg; + + // Read return value, if set. + if (m_result != null) + { + if (align) + { + input.align(8); + align = false; + } + m_result.value().read_value(input, m_result.value().type()); + } + + // Read returned parameters, if set. + if (m_args != null) + for (int i = 0; i < m_args.count(); i++) + { + try + { + arg = m_args.item(i); + + // Both ARG_INOUT and ARG_OUT have this binary flag set. + if ((arg.flags() & ARG_OUT.value) != 0) + { + if (align) + { + input.align(8); + align = false; + } + + arg.value().read_value(input, arg.value().type()); + } + } + catch (Bounds ex) + { + Unexpected.error(ex); + } + } + + break; + + case ReplyHeader.SYSTEM_EXCEPTION : + if (align) + { + input.align(8); + align = false; + } + + SystemException exception = ObjectCreator.readSystemException(input); + + m_environment.exception(exception); + + throw exception; + + case ReplyHeader.USER_EXCEPTION : + if (align) + { + input.align(8); + align = false; + } + + // Prepare an Any that will hold the exception. + gnuAny exc = new gnuAny(); + + exc.insert_Streamable(new streamReadyHolder(input)); + + UnknownUserException unuex = new UnknownUserException(exc); + m_environment.exception(unuex); + + break; + + case ReplyHeader.LOCATION_FORWARD_PERM : + case ReplyHeader.LOCATION_FORWARD : + if (response.header.version.since_inclusive(1, 2)) + input.align(8); + + IOR forwarded = new IOR(); + try + { + forwarded._read_no_endian(input); + } + catch (IOException ex) + { + throw new MARSHAL(ex + " while reading the forwarding info"); + } + + setIor(forwarded); + + // Repeat with the forwarded information. + p_invoke(); + return; + + default : + throw new MARSHAL("Unknow reply status: " + rh.reply_status); + } + } + + /** + * Write the operation parameters. + * + * @param header the message header + * @param request_part the stream to write parameters into + * + * @throws MARSHAL if the attempt to write the parameters has failde. + */ + private void write_parameter_buffer(MessageHeader header, + cdrBufOutput request_part + ) + throws MARSHAL + { + try + { + if (header.version.since_inclusive(1, 2)) + { + request_part.align(8); + } + m_parameter_buffer.buffer.writeTo(request_part); + } + catch (IOException ex) + { + throw new MARSHAL("Unable to write method arguments to CDR output."); + } + } + + /** + * Write the operation parameters. + * + * @param header the message header + * @param request_part the stream to write parameters into + * + * @throws MARSHAL if the attempt to write the parameters has failde. + */ + private void write_parameters(MessageHeader header, cdrBufOutput request_part) + throws MARSHAL + { + // Align after 1.2, but only once. + boolean align = header.version.since_inclusive(1, 2); + NamedValue para; + + try + { + // Write parameters now. + for (int i = 0; i < m_args.count(); i++) + { + para = m_args.item(i); + + //This bit is set both for ARG_IN and ARG_INOUT + if ((para.flags() & ARG_IN.value) != 0) + { + if (align) + { + request_part.align(8); + align = false; + } + para.value().write_value(request_part); + } + } + } + catch (Bounds ex) + { + throw new MARSHAL("Unable to write method arguments to CDR output."); + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/holderFactory.java b/libjava/classpath/gnu/CORBA/holderFactory.java new file mode 100644 index 0000000..177797a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/holderFactory.java @@ -0,0 +1,183 @@ +/* holderFactory.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; + +import org.omg.CORBA.AnyHolder; +import org.omg.CORBA.AnySeqHolder; +import org.omg.CORBA.BooleanHolder; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.DoubleHolder; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FixedHolder; +import org.omg.CORBA.FloatHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.IntHolder; +import org.omg.CORBA.LongHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.PrincipalHolder; +import org.omg.CORBA.ShortHolder; +import org.omg.CORBA.ShortSeqHolder; +import org.omg.CORBA.StringHolder; +import org.omg.CORBA.StringSeqHolder; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodeHolder; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; +import org.omg.CORBA.WStringSeqHolder; +import org.omg.CORBA.portable.Streamable; + +/** + * Creates the suitable holder for storing the value of the given + * type. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class holderFactory +{ + /** + * The array, sufficiently large to use any {@link TCKind}._tk* constant + * as an index. + */ + private static final Class[] holders; + private static final Class[] seqHolders; + + static + { + holders = new Class[ 32 ]; + holders [ TCKind._tk_Principal ] = PrincipalHolder.class; + holders [ TCKind._tk_TypeCode ] = TypeCodeHolder.class; + holders [ TCKind._tk_any ] = AnyHolder.class; + holders [ TCKind._tk_boolean ] = BooleanHolder.class; + holders [ TCKind._tk_char ] = CharHolder.class; + holders [ TCKind._tk_double ] = DoubleHolder.class; + holders [ TCKind._tk_float ] = FloatHolder.class; + holders [ TCKind._tk_fixed ] = FixedHolder.class; + holders [ TCKind._tk_long ] = IntHolder.class; + holders [ TCKind._tk_longdouble ] = DoubleHolder.class; + holders [ TCKind._tk_longlong ] = LongHolder.class; + holders [ TCKind._tk_octet ] = OctetHolder.class; + holders [ TCKind._tk_short ] = ShortHolder.class; + holders [ TCKind._tk_string ] = StringHolder.class; + holders [ TCKind._tk_ulong ] = IntHolder.class; + holders [ TCKind._tk_ulonglong ] = LongHolder.class; + holders [ TCKind._tk_ushort ] = ShortHolder.class; + holders [ TCKind._tk_wchar ] = WCharHolder.class; + holders [ TCKind._tk_wstring ] = WStringHolder.class; + + seqHolders = new Class[ 32 ]; + + seqHolders [ TCKind._tk_ulonglong ] = ULongLongSeqHolder.class; + seqHolders [ TCKind._tk_short ] = ShortSeqHolder.class; + seqHolders [ TCKind._tk_octet ] = OctetSeqHolder.class; + seqHolders [ TCKind._tk_any ] = AnySeqHolder.class; + seqHolders [ TCKind._tk_long ] = LongSeqHolder.class; + seqHolders [ TCKind._tk_longlong ] = LongLongSeqHolder.class; + seqHolders [ TCKind._tk_float ] = FloatSeqHolder.class; + seqHolders [ TCKind._tk_double ] = DoubleSeqHolder.class; + seqHolders [ TCKind._tk_char ] = CharSeqHolder.class; + seqHolders [ TCKind._tk_boolean ] = BooleanSeqHolder.class; + seqHolders [ TCKind._tk_wchar ] = WCharSeqHolder.class; + seqHolders [ TCKind._tk_ushort ] = UShortSeqHolder.class; + seqHolders [ TCKind._tk_ulong ] = ULongSeqHolder.class; + seqHolders [ TCKind._tk_string ] = StringSeqHolder.class; + seqHolders [ TCKind._tk_wstring ] = WStringSeqHolder.class; + } + + /** + * Create a holder for storing the value of the given built-in type. + * This function returns the defined holders for the built-in primitive + * types and they sequences. + * + * @param t the typecode + * + * @return an instance of the corresponding built-in holder of null + * if no such is defined for this type. The holder is created with a + * parameterless constructor. + */ + public static Streamable createHolder(TypeCode t) + { + try + { + int kind = t.kind().value(); + int componentKind; + + Streamable holder = null; + Streamable component; + + if (kind < holders.length && holders [ kind ] != null) + holder = (Streamable) holders [ kind ].newInstance(); + + if (holder != null) + return holder; + + switch (kind) + { + case TCKind._tk_sequence : + componentKind = t.content_type().kind().value(); + if (componentKind < seqHolders.length) + return (Streamable) seqHolders [ componentKind ].newInstance(); + break; + + default : + break; + } + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + + try + { + Object ox = ObjectCreator.createObject(t.id(), "Holder"); + return (Streamable) ox; + } + catch (Exception ex) + { + return null; + } + } +} diff --git a/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java b/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java new file mode 100644 index 0000000..7e2beeb --- /dev/null +++ b/libjava/classpath/gnu/CORBA/primitiveArrayTypeCode.java @@ -0,0 +1,265 @@ +/* primitiveArrayTypeCode.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A TypeCode for arrays. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class primitiveArrayTypeCode + extends primitiveTypeCode +{ + /** + * The array components. + */ + TypeCode of; + + /** + * The length of the array, must be updated when setting + * a new value. + */ + private int length; + + /** + * Create a primitive array type code, defining the sequence + * {@link TCKind.tk_sequence)} with + * the given member type. + * + * @param array_of the sequence member type. + */ + public primitiveArrayTypeCode(TCKind array_of) + { + super(TCKind.tk_sequence); + of = new primitiveTypeCode(array_of); + } + + /** + * Create a primitive array type code, defining the array, sequence + * or other type with the given member type. + * + * @param this_type the type of this type (normally either + * sequence of array). + * @param array_of the sequence member type. + */ + public primitiveArrayTypeCode(TCKind this_type, TypeCode array_of) + { + super(this_type); + of = array_of; + } + + /** + * Return the array component type. + * @return the array component type + * @throws org.omg.CORBA.TypeCodePackage.BadKind + */ + public TypeCode content_type() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return of; + } + + /** + * Return true if the other TypeCode defines the array, having elements + * of the same type. The sizes of arrays are not taken into + * consideration. + * + * @param other the other TypeCode + * @return true if <code>other</code> is an array with the same + * component type. + */ + public boolean equal(TypeCode other) + { + try + { + return kind() == other.kind() && + content_type() == other.content_type(); + } + catch (BadKind ex) + { + // Should not be thrown. + return false; + } + } + + /** + * Returns the agreed Id in the form of + * <code>IDL:omg.org/CORBA/ {type name} Seq:1.0</code>. + * + * @return the Id of this TypeCode. + * + * @throws org.omg.CORBA.TypeCodePackage.BadKind if the content type + * is not one of the constants, defined in {@link TCKind}. + * This package class should not be used as TypeCode for the arrays, + * holding the user defined components. + */ + public String id() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + switch (content_type().kind().value()) + { + case TCKind._tk_null : + return "IDL:omg.org/CORBA/NullSeq:1.0"; + + case TCKind._tk_void : + return "IDL:omg.org/CORBA/VoidSeq:1.0"; + + case TCKind._tk_short : + return "IDL:omg.org/CORBA/ShortSeq:1.0"; + + case TCKind._tk_long : + return "IDL:omg.org/CORBA/LongSeq:1.0"; + + case TCKind._tk_ushort : + return "IDL:omg.org/CORBA/UShortSeq:1.0"; + + case TCKind._tk_ulong : + return "IDL:omg.org/CORBA/ULongSeq:1.0"; + + case TCKind._tk_float : + return "IDL:omg.org/CORBA/FloatSeq:1.0"; + + case TCKind._tk_double : + return "IDL:omg.org/CORBA/DoubleSeq:1.0"; + + case TCKind._tk_boolean : + return "IDL:omg.org/CORBA/BooleanSeq:1.0"; + + case TCKind._tk_char : + return "IDL:omg.org/CORBA/CharSeq:1.0"; + + case TCKind._tk_octet : + return "IDL:omg.org/CORBA/OctetSeq:1.0"; + + case TCKind._tk_any : + return "IDL:omg.org/CORBA/AnySeq:1.0"; + + case TCKind._tk_TypeCode : + return "IDL:omg.org/CORBA/TypeCodeSeq:1.0"; + + case TCKind._tk_Principal : + return "IDL:omg.org/CORBA/PrincipalSeq:1.0"; + + case TCKind._tk_objref : + return "IDL:omg.org/CORBA/ObjrefSeq:1.0"; + + case TCKind._tk_struct : + return "IDL:omg.org/CORBA/StructSeq:1.0"; + + case TCKind._tk_union : + return "IDL:omg.org/CORBA/UnionSeq:1.0"; + + case TCKind._tk_enum : + return "IDL:omg.org/CORBA/EnumSeq:1.0"; + + case TCKind._tk_string : + return "IDL:omg.org/CORBA/StringSeq:1.0"; + + case TCKind._tk_sequence : + return "IDL:omg.org/CORBA/SequenceSeq:1.0"; + + case TCKind._tk_array : + return "IDL:omg.org/CORBA/ArraySeq:1.0"; + + case TCKind._tk_alias : + return "IDL:omg.org/CORBA/AliasSeq:1.0"; + + case TCKind._tk_except : + return "IDL:omg.org/CORBA/ExceptSeq:1.0"; + + case TCKind._tk_longlong : + return "IDL:omg.org/CORBA/LongLongSeq:1.0"; + + case TCKind._tk_ulonglong : + return "IDL:omg.org/CORBA/ULongLongSeq:1.0"; + + case TCKind._tk_longdouble : + return "IDL:omg.org/CORBA/LongDoubleSeq:1.0"; + + case TCKind._tk_wchar : + return "IDL:omg.org/CORBA/WCharSeq:1.0"; + + case TCKind._tk_wstring : + return "IDL:omg.org/CORBA/WStringSeq:1.0"; + + case TCKind._tk_fixed : + return "IDL:omg.org/CORBA/FixedSeq:1.0"; + + case TCKind._tk_value : + return "IDL:omg.org/CORBA/ValueSeq:1.0"; + + case TCKind._tk_value_box : + return "IDL:omg.org/CORBA/Value_boxSeq:1.0"; + + case TCKind._tk_native : + return "IDL:omg.org/CORBA/NativeSeq:1.0"; + + case TCKind._tk_abstract_interface : + return "IDL:omg.org/CORBA/Abstract_interfaceSeq:1.0"; + + default : + throw new BadKind(); + } + } + + /** + * Return the array length. + * @return the length of the array. + * @throws org.omg.CORBA.TypeCodePackage.BadKind + */ + public int length() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return length; + } + + /** + * Sets the array length to the supplied value. + * + * @param l the new length. + */ + public void setLength(int l) + { + this.length = l; + } + +} diff --git a/libjava/classpath/gnu/CORBA/primitiveTypeCode.java b/libjava/classpath/gnu/CORBA/primitiveTypeCode.java new file mode 100644 index 0000000..1fa5cd0 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/primitiveTypeCode.java @@ -0,0 +1,195 @@ +/* primitiveTypeCode.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; + +import java.io.Serializable; + +import org.omg.CORBA.Any; +import org.omg.CORBA.IDLEntity; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; + +/** + * An information about a primitive CORBA data type + * (boolean, char, wchar, octet and also signed or unsigned short, long, + * long long, float and double). + * This class only implements the methods {@link #kind() } + * and {@link equal() } that are valid for + * all TypeCode kinds. Other methods are implemented in derived + * subclasses. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class primitiveTypeCode + extends TypeCode + implements IDLEntity, Serializable +{ + /** + * The kind of this TypeCode. + */ + protected final TCKind kind; + + public primitiveTypeCode(TCKind a_kind) + { + kind = a_kind; + } + + public TypeCode concrete_base_type() + throws BadKind + { + throw new BadKind(); + } + + public TypeCode content_type() + throws BadKind + { + throw new BadKind(); + } + + public int default_index() + throws BadKind + { + throw new BadKind(); + } + + public TypeCode discriminator_type() + throws BadKind + { + throw new BadKind(); + } + + /** + * Test two types for equality. The default implementation + * returs true of the types of the same kind. + * @param other the other type to compere with + * @return true if the types are interchangeable. + */ + public boolean equal(TypeCode other) + { + return kind() == other.kind(); + } + + public boolean equivalent(TypeCode parm1) + { + throw new NO_IMPLEMENT(); + } + + public short fixed_digits() + throws BadKind + { + throw new BadKind("fixed_digits"); + } + + public short fixed_scale() + throws BadKind + { + throw new BadKind("fixed_scale"); + } + + public TypeCode get_compact_typecode() + { + throw new NO_IMPLEMENT(); + } + + public String id() + throws BadKind + { + throw new BadKind("id"); + } + + /** + * Return the kind of this type code object. + * @return one of the <code>TCKind.t_..</code> fields. + */ + public TCKind kind() + { + return kind; + } + + public int length() + throws BadKind + { + throw new BadKind("length"); + } + + public int member_count() + throws BadKind + { + throw new BadKind("member_count"); + } + + public Any member_label(int index) + throws BadKind, Bounds + { + throw new BadKind("member_label"); + } + + public String member_name(int index) + throws BadKind, Bounds + { + throw new BadKind("member_name"); + } + + public TypeCode member_type(int index) + throws BadKind, Bounds + { + throw new BadKind("member_type"); + } + + public short member_visibility(int index) + throws BadKind, Bounds + { + throw new BadKind("member_visibility"); + } + + public String name() + throws BadKind + { + throw new BadKind("name"); + } + + public short type_modifier() + throws BadKind + { + throw new BadKind("type_modifier"); + } +} diff --git a/libjava/classpath/gnu/CORBA/recordTypeCode.java b/libjava/classpath/gnu/CORBA/recordTypeCode.java new file mode 100644 index 0000000..8f2ecde --- /dev/null +++ b/libjava/classpath/gnu/CORBA/recordTypeCode.java @@ -0,0 +1,245 @@ +/* recordTypeCode.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; + +import org.omg.CORBA.Any; +import org.omg.CORBA.StructMember; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.UnionMember; +import org.omg.CORBA.ValueMember; + +/** + * The type code that also has the member property getters + * supported. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class recordTypeCode + extends generalTypeCode +{ + /** + * The individual field of the record. + */ + public static class Field + { + /** + * The record label. + */ + public Any label; + + /** + * The record name. + */ + public String name; + + /** + * The record type. + */ + public TypeCode type; + + /** + * The record visibility. + */ + public int visibility = UNSET; + } + + /** + * The members of this data structure. + */ + protected corbaArrayList members = new corbaArrayList(); + private TypeCode discriminator_type; + private int default_index = UNSET; + + /** + * Creates the type code of the given kind. + */ + public recordTypeCode(TCKind kind) + { + super(kind); + } + + /** + * Set the default index. + */ + public void setDefaultIndex(int a_default_index) + { + this.default_index = a_default_index; + } + + /** + * Set the discriminator type. + */ + public void setDiscriminator_type(TypeCode a_discriminator_type) + { + this.discriminator_type = a_discriminator_type; + } + + public Field getField(int p) + { + return (Field) members.get(p); + } + + public void add(Field field) + { + members.add(field); + } + + /** + * Adds a new field, taking values from the passed + * {@link StructMember}. + */ + public void add(StructMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + } + + /** + * Adds a new field, taking values from the passed + * {@link ValueMember}. + */ + public void add(ValueMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + f.visibility = m.access; + + } + + /** + * Adds a new field, taking values from the passed + * {@link UnionMember}. + */ + public void add(UnionMember m) + { + Field f = field(); + f.name = m.name; + f.type = m.type; + f.label = m.label; + } + + public int default_index() + throws BadKind + { + if (default_index != UNSET) + return default_index; + throw new BadKind(); + } + + public TypeCode discriminator_type() + throws BadKind + { + if (discriminator_type != null) + return discriminator_type; + throw new BadKind(); + } + + /** + * Creates, adds and returns new field. + */ + public Field field() + { + Field f = new Field(); + members.add(f); + return f; + } + + /** {@inheritDoc} */ + public int member_count() + { + return members.size(); + } + + /** {@inheritDoc} */ + public Any member_label(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.label != null) + { + return f.label; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public String member_name(int index) + throws BadKind + { + Field f = getField(index); + if (f.name != null) + { + return f.name; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public TypeCode member_type(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.type != null) + { + return f.type; + } + else + throw new BadKind(); + } + + /** {@inheritDoc} */ + public short member_visibility(int index) + throws BadKind, Bounds + { + Field f = getField(index); + if (f.visibility != UNSET) + { + return (short) f.visibility; + } + else + throw new BadKind(); + } +} diff --git a/libjava/classpath/gnu/CORBA/recursiveTypeCode.java b/libjava/classpath/gnu/CORBA/recursiveTypeCode.java new file mode 100644 index 0000000..6bc672e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/recursiveTypeCode.java @@ -0,0 +1,78 @@ +/* recursiveTypeCode.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; + +import org.omg.CORBA.TCKind; + +/** + * The typecode, serving as a placeholder in defining + * typecodes, containing recursion. + */ +public class recursiveTypeCode + extends primitiveTypeCode +{ + /** + * The id of the type for that this type serves as a + * placeholder. + */ + private final String the_id; + + /** + * Create a typecode that serves as a placeholder for + * the typecode with the given id. + * + * @param id the Id of the type for that this type serves as a + * placeholder. + */ + public recursiveTypeCode(String an_id) + { + super(TCKind.tk_null); + the_id = an_id; + } + + /** + * Get the id of the type for that this type serves as a + * placeholder. + */ + public String id() + throws org.omg.CORBA.TypeCodePackage.BadKind + { + return the_id; + } +} diff --git a/libjava/classpath/gnu/CORBA/streamReadyHolder.java b/libjava/classpath/gnu/CORBA/streamReadyHolder.java new file mode 100644 index 0000000..a777bd5 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/streamReadyHolder.java @@ -0,0 +1,120 @@ +/* streamReadyHolder.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; + +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; + +/** + * A holder that stores the input stream, from that the holder data + * can be read. There is no way to write the data into this holder. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class streamReadyHolder + implements Streamable +{ + /** + * The stream, holding the data for this holder. + */ + protected final InputStream stream; + + /** + * Create a holder that will read from the given stream. + * + * @param a_stream a stream. + */ + public streamReadyHolder(InputStream a_stream) + { + stream = a_stream; + } + + /** + * This method is not in use, should never be called. + */ + public TypeCode _type() + { + throw new NO_IMPLEMENT(); + } + + /** + * Writes the data from the stored stream into the provided + * output stream till the end of the input stream is reached. + * + * @throws MARSHAL if the IOException is thrown during operation. + */ + public void _write(OutputStream output) + { + try + { + int d = stream.read(); + + while (d >= 0) + { + output.write(d); + d = stream.read(); + } + } + catch (IOException ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * This method is not in use, should never be called. + */ + public void _read(InputStream input) + { + throw new NO_IMPLEMENT(); + } + + /** + * Get the input stream that has been passed in constructor. + */ + InputStream getInputStream() + { + return stream; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/streamRequest.java b/libjava/classpath/gnu/CORBA/streamRequest.java new file mode 100644 index 0000000..a0f7eb0 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/streamRequest.java @@ -0,0 +1,60 @@ +/* gnuStreamRequest.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; + +import gnu.CORBA.CDR.cdrBufOutput; + +/** + * A stream, additionally holding the gnu request. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class streamRequest + extends cdrBufOutput +{ + /** + * The enclosed request. + */ + public gnuRequest request; + + /** + * True if the response is expected. + */ + public boolean response_expected = true; +} diff --git a/libjava/classpath/gnu/CORBA/stringTypeCode.java b/libjava/classpath/gnu/CORBA/stringTypeCode.java new file mode 100644 index 0000000..27aa119 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/stringTypeCode.java @@ -0,0 +1,83 @@ +/* stringTypeCode.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; + +import org.omg.CORBA.TCKind; + +/** + * The typecode for string and wide string. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class stringTypeCode + extends primitiveTypeCode +{ + private int len = 0; + + /** + * Create a new instance of the string type code. + * + * @param a_kind a kind of this typecode, normally + * either tk_string or tk_wstring. + */ + public stringTypeCode(TCKind a_kind) + { + super(a_kind); + } + + /** + * Set the length property. + * + * @param a_length a length. + */ + public void setLength(int a_length) + { + len = a_length; + } + + /** + * Get the length of the string. This method returns 0 + * (unbounded) if the property has not been set. + * + * @return the length (bound) of the string. + */ + public int length() + { + return len; + } +} diff --git a/libjava/classpath/gnu/CORBA/stubFinder.java b/libjava/classpath/gnu/CORBA/stubFinder.java new file mode 100644 index 0000000..77efd00 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/stubFinder.java @@ -0,0 +1,110 @@ +/* stubFinder.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; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * Finds a stub class like "_HelloStub" that can be instantiated + * from IOR reference. The returned object can be casted to the + * used type like "Hello" without using the helper .narrow method, + * and the object is not unnsecessarily re - instantiated if + * the .narrow method is used anyway. If no stub, matching the naming + * conventions, is available, the returned stub replacement can still be used + * to get the valid request, add parameter and invoke the method by name. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class stubFinder +{ + /** + * Search for the possibly available default stub. + * + * @param orb the current ORB. It is not required to find the binding + * classes, but is needed to instantiate the default implementation + * if no binding classes are found. + * + * @param ior the IOR, possibly containing the information about the + * correct implementation class. + */ + public static ObjectImpl search(ORB orb, IOR ior) + { + try + { + int a = ior.Id.indexOf(':'); + int b = ior.Id.lastIndexOf(':'); + + String s = ior.Id.substring(a + 1, b).replace('/', '.'); + + String path; + + b = s.lastIndexOf('.'); + if (b > 0) + path = s.substring(0, b + 1); + else + path = ""; + + String stub = "_" + s.substring(b + 1) + "Stub"; + + Class stubClass = Class.forName(path + stub); + + return (ObjectImpl) stubClass.newInstance(); + } + catch (Exception failed) + { + // Various exceptions can be thrown if the Id cannot be parsed, + // the class is missing, cannot be instantiated or is not an + // instance of the ObjectImpl. + return createDefaultStub(orb, ior); + } + } + + /** + * Return the default stub for the case when the client binding classes + * are not locally available. The returned stub can still be used + * to get the valid request, add parameter and invoke the method by name. + * + * @return the default implementation. + */ + protected static ObjectImpl createDefaultStub(ORB orb, IOR ior) + { + return new IOR_contructed_object(orb, ior); + } +} diff --git a/libjava/classpath/gnu/CORBA/typeNamer.java b/libjava/classpath/gnu/CORBA/typeNamer.java new file mode 100644 index 0000000..8b70101 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/typeNamer.java @@ -0,0 +1,171 @@ +/* primitiveTypes.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; + +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; + +/** + * A conveniency method for naming the built-in types. + * This is used in error reporting that is part of the user interface. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class typeNamer +{ + /** + * Names of the primitve types. + */ + protected static final String[] tk = + new String[] + { + "null", "void", "short", "long", "ushort", "ulong", "float", "double", + "boolean", "char", "octet", "any", "TypeCode", "Principal", "objref", + "struct", "union", "enum", "string", "sequence", "array", "alias", + "exception", "longlong", "ulonglong", "longdouble", "wchar", "wstring", + "fixed", "value", "value_box", "native", "abstract_interface" + }; + + /** + * Primitve TypeCodes. + */ + protected static final TypeCode[] primitveCodes = + new TypeCode[] + { + new primitiveTypeCode(TCKind.tk_null), + new primitiveTypeCode(TCKind.tk_void), + new primitiveTypeCode(TCKind.tk_short), + new primitiveTypeCode(TCKind.tk_long), + new primitiveTypeCode(TCKind.tk_ushort), + new primitiveTypeCode(TCKind.tk_ulong), + new primitiveTypeCode(TCKind.tk_float), + new primitiveTypeCode(TCKind.tk_double), + new primitiveTypeCode(TCKind.tk_boolean), + new primitiveTypeCode(TCKind.tk_char), + new primitiveTypeCode(TCKind.tk_octet), + new primitiveTypeCode(TCKind.tk_any), + new primitiveTypeCode(TCKind.tk_TypeCode), + new primitiveTypeCode(TCKind.tk_Principal), + new primitiveTypeCode(TCKind.tk_objref), + new primitiveTypeCode(TCKind.tk_struct), + new primitiveTypeCode(TCKind.tk_union), + new primitiveTypeCode(TCKind.tk_enum), + new primitiveTypeCode(TCKind.tk_string), + new primitiveTypeCode(TCKind.tk_sequence), + new primitiveTypeCode(TCKind.tk_array), + new primitiveTypeCode(TCKind.tk_alias), + new primitiveTypeCode(TCKind.tk_except), + new primitiveTypeCode(TCKind.tk_longlong), + new primitiveTypeCode(TCKind.tk_ulonglong), + new primitiveTypeCode(TCKind.tk_longdouble), + new primitiveTypeCode(TCKind.tk_wchar), + new primitiveTypeCode(TCKind.tk_wstring), + new primitiveTypeCode(TCKind.tk_fixed), + new primitiveTypeCode(TCKind.tk_value), + new primitiveTypeCode(TCKind.tk_value_box), + new primitiveTypeCode(TCKind.tk_native), + new primitiveTypeCode(TCKind.tk_abstract_interface) + }; + + /** + * Get the primitive type code. + * + * @return the primitve type code, corresponding the passed value. + * + * @throws BadKind if this is not a primitive type code. + */ + public static TypeCode getPrimitveTC(TCKind tc) + throws BadKind + { + try + { + return primitveCodes [ tc.value() ]; + } + catch (ArrayIndexOutOfBoundsException ex) + { + throw new BadKind(tc.value() + " is not a primitve type."); + } + } + + /** + * Get the string name of the passed primitive type. + * + * @param kind the kind of the primitive type the must be defined + * in {@link omg.org.CORBA.TCKind}. + * + * @return the short string name, used in error reporting, etc. + */ + public static String nameIt(int kind) + { + try + { + return tk [ kind ]; + } + catch (ArrayIndexOutOfBoundsException ex) + { + return "type of kind '" + kind + "'"; + } + } + + /** + * Get the string name of the passed primitive type. + * + * @param kind the kind of the primitive type the must be defined + * in {@link omg.org.CORBA.TCKind}. + * + * @return the short string name, used in error reporting, etc. + */ + public static String nameIt(TypeCode type) + { + try + { + if (type.kind().value() == TCKind._tk_array) + return "array of " + nameIt(type.content_type()); + else if (type.kind().value() == TCKind._tk_sequence) + return "sequence of " + nameIt(type.content_type()); + else + return nameIt(type.kind().value()); + } + catch (Exception ex) + { + return "type of kind '" + type.kind().value() + "'"; + } + } +} diff --git a/libjava/classpath/gnu/CORBA/universalHolder.java b/libjava/classpath/gnu/CORBA/universalHolder.java new file mode 100644 index 0000000..6d8b774 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/universalHolder.java @@ -0,0 +1,157 @@ +/* universalStreamable.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; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +import java.io.IOException; + +/** + * This class holds the abstract binary data array of the Streamable + * being stored. It is used to insert and extract into {@link Any} objects + * that have no holder, but have the helper classes. + * Encoding/decoding then must be performed by the helper. This class is + * defined as package private because it is not idiot proof and + * must be used with care. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +class universalHolder + implements Streamable +{ + /** + * The binary data, stored inside this holder. + */ + private cdrBufOutput value = new cdrBufOutput(); + + /** + * Create the universal holder that uses the given buffer to store the data. + */ + universalHolder(cdrBufOutput buffer) + { + value = buffer; + } + + /** + * Reads into the internal buffer till the end of stream is + * reached. No alignment operations are performed. This operation + * normally reads from the stream, where the single value, + * stored using {@link #_write}, is written. + * + * @throws MARSHALL, if the IOException is thrown during the + * stream operation. + */ + public void _read(InputStream input) + { + try + { + if (input instanceof cdrBufInput) + { + cdrBufInput b = (cdrBufInput) input; + value.write(b.buffer.getBuffer()); + } + else + { + int c; + + do + { + c = input.read(); + if (c >= 0) + value.write(c); + } + while (c >= 0); + } + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.initCause(ex); + throw t; + } + } + + /** + * The type is not known and cannot be returned. + * + * @throws BAD_OPERATION, always. + */ + public TypeCode _type() + { + throw new BAD_OPERATION(); + } + + /** + * Writes the binary data being stored into the given output + * stream. This operation supposes that the current stream + * position is 0 or satisfies the required alignments anyway. + * + * @throws MARSHAL if the IOExeption is thrown when writing the + * byte array. + */ + public void _write(OutputStream output) + { + try + { + value.buffer.writeTo(output); + } + catch (IOException ex) + { + MARSHAL t = new MARSHAL(); + t.initCause(ex); + throw t; + } + } + + /** + * Get the input stream that reads the fields of the stored value. + */ + InputStream getInputStream() + { + return value.create_input_stream(); + } +} |