Initial revision

From-SVN: r102074
This commit is contained in:
Tom Tromey
2005-07-16 00:30:23 +00:00
parent 6f4434b39b
commit f911ba985a
4557 changed files with 1000262 additions and 0 deletions
+185
View File
@@ -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)
{
}
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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 &amp; 0xFF) &lt;&lt; 8) | (byte2 &amp; 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 &amp; 0xFF) &lt;&lt; 24) + ((byte2 &amp; 0xFF) &lt;&lt; 16) +
* ((byte3 &amp; 0xFF)&lt;&lt; 8) + (byte4 &amp; 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 &amp; 0xFF) &lt;&lt; 56) + ((byte2 &amp; 0xFF) &lt;&lt; 48) +
* ((byte3 &amp; 0xFF) &lt;&lt; 40) + ((byte4 &amp; 0xFF) &lt;&lt; 32) +
* ((byte5 &amp; 0xFF) &lt;&lt; 24) + ((byte6 &amp; 0xFF) &lt;&lt; 16) +
* ((byte7 &amp; 0xFF) &lt;&lt; 8) + (byte8 &amp; 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 &amp; 0xFF) &lt;&lt; 8) | (byte2 &amp; 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 &amp; 0xFF) &lt;&lt; 8) + (byte2 &amp; 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();
}
}
@@ -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));
}
}
+638
View File
@@ -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
);
}
}
@@ -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 &amp; 0xFF) &lt;&lt; 8) | (byte2 &amp; 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 &amp; 0xFF) &lt;&lt; 24) + ((byte2 &amp; 0xFF) &lt;&lt; 16) +
* ((byte3 &amp; 0xFF)&lt;&lt; 8) + (byte4 &amp; 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 &amp; 0xFF) &lt;&lt; 56) + ((byte2 &amp; 0xFF) &lt;&lt; 48) +
* ((byte3 &amp; 0xFF) &lt;&lt; 40) + ((byte4 &amp; 0xFF) &lt;&lt; 32) +
* ((byte5 &amp; 0xFF) &lt;&lt; 24) + ((byte6 &amp; 0xFF) &lt;&lt; 16) +
* ((byte7 &amp; 0xFF) &lt;&lt; 8) + (byte8 &amp; 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 &amp; 0xFF) &lt;&lt; 8) | (byte2 &amp; 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 &amp; 0xFF) &lt;&lt; 8) + (byte2 &amp; 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;
}
@@ -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;
}
@@ -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;
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
File diff suppressed because it is too large Load Diff
@@ -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);
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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);
}
}
@@ -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;
}
}
}
@@ -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";
}
}
File diff suppressed because it is too large Load Diff
@@ -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);
}
@@ -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);
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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;
}
}
}
@@ -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);
}
@@ -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);
}
@@ -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;
}
}
@@ -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) +
") ";
}
}
@@ -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);
}
}
@@ -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));
}
}
@@ -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));
}
}
@@ -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));
}
}
@@ -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));
}
}
+563
View File
@@ -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();
}
}
@@ -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.
}
}
}
@@ -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);
}
}
@@ -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;
}
}
}
@@ -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);
}
}
@@ -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");
}
}
}
@@ -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();
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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();
}
}
}
@@ -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";
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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();
}
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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;
}
}
}
@@ -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 :}
}
}
+128
View File
@@ -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();
}
}
+206
View File
@@ -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");
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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));
}
}
@@ -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;
}
}
@@ -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() + "]");
}
}
}
@@ -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;
}
}
@@ -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");
}
}
+830
View File
@@ -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;
}
}
@@ -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
)
);
}
}
+202
View File
@@ -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.");
}
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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);
}
}
+127
View File
@@ -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);
}
}
@@ -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;
}
}
File diff suppressed because it is too large Load Diff
@@ -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;
}
}
}
@@ -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;
}
}
@@ -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");
}
}
@@ -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();
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
@@ -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;
}
}
+110
View File
@@ -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);
}
}
+171
View File
@@ -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() + "'";
}
}
}
@@ -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();
}
}
@@ -0,0 +1 @@
Configuration.java
@@ -0,0 +1,131 @@
/* Configuration.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.classpath;
/**
* This file defines compile-time constants that can be accessed by
* java code. It is pre-processed by configure.
*/
public interface Configuration
{
/**
* The value of CLASSPATH_HOME is the location that the classpath
* libraries and support files where installed in. It is set according to
* the argument for --prefix given to configure and used to set the
* System property gnu.classpath.home.
*/
String CLASSPATH_HOME = "@prefix@";
/**
* The release version number of GNU Classpath.
* It is set according to the value of 'version' in the configure[.in] file
* and used to set the System property gnu.classpath.version.
*/
String CLASSPATH_VERSION = "@VERSION@";
/**
* The value of DEBUG is substituted according to whether the
* "--enable-debug" argument was passed to configure. Code
* which is made conditional based on the value of this flag - typically
* code that generates debugging output - will be removed by the optimizer
* in a non-debug build.
*/
boolean DEBUG = @LIBDEBUG@;
/**
* The value of LOAD_LIBRARY is substituted according to whether the
* "--enable-load-library" or "--disable-load-library" argument was passed
* to configure. By default, configure should define this is as true.
* If set to false, loadLibrary() calls to load native function
* implementations, typically found in static initializers of classes
* which contain native functions, will be omitted. This is useful for
* runtimes which pre-link their native function implementations and do
* not require additional shared libraries to be loaded.
*/
boolean INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@;
/**
* Set to true if the VM provides a native method to implement
* Proxy.getProxyClass completely, including argument verification.
* If this is true, HAVE_NATIVE_GET_PROXY_DATA and
* HAVE_NATIVE_GENERATE_PROXY_CLASS should be false.
* @see java.lang.reflect.Proxy
*/
boolean HAVE_NATIVE_GET_PROXY_CLASS = false;
/**
* Set to true if the VM provides a native method to implement
* the first part of Proxy.getProxyClass: generation of the array
* of methods to convert, and verification of the arguments.
* If this is true, HAVE_NATIVE_GET_PROXY_CLASS should be false.
* @see java.lang.reflect.Proxy
*/
boolean HAVE_NATIVE_GET_PROXY_DATA = false;
/**
* Set to true if the VM provides a native method to implement
* the second part of Proxy.getProxyClass: conversion of an array of
* methods into an actual proxy class.
* If this is true, HAVE_NATIVE_GET_PROXY_CLASS should be false.
* @see java.lang.reflect.Proxy
*/
boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = false;
/**
* Name of default AWT peer library.
*/
String default_awt_peer_toolkit = "@default_toolkit@";
/**
* Whether to automatically run the init* methods in java.lang.System
* (the default) at class initialization time or whether to have the VM
* explicitly invoke them.
*
* The default is false, meaning the VM does not explicitly run the
* initializers.
*
*/
boolean JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION =
@JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@;
/**
* Set to true if Cairo was found and enabled during configure,
* false otherwise.
*/
boolean GTK_CAIRO_ENABLED = @GTK_CAIRO_ENABLED@;
}
@@ -0,0 +1,47 @@
/* RawData.java -- Pointer to VM specific data
Copyright (C) 1999, 2000, 2004 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. */
/* This file is originally part of libgcj. */
package gnu.classpath;
/** A type used to indicate special data used by native code that should not
be marked by the garbage collector. */
public abstract class RawData
{
}
@@ -0,0 +1,52 @@
/* RawData32.java -- 32 bit Pointer
Copyright (C) 2004 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.classpath;
/**
* A type used to indicate special data used by native code that should not
* be marked by the garbage collector.
*/
public final class RawData32 extends RawData
{
final int data;
public RawData32(int data)
{
this.data = data;
}
}
@@ -0,0 +1,52 @@
/* RawData64.java -- 64 bit Pointer
Copyright (C) 2004 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.classpath;
/**
* A type used to indicate special data used by native code that should not
* be marked by the garbage collector.
*/
public final class RawData64 extends RawData
{
final long data;
public RawData64(long data)
{
this.data = data;
}
}
@@ -0,0 +1,573 @@
/* ServiceFactory.java -- Factory for plug-in services.
Copyright (C) 2004 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.classpath;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* A factory for plug-ins that conform to a service provider
* interface. This is a general mechanism that gets used by a number
* of packages in the Java API. For instance, {@link
* java.nio.charset.spi.CharsetProvider} allows to write custom
* encoders and decoders for character sets, {@link
* javax.imageio.spi.ImageReaderSpi} allows to support custom image
* formats, and {@link javax.print.PrintService} makes it possible to
* write custom printer drivers.
*
* <p>The plug-ins are concrete implementations of the service
* provider interface, which is defined as an interface or an abstract
* class. The implementation classes must be public and have a public
* constructor that takes no arguments.
*
* <p>Plug-ins are usually deployed in JAR files. A JAR that provides
* an implementation of a service must declare this in a resource file
* whose name is the fully qualified service name and whose location
* is the directory <code>META-INF/services</code>. This UTF-8 encoded
* text file lists, on separate lines, the fully qualified names of
* the concrete implementations. Thus, one JAR file can provide an
* arbitrary number of implementations for an arbitrary count of
* service provider interfaces.
*
* <p><b>Example</b>
*
* <p>For example, a JAR might provide two implementations of the
* service provider interface <code>org.foo.ThinkService</code>,
* namely <code>com.acme.QuickThinker</code> and
* <code>com.acme.DeepThinker</code>. The code for <code>QuickThinker</code>
* woud look as follows:
*
* <pre>
* package com.acme;
*
* &#x2f;**
* * Provices a super-quick, but not very deep implementation of ThinkService.
* *&#x2f;
* public class QuickThinker
* implements org.foo.ThinkService
* {
* &#x2f;**
* * Constructs a new QuickThinker. The service factory (which is
* * part of the Java environment) calls this no-argument constructor
* * when it looks up the available implementations of ThinkService.
* *
* * &lt;p&gt;Note that an application might query all available
* * ThinkService providers, but use just one of them. Therefore,
* * constructing an instance should be very inexpensive. For example,
* * large data structures should only be allocated when the service
* * actually gets used.
* *&#x2f;
* public QuickThinker()
* {
* }
*
* &#x2f;**
* * Returns the speed of this ThinkService in thoughts per second.
* * Applications can choose among the available service providers
* * based on this value.
* *&#x2f;
* public double getSpeed()
* {
* return 314159.2654;
* }
*
* &#x2f;**
* * Produces a thought. While the returned thoughts are not very
* * deep, they are generated in very short time.
* *&#x2f;
* public Thought think()
* {
* return null;
* }
* }
* </pre>
*
* <p>The code for <code>com.acme.DeepThinker</code> is left as an
* exercise to the reader.
*
* <p>Acme&#x2019;s <code>ThinkService</code> plug-in gets deployed as
* a JAR file. Besides the bytecode and resources for
* <code>QuickThinker</code> and <code>DeepThinker</code>, it also
* contains the text file
* <code>META-INF/services/org.foo.ThinkService</code>:
*
* <pre>
* # Available implementations of org.foo.ThinkService
* com.acme.QuickThinker
* com.acme.DeepThinker
* </pre>
*
* <p><b>Thread Safety</b>
*
* <p>It is safe to use <code>ServiceFactory</code> from multiple
* concurrent threads without external synchronization.
*
* <p><b>Note for User Applications</b>
*
* <p>User applications that want to load plug-ins should not directly
* use <code>gnu.classpath.ServiceFactory</code>, because this class
* is only available in Java environments that are based on GNU
* Classpath. Instead, it is recommended that user applications call
* {@link
* javax.imageio.spi.ServiceRegistry#lookupProviders(Class)}. This API
* is actually independent of image I/O, and it is available on every
* environment.
*
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
*/
public final class ServiceFactory
{
/**
* A logger that gets informed when a service gets loaded, or
* when there is a problem with loading a service.
*
* <p>Because {@link java.util.logging.Logger#getLogger(String)}
* is thread-safe, we do not need to worry about synchronization
* here.
*/
private static final Logger LOGGER = Logger.getLogger("gnu.classpath");
/**
* Declared private in order to prevent constructing instances of
* this utility class.
*/
private ServiceFactory()
{
}
/**
* Finds service providers that are implementing the specified
* Service Provider Interface.
*
* <p><b>On-demand loading:</b> Loading and initializing service
* providers is delayed as much as possible. The rationale is that
* typical clients will iterate through the set of installed service
* providers until one is found that matches some criteria (like
* supported formats, or quality of service). In such scenarios, it
* might make sense to install only the frequently needed service
* providers on the local machine. More exotic providers can be put
* onto a server; the server will only be contacted when no suitable
* service could be found locally.
*
* <p><b>Security considerations:</b> Any loaded service providers
* are loaded through the specified ClassLoader, or the system
* ClassLoader if <code>classLoader</code> is
* <code>null</code>. When <code>lookupProviders</code> is called,
* the current {@link AccessControlContext} gets recorded. This
* captured security context will determine the permissions when
* services get loaded via the <code>next()</code> method of the
* returned <code>Iterator</code>.
*
* @param spi the service provider interface which must be
* implemented by any loaded service providers.
*
* @param loader the class loader that will be used to load the
* service providers, or <code>null</code> for the system class
* loader. For using the context class loader, see {@link
* #lookupProviders(Class)}.
*
* @return an iterator over instances of <code>spi</code>.
*
* @throws IllegalArgumentException if <code>spi</code> is
* <code>null</code>.
*/
public static Iterator lookupProviders(Class spi,
ClassLoader loader)
{
String resourceName;
Enumeration urls;
if (spi == null)
throw new IllegalArgumentException();
if (loader == null)
loader = ClassLoader.getSystemClassLoader();
resourceName = "META-INF/services/" + spi.getName();
try
{
urls = loader.getResources(resourceName);
}
catch (IOException ioex)
{
/* If an I/O error occurs here, we cannot provide any service
* providers. In this case, we simply return an iterator that
* does not return anything (no providers installed).
*/
log(Level.WARNING, "cannot access {0}", resourceName, ioex);
return Collections.EMPTY_LIST.iterator();
}
return new ServiceIterator(spi, urls, loader,
AccessController.getContext());
}
/**
* Finds service providers that are implementing the specified
* Service Provider Interface, using the context class loader
* for loading providers.
*
* @param spi the service provider interface which must be
* implemented by any loaded service providers.
*
* @return an iterator over instances of <code>spi</code>.
*
* @throws IllegalArgumentException if <code>spi</code> is
* <code>null</code>.
*
* @see #lookupProviders(Class, ClassLoader)
*/
public static Iterator lookupProviders(Class spi)
{
ClassLoader ctxLoader;
ctxLoader = Thread.currentThread().getContextClassLoader();
return lookupProviders(spi, ctxLoader);
}
/**
* An iterator over service providers that are listed in service
* provider configuration files, which get passed as an Enumeration
* of URLs. This is a helper class for {@link
* ServiceFactory#lookupProviders}.
*
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
*/
private static final class ServiceIterator
implements Iterator
{
/**
* The service provider interface (usually an interface, sometimes
* an abstract class) which the services must implement.
*/
private final Class spi;
/**
* An Enumeration<URL> over the URLs that contain a resource
* <code>META-INF/services/&lt;org.foo.SomeService&gt;</code>,
* as returned by {@link ClassLoader#getResources(String)}.
*/
private final Enumeration urls;
/**
* The class loader used for loading service providers.
*/
private final ClassLoader loader;
/**
* The security context used when loading and initializing service
* providers. We want to load and initialize all plug-in service
* providers under the same security context, namely the one that
* was active when {@link #lookupProviders} has been called.
*/
private final AccessControlContext securityContext;
/**
* A reader for the current file listing class names of service
* implementors, or <code>null</code> when the last reader has
* been fetched.
*/
private BufferedReader reader;
/**
* The URL currently being processed. This is only used for
* emitting error messages.
*/
private URL currentURL;
/**
* The service provider that will be returned by the next call to
* {@link #next()}, or <code>null</code> if the iterator has
* already returned all service providers.
*/
private Object nextProvider;
/**
* Constructs an Iterator that loads and initializes services on
* demand.
*
* @param spi the service provider interface which the services
* must implement. Usually, this is a Java interface type, but it
* might also be an abstract class or even a concrete superclass.
*
* @param urls an Enumeration<URL> over the URLs that contain a
* resource
* <code>META-INF/services/&lt;org.foo.SomeService&gt;</code>, as
* determined by {@link ClassLoader#getResources(String)}.
*
* @param loader the ClassLoader that gets used for loading
* service providers.
*
* @param securityContext the security context to use when loading
* and initializing service providers.
*/
ServiceIterator(Class spi, Enumeration urls, ClassLoader loader,
AccessControlContext securityContext)
{
this.spi = spi;
this.urls = urls;
this.loader = loader;
this.securityContext = securityContext;
this.nextProvider = loadNextServiceProvider();
}
/**
* @throws NoSuchElementException if {@link #hasNext} returns
* <code>false</code>.
*/
public Object next()
{
Object result;
if (!hasNext())
throw new NoSuchElementException();
result = nextProvider;
nextProvider = loadNextServiceProvider();
return result;
}
public boolean hasNext()
{
return nextProvider != null;
}
public void remove()
{
throw new UnsupportedOperationException();
}
private Object loadNextServiceProvider()
{
String line;
if (reader == null)
advanceReader();
for (;;)
{
/* If we have reached the last provider list, we cannot
* retrieve any further lines.
*/
if (reader == null)
return null;
try
{
line = reader.readLine();
}
catch (IOException readProblem)
{
log(Level.WARNING, "IOException upon reading {0}", currentURL,
readProblem);
line = null;
}
/* When we are at the end of one list of services,
* switch over to the next one.
*/
if (line == null)
{
advanceReader();
continue;
}
// Skip whitespace at the beginning and end of each line.
line = line.trim();
// Skip empty lines.
if (line.length() == 0)
continue;
// Skip comment lines.
if (line.charAt(0) == '#')
continue;
try
{
log(Level.FINE,
"Loading service provider \"{0}\", specified"
+ " by \"META-INF/services/{1}\" in {2}.",
new Object[] { line, spi.getName(), currentURL },
null);
/* Load the class in the security context that was
* active when calling lookupProviders.
*/
return AccessController.doPrivileged(
new ServiceProviderLoadingAction(spi, line, loader),
securityContext);
}
catch (Exception ex)
{
String msg = "Cannot load service provider class \"{0}\","
+ " specified by \"META-INF/services/{1}\" in {2}";
if (ex instanceof PrivilegedActionException
&& ex.getCause() instanceof ClassCastException)
msg = "Service provider class \"{0}\" is not an instance"
+ " of \"{1}\". Specified"
+ " by \"META-INF/services/{1}\" in {2}.";
log(Level.WARNING, msg,
new Object[] { line, spi.getName(), currentURL },
ex);
continue;
}
}
}
private void advanceReader()
{
do
{
if (reader != null)
{
try
{
reader.close();
log(Level.FINE, "closed {0}", currentURL, null);
}
catch (Exception ex)
{
log(Level.WARNING, "cannot close {0}", currentURL, ex);
}
reader = null;
currentURL = null;
}
if (!urls.hasMoreElements())
return;
currentURL = (URL) urls.nextElement();
try
{
reader = new BufferedReader(new InputStreamReader(
currentURL.openStream(), "UTF-8"));
log(Level.FINE, "opened {0}", currentURL, null);
}
catch (Exception ex)
{
log(Level.WARNING, "cannot open {0}", currentURL, ex);
}
}
while (reader == null);
}
}
// Package-private to avoid a trampoline.
/**
* Passes a log message to the <code>java.util.logging</code>
* framework. This call returns very quickly if no log message will
* be produced, so there is not much overhead in the standard case.
*
* @param the severity of the message, for instance {@link
* Level#WARNING}.
*
* @param msg the log message, for instance <code>&#x201c;Could not
* load {0}.&#x201d;</code>
*
* @param param the parameter(s) for the log message, or
* <code>null</code> if <code>msg</code> does not specify any
* parameters. If <code>param</code> is not an array, an array with
* <code>param</code> as its single element gets passed to the
* logging framework.
*
* @param t a Throwable that is associated with the log record, or
* <code>null</code> if the log message is not associated with a
* Throwable.
*/
static void log(Level level, String msg, Object param, Throwable t)
{
LogRecord rec;
// Return quickly if no log message will be produced.
if (!LOGGER.isLoggable(level))
return;
rec = new LogRecord(level, msg);
if (param != null && param.getClass().isArray())
rec.setParameters((Object[]) param);
else
rec.setParameters(new Object[] { param });
rec.setThrown(t);
// While java.util.logging can sometimes infer the class and
// method of the caller, this automatic inference is not reliable
// on highly optimizing VMs. Also, log messages make more sense to
// developers when they display a public method in a public class;
// otherwise, they might feel tempted to figure out the internals
// of ServiceFactory in order to understand the problem.
rec.setSourceClassName(ServiceFactory.class.getName());
rec.setSourceMethodName("lookupProviders");
LOGGER.log(rec);
}
}
@@ -0,0 +1,149 @@
/* ServiceProviderLoadingAction.java -- Action for loading plug-in services.
Copyright (C) 2004 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.classpath;
import java.security.PrivilegedExceptionAction;
/**
* A privileged action for creating a new instance of a service
* provider.
*
* <p>Class loading and instantiation is encapsulated in a
* <code>PriviledgedAction</code> in order to restrict the loaded
* service providers to the {@link java.security.AccessControlContext}
* that was active when {@link
* gnu.classpath.ServiceFactory#lookupProviders} was called, even
* though the actual loading is delayed to the time when the provider
* is actually needed.
*
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
*/
final class ServiceProviderLoadingAction
implements PrivilegedExceptionAction
{
/**
* The interface to which the loaded service provider implementation
* must conform. Usually, this is a Java interface type, but it
* might also be an abstract class or even a concrete class.
*/
private final Class spi;
/**
* The fully qualified name of the class that gets loaded when
* this action is executed.
*/
private final String providerName;
/**
* The ClassLoader that gets used for loading the service provider
* class.
*/
private final ClassLoader loader;
/**
* Constructs a privileged action for loading a service provider.
*
* @param spi the interface to which the loaded service provider
* implementation must conform. Usually, this is a Java interface
* type, but it might also be an abstract class or even a concrete
* superclass.
*
* @param providerName the fully qualified name of the class that
* gets loaded when this action is executed.
*
* @param loader the ClassLoader that gets used for loading the
* service provider class.
*
* @throws IllegalArgumentException if <code>spi</code>,
* <code>providerName</code> or <code>loader</code> is
* <code>null</code>.
*/
ServiceProviderLoadingAction(Class spi, String providerName,
ClassLoader loader)
{
if (spi == null || providerName == null || loader == null)
throw new IllegalArgumentException();
this.spi = spi;
this.providerName = providerName;
this.loader = loader;
}
/**
* Loads an implementation class for a service provider, and creates
* a new instance of the loaded class by invoking its public
* no-argument constructor.
*
* @return a new instance of the class whose name was passed as
* <code>providerName</code> to the constructor.
*
* @throws ClassCastException if the service provider does not
* implement the <code>spi</code> interface that was passed to the
* constructor.
*
* @throws IllegalAccessException if the service provider class or
* its no-argument constructor are not <code>public</code>.
*
* @throws InstantiationException if the service provider class is
* <code>abstract</code>, an interface, a primitive type, an array
* class, or void; or if service provider class does not have a
* no-argument constructor; or if there some other problem with
* creating a new instance of the service provider.
*/
public Object run()
throws Exception
{
Class loadedClass;
Object serviceProvider;
loadedClass = loader.loadClass(providerName);
serviceProvider = loadedClass.newInstance();
// Ensure that the loaded provider is actually implementing
// the service provider interface.
if (!spi.isInstance(serviceProvider))
throw new ClassCastException(spi.getName());
return serviceProvider;
}
}
@@ -0,0 +1,158 @@
/* SystemProperties.java -- Manage the System properties.
Copyright (C) 2004, 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.classpath;
import java.util.Properties;
/**
* The class manages the System properties. This class is only available to
* privileged code (i.e. code loaded by the bootstrap class loader) and
* therefore doesn't do any security checks.
* This class is separated out from java.lang.System to simplify bootstrap
* dependencies and to allow trusted code a simple and efficient mechanism
* to access the system properties.
*/
public class SystemProperties
{
/**
* Stores the current system properties. This can be modified by
* {@link #setProperties(Properties)}, but will never be null, because
* setProperties(null) sucks in the default properties.
*/
private static Properties properties;
/**
* The default properties. Once the default is stabilized,
* it should not be modified;
* instead it is cloned when calling <code>setProperties(null)</code>.
*/
private static final Properties defaultProperties = new Properties();
static
{
VMSystemProperties.preInit(defaultProperties);
defaultProperties.put("gnu.classpath.home", Configuration.CLASSPATH_HOME);
defaultProperties.put("gnu.classpath.version",
Configuration.CLASSPATH_VERSION);
// Set base URL if not already set.
if (defaultProperties.get("gnu.classpath.home.url") == null)
defaultProperties.put("gnu.classpath.home.url",
"file://"
+ Configuration.CLASSPATH_HOME
+ "/lib");
// Set short name if not already set.
if (defaultProperties.get("gnu.classpath.vm.shortname") == null)
{
String value = defaultProperties.getProperty("java.vm.name");
int index = value.lastIndexOf(' ');
if (index != -1)
value = value.substring(index + 1);
defaultProperties.put("gnu.classpath.vm.shortname", value);
}
// Network properties
if (defaultProperties.get("http.agent") == null)
{
String userAgent = ("gnu-classpath/"
+ defaultProperties.getProperty("gnu.classpath.version")
+ " ("
+ defaultProperties.getProperty("gnu.classpath.vm.shortname")
+ "/"
+ defaultProperties.getProperty("java.vm.version")
+ ")");
defaultProperties.put("http.agent", userAgent);
}
// 8859_1 is a safe default encoding to use when not explicitly set
if (defaultProperties.get("file.encoding") == null)
defaultProperties.put("file.encoding", "8859_1");
// Default to the Swing FocusManager so that the old-style Swing API
// for FocusManager can be supported without hardcoding it in AWT.
if (defaultProperties.get("gnu.java.awt.FocusManager") == null)
defaultProperties.put("gnu.java.awt.FocusManager",
"gnu.java.awt.FocusManager");
// XXX FIXME - Temp hack for old systems that set the wrong property
if (defaultProperties.get("java.io.tmpdir") == null)
defaultProperties.put("java.io.tmpdir",
defaultProperties.get("java.tmpdir"));
VMSystemProperties.postInit(defaultProperties);
// Note that we use clone here and not new. Some programs assume
// that the system properties do not have a parent.
properties = (Properties) defaultProperties.clone();
}
public static String getProperty(String name)
{
return properties.getProperty(name);
}
public static String getProperty(String name, String defaultValue)
{
return properties.getProperty(name, defaultValue);
}
public static String setProperty(String name, String value)
{
return (String) properties.setProperty(name, value);
}
public static Properties getProperties()
{
return properties;
}
public static void setProperties(Properties properties)
{
if (properties == null)
{
// Note that we use clone here and not new. Some programs
// assume that the system properties do not have a parent.
properties = (Properties)defaultProperties.clone();
}
SystemProperties.properties = properties;
}
}
@@ -0,0 +1,159 @@
/* Component.java -- a component log level.
Copyright (C) 2005 Free Software Foundation, Inc.
This file is a 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 of the License, 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; 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.classpath.debug;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.logging.Level;
public final class Component extends Level
{
/*
* HOW TO ADD NEW COMPONENTS:
*
* If you want to add a new, simple component, that you will use in
* logging statements, simply create a new class variable that
* instantiates this class, and choose an appropriate string name
* and a integer constant not used by any other component level.
*
* For example, if my component had to do with 'frobbing', I would
* add this entry below:
*
* private static final Component FROBBING = new Component ("FROBBING", 7);
*
* Then, I would update the component 'EVERYTHING' to have and end
* index ONE GREATER THAN the index of the new component.
*
* ADDING NEW COMPONENT CLASSES:
*
* A "component class" is a run of more than one component, which can
* be enabled all at once. EVERYTHING and SSL are examples of component
* classes. To add a new class, create a new component with a start index
* equal to the index of the first member component, and with an end
* index equal to the index of the last member component plus one.
*/
/**
* Signifies that everything should be logged. This should be used to
* enable or disable levels only; logging code should not use it.
*/
public static final Component EVERYTHING = new Component ("*", 0, 7);
/**
* Signifies that all SSL related messages should be logged. This should
* be used to enable or disable levels only; logging code should not use
* it.
*/
public static final Component SSL = new Component ("SSL", 0, 5);
/**
* Traces the progression of an SSL handshake.
*/
public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0);
/**
* Traces the application messages during SSL communications.
*/
public static final Component SSL_APPLICATION = new Component ("SSL APPLICATION", 1);
/**
* Trace details about the SSL key exchange.
*/
public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2);
/* Indices 3 and 4 reserved for future use by SSL components. */
/**
* Trace the operation of cryptographic primitives.
*/
public static final Component CRYPTO = new Component ("CRYPTO", 5);
/**
* Trace the parsing of X.509 certificates and related objects.
*/
public static final Component X509 = new Component ("X.509", 6);
private final int startIndex;
private final int endIndex;
private Component (final String name, final int bitIndex)
{
this (name, bitIndex, bitIndex + 1);
}
private Component (final String name, final int startIndex, final int endIndex)
{
super (name, Level.FINE.intValue ());
this.startIndex = startIndex;
this.endIndex = endIndex;
}
/**
* Return the component for the given name.
*
* @param name The name of the component to get.
* @return The named component, or null if there is no such component.
*/
public static Component forName (final String name)
{
try
{
Field f = Component.class.getField (name.toUpperCase ());
if (!Modifier.isStatic (f.getModifiers ())
|| Component.class.isAssignableFrom (f.getClass ()))
return null;
return (Component) f.get (null);
}
catch (Throwable _)
{
return null;
}
}
public int startIndex ()
{
return startIndex;
}
public int endIndex ()
{
return endIndex;
}
}

Some files were not shown because too many files have changed in this diff Show More