diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-02 20:12:05 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-02 20:12:05 +0000 |
commit | 33bace404a240c1335ab1f6e95bd6616e22c0ecd (patch) | |
tree | 004ab1587e14d3df272c6944ce325d3584b95aa5 /gnu/CORBA | |
parent | d30622846e00f908cb5d4beac7de4e5e78dcd630 (diff) | |
download | classpath-33bace404a240c1335ab1f6e95bd6616e22c0ecd.tar.gz |
2005-08-02 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics-branch for 2005/06/05 - 2005/07/31.
See patch on classpath-patches@gnu.org for a full ChangeLog.
Diffstat (limited to 'gnu/CORBA')
116 files changed, 9044 insertions, 384 deletions
diff --git a/gnu/CORBA/Asynchron.java b/gnu/CORBA/Asynchron.java index 4ea222543..275b57091 100644 --- a/gnu/CORBA/Asynchron.java +++ b/gnu/CORBA/Asynchron.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/BigDecimalHelper.java b/gnu/CORBA/BigDecimalHelper.java index 9ef7ad151..f1e1dd6b4 100644 --- a/gnu/CORBA/BigDecimalHelper.java +++ b/gnu/CORBA/BigDecimalHelper.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/ByteArrayComparator.java b/gnu/CORBA/ByteArrayComparator.java index 3dedc7f96..849115463 100644 --- a/gnu/CORBA/ByteArrayComparator.java +++ b/gnu/CORBA/ByteArrayComparator.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/BigEndianInputStream.java b/gnu/CORBA/CDR/BigEndianInputStream.java index 8218b0347..bc019396a 100644 --- a/gnu/CORBA/CDR/BigEndianInputStream.java +++ b/gnu/CORBA/CDR/BigEndianInputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/BigEndianOutputStream.java b/gnu/CORBA/CDR/BigEndianOutputStream.java index fe80bbc4f..e0aa7da77 100644 --- a/gnu/CORBA/CDR/BigEndianOutputStream.java +++ b/gnu/CORBA/CDR/BigEndianOutputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/LittleEndianInputStream.java b/gnu/CORBA/CDR/LittleEndianInputStream.java index 412608b0b..b71a9a4f6 100644 --- a/gnu/CORBA/CDR/LittleEndianInputStream.java +++ b/gnu/CORBA/CDR/LittleEndianInputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/LittleEndianOutputStream.java b/gnu/CORBA/CDR/LittleEndianOutputStream.java index 7ff8263db..a6d56cfa6 100644 --- a/gnu/CORBA/CDR/LittleEndianOutputStream.java +++ b/gnu/CORBA/CDR/LittleEndianOutputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/Vio.java b/gnu/CORBA/CDR/Vio.java new file mode 100644 index 000000000..8f17bd2f5 --- /dev/null +++ b/gnu/CORBA/CDR/Vio.java @@ -0,0 +1,638 @@ +/* gnuValueBaseHelper.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.CDR; + +import gnu.CORBA.ObjectCreator; + +import org.omg.CORBA.CustomMarshal; +import org.omg.CORBA.DataInputStream; +import org.omg.CORBA.DataOutputStream; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.StringSeqHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.portable.ValueFactory; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.Serializable; + +/** + * A specialised class for reading and writing the value types. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class Vio +{ + /** + * If true, wrap value type data into chunks. This decrease the + * performance, but is required for the interoperability with + * Sun's CORBA implementation. Chunking may increase the security, + * as there is more control on the number of bytes being transferred. + * + * The current implementation would accept both single chunk or multiple + * chunks, but will always send a single chunk. + */ + public static boolean USE_CHUNKING = true; + + /** + * The first field in the value record. The last octet may contain + * additional flags (vf_CODEBASE, vf_ID and vf_MULTIPLE_IDS). The tag + * value is different for the indirections (vt_INDIRECTION) and + * nulls (vt_NULL). + */ + public static final int vt_VALUE_TAG = 0x7fffff00; + + /** + * The value tag flag, indicating that the codebase URL is present + * in the value tag record. + */ + public static final int vf_CODEBASE = 0x1; + + /** + * The value tag flag, indicating that a single repository id is present + * in the value tag record. + */ + public static final int vf_ID = 0x2; + + /** + * The value tag flag, indicating, that there are multiple repository + * ids present in the record. If this flag is set, the flag vf_ID must + * also be set, resulting the value of the least significant byte 0x6. + */ + public static final int vf_MULTIPLE_IDS = 0x4; + + /** + * The value tag flag, indicating the presence of chunking. Each chunk is + * preceeded by a positive int, indicating the number of bytes in the chunk. + * A sequence of chunks is terminated by a non positive int. + */ + public static final int vf_CHUNKING = 0x8; + + /** + * The indirection tag value. Such tag must be followed by the CORBA long, + * indicating the offset in the CORBA message, where the indirected + * information is present. This offset is assumed zero at the position + * where the mentioned CORBA long starts and can refer both forward + * (positive values) and backward (negative values). + */ + public static final int vt_INDIRECTION = 0xffffffff; + + /** + * This tag value means that the value object being transferred is equal + * to null. + */ + public static final int vt_NULL = 0x0; + + /** + * Read the value base from the given input stream. Determines the + * required class from the repository id. This includes operations + * that are not required when an unitialised instance or at least + * class of the value type is known. Hence it may be faster to use + * the alternative methods, read(InputStream, Class) or + * read(InputStream, Serializable). + * + * @param input a stream to read from. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + // We may need to jump back if the value is read via value factory. + input.mark(512); + + int value_tag = input.read_long(); + checkTag(value_tag); + + String codebase = null; + String[] ids = null; + String id = null; + + // The existing implementing object. + java.lang.Object ox = null; + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present. The codebase is a space + // separated list of URLs from where the implementing + // code can be downloaded. + codebase = input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present. + ids = StringSeqHelper.read(input); + for (int i = 0; (i < ids.length) && (ox == null); i++) + { + ox = ObjectCreator.Idl2Object(ids [ i ]); + + if (ox == null) + { + // Try to find the value factory. + ValueFactory f = + ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(ids [ i ]); + + if (f != null) + { + // Reset, as the value factory reads from beginning. + input.reset(); + return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); + } + } + } + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present. + id = input.read_string(); + ox = ObjectCreator.Idl2Object(id); + + if (ox == null) + { + // Try to find the value factory. + ValueFactory f = + ((org.omg.CORBA_2_3.ORB) input.orb()).lookup_value_factory(id); + + if (f != null) + { + input.reset(); + return f.read_value((org.omg.CORBA_2_3.portable.InputStream) input); + } + } + } + } + + if (ox == null) + throw new MARSHAL("Unable to instantiate the value type"); + else + { + read_instance(input, ox, value_tag); + return (Serializable) ox; + } + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Read the value base from the given input stream when + * the value base class is available. Hence there is no need + * to guess it from the repository id. + * + * @param input a stream to read from. + * @param value_class the class of the value being read. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input, Class value_class) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + int value_tag = input.read_long(); + checkTag(value_tag); + + // The existing implementing object. + java.lang.Object ox = value_class.newInstance(); + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present, but skip it. + input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present, but skip them. + StringSeqHelper.read(input); + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present, but skip it. + input.read_string(); + } + } + + read_instance(input, ox, value_tag); + return (Serializable) ox; + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Read the value base from the given input stream when + * the unitialised instance is available. Hence there is no need + * to guess the class from the repository id and then to instantiate + * an instance. + * + * @param input a stream to read from. + * @param value_instance an instance of the value. + * + * @return the loaded value. + * + * @throws MARSHAL if the reading has failed due any reason. + */ + public static Serializable read(InputStream input, Serializable value_instance) + { + // Explicitly prevent the stream from closing as we may need + // to read the subsequent bytes as well. Stream may be auto-closed + // in its finalizer. + try + { + int value_tag = input.read_long(); + checkTag(value_tag); + + // Check for the agreed null value. + if (value_tag == vt_NULL) + return null; + else if (value_tag == vt_INDIRECTION) + + // TODO FIXME Implement support for indirections. + throw new NO_IMPLEMENT("Indirections unsupported"); + else + { + // Read the value. + if ((value_tag & vf_CODEBASE) != 0) + { + // The codebase is present, but skip it. + input.read_string(); + } + + if ((value_tag & vf_MULTIPLE_IDS) != 0) + { + // Multiple supported repository ids are present, but skip them. + StringSeqHelper.read(input); + } + else if ((value_tag & vf_ID) != 0) + { + // Single supported repository id is present, but skip it. + input.read_string(); + } + } + + read_instance(input, value_instance, value_tag); + return (Serializable) value_instance; + } + catch (Exception ex) + { + throw new MARSHAL(ex + ":" + ex.getMessage()); + } + } + + /** + * Fill in the instance fields by the data from the input stream. + * The method assumes that the value header, if any, is already + * behind. The information from the stream is stored into the + * passed ox parameter. + * + * @param input an input stream to read from. + * @param value a value type object, must be either Streamable or + * CustomMarshal. + */ + public static void read_instance(InputStream input, Object value, + int value_tag + ) + { + try + { + if ((value_tag & vf_CHUNKING) != 0) + { + ByteArrayOutputStream bout = null; + int n = -1; + + // Read all chunks. + int chunk_size = input.read_long(); + if (chunk_size <= 0) + throw new MARSHAL("Invalid first chunk size " + chunk_size); + + byte[] r = new byte[ chunk_size ]; + + while (chunk_size > 0) + { + if (r.length < chunk_size) + r = new byte[ chunk_size + 256 ]; + + n = 0; + reading: + while (n < chunk_size) + n += input.read(r, n, r.length - n); + + // Read the size of the next chunk. + chunk_size = input.read_long(); + + // If the value is non negative, there is more than one chunk. + // Accumulate chunks in the buffer. + // The last chunk (or the only chunk, if only one chunk is + // present) is not written in the buffer. It is stored in the + // array r, avoiding unnecessary buffer operations. + if (chunk_size > 0) + { + bout = new ByteArrayOutputStream(2 * chunk_size); + bout.write(r, 0, chunk_size); + } + } + + if (bout != null) + { + // More than one chunk was present. + // Add the last chunk. + bout.write(r, 0, n); + input = new cdrBufInput(bout.toByteArray()); + } + else + { + // Only one chunk was present. + input = new cdrBufInput(r); + } + } + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL("Unable to read chunks"); + m.initCause(ex); + throw m; + } + + // The user-defines io operations are implemented. + if (value instanceof CustomMarshal) + { + CustomMarshal marsh = (CustomMarshal) value; + try + { + marsh.unmarshal((DataInputStream) input); + } + catch (ClassCastException ex) + { + incorrect_plug_in(ex); + } + } + else + // The IDL-generated io operations are implemented. + if (value instanceof Streamable) + { + ((Streamable) value)._read(input); + } + else + + // Stating the interfaces that the USER should use. + throw new MARSHAL("The " + value.getClass().getName() + + " must implement either StreamableValue or CustomValue." + ); + + // The negative end of state marker is expected from OMG standard. + // If the chunking is used, this marker is already extracted. + if ((value_tag & vf_CHUNKING) == 0) + { + int eor = input.read_long(); + if (eor >= 0) + throw new MARSHAL("End of state marker has an invalid value " + eor); + } + } + + /** + * Write the value base into the given stream. + * + * @param output a stream to write to. + * + * @param value a value type object, must be either Streamable or + * CustomMarshal. + * + * @throws MARSHAL if the writing failed due any reason. + */ + public static void write(OutputStream output, Serializable value) + { + // Write null if this is a null value. + if (value == null) + output.write_long(vt_NULL); + else + write(output, value, ObjectCreator.toIDL(value.getClass().getName())); + } + + /** + * Write the value base into the given stream, stating that it is an + * instance of the given class. The written record has no repository + * id and requires to supply a class or initialised instance for reading + * rather than an actual class it is. + * + * This results writing a different repository id. + * + * If the passed value implements the {@link CustomMarshal}, + * the helper uses {@link CustomMarshal#marshal} + * to write the content in a user defined way. Otherwise, + * this implementation initialises the {@link ObjectOutputStream} + * and writes through it. + * + * @param output a stream to write to. + * + * @param value a value to write. + * + * @throws MARSHAL if the writing failed due any reason. + */ + public static void write(OutputStream output, Serializable value, + Class substitute + ) + { + // Write null if this is a null value. + if (value == null) + output.write_long(vt_NULL); + + else + write(output, value, ObjectCreator.toIDL(substitute.getName())); + } + + /** + * Write value when its repository Id is explicitly given. + * + * @param output an output stream to write into. + * @param value a value to write. + * @param id a value repository id. + */ + public static void write(OutputStream output, Serializable value, String id) + { + if (value == null) + output.write_long(vt_NULL); + else + write_instance(output, value, id); + } + + /** + * Write value when its repository Id is explicitly given. + * Does not handle null. + * + * @param output an output stream to write into. + * @param value a value to write. + * @param id a value repository id. + */ + private static void write_instance(OutputStream output, Serializable value, + String id + ) + { + // This implementation always writes a single repository id. + // It never writes multiple repository ids and currently does not use + // a codebase. + int value_tag = vt_VALUE_TAG | vf_ID; + + OutputStream outObj; + cdrBufOutput out = null; + + if (USE_CHUNKING) + { + out = new cdrBufOutput(); + out.setOrb(output.orb()); + outObj = out; + value_tag |= vf_CHUNKING; + } + else + outObj = output; + + output.write_long(value_tag); + output.write_string(id); + + // User defince write method is present. + if (value instanceof CustomMarshal) + { + try + { + ((CustomMarshal) value).marshal((DataOutputStream) outObj); + } + catch (ClassCastException ex) + { + incorrect_plug_in(ex); + } + } + else if (value instanceof Streamable) + { + ((Streamable) value)._write(outObj); + } + else + + // Stating the interfaces that the USER should use. + throw new MARSHAL("The " + value.getClass().getName() + + " must implement either StreamableValue or CustomValue." + ); + + if (USE_CHUNKING) + { + output.write_long(out.buffer.size()); + try + { + out.buffer.writeTo(output); + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + } + + // The end of record marker, required by OMG standard. + output.write_long(-1); + } + + /** + * This can be called if the alternative CORBA implementation + * is incorrectly plugged in. + * + * @throws NO_IMPLEMENT, always. + */ + private static void incorrect_plug_in(Throwable ex) + throws NO_IMPLEMENT + { + NO_IMPLEMENT no = new NO_IMPLEMENT("Incorrect CORBA plug-in"); + no.initCause(ex); + throw no; + } + + /** + * Check the passed value tag for correctness. + * + * @param value_tag a tag to check, must be between 0x7fffff00 and 0x7fffffff + * + * @throws MARSHAL if the tag is outside this interval. + */ + private static final void checkTag(int value_tag) + { + if ((value_tag < 0x7fffff00 || value_tag > 0x7fffffff) && + value_tag != vt_NULL && value_tag != vt_INDIRECTION + ) + throw new MARSHAL("Invalid value record, unsupported header tag: " + + value_tag + ); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/CDR/abstractDataInputStream.java b/gnu/CORBA/CDR/abstractDataInputStream.java index 4da48bb27..be926254d 100644 --- a/gnu/CORBA/CDR/abstractDataInputStream.java +++ b/gnu/CORBA/CDR/abstractDataInputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/abstractDataOutputStream.java b/gnu/CORBA/CDR/abstractDataOutputStream.java index b54dc0f7f..2f9b8c419 100644 --- a/gnu/CORBA/CDR/abstractDataOutputStream.java +++ b/gnu/CORBA/CDR/abstractDataOutputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/aligningInputStream.java b/gnu/CORBA/CDR/aligningInputStream.java index c29a52cfa..a719b32ee 100644 --- a/gnu/CORBA/CDR/aligningInputStream.java +++ b/gnu/CORBA/CDR/aligningInputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/aligningOutputStream.java b/gnu/CORBA/CDR/aligningOutputStream.java index f4009c47c..8a682c1fd 100644 --- a/gnu/CORBA/CDR/aligningOutputStream.java +++ b/gnu/CORBA/CDR/aligningOutputStream.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/cdrBufInput.java b/gnu/CORBA/CDR/cdrBufInput.java index 58715c64a..3cab7216c 100644 --- a/gnu/CORBA/CDR/cdrBufInput.java +++ b/gnu/CORBA/CDR/cdrBufInput.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/cdrBufOutput.java b/gnu/CORBA/CDR/cdrBufOutput.java index d8d34f7d4..47f5f176b 100644 --- a/gnu/CORBA/CDR/cdrBufOutput.java +++ b/gnu/CORBA/CDR/cdrBufOutput.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/CDR/cdrInput.java b/gnu/CORBA/CDR/cdrInput.java index 644e01930..859f93ae5 100644 --- a/gnu/CORBA/CDR/cdrInput.java +++ b/gnu/CORBA/CDR/cdrInput.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -51,22 +51,32 @@ import gnu.CORBA.gnuAny; import gnu.CORBA.stubFinder; import org.omg.CORBA.Any; +import org.omg.CORBA.AnySeqHolder; import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BooleanSeqHolder; +import org.omg.CORBA.CharSeqHolder; +import org.omg.CORBA.DoubleSeqHolder; +import org.omg.CORBA.FloatSeqHolder; +import org.omg.CORBA.LongLongSeqHolder; +import org.omg.CORBA.LongSeqHolder; import org.omg.CORBA.MARSHAL; -import org.omg.CORBA.NO_IMPLEMENT; import org.omg.CORBA.ORB; -import org.omg.CORBA.Object; +import org.omg.CORBA.OctetSeqHolder; +import org.omg.CORBA.ShortSeqHolder; import org.omg.CORBA.TypeCode; import org.omg.CORBA.TypeCodePackage.BadKind; import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.ULongLongSeqHolder; +import org.omg.CORBA.ULongSeqHolder; +import org.omg.CORBA.UShortSeqHolder; +import org.omg.CORBA.WCharSeqHolder; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.ObjectImpl; -import java.io.DataInput; -import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStreamReader; +import java.io.Serializable; import java.math.BigDecimal; @@ -74,13 +84,17 @@ import java.math.BigDecimal; * A simple CORBA CDR (common data representation) * input stream, reading data from the * given {@link java.io.InputStream}. The primitive types - * are aligned on they natural boundaries by implamenting the + * are aligned on they natural boundaries by implementing the * abstract method {@link #align(int boundary)}. * + * The same class also implements {@link org.omg.CORBA.DataInputStream} to + * read the object content in a user defined way. + * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public abstract class cdrInput - extends org.omg.CORBA.portable.InputStream + extends org.omg.CORBA_2_3.portable.InputStream + implements org.omg.CORBA.DataInputStream { /** * The message, explaining that the exception has been thrown due @@ -110,7 +124,7 @@ public abstract class cdrInput /** * The GIOP version. */ - protected Version giop = new Version(1, 0); + protected Version giop = new Version(1, 2); /** * The code set information. @@ -352,22 +366,28 @@ public abstract class cdrInput * the .narrow method of its helper, despite in some cases the direct * cast would also work. * + * The null objects are recognised from the empty profile set. + * For such objects, null is returned. + * * @return the loaded and constructed object. */ - public Object read_Object() + public org.omg.CORBA.Object read_Object() { try { IOR ior = new IOR(); ior._read_no_endian(this); + if (ior.Id == null) + return null; + // Check maybe this is a remote reference to the local object. // This is only possible if we access the repository of the // connected object. if (orb instanceof Functional_ORB) { Functional_ORB forb = (Functional_ORB) orb; - Object local = forb.find_local_object(ior); + org.omg.CORBA.Object local = forb.find_local_object(ior); if (local != null) return local; } @@ -1219,8 +1239,433 @@ public abstract class cdrInput * * @return the returned object. */ - public Object read_Object(Class klass) + public org.omg.CORBA.Object read_Object(Class klass) { return read_Object(); } + + /** + * Read a value type structure from the stream. + * + * OMG specification states the writing format is outside the scope + * of GIOP definition. This implementation uses java serialization + * mechanism, calling {@link ObjectInputStream#readObject} + * + * @return an value type structure, unmarshaled from the stream + */ + public Serializable read_Value() + { + return read_value(); + } + + /** + * Read the abstract interface. An abstract interface can be either + * CORBA value type or CORBA object and is returned as an abstract + * java.lang.Object. + * + * As specified in OMG specification, this reads a single + * boolean and then delegates either to {@link #read_Object()} (for false) + * or to {@link #read_Value()} (for true). + * + * @return an abstract interface, unmarshaled from the stream + */ + public java.lang.Object read_Abstract() + { + return read_abstract_interface(); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_char_array(CharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_char_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_wchar_array(WCharSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_wchar_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the char array to fit the newly + * read values. + * + * @param holder_value the existing char array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private char[] ensureArray(char[] holder_value, int offset, int length) + { + if (holder_value == null) + return new char[ offset + length ]; + else if (holder_value.length < offset + length) + { + char[] value = new char[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_ulong_array(ULongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_long_array(LongSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the int array to fit the newly + * read values. + * + * @param holder_value the existing int array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private int[] ensureArray(int[] holder_value, int offset, int length) + { + if (holder_value == null) + return new int[ offset + length ]; + else if (holder_value.length < offset + length) + { + int[] value = new int[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_float_array(FloatSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_float_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the float array to fit the newly + * read values. + * + * @param holder_value the existing float array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private float[] ensureArray(float[] holder_value, int offset, int length) + { + if (holder_value == null) + return new float[ offset + length ]; + else if (holder_value.length < offset + length) + { + float[] value = new float[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_double_array(DoubleSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_double_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the double array to fit the newly + * read values. + * + * @param holder_value the existing double array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private double[] ensureArray(double[] holder_value, int offset, int length) + { + if (holder_value == null) + return new double[ offset + length ]; + else if (holder_value.length < offset + length) + { + double[] value = new double[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_short_array(ShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_short_array(holder.value, offset, length); + } + + /** {@inheritDoc} */ + public void read_ushort_array(UShortSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_ushort_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the short array to fit the newly + * read values. + * + * @param holder_value the existing short array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private short[] ensureArray(short[] holder_value, int offset, int length) + { + if (holder_value == null) + return new short[ offset + length ]; + else if (holder_value.length < offset + length) + { + short[] value = new short[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_octet_array(OctetSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_octet_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the byte array to fit the newly + * read values. + * + * @param holder_value the existing byte array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private byte[] ensureArray(byte[] holder_value, int offset, int length) + { + if (holder_value == null) + return new byte[ offset + length ]; + else if (holder_value.length < offset + length) + { + byte[] value = new byte[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_longlong_array(LongLongSeqHolder holder, int offset, + int length + ) + { + holder.value = ensureArray(holder.value, offset, length); + read_longlong_array(holder.value, offset, length); + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_ulonglong_array(ULongLongSeqHolder holder, int offset, + int length + ) + { + holder.value = ensureArray(holder.value, offset, length); + read_ulonglong_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of longs to fit the newly + * read values. + * + * @param holder_value the existing array, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private long[] ensureArray(long[] holder_value, int offset, int length) + { + if (holder_value == null) + return new long[ offset + length ]; + else if (holder_value.length < offset + length) + { + long[] value = new long[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_boolean_array(BooleanSeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + read_boolean_array(holder.value, offset, length); + } + + /** + * If required, allocate or resize the array of booleans to fit the newly + * read values. + * + * @param holder_value the existing array of booleans, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private boolean[] ensureArray(boolean[] holder_value, int offset, int length) + { + if (holder_value == null) + return new boolean[ offset + length ]; + else if (holder_value.length < offset + length) + { + boolean[] value = new boolean[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * Read an array. In OMG specification is written that if the data does + * not fit into the holder value field, that array must be resized. + * The implementation follows this rule. If the holder value field + * contains null, it is newly instantiated. + */ + public void read_any_array(AnySeqHolder holder, int offset, int length) + { + holder.value = ensureArray(holder.value, offset, length); + for (int i = offset; i < offset + length; i++) + { + holder.value [ i ] = read_any(); + } + } + + /** + * If required, allocate or resize the array of Anys to fit the newly + * read values. + * + * @param holder_value the existing array of Anys, may be null. + * @param offset the required offset to read. + * @param length the length of the new sequence. + * + * @return the allocated or resized array, same array if no such operations + * are required. + */ + private Any[] ensureArray(Any[] holder_value, int offset, int length) + { + if (holder_value == null) + return new Any[ offset + length ]; + else if (holder_value.length < offset + length) + { + Any[] value = new Any[ offset + length ]; + System.arraycopy(holder_value, 0, value, 0, holder_value.length); + return value; + } + else + return holder_value; + } + + /** + * This method is required to represent the DataInputStream as a value + * type object. + * + * @return a single entity "IDL:omg.org/CORBA/DataInputStream:1.0", + * always. + */ + public String[] _truncatable_ids() + { + return new String[] { "IDL:omg.org/CORBA/DataInputStream:1.0" }; + } }
\ No newline at end of file diff --git a/gnu/CORBA/CDR/cdrOutput.java b/gnu/CORBA/CDR/cdrOutput.java index 30efaa854..86ca3b1cb 100644 --- a/gnu/CORBA/CDR/cdrOutput.java +++ b/gnu/CORBA/CDR/cdrOutput.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -64,9 +64,9 @@ import org.omg.CORBA.portable.ObjectImpl; import org.omg.CORBA.portable.OutputStream; import org.omg.CORBA.portable.Streamable; -import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.Serializable; import java.math.BigDecimal; @@ -75,14 +75,15 @@ import java.math.BigDecimal; * output stream, writing data into the * given {@link java.io.OutputStream}. * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * The same class also implements the {@link DataInputStream}, + * providing support for writing the value type objects + * in a user defined way. * - * TODO the standalone chars and char arrays are still written using - * the native encoding, as the size under arbitrary encoding is not - * evident. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public abstract class cdrOutput - extends org.omg.CORBA.portable.OutputStream + extends org.omg.CORBA_2_3.portable.OutputStream + implements org.omg.CORBA.DataOutputStream { /** * This instance is used to convert primitive data types into the @@ -315,10 +316,18 @@ public abstract class cdrOutput * 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 instanceof ObjectImpl) + if (x == null) + { + IOR.write_null(this); + return; + } + else if (x instanceof ObjectImpl) { Delegate d = ((ObjectImpl) x)._get_delegate(); @@ -960,4 +969,31 @@ public abstract class cdrOutput Unexpected.error(ex); } } + + /** {@inheritDoc} */ + public void write_any_array(Any[] anys, int offset, int length) + { + for (int i = offset; i < offset + length; i++) + { + write_any(anys [ i ]); + } + } + + public String[] _truncatable_ids() + { + /**@todo Implement this org.omg.CORBA.portable.ValueBase abstract method*/ + throw new java.lang.UnsupportedOperationException("Method _truncatable_ids() not yet implemented."); + } + + /** {@inheritDoc} */ + public void write_Abstract(java.lang.Object value) + { + write_Abstract(value); + } + + /** {@inheritDoc} */ + public void write_Value(Serializable value) + { + write_Value(value); + } }
\ No newline at end of file diff --git a/gnu/CORBA/CDR/encapsulatedOutput.java b/gnu/CORBA/CDR/encapsulatedOutput.java index e4673b099..3350291bc 100644 --- a/gnu/CORBA/CDR/encapsulatedOutput.java +++ b/gnu/CORBA/CDR/encapsulatedOutput.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/Connected_objects.java b/gnu/CORBA/Connected_objects.java index 298d49757..b7eefb133 100644 --- a/gnu/CORBA/Connected_objects.java +++ b/gnu/CORBA/Connected_objects.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -60,11 +60,14 @@ public class Connected_objects /** * Create an initialised instance. */ - cObject(org.omg.CORBA.Object _object, int _port, byte[] _key) + cObject(org.omg.CORBA.Object _object, int _port, byte[] _key, + java.lang.Object an_identity + ) { object = _object; port = _port; key = _key; + identity = an_identity; } /** @@ -82,6 +85,12 @@ public class Connected_objects */ public final byte[] key; + /** + * The shared serving identity (usually POA) or null if no such + * applicable. + */ + public final java.lang.Object identity; + public boolean equals(java.lang.Object other) { if (other instanceof cObject) @@ -118,17 +127,23 @@ public class Connected_objects */ public cObject getKey(org.omg.CORBA.Object stored_object) { - Map.Entry item; - Iterator iter = objects.entrySet().iterator(); - cObject ref; - - while (iter.hasNext()) + synchronized (objects) { - item = (Map.Entry) iter.next(); - ref = (cObject) item.getValue(); - if (stored_object.equals(ref.object)) - return ref; + 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) || + stored_object._is_equivalent(ref.object) + ) + return ref; + } } + return null; } @@ -144,7 +159,7 @@ public class Connected_objects */ public cObject add(org.omg.CORBA.Object object, int port) { - return add(generateObjectKey(object), object, port); + return add(generateObjectKey(object), object, port, null); } /** @@ -155,10 +170,15 @@ public class Connected_objects * @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) + public cObject add(byte[] key, org.omg.CORBA.Object object, int port, + java.lang.Object identity + ) { - cObject rec = new cObject(object, port, key); - objects.put(key, rec); + cObject rec = new cObject(object, port, key, identity); + synchronized (objects) + { + objects.put(key, rec); + } return rec; } @@ -171,12 +191,14 @@ public class Connected_objects */ public cObject get(byte[] key) { - return (cObject) objects.get(key); + synchronized (objects) + { + return (cObject) objects.get(key); + } } /** * Get the map entry set. - * @return */ public Set entrySet() { @@ -190,9 +212,12 @@ public class Connected_objects */ public void remove(org.omg.CORBA.Object object) { - cObject ref = getKey(object); - if (ref != null) - objects.remove(ref.key); + synchronized (objects) + { + cObject ref = getKey(object); + if (ref != null) + objects.remove(ref.key); + } } /** diff --git a/gnu/CORBA/DefinitionKindHolder.java b/gnu/CORBA/DefinitionKindHolder.java index dc6dcc0be..1ef7350dd 100644 --- a/gnu/CORBA/DefinitionKindHolder.java +++ b/gnu/CORBA/DefinitionKindHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/DuplicateNameHolder.java b/gnu/CORBA/DuplicateNameHolder.java new file mode 100644 index 000000000..ad004bc41 --- /dev/null +++ b/gnu/CORBA/DuplicateNameHolder.java @@ -0,0 +1,106 @@ +/* DuplicateNameHolder.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName; +import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateNameHelper; + +/** +* A holder for the exception {@link DuplicateName}. + +* @author Audrius Meskauskas, Lithiania (AudriusA@Bioinformatics.org) +*/ +public class DuplicateNameHolder + implements Streamable +{ + /** + * The stored DuplicateName value. + */ + public DuplicateName value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public DuplicateNameHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public DuplicateNameHolder(DuplicateName initialValue) + { + value = initialValue; + } + + /** + * Fill in the {@link value} by data from the CDR stream. + * + * @param input the org.omg.CORBA.portable stream to read. + */ + public void _read(InputStream input) + { + value = DuplicateNameHelper.read(input); + } + + /** + * Write the stored value into the CDR stream. + * + * @param output the org.omg.CORBA.portable stream to write. + */ + public void _write(OutputStream output) + { + DuplicateNameHelper.write(output, value); + } + + /** + * Get the typecode of the DuplicateName. + */ + public TypeCode _type() + { + return DuplicateNameHelper.type(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/DynAn/NameValuePairHolder.java b/gnu/CORBA/DynAn/NameValuePairHolder.java index 13ea8cf70..7afc81cd4 100644 --- a/gnu/CORBA/DynAn/NameValuePairHolder.java +++ b/gnu/CORBA/DynAn/NameValuePairHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/EmptyExceptionHolder.java b/gnu/CORBA/EmptyExceptionHolder.java new file mode 100644 index 000000000..890ca5fe5 --- /dev/null +++ b/gnu/CORBA/EmptyExceptionHolder.java @@ -0,0 +1,132 @@ +/* EmptyStructHolder.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UNKNOWN; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; + +/** + * This holder can store any CORBA exception that has no user defined fields. + * Only the repository ID is written when the method {@link #_write} is called. + * The _read method is not supported for this holder. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class EmptyExceptionHolder + implements Streamable +{ + /** + * The wrapped exception. + */ + public Throwable value; + + /** + * The typecode of the wrapped exception. + */ + public TypeCode typecode; + + /** + * Create the exception holder, initialised to the given values. + * + * @param an_exception the wrapped exception. + * @param an_id the exception repository id. + */ + public EmptyExceptionHolder(Throwable an_exception, TypeCode a_typecode) + { + value = an_exception; + typecode = a_typecode; + } + + /** + * Reads the exception from the input stream. + * + * The value field obtains the value of either the read exception or + * the UNKNOWN if the repository ID does not match + * the exception from the reachable code. + */ + public void _read(InputStream input) + { + String id = input.read_string(); + Object ex = ObjectCreator.Idl2Object(id); + if (ex == null) + value = new UNKNOWN(id); + else + value = (Throwable) ex; + } + + /** + * Return the typecode of the stored exception. + * + * @return the value, passed as a_typecode in constructor. + */ + public TypeCode _type() + { + return typecode; + } + + /** + * Write the exception into the give output stream. Writes the + * repository id that is taken from the typecode. This method also + * works when no helper class is available. + * + * @param output a stream to write into. + * + * @throws BAD_OPERATION if the value for the holder is not set or + * the typecode cannot provide repository id. + */ + public void _write(OutputStream output) + { + try + { + output.write_string(typecode.id()); + } + catch (Exception ex) + { + BAD_OPERATION bad = new BAD_OPERATION(); + bad.initCause(ex); + throw bad; + } + } +}
\ No newline at end of file diff --git a/gnu/CORBA/ExceptionCreator.java b/gnu/CORBA/ExceptionCreator.java index 724eb86d4..536053cef 100644 --- a/gnu/CORBA/ExceptionCreator.java +++ b/gnu/CORBA/ExceptionCreator.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/ForwardRequestHelper.java b/gnu/CORBA/ForwardRequestHelper.java new file mode 100644 index 000000000..74666aaf6 --- /dev/null +++ b/gnu/CORBA/ForwardRequestHelper.java @@ -0,0 +1,160 @@ +/* ForwardRequestHelper.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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.Poa.ForwardRequestHolder; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ObjectHelper; +import org.omg.CORBA.StructMember; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.PortableServer.ForwardRequest; + +/** + * The helper operations for the exception {@link ForwardRequest}. + * + * @specnote The helper must be here and not in POA subpackage as it must + * be discovered by the {@link ObjectCreator} when reading this remote + * exception. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class ForwardRequestHelper +{ + /** + * The cached typecode value, computed only once. + */ + private static TypeCode typeCode; + + /** + * Extract the ForwardRequest from given Any. + * This method uses the ForwardRequestHolder. + * + * @throws BAD_OPERATION if the passed Any does not contain ForwardRequest. + */ + public static ForwardRequest extract(Any any) + { + try + { + return ((ForwardRequestHolder) any.extract_Streamable()).value; + } + catch (ClassCastException cex) + { + BAD_OPERATION bad = new BAD_OPERATION("ForwardRequest expected"); + bad.initCause(cex); + throw bad; + } + } + + /** + * Get the ForwardRequest repository id. + * + * @return "ForwardRequest", always. + */ + public static String id() + { + return "ForwardRequest"; + } + + /** + * Insert the ForwardRequest into the given Any. + * This method uses the ForwardRequestHolder. + * + * @param any the Any to insert into. + * @param that the ForwardRequest to insert. + */ + public static void insert(Any any, ForwardRequest that) + { + any.insert_Streamable(new ForwardRequestHolder(that)); + } + + /** + * Read the exception from the CDR intput stream. + * + * @param input a org.omg.CORBA.portable stream to read from. + */ + public static ForwardRequest read(InputStream input) + { + // Read the exception repository id. + String id = input.read_string(); + ForwardRequest value = new ForwardRequest(); + + value.forward_reference = input.read_Object(); + return value; + } + + /** + * Create the ForwardRequest typecode (structure, + * named "ForwardRequest"). + * The typecode states that the structure contains the + * following fields: forward_reference. + */ + public static TypeCode type() + { + if (typeCode == null) + { + ORB orb = ORB.init(); + StructMember[] members = new StructMember[ 1 ]; + + TypeCode field; + + field = ObjectHelper.type(); + members [ 0 ] = new StructMember("forward_reference", field, null); + typeCode = orb.create_exception_tc(id(), "ForwardRequest", members); + } + return typeCode; + } + + /** + * Write the exception to the CDR output stream. + * + * @param output a org.omg.CORBA.portable stream stream to write into. + * @param value a value to write. + */ + public static void write(OutputStream output, ForwardRequest value) + { + // Write the exception repository id. + output.write_string(id()); + output.write_Object(value.forward_reference); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Functional_ORB.java b/gnu/CORBA/Functional_ORB.java index 437f420c4..c8d6a4c93 100644 --- a/gnu/CORBA/Functional_ORB.java +++ b/gnu/CORBA/Functional_ORB.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,13 +40,14 @@ package gnu.CORBA; import gnu.CORBA.CDR.cdrBufInput; import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.GIOP.CloseMessage; import gnu.CORBA.GIOP.ErrorMessage; import gnu.CORBA.GIOP.MessageHeader; import gnu.CORBA.GIOP.ReplyHeader; import gnu.CORBA.GIOP.RequestHeader; import gnu.CORBA.NamingService.NamingServiceTransient; +import gnu.CORBA.Poa.gnuForwardRequest; -import org.omg.CORBA.BAD_INV_ORDER; import org.omg.CORBA.BAD_OPERATION; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.CompletionStatus; @@ -77,6 +78,7 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Enumeration; +import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; @@ -86,7 +88,9 @@ import java.util.TreeMap; /** * The ORB implementation, capable to handle remote invocations on the - * registered object. + * registered object. This class implements all features, required till + * the jdk 1.3 inclusive, but does not support the POA that appears since + * 1.4. The POA is supported by {@link gnu.CORBA.Poa.ORB_1_4}. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ @@ -154,7 +158,7 @@ public class Functional_ORB { try { - serve(this, service); + tick(); } catch (SocketException ex) { @@ -179,6 +183,16 @@ public class Functional_ORB } /** + * Perform a single serving step. + * @throws java.lang.Exception + */ + void tick() + throws Exception + { + serve(this, service); + } + + /** * Forcibly close the server socket and mark this port as free. */ public void close_now() @@ -205,6 +219,40 @@ public class Functional_ORB } /** + * A server, responsible for listening on requests on some + * local port and serving multiple requests (probably to the + * different objects) on the same thread. + */ + class sharedPortServer + extends portServer + { + /** + * Create a new portServer, serving on specific port. + */ + sharedPortServer(int _port) + { + super(_port); + } + + /** + * Perform a single serving step. + * @throws java.lang.Exception + */ + void tick() + throws Exception + { + Socket request = service.accept(); + serveStep(request, false); + } + } + + /** + * The default value where the first instance of this ORB will start + * looking for a free port. + */ + public static int DEFAULT_INITIAL_PORT = 1126; + + /** * The property of port, on that this ORB is listening for requests from clients. * This class supports one port per ORB only. */ @@ -266,7 +314,7 @@ public class Functional_ORB */ private int TOUT_START_READING_MESSAGE = 20 * 1000; - // (Here and below, we use * to make meaning of the constant clearler). + // (Here and below, we use * to make the meaning of the constant clearler). /** * If the client has started to send the request message, the socket time @@ -285,17 +333,11 @@ public class Functional_ORB * Some clients tend to submit multiple requests over the * same socket. The server waits for the next request on * the same socket for the duration, specified - * below. The default time is seven seconds. - */ - public int TANDEM_REQUESTS = 7000; - - /** - * If the maximal number of threads per object is reached, - * the server waits for the given time interval before checking - * again maybe some threads are already complete. - * Thr default time is 0.5 second. + * below. In additions, the request of this implementation also + * waits for the same duration before closing the socket. + * The default time is seven seconds. */ - public int PAUSE_ON_THREAD_OVERLOAD = 500; + public static int TANDEM_REQUESTS = 7000; /** * The map of the already conncted objects. @@ -318,7 +360,7 @@ public class Functional_ORB /** * The map of the initial references. */ - private Map initial_references = new TreeMap(); + protected Map initial_references = new TreeMap(); /** * The currently active portServers. @@ -331,13 +373,14 @@ public class Functional_ORB private String ns_host; /** - * The port, under that the ORB is listening for remote requests. - * Then the new object is connected, this port is used first, then - * it is incremented by 1, etc. If the given port is not available, - * up to 20 subsequent values are tried and then the parameterless - * server socket contructor is called. + * Probably free port, under that the ORB will try listening for + * remote requests first. When the new object is connected, this + * port is used first, then it is incremented by 1, etc. If the given + * port is not available, up to 20 subsequent values are tried and then + * the parameterless server socket contructor is called. The constant is + * shared between multiple instances of this ORB. */ - private static int Port = 1126; + private static int Port = DEFAULT_INITIAL_PORT; /** * The port, on that the name service is expected to be running. @@ -356,6 +399,11 @@ public class Functional_ORB protected LinkedList freed_ports = new LinkedList(); /** + * Maps a single-threaded POAs to they sharedPortServants. + */ + protected Hashtable identities = new Hashtable(); + + /** * The maximal allowed number of the currently running parallel * threads per object. For security reasons, this is made private and * unchangeable. After exceeding this limit, the NO_RESOURCES @@ -371,6 +419,7 @@ public class Functional_ORB try { LOCAL_HOST = ns_host = InetAddress.getLocalHost().getHostAddress(); + initial_references.put("CodecFactory", new gnuCodecFactory(this)); } catch (UnknownHostException ex) { @@ -471,31 +520,17 @@ public class Functional_ORB /** * Set the port, on that the server is listening for the client requests. - * In this implementation, the server is listening at only one port, - * the default value being 1126. + * If only one object is connected to the orb, the server will be + * try listening on this port first. It the port is busy, or if more + * objects are connected, the subsequent object will receive a larger + * port values, skipping unavailable ports, if required. The change + * applies globally. * * @param a_Port a port, on that the server is listening for requests. - * - * @throws BAD_INV_ORDER if the server has already been started. The port - * can only be changed when the server is not yet started. - */ - public void setPort(int a_Port) - { - if (running) - throw new BAD_INV_ORDER("The server is running"); - this.Port = a_Port; - } - - /** - * Get the port, on that the server is listening for the client requests. - * In this implementation, the server is listening at only one port, - * the default value being 1126. - * - * @return the port. */ - public int getPort() + public static void setPort(int a_Port) { - return Port; + Port = a_Port; } /** @@ -547,7 +582,8 @@ public class Functional_ORB { int a_port = getFreePort(); - Connected_objects.cObject ref = connected_objects.add(key, object, a_port); + Connected_objects.cObject ref = + connected_objects.add(key, object, a_port, null); IOR ior = createIOR(ref); prepareObject(object, ior); if (running) @@ -555,11 +591,57 @@ public class Functional_ORB } /** + * Connect the given CORBA object to this ORB, explicitly specifying + * the object key and the identity of the thread (and port), where the + * object must be served. The identity is normally the POA. + * + * The new port server will be started only if there is no one + * already running for the same identity. Otherwise, the task of + * the existing port server will be widened, including duty to serve + * the given object. All objects, connected to a single identity by + * this method, will process they requests subsequently in the same + * thread. The method is used when the expected number of the + * objects is too large to have a single port and thread per object. + * This method is used by POAs, having a single thread policy. + * + * @param object the object, must implement the {@link InvokeHandler}) + * interface. + * @param key the object key, usually used to identify the object from + * remote side. + * @param port the port, where the object must be connected. + * + * @throws BAD_PARAM if the object does not implement the + * {@link InvokeHandler}). + */ + public void connect_1_thread(org.omg.CORBA.Object object, byte[] key, + java.lang.Object identity + ) + { + sharedPortServer shared = (sharedPortServer) identities.get(identity); + if (shared == null) + { + int a_port = getFreePort(); + shared = new sharedPortServer(a_port); + identities.put(identity, shared); + if (running) + { + portServers.add(shared); + shared.start(); + } + } + + Connected_objects.cObject ref = + connected_objects.add(key, object, shared.s_port, identity); + IOR ior = createIOR(ref); + prepareObject(object, ior); + } + + /** * Start the service on the given port of this IOR. * * @param ior the ior (only Internet.port is used). */ - private void startService(IOR ior) + public void startService(IOR ior) { portServer p = new portServer(ior.Internet.port); portServers.add(p); @@ -620,7 +702,7 @@ public class Functional_ORB for (int i = 0; i < portServers.size(); i++) { p = (portServer) portServers.get(i); - if (p.s_port == rmKey.port) + if (p.s_port == rmKey.port && !(p instanceof sharedPortServer)) { p.close_now(); freed_ports.addFirst(new Integer(rmKey.port)); @@ -632,6 +714,41 @@ public class Functional_ORB } /** + * Notifies ORB that the shared service indentity (usually POA) + * is destroyed. The matching shared port server is terminated + * and the identity table entry is deleted. If this identity + * is not known for this ORB, the method returns without action. + * + * @param identity the identity that has been destroyed. + */ + public void identityDestroyed(java.lang.Object identity) + { + if (identity == null) + return; + + sharedPortServer ise = (sharedPortServer) identities.get(identity); + if (ise != null) + synchronized (connected_objects) + { + ise.close_now(); + identities.remove(identity); + + Connected_objects.cObject obj; + Map.Entry m; + Iterator iter = connected_objects.entrySet().iterator(); + while (iter.hasNext()) + { + m = (Map.Entry) iter.next(); + obj = (Connected_objects.cObject) m.getValue(); + if (obj.identity == identity) + { + iter.remove(); + } + } + } + } + + /** * Find the local object, connected to this ORB. * * @param ior the ior of the potentially local object. @@ -769,19 +886,31 @@ public class Functional_ORB m = (Map.Entry) iter.next(); obj = (Connected_objects.cObject) m.getValue(); - portServer subserver = new portServer(obj.port); - portServers.add(subserver); + portServer subserver; - // Reuse the current thread for the last portServer. - if (!iter.hasNext()) + if (obj.identity == null) { - // Discard the iterator, eliminating lock checks. - iter = null; - subserver.run(); - return; + subserver = new portServer(obj.port); + portServers.add(subserver); } else - subserver.start(); + { + subserver = (portServer) identities.get(obj.identity); + } + + if (!subserver.isAlive()) + { + // Reuse the current thread for the last portServer. + if (!iter.hasNext()) + { + // Discard the iterator, eliminating lock checks. + iter = null; + subserver.run(); + return; + } + else + subserver.start(); + } } } @@ -839,7 +968,7 @@ public class Functional_ORB } object = impl; - connected_objects.add(ior.key, impl, ior.Internet.port); + connected_objects.add(ior.key, impl, ior.Internet.port, null); } return object; } @@ -1029,10 +1158,12 @@ public class Functional_ORB private void prepareObject(org.omg.CORBA.Object object, IOR ior) throws BAD_PARAM { + /* if (!(object instanceof InvokeHandler)) throw new BAD_PARAM(object.getClass().getName() + " does not implement InvokeHandler. " ); + */ // If no delegate is set, set the default delegate. if (object instanceof ObjectImpl) @@ -1109,6 +1240,43 @@ public class Functional_ORB } /** + * Forward request to another target, as indicated by the passed + * exception. + */ + private void forward_request(OutputStream net_out, MessageHeader msh_request, + RequestHeader rh_request, gnuForwardRequest info + ) + throws IOException + { + MessageHeader msh_forward = new MessageHeader(); + msh_forward.version = msh_request.version; + + ReplyHeader rh_forward = msh_forward.create_reply_header(); + msh_forward.message_type = MessageHeader.REPLY; + rh_forward.reply_status = info.forwarding_code; + rh_forward.request_id = rh_request.request_id; + + // The forwarding code is either LOCATION_FORWARD or LOCATION_FORWARD_PERM. + cdrBufOutput out = new cdrBufOutput(); + out.setOrb(this); + out.setOffset(msh_forward.getHeaderSize()); + + rh_forward.write(out); + + if (msh_forward.version.since_inclusive(1, 2)) + out.align(8); + + out.write_Object(info.forward_reference); + + msh_forward.message_size = out.buffer.size(); + + // Write the forwarding instruction. + msh_forward.write(net_out); + out.buffer.writeTo(net_out); + net_out.flush(); + } + + /** * Contains a single servicing task. * * Normally, each task matches a single remote invocation. @@ -1127,9 +1295,10 @@ public class Functional_ORB service = serverSocket.accept(); // Tell the server there are no more resources. - while (p.running_threads >= MAX_RUNNING_THREADS) + if (p.running_threads >= MAX_RUNNING_THREADS) { serveStep(service, true); + return; } new Thread() @@ -1256,6 +1425,18 @@ public class Functional_ORB throw new OBJECT_NOT_EXIST(); target._invoke(rh_request.operation, cin, handler); } + catch (gnuForwardRequest forwarded) + { + OutputStream sou = service.getOutputStream(); + forward_request(sou, msh_request, rh_request, forwarded); + if (service != null && !service.isClosed()) + { + // Wait for the subsequent invocations on the + // same socket for the TANDEM_REQUEST duration. + service.setSoTimeout(TANDEM_REQUESTS); + continue Serving; + } + } catch (SystemException ex) { sysEx = ex; @@ -1266,6 +1447,7 @@ public class Functional_ORB } catch (Exception except) { + except.printStackTrace(); sysEx = new UNKNOWN("Unknown", 2, CompletionStatus.COMPLETED_MAYBE); @@ -1284,14 +1466,21 @@ public class Functional_ORB ); } } - else - ; + else if (msh_request.message_type == MessageHeader.CLOSE_CONNECTION || + msh_request.message_type == MessageHeader.MESSAGE_ERROR + ) + { + CloseMessage.close(service.getOutputStream()); + service.close(); + return; + } + ; // TODO log error: "Not a request message." if (service != null && !service.isClosed()) { // Wait for the subsequent invocations on the - // same socket for 2 minutes. + // same socket for the TANDEM_REQUEST duration. service.setSoTimeout(TANDEM_REQUESTS); } else diff --git a/gnu/CORBA/GIOP/CancelHeader.java b/gnu/CORBA/GIOP/CancelHeader.java index d40a32fe6..9f4de0d87 100644 --- a/gnu/CORBA/GIOP/CancelHeader.java +++ b/gnu/CORBA/GIOP/CancelHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/CharSets_OSF.java b/gnu/CORBA/GIOP/CharSets_OSF.java index 7690f3a00..f3f35dbaa 100644 --- a/gnu/CORBA/GIOP/CharSets_OSF.java +++ b/gnu/CORBA/GIOP/CharSets_OSF.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/CloseMessage.java b/gnu/CORBA/GIOP/CloseMessage.java new file mode 100644 index 000000000..d884329c4 --- /dev/null +++ b/gnu/CORBA/GIOP/CloseMessage.java @@ -0,0 +1,102 @@ +/* CloseMessage.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.GIOP; + +import gnu.CORBA.IOR; + +import org.omg.CORBA.MARSHAL; + +import java.io.IOException; +import java.io.OutputStream; + +import java.net.Socket; + +/** + * The explicit command to close the connection. + * + * + * The close message consists from the message header only and + * is the same for GIOP 1.0, 1.1, 1.2 and 1.3. The CloseMessage + * uses the default value from the {@link MessageHeader}. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class CloseMessage + extends MessageHeader +{ + /** + * The singleton close message is typically enough, despite new + * instances may be instantiated if the specific version field + * value is mandatory. + */ + private static final CloseMessage Singleton = new CloseMessage(); + + /** + * Create a new error message, setting the message field + * to the {@link MESSAGE_CLOSE} and the version number to + * the given major and minor values. + */ + public CloseMessage() + { + message_type = CLOSE_CONNECTION; + } + + /** + * Send the close message to the given output stream. The method, + * however, does not close the socket itself, this must be done + * explicitly in the calling code. + * + * @param socketStream a stream, where the close message is + * written. + */ + public static void close(OutputStream socketStream) + { + try + { + Singleton.write(socketStream); + socketStream.flush(); + } + catch (IOException ex) + { + MARSHAL m = new MARSHAL("Unable to flush the stream"); + m.initCause(ex); + throw m; + } + } +}
\ No newline at end of file diff --git a/gnu/CORBA/GIOP/ErrorMessage.java b/gnu/CORBA/GIOP/ErrorMessage.java index 0da5f649c..8d3b3539b 100644 --- a/gnu/CORBA/GIOP/ErrorMessage.java +++ b/gnu/CORBA/GIOP/ErrorMessage.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/MessageHeader.java b/gnu/CORBA/GIOP/MessageHeader.java index 7640b6bfd..61c46e11e 100644 --- a/gnu/CORBA/GIOP/MessageHeader.java +++ b/gnu/CORBA/GIOP/MessageHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/ReplyHeader.java b/gnu/CORBA/GIOP/ReplyHeader.java index 76c6df944..1e0e154f8 100644 --- a/gnu/CORBA/GIOP/ReplyHeader.java +++ b/gnu/CORBA/GIOP/ReplyHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/RequestHeader.java b/gnu/CORBA/GIOP/RequestHeader.java index 77ef6dd97..f2de4e271 100644 --- a/gnu/CORBA/GIOP/RequestHeader.java +++ b/gnu/CORBA/GIOP/RequestHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/ServiceContext.java b/gnu/CORBA/GIOP/ServiceContext.java index d14eabbc9..7e44bdcea 100644 --- a/gnu/CORBA/GIOP/ServiceContext.java +++ b/gnu/CORBA/GIOP/ServiceContext.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/cxCodeSet.java b/gnu/CORBA/GIOP/cxCodeSet.java index 0fbf00bfe..7f42c07f2 100644 --- a/gnu/CORBA/GIOP/cxCodeSet.java +++ b/gnu/CORBA/GIOP/cxCodeSet.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/v1_0/CancelHeader.java b/gnu/CORBA/GIOP/v1_0/CancelHeader.java index 5b07e89ad..6e3650c4b 100644 --- a/gnu/CORBA/GIOP/v1_0/CancelHeader.java +++ b/gnu/CORBA/GIOP/v1_0/CancelHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/v1_0/ReplyHeader.java b/gnu/CORBA/GIOP/v1_0/ReplyHeader.java index 74512d617..27181ca63 100644 --- a/gnu/CORBA/GIOP/v1_0/ReplyHeader.java +++ b/gnu/CORBA/GIOP/v1_0/ReplyHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/v1_0/RequestHeader.java b/gnu/CORBA/GIOP/v1_0/RequestHeader.java index dd3e20349..ffa45c37b 100644 --- a/gnu/CORBA/GIOP/v1_0/RequestHeader.java +++ b/gnu/CORBA/GIOP/v1_0/RequestHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/v1_2/ReplyHeader.java b/gnu/CORBA/GIOP/v1_2/ReplyHeader.java index 87c97b3ec..c3f51a37b 100644 --- a/gnu/CORBA/GIOP/v1_2/ReplyHeader.java +++ b/gnu/CORBA/GIOP/v1_2/ReplyHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/GIOP/v1_2/RequestHeader.java b/gnu/CORBA/GIOP/v1_2/RequestHeader.java index 184893bb3..d294d0067 100644 --- a/gnu/CORBA/GIOP/v1_2/RequestHeader.java +++ b/gnu/CORBA/GIOP/v1_2/RequestHeader.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/IOR.java b/gnu/CORBA/IOR.java index 056009f06..cedbce461 100644 --- a/gnu/CORBA/IOR.java +++ b/gnu/CORBA/IOR.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -371,6 +371,13 @@ public class IOR * 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. */ @@ -381,6 +388,13 @@ public class IOR 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(); @@ -435,6 +449,21 @@ public class IOR } /** + * 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. diff --git a/gnu/CORBA/IOR_Delegate.java b/gnu/CORBA/IOR_Delegate.java index 5b02fc2db..e3fde60ee 100644 --- a/gnu/CORBA/IOR_Delegate.java +++ b/gnu/CORBA/IOR_Delegate.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -40,7 +40,9 @@ package gnu.CORBA; import gnu.CORBA.CDR.cdrBufInput; import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.Poa.activeObjectMap; +import org.omg.CORBA.CompletionStatus; import org.omg.CORBA.Context; import org.omg.CORBA.ContextList; import org.omg.CORBA.ExceptionList; @@ -56,6 +58,8 @@ 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 @@ -69,6 +73,17 @@ public class IOR_Delegate extends Simple_delegate { /** + * True if the current IOR does not map into the local servant. + * If false, the IOR is either local or should be checked. + */ + boolean remote_ior; + + /** + * If not null, this field contains data about the local servant. + */ + activeObjectMap.Obj local_ior; + + /** * Contructs an instance of object using the given IOR. */ public IOR_Delegate(ORB an_orb, IOR an_ior) @@ -94,7 +109,7 @@ public class IOR_Delegate NamedValue returns ) { - gnuRequest request = new gnuRequest(); + gnuRequest request = getRequestInstance(target); request.setIor(getIor()); request.set_target(target); @@ -125,7 +140,7 @@ public class IOR_Delegate ContextList ctx_list ) { - gnuRequest request = new gnuRequest(); + gnuRequest request = getRequestInstance(target); request.setIor(ior); request.set_target(target); @@ -142,8 +157,19 @@ public class IOR_Delegate } /** - * Invoke operation on the given object, writing parameters to the given - * output stream. + * Get the instance of request. + */ + protected gnuRequest getRequestInstance(org.omg.CORBA.Object target) + { + return new gnuRequest(); + } + + /** + * Invoke operation on the given object, als handling temproray and permanent + * redirections. The ReplyHeader.LOCATION_FORWARD will cause to resend + * the request to the new direction. The ReplyHeader.LOCATION_FORWARD_PERM + * will cause additionally to remember the new location by this delegate, + * so subsequent calls will be immediately delivered to the new target. * * @param target the target object. * @param output the output stream, previously returned by @@ -211,21 +237,56 @@ public class IOR_Delegate } catch (IOException ex) { - MARSHAL t = new MARSHAL("Cant read forwarding info"); + MARSHAL t = + new MARSHAL("Cant read forwarding info", 5102, + CompletionStatus.COMPLETED_NO + ); t.initCause(ex); throw t; } - request.request.setIor(forwarded); + gnuRequest prev = request.request; + gnuRequest r = getRequestInstance(target); - // If the object has moved permanently, its IOR is replaced. - if (moved_permanently) - setIor(forwarded); + r.m_args = prev.m_args; + r.m_context = prev.m_context; + r.m_context_list = prev.m_context_list; + r.m_environment = prev.m_environment; + r.m_exceptions = prev.m_exceptions; + r.m_operation = prev.m_operation; + r.m_parameter_buffer = prev.m_parameter_buffer; + r.m_parameter_buffer.request = r; + r.m_result = prev.m_result; + r.m_target = prev.m_target; + r.oneWay = prev.oneWay; + r.setIor(forwarded); - return invoke(target, request); + IOR_contructed_object it = + new IOR_contructed_object(orb, forwarded); + + r.m_target = it; + + request.request = r; + + IOR prev_ior = getIor(); + + setIor(forwarded); + + try + { + return invoke(it, request); + } + finally + { + if (!moved_permanently) + setIor(prev_ior); + } default : - throw new MARSHAL("Unknow reply status: " + rh.reply_status); + throw new MARSHAL("Unknow reply status: " + rh.reply_status, + 8000 + rh.reply_status, + CompletionStatus.COMPLETED_NO + ); } } else @@ -245,7 +306,7 @@ public class IOR_Delegate */ public Request request(org.omg.CORBA.Object target, String operation) { - gnuRequest request = new gnuRequest(); + gnuRequest request = getRequestInstance(target); request.setIor(ior); request.set_target(target); @@ -270,7 +331,7 @@ public class IOR_Delegate boolean response_expected ) { - gnuRequest request = new gnuRequest(); + gnuRequest request = getRequestInstance(target); request.setIor(ior); request.set_target(target); @@ -281,4 +342,53 @@ public class IOR_Delegate 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. + } + } + + /** + * Reset the remote_ior flag, forcing to check if the object is local + * on the next getRequestInstance call. + */ + public void setIor(IOR an_ior) + { + super.setIor(an_ior); + remote_ior = false; + local_ior = null; + } + + /** + * Checks if the ior is local so far it is easy. + */ + public boolean is_local(org.omg.CORBA.Object self) + { + if (remote_ior) + return false; + else if (local_ior != null) + return true; + else + return super.is_local(self); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/IOR_contructed_object.java b/gnu/CORBA/IOR_contructed_object.java index 5c8ba7350..2fab70799 100644 --- a/gnu/CORBA/IOR_contructed_object.java +++ b/gnu/CORBA/IOR_contructed_object.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -97,4 +97,13 @@ public class IOR_contructed_object { return getClass().getName() + ":IOR:" + ior; } -} + + /** + * Calls realease on the delegate. + */ + protected void finalize() + throws java.lang.Throwable + { + _get_delegate().release(this); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/NamingService/Binding_iterator_impl.java b/gnu/CORBA/NamingService/Binding_iterator_impl.java index 6d00c8529..79d787083 100644 --- a/gnu/CORBA/NamingService/Binding_iterator_impl.java +++ b/gnu/CORBA/NamingService/Binding_iterator_impl.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/Ext.java b/gnu/CORBA/NamingService/Ext.java index 69e11e275..fb7406c46 100644 --- a/gnu/CORBA/NamingService/Ext.java +++ b/gnu/CORBA/NamingService/Ext.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/NameValidator.java b/gnu/CORBA/NamingService/NameValidator.java index 797202fd6..d7d5a14bb 100644 --- a/gnu/CORBA/NamingService/NameValidator.java +++ b/gnu/CORBA/NamingService/NameValidator.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/NamingMap.java b/gnu/CORBA/NamingService/NamingMap.java index d9bbf6a8c..a69b06172 100644 --- a/gnu/CORBA/NamingService/NamingMap.java +++ b/gnu/CORBA/NamingService/NamingMap.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/NamingServiceTransient.java b/gnu/CORBA/NamingService/NamingServiceTransient.java index 295c0e488..fda46adbb 100644 --- a/gnu/CORBA/NamingService/NamingServiceTransient.java +++ b/gnu/CORBA/NamingService/NamingServiceTransient.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -104,12 +104,6 @@ public class NamingServiceTransient { // Create and initialize the ORB final Functional_ORB orb = new Functional_ORB(); - orb.setPort(PORT); - orb.init(args, null); - - // Create the servant and register it with the ORB - NamingContextExt namer = new Ext(new TransientContext()); - orb.connect(namer, getDefaultKey()); if (args.length > 1) for (int i = 0; i < args.length - 1; i++) @@ -121,7 +115,11 @@ public class NamingServiceTransient iorf = args [ i + 1 ]; } - orb.setPort(port); + 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); @@ -145,7 +143,7 @@ public class NamingServiceTransient { public void run() { - // wait for invocations from clients + // Wait for invocations from clients. orb.run(); } }.start(); @@ -155,5 +153,8 @@ public class NamingServiceTransient System.err.println("ERROR: " + e); e.printStackTrace(System.out); } + + // Restore the default value for allocating ports for the subsequent objects. + Functional_ORB.setPort(Functional_ORB.DEFAULT_INITIAL_PORT); } } diff --git a/gnu/CORBA/NamingService/TransientContext.java b/gnu/CORBA/NamingService/TransientContext.java index 70deec28a..4b7c1938f 100644 --- a/gnu/CORBA/NamingService/TransientContext.java +++ b/gnu/CORBA/NamingService/TransientContext.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/cmpNameComponent.java b/gnu/CORBA/NamingService/cmpNameComponent.java index c8cc03ad7..1e06fb8ee 100644 --- a/gnu/CORBA/NamingService/cmpNameComponent.java +++ b/gnu/CORBA/NamingService/cmpNameComponent.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/NamingService/snConverter.java b/gnu/CORBA/NamingService/snConverter.java index dc46b7ab3..a9b9219d7 100644 --- a/gnu/CORBA/NamingService/snConverter.java +++ b/gnu/CORBA/NamingService/snConverter.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/ObjectCreator.java b/gnu/CORBA/ObjectCreator.java index 4b17dbab3..b99c46ba6 100644 --- a/gnu/CORBA/ObjectCreator.java +++ b/gnu/CORBA/ObjectCreator.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -73,7 +73,7 @@ public class ObjectCreator * The prefix for classes that are placed instide the * gnu.CORBA namespace. */ - public static final String CLASSPATH_PREFIX = "gnu.CORBA"; + public static final String CLASSPATH_PREFIX = "gnu.CORBA."; /** * Try to instantiate an object with the given IDL name. @@ -184,11 +184,11 @@ public class ObjectCreator { try { - String holder = toHelperName(idl); - Class holderClass = Class.forName(holder); + String helper = toHelperName(idl); + Class helperClass = Class.forName(helper); Method read = - holderClass.getMethod("read", + helperClass.getMethod("read", new Class[] { org.omg.CORBA.portable.InputStream.class @@ -266,19 +266,83 @@ public class ObjectCreator } /** + * 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. */ - protected static String toIDL(String cn) + public static String toIDL(String cn) { if (cn.startsWith(JAVA_PREFIX)) - cn = cn.substring(JAVA_PREFIX.length()); - - cn = cn.replace('.', '/'); + 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:" + OMG_PREFIX + cn + ":1.0"; + return "IDL:" + cn + ":1.0"; } -} +}
\ No newline at end of file diff --git a/gnu/CORBA/OctetHolder.java b/gnu/CORBA/OctetHolder.java index 9b0184c16..02fd9a432 100644 --- a/gnu/CORBA/OctetHolder.java +++ b/gnu/CORBA/OctetHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/Poa/ForwardRequestHolder.java b/gnu/CORBA/Poa/ForwardRequestHolder.java new file mode 100644 index 000000000..5e2455952 --- /dev/null +++ b/gnu/CORBA/Poa/ForwardRequestHolder.java @@ -0,0 +1,107 @@ +/* ForwardRequestHolder.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 gnu.CORBA.ForwardRequestHelper; + +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.ForwardRequest; + +/** +* A holder for the exception {@link ForwardRequest}. + +* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) +*/ +public class ForwardRequestHolder + implements Streamable +{ + /** + * The stored ForwardRequest value. + */ + public ForwardRequest value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public ForwardRequestHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public ForwardRequestHolder(ForwardRequest 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 = ForwardRequestHelper.read(input); + } + + /** + * Get the typecode of the ForwardRequest. + */ + public TypeCode _type() + { + return ForwardRequestHelper.type(); + } + + /** + * Write the stored value into the CDR stream. + * + * @param output the org.omg.CORBA.portable stream to write. + */ + public void _write(OutputStream output) + { + ForwardRequestHelper.write(output, value); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/ForwardedServant.java b/gnu/CORBA/Poa/ForwardedServant.java new file mode 100644 index 000000000..2df378df6 --- /dev/null +++ b/gnu/CORBA/Poa/ForwardedServant.java @@ -0,0 +1,207 @@ +/* ForwardedServant.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 gnu.CORBA.IOR; +import gnu.CORBA.IOR_Delegate; +import gnu.CORBA.IOR_contructed_object; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.Delegate; +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.RemarshalException; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.Servant; + +import java.io.IOException; + +/** + * A "virtual servant", delegating all invocation to the wrapped + * object (usually remote). Used in cases when it is necessary to + * handle the request forwarding. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ForwardedServant + extends Servant + implements InvokeHandler +{ + /** + * The reference object, handling requests. + */ + public final ObjectImpl ref; + + /** + * Create an instance, forwarding requests to the given object. + */ + ForwardedServant(ObjectImpl a_ref) + { + ref = a_ref; + } + + /** + * Create an instance of the forwarded servant. + * + * @param a_ref a reference where request should be forwarded. + * + * @return a created forwarded servant or null if the parameter + * forwards request to itself. Returning null will force to find + * a right servant in one of many possible ways, depending on + * policies. + */ + public static Servant create(org.omg.CORBA.Object a_ref) + { + try + { + ObjectImpl fto = (ObjectImpl) a_ref; + + // Check maybe the remote side forwarded back to our local object. + if (fto instanceof IOR_contructed_object) + { + IOR_contructed_object iref = (IOR_contructed_object) fto; + + // Check maybe the IOR is local. + ORB t_orb = iref._orb(); + if (t_orb instanceof ORB_1_4) + { + ORB_1_4 orb = (ORB_1_4) t_orb; + Delegate d = iref._get_delegate(); + if (d instanceof IOR_Delegate) + { + IOR_Delegate ird = (IOR_Delegate) iref._get_delegate(); + IOR ior = ird.getIor(); + if (orb.LOCAL_HOST.equalsIgnoreCase(ior.Internet.host)) + { + activeObjectMap.Obj rx = orb.rootPOA.findIorKey(ior.key); + if (rx != null) + { + if (rx.object == fto || + rx.object._is_equivalent(fto) + ) + return rx.primary_servant; + else + fto = (ObjectImpl) rx.object; + } + } + } + } + } + return new ForwardedServant(fto); + } + catch (ClassCastException ex) + { + throw new BAD_PARAM("ObjectImpl required but " + a_ref + " passed ", + 0x5005, CompletionStatus.COMPLETED_NO + ); + } + } + + /** + * Forward the call to the wrapped object. + */ + public OutputStream _invoke(String method, InputStream input, + ResponseHandler handler + ) + throws SystemException + { + org.omg.CORBA.portable.InputStream in = null; + org.omg.CORBA.portable.OutputStream out = null; + try + { + try + { + out = ref._request(method, true); + + // Transfer request information. + int b; + while ((b = input.read()) >= 0) + { + out.write(b); + } + in = ref._invoke(out); + + // Read the returned data. + out = handler.createReply(); + while ((b = in.read()) >= 0) + { + out.write(b); + } + } + catch (IOException io_ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(io_ex); + throw m; + } + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String _id = ex.getId(); + throw new MARSHAL(_id, 5101, CompletionStatus.COMPLETED_NO); + } + catch (RemarshalException remarsh) + { + _invoke(method, input, handler); + } + finally + { + ref._releaseReply(in); + } + return out; + } + + /** + * Delegates to the wrapped object. + */ + public String[] _all_interfaces(POA poa, byte[] key) + { + return ref._ids(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/InvalidPolicyHolder.java b/gnu/CORBA/Poa/InvalidPolicyHolder.java new file mode 100644 index 000000000..154762acf --- /dev/null +++ b/gnu/CORBA/Poa/InvalidPolicyHolder.java @@ -0,0 +1,106 @@ +/* InvalidPolicyHolder.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.Poa; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import org.omg.PortableServer.POAPackage.InvalidPolicyHelper; + +/** +* A holder for the exception {@link InvalidPolicy}. + +* @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) +*/ +public class InvalidPolicyHolder + implements Streamable +{ + /** + * The stored InvalidPolicy value. + */ + public InvalidPolicy value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public InvalidPolicyHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public InvalidPolicyHolder(InvalidPolicy initialValue) + { + value = initialValue; + } + + /** + * Fill in the {@link value} by data from the CDR stream. + * + * @param input the org.omg.CORBA.portable stream to read. + */ + public void _read(InputStream input) + { + value = InvalidPolicyHelper.read(input); + } + + /** + * Write the stored value into the CDR stream. + * + * @param output the org.omg.CORBA.portable stream to write. + */ + public void _write(OutputStream output) + { + InvalidPolicyHelper.write(output, value); + } + + /** + * Get the typecode of the InvalidPolicy. + */ + public TypeCode _type() + { + return InvalidPolicyHelper.type(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/LocalDelegate.java b/gnu/CORBA/Poa/LocalDelegate.java new file mode 100644 index 000000000..950e6e2ff --- /dev/null +++ b/gnu/CORBA/Poa/LocalDelegate.java @@ -0,0 +1,362 @@ +/* LocalDelegate.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 gnu.CORBA.CDR.cdrOutput; +import gnu.CORBA.streamRequest; + +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.Bounds; +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.OBJECT_NOT_EXIST; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.portable.ApplicationException; +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_2_3.portable.Delegate; +import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; + +import java.util.Arrays; + +/** + * A local delegate, transferring all object requests to the locally + * available servant. This class is involved in handling the method + * invocations on the local object, obtained by + * POA.create_reference_with_id. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class LocalDelegate + extends org.omg.CORBA_2_3.portable.Delegate +{ + /** + * The same servant as an invocation handler. + */ + gnuServantObject object; + String operation; + final gnuPOA poa; + final byte[] Id; + + /** + * Create a local delegate, forwarding requests to the + * servant that must also be an invocation handler. + */ + public LocalDelegate(gnuServantObject an_object, gnuPOA a_poa, byte[] an_id) + { + object = an_object; + poa = a_poa; + Id = an_id; + } + + public Request request(org.omg.CORBA.Object target, String method) + { + operation = method; + + LocalRequest rq = new LocalRequest(object, poa, Id); + rq.setOperation(method); + rq.setORB(orb(target)); + return rq; + } + + public void release(org.omg.CORBA.Object target) + { + } + + public boolean is_equivalent(org.omg.CORBA.Object target, + org.omg.CORBA.Object other + ) + { + if (target == other) + return true; + else if (target instanceof ObjectImpl && other instanceof ObjectImpl) + { + org.omg.CORBA.portable.Delegate a = null; + org.omg.CORBA.portable.Delegate b = null; + try + { + a = ((ObjectImpl) target)._get_delegate(); + b = ((ObjectImpl) other)._get_delegate(); + } + catch (Exception ex) + { + // Unable to get one of the delegates. + return false; + } + if (a instanceof LocalDelegate && b instanceof LocalDelegate) + { + byte[] k1 = ((LocalDelegate) a).Id; + byte[] k2 = ((LocalDelegate) b).Id; + return Arrays.equals(k1, k2); + } + else + return false; + } + else + return false; + } + + /** + * Always return false. + */ + public boolean non_existent(org.omg.CORBA.Object target) + { + return false; + } + + /** + * Get hash code. + */ + public int hash(org.omg.CORBA.Object target, int maximum) + { + return hashCode() % maximum; + } + + /** + * Check if this object could be named by the given repository id. + * @param idl_id the repository id to check. + * + * @return true if it is one of the possible repository ids of this + * object. + */ + public boolean is_a(org.omg.CORBA.Object a_servant, String idl_id) + { + String[] maybe = object._ids(); + for (int i = 0; i < maybe.length; i++) + { + if (maybe [ i ].equals(idl_id)) + return true; + } + return false; + } + + /** + * Return <code>this</code>. + */ + public org.omg.CORBA.Object duplicate(org.omg.CORBA.Object target) + { + return target; + } + + /** + * Create request for using with DII. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String method, NVList parameters, + NamedValue returns, ExceptionList exceptions, + ContextList ctx_list + ) + { + operation = method; + + LocalRequest rq = new LocalRequest(object, poa, Id); + rq.setOperation(method); + rq.set_args(parameters); + rq.set_result(returns); + rq.set_exceptions(exceptions); + rq.set_context_list(ctx_list); + return rq; + } + + /** + * Create request for using with DII. + */ + public Request create_request(org.omg.CORBA.Object target, Context context, + String method, NVList parameters, + NamedValue returns + ) + { + operation = method; + + LocalRequest rq = new LocalRequest(object, poa, Id); + rq.setOperation(method); + rq.set_args(parameters); + rq.set_result(returns); + return rq; + } + + /** + * Not in use. + */ + public org.omg.CORBA.Object get_interface_def(org.omg.CORBA.Object target) + { + throw new NO_IMPLEMENT(); + } + + /** + * Create a request to invoke the method of this CORBA object. + * + * @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 org.omg.CORBA.portable.OutputStream request(org.omg.CORBA.Object target, + String method, + boolean response_expected + ) + { + operation = method; + + // Check if the object is not explicitly deactivated. + activeObjectMap.Obj e = poa.aom.get(Id); + if (e != null && e.isDeactiveted()) + { + if (poa.servant_activator != null || poa.servant_locator != null) + { + // This will force the subsequent activation. + object.setServant(null); + e.setServant(null); + e.setDeactivated(false); + } + else + throw new OBJECT_NOT_EXIST("Deactivated"); + } + + LocalRequest rq = new LocalRequest(object, poa, Id); + rq.setOperation(method); + rq.setORB(orb(target)); + return rq.getParameterStream(); + } + + /** + * Return the associated invocation handler. + */ + public InvokeHandler getHandler(String method, CookieHolder cookie) + { + return object.getHandler(method, cookie, false); + } + + /** + * Return the ORB of the associated POA. The parameter is not in use. + */ + public ORB orb(org.omg.CORBA.Object target) + { + return poa.orb(); + } + + /** + * Make an invocation. + * + * @param target not in use. + * @param output the stream request that should be returned by {@link #request} + * in this method. + * @throws ApplicationException if the use exception is thrown by + * the servant method. + */ + public InputStream invoke(org.omg.CORBA.Object target, OutputStream output) + throws ApplicationException + { + streamRequest sr = (streamRequest) output; + + LocalRequest lr = (LocalRequest) sr.request; + InvokeHandler handler = lr.object.getHandler(lr.operation(), lr.cookie, false); + + if (handler instanceof dynImpHandler) + { + // The local request known how to handle it, but the different + // method must be called. + lr.invoke(); + + // The encapsulation will inherit orb, endian, charsets, etc. + cdrOutput buf = sr.createEncapsulation(); + + // Write all request parameters to the buffer stream. + if (lr.env().exception() != null) + { + try + { + UnknownUserException uex = + (UnknownUserException) lr.env().exception(); + throw new ApplicationException(uex.except.type().id(), + uex.except.create_input_stream() + ); + } + catch (BadKind ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + } + if (lr.return_value() != null) + lr.return_value().write_value(buf); + + NamedValue a; + try + { + for (int i = 0; i < lr.arguments().count(); i++) + { + a = lr.arguments().item(i); + if (a.flags() == ARG_INOUT.value || + a.flags() == ARG_INOUT.value + ) + { + a.value().write_value(buf); + } + } + } + catch (Bounds ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + + return buf.create_input_stream(); + } + else + return ((LocalRequest) sr.request).s_invoke(handler); + } + + public void releaseReply(org.omg.CORBA.Object target, InputStream input) + { + release(target); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/LocalRequest.java b/gnu/CORBA/Poa/LocalRequest.java new file mode 100644 index 000000000..3c2816d70 --- /dev/null +++ b/gnu/CORBA/Poa/LocalRequest.java @@ -0,0 +1,426 @@ +/* LocalRequest.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 gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.GIOP.MessageHeader; +import gnu.CORBA.Unexpected; +import gnu.CORBA.gnuAny; +import gnu.CORBA.gnuRequest; +import gnu.CORBA.streamReadyHolder; +import gnu.CORBA.streamRequest; + +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ORB; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.PortableServer.CurrentOperations; +import org.omg.PortableServer.CurrentPackage.NoContext; +import org.omg.PortableServer.DynamicImplementation; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; +import org.omg.PortableServer.portable.Delegate; + +import java.io.IOException; + +/** + * Directs the invocation to the locally available servant. + * The POA servant does not longer implement the CORBA object and + * cannot be substituted directly. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class LocalRequest + extends gnuRequest + implements ResponseHandler, CurrentOperations +{ + /** + * Used by servant locator, if involved. + */ + CookieHolder cookie; + + /** + * The object Id. + */ + final byte[] Id; + + /** + * The message header (singleton is sufficient). + */ + private static final MessageHeader header = new MessageHeader(); + + /** + * True if the stream was obtained by invoking {@link #createExceptionReply()}, + * false otherwise. + */ + boolean exceptionReply; + + /** + * The buffer to write into. + */ + cdrBufOutput buffer; + + /** + * The responsible POA. + */ + final gnuPOA poa; + + /** + * The servant delegate to obtain the handler. + */ + gnuServantObject object; + + /** + * Used (reused) with dynamic implementation. + */ + LocalServerRequest serverRequest; + + /** + * Create an instance of the local request. + */ + public LocalRequest(gnuServantObject local_object, gnuPOA a_poa, byte[] an_id) + { + Id = an_id; + poa = a_poa; + + // Instantiate the cookie holder only if required. + if (poa.servant_locator != null) + cookie = new CookieHolder(); + object = local_object; + prepareStream(); + } + + /** + * Make an invocation and return a stream from where the results + * can be read and throw ApplicationException, where applicable. + */ + org.omg.CORBA.portable.InputStream s_invoke(InvokeHandler handler) + throws ApplicationException + { + try + { + poa.m_orb.currents.put(Thread.currentThread(), this); + + org.omg.CORBA.portable.InputStream input = v_invoke(handler); + + if (!exceptionReply) + return input; + else + { + input.mark(500); + + String id = input.read_string(); + try + { + input.reset(); + } + catch (IOException ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + throw new ApplicationException(id, input); + } + } + finally + { + poa.m_orb.currents.remove(Thread.currentThread()); + } + } + + /** + * Make an invocation and return a stream from where the results + * can be read. + * + * @param the invoke handler (can be null, then it is obtained self + * dependently). + */ + public org.omg.CORBA.portable.InputStream v_invoke(InvokeHandler handler) + { + if (handler == null) + handler = object.getHandler(operation(), cookie, false); + + cdrBufOutput request_part = new cdrBufOutput(); + + request_part.setOrb(orb()); + + if (m_args != null && m_args.count() > 0) + { + write_parameters(header, request_part); + + if (m_parameter_buffer != null) + throw new BAD_INV_ORDER("Please either add parameters or " + + "write them into stream, but not both " + + "at once." + ); + } + + if (m_parameter_buffer != null) + { + write_parameter_buffer(header, request_part); + } + + Servant servant; + + if (handler instanceof Servant) + servant = (Servant) handler; + else + throw new BAD_OPERATION("Unexpected handler type " + handler); + + org.omg.CORBA.portable.InputStream input = + request_part.create_input_stream(); + + // Ensure the servant (handler) has a delegate set. + servantDelegate sd = null; + + Delegate d = null; + + try + { + d = servant._get_delegate(); + } + catch (Exception ex) + { + // In some cases exception is thrown if the delegate is not set. + } + if (d instanceof servantDelegate) + { + // If the delegate is already set, try to reuse the existing + // instance. + sd = (servantDelegate) d; + if (sd.object != object) + sd = new servantDelegate(servant, poa, Id); + } + else + sd = new servantDelegate(servant, poa, Id); + servant._set_delegate(sd); + + try + { + ORB o = orb(); + if (o instanceof ORB_1_4) + { + ((ORB_1_4) o).currents.put(Thread.currentThread(), this); + } + + handler._invoke(m_operation, input, this); + } + finally + { + ORB o = orb(); + if (o instanceof ORB_1_4) + ((ORB_1_4) o).currents.remove(Thread.currentThread()); + } + + if (poa.servant_locator != null) + poa.servant_locator.postinvoke(object.Id, poa, operation(), cookie.value, + object.getServant() + ); + + return buffer.create_input_stream(); + } + + /** + * Make an invocation and store the result in the fields of this + * Request. Used with DII only. + */ + public void invoke() + { + InvokeHandler handler = object.getHandler(operation(), cookie, false); + + if (handler instanceof dynImpHandler) + { + DynamicImplementation dyn = ((dynImpHandler) handler).servant; + if (serverRequest == null) + serverRequest = new LocalServerRequest(this); + try + { + poa.m_orb.currents.put(Thread.currentThread(), this); + dyn.invoke(serverRequest); + } + finally + { + poa.m_orb.currents.remove(Thread.currentThread()); + } + } + else + { + org.omg.CORBA.portable.InputStream input = v_invoke(handler); + + if (!exceptionReply) + { + NamedValue arg; + + // Read return value, if set. + if (m_result != null) + { + m_result.value().read_value(input, m_result.value().type()); + } + + // Read returned parameters, if set. + if (m_args != null) + for (int i = 0; i < m_args.count(); i++) + { + try + { + arg = m_args.item(i); + + // Both ARG_INOUT and ARG_OUT have this binary flag set. + if ((arg.flags() & ARG_OUT.value) != 0) + { + arg.value().read_value(input, arg.value().type()); + } + } + catch (Bounds ex) + { + Unexpected.error(ex); + } + } + } + else // User exception reply + { + // Prepare an Any that will hold the exception. + gnuAny exc = new gnuAny(); + + exc.insert_Streamable(new streamReadyHolder(input)); + + UnknownUserException unuex = new UnknownUserException(exc); + m_environment.exception(unuex); + } + } + } + + /** + * 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(); + 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()); + } + + /** + * Get the parameter stream, where the invocation arguments should + * be written if they are written into the stream directly. + */ + public streamRequest getParameterStream() + { + m_parameter_buffer = new streamRequest(); + m_parameter_buffer.request = this; + m_parameter_buffer.setOrb(poa.orb()); + return m_parameter_buffer; + } + + public byte[] get_object_id() + throws NoContext + { + return Id; + } + + public POA get_POA() + throws NoContext + { + return poa; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/LocalServerRequest.java b/gnu/CORBA/Poa/LocalServerRequest.java new file mode 100644 index 000000000..6d0b39650 --- /dev/null +++ b/gnu/CORBA/Poa/LocalServerRequest.java @@ -0,0 +1,199 @@ +/* LocalServerRequest.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 gnu.CORBA.gnuNamedValue; + +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.Context; +import org.omg.CORBA.NVList; +import org.omg.CORBA.NamedValue; +import org.omg.CORBA.ServerRequest; +import org.omg.CORBA.UnknownUserException; + +/** + * Used to make local invocations via LocalRequest. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class LocalServerRequest + extends ServerRequest +{ + /** + * The local request, on the base of that this instance is created. + */ + final LocalRequest request; + + /** + * Create a new instance. + */ + public LocalServerRequest(LocalRequest _request) + { + request = _request; + } + + /** + * Get the argument list that can be modified. + */ + public void params(NVList args) + { + arguments(args); + } + + /** + * Get contexts. + */ + public Context ctx() + { + return request.ctx(); + } + + /** + * Get the operatin being performed. + */ + public String operation() + { + return request.operation(); + } + + /** + * Get the argument list that can be modified. + * The direction depends on the size of the passed list. + * The empty list is filled with the request arguments. + * The non-empty list is used to set the request arguments. + */ + public void arguments(NVList args) + { + NVList l = request.arguments(); + NamedValue a; + + try + { + if (args.count() == 0) + { + // Transfer to the passed parameter. + for (int i = 0; i < l.count(); i++) + { + a = l.item(i); + args.add_value(a.name(), a.value(), a.flags()); + } + } + else + { + // Transfer from the passed parameter. + if (l.count() != args.count()) + throw new BAD_PARAM("Argument number mismatch, current " + + l.count() + ", passed " + args.count() + ); + try + { + for (int i = 0; i < l.count(); i++) + { + a = l.item(i); + if (a.flags() == ARG_INOUT.value || + a.flags() == ARG_OUT.value + ) + { + ((gnuNamedValue) a).setValue(args.item(i).value()); + } + } + } + catch (ClassCastException cex) + { + InternalError ierr = new InternalError(); + ierr.initCause(cex); + throw ierr; + } + } + } + catch (Bounds ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + } + + /** + * Set the result. + */ + public void set_result(Any result) + { + gnuNamedValue g = new gnuNamedValue(); + g.setValue(result); + g.setFlags(ARG_OUT.value); + request.set_result(g); + } + + /** + * Get the name of the method being called. + */ + public String op_name() + { + return request.operation(); + } + + /** + * Set the exception that has been thrown. + */ + public void set_exception(Any exc) + { + request.env().exception(new UnknownUserException(exc)); + } + + /** + * Set the result. + */ + public void result(Any r) + { + set_result(r); + } + + /** + * Set the exception. + */ + public void except(Any exc) + { + set_exception(exc); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/ORB_1_4.java b/gnu/CORBA/Poa/ORB_1_4.java new file mode 100644 index 000000000..6302ddf12 --- /dev/null +++ b/gnu/CORBA/Poa/ORB_1_4.java @@ -0,0 +1,136 @@ +/* poaORB.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 gnu.CORBA.Functional_ORB; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableServer.POAPackage.InvalidPolicy; + +/** + * The ORB, supporting POAs that are the feature of jdk 1.4. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ORB_1_4 + extends Functional_ORB +{ + /** + * The root POA. + */ + public final gnuPOA rootPOA; + + /** + * Maps the active threads to the invocation data ("Current's"). + */ + public gnuPoaCurrent currents = new gnuPoaCurrent(); + + /** + * Calls the parent constructor and additionally puts the "RootPOA" and + * "RootPOAManager" into initial references. + */ + public ORB_1_4() + { + super(); + try + { + rootPOA = new gnuPOA(null, "RootPOA", null, policySets.rootPoa(), this); + } + catch (InvalidPolicy ex) + { + // Invalid default policy set. + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + initial_references.put("RootPOA", rootPOA); + initial_references.put("RootPOAManager", rootPOA.the_POAManager()); + initial_references.put("POACurrent", currents); + } + + /** + * If the super method detects that the object is not connected to + * this ORB, try to find and activate the object. + */ + public String object_to_string(org.omg.CORBA.Object forObject) + { + try + { + return super.object_to_string(forObject); + } + catch (Exception ex) + { + try + { + activeObjectMap.Obj exists = rootPOA.findObject(forObject); + if (exists == null) + throw new OBJECT_NOT_EXIST(forObject == null ? "null" + : forObject.toString() + ); + else if (exists.poa instanceof gnuPOA) + ((gnuPOA) exists.poa).connect_to_orb(exists.key, forObject); + else + exists.poa.create_reference_with_id(exists.key, + ((ObjectImpl) exists.object)._ids() [ 0 ] + ); + } + catch (Exception bex) + { + BAD_PARAM bad = new BAD_PARAM("Unable to activate " + forObject); + bad.initCause(bex); + throw bad; + } + + return super.object_to_string(forObject); + } + } + + /** + * Destroy all poas and then call the superclass method. + */ + public void destroy() + { + // This will propagate through the whole POA tree. + rootPOA.destroy(true, false); + + super.destroy(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/activeObjectMap.java b/gnu/CORBA/Poa/activeObjectMap.java new file mode 100644 index 000000000..1354ba9c5 --- /dev/null +++ b/gnu/CORBA/Poa/activeObjectMap.java @@ -0,0 +1,394 @@ +/* activeObjectMap.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 gnu.CORBA.ByteArrayComparator; + +import org.omg.PortableServer.POA; +import org.omg.PortableServer.Servant; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * Implements the conception of the Active Object Map. + * If the POA supports the RETAIN policy, it maintains an Active + * Object Map, that associates Object Ids with active servants. + * Each association constitutes an active object. We use a single map + * for all POAs on the given orb. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class activeObjectMap +{ + /** + * The reference data about the object, placed on the AOM. + */ + public class Obj + { + /** + * Create an initialised instance. + */ + Obj(org.omg.CORBA.Object _object, byte[] _key, Servant _servant, POA _poa) + { + object = _object; + key = _key; + servant = _servant; + poa = _poa; + } + + /** + * The object. + */ + public final org.omg.CORBA.Object object; + + /** + * The servant, serving the given object. + */ + public Servant servant; + + /** + * The local servant that once served this object. + * This field is used by {@link ForwardedServant} when it discovers that + * the forwarding chaing returns back to the original location. + * It should not be used anywhere else. + */ + Servant primary_servant; + + /** + * The POA, where the object is connected. + */ + public final POA poa; + + /** + * The object key. + */ + public final byte[] key; + + /** + * If true, this entry is deactivated. + */ + public boolean deactivated; + + /** + * Set the servant value, preserving any non null + * value as the primary servant. + */ + public void setServant(Servant s) + { + if (primary_servant == null) + primary_servant = s; + servant = s; + } + + /** + * Get the servant. + */ + public Servant getServant() + { + return servant; + } + + /** + * Get the deactivation state. + */ + public boolean isDeactiveted() + { + return deactivated; + } + + /** + * Set the deactivation state. + */ + public void setDeactivated(boolean state) + { + deactivated = state; + } + + public boolean equals(java.lang.Object other) + { + if (other instanceof Obj) + { + Obj o = (Obj) other; + return o.object.equals(object); + } + 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_id; + + /** + * The map of the all connected objects, maps the object key to the + * object. + */ + Map objects = new TreeMap(new ByteArrayComparator()); + + /** + * Get the record of the stored object. If the object is mapped + * several times under the different keys, one of the mappings + * is used. + * + * @param object the stored object + * + * @return the record about the stored object, null if + * this object is not stored here. + */ + public Obj findObject(org.omg.CORBA.Object stored_object) + { + if (stored_object == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (stored_object.equals(ref.object)) + return ref; + } + return null; + } + + /** + * Find the reference info for the given servant. + * If the servant is mapped to several objects, this + * returns the first found occurence. + * + * @param servant a servant to find. + * + * @return the servant/object/POA binding or null if no such found. + */ + public Obj findServant(Servant servant) + { + if (servant == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (servant.equals(ref.servant)) + return ref; + } + return null; + } + + /** + * Find the reference info for the given servant. + * If the servant is mapped to several objects, this + * returns the first found occurence. + * + * @param servant a servant to find. + * @param speficies if to search for the inactive (true) or active + * (false) servant. A servant with unmatching activity is ignored + * by this method. + * + * @return the servant/object/POA binding or null if no such found. + */ + public Obj findServant(Servant servant, boolean inactive) + { + if (servant == null) + return null; + + Map.Entry item; + Iterator iter = objects.entrySet().iterator(); + Obj ref; + + while (iter.hasNext()) + { + item = (Map.Entry) iter.next(); + ref = (Obj) item.getValue(); + if (ref.deactivated == inactive) + if (ref.servant != null) + if (servant.equals(ref.servant)) + return ref; + } + return null; + } + + /** + * Add the new object to the repository. The object key is + * generated automatically. + * + * @param object the object to add. + * @param servant a servant, serving the given object. + * @param poa the poa, where the object is connected. + * + * @return the newly created object record. + */ + public Obj add(org.omg.CORBA.Object object, Servant servant, POA poa) + { + return add(generateObjectKey(object), object, servant, poa); + } + + /** + * Add the new object to the repository. + * + * @param key the object key. + * @param object the object to add. + * @param servant a servant, serving the given object. + * @param poa the POA, where the object is connected. + */ + public Obj add(byte[] key, org.omg.CORBA.Object object, Servant servant, + POA poa + ) + { + Obj rec = new Obj(object, key, servant, poa); + objects.put(key, rec); + return rec; + } + + /** + * Add the new object to the repository. + * + * @param delegate the delegate, providing data about the servant, key, POA + * and object. + * @param port the port that this object would take. + */ + public Obj add(servantDelegate delegate) + { + Obj rec = + new Obj(delegate.object, delegate.servant_id, delegate.servant, + delegate.poa + ); + objects.put(delegate.servant_id, rec); + return rec; + } + + /** + * Put back the definition structure that has probably been removed earlier. + */ + public void put(Obj obj) + { + objects.put(obj.key, obj); + } + + /** + * Get the stored object. + * + * @param key the key (in the byte array form). + * + * @return the matching object, null if none is matching. + */ + public Obj get(byte[] key) + { + return (Obj) objects.get(key); + } + + /** + * Get the map key set. + */ + public Set keySet() + { + return objects.keySet(); + } + + /** + * 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 passed object + * parameter is currently not in use. + * + * @return the generated key. + */ + protected byte[] generateObjectKey(org.omg.CORBA.Object object) + { + byte[] key; + + // The repetetive keys cannot be generated, but theoretically + // the same keys can be passed when calling add(byte[]...). + // Hence we check if the key is not already in the map and, + // if it is, use the subsequent value. + do + { + key = getFreeId(); + } + while (objects.containsKey(key)); + return key; + } + + /** + * Get the next free 8 byte id, surely unique between calls of this + * method for the currently running virtual machine. + */ + public static synchronized byte[] getFreeId() + { + byte[] r = new byte[ 8 ]; + + // Start from the faster-changing. + r [ 0 ] = ((byte) (0xff & free_id)); + r [ 1 ] = ((byte) (0xff & (free_id >> 8))); + r [ 2 ] = ((byte) (0xff & (free_id >> 16))); + r [ 3 ] = ((byte) (0xff & (free_id >> 24))); + r [ 4 ] = ((byte) (0xff & (free_id >> 32))); + r [ 5 ] = ((byte) (0xff & (free_id >> 40))); + r [ 6 ] = ((byte) (0xff & (free_id >> 48))); + r [ 7 ] = ((byte) (0xff & (free_id >> 56))); + + free_id++; + + return r; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/dynImpHandler.java b/gnu/CORBA/Poa/dynImpHandler.java new file mode 100644 index 000000000..1cc3e131c --- /dev/null +++ b/gnu/CORBA/Poa/dynImpHandler.java @@ -0,0 +1,85 @@ +/* dynImpHandler.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.BAD_OPERATION; +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.PortableServer.DynamicImplementation; + +/** + * The InvokeHandler, indicating, that the target is a dynamic + * implementation rather than an invoke handler. These two + * types are not substitutable, but in some methods have possibility + * just to handle them differently. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class dynImpHandler + implements InvokeHandler +{ + /** + * The servant that is a dynamic implementation rather than + * invoke handler. + */ + public final DynamicImplementation servant; + + /** + * Create a new instance, wrapping some dyn implementation. + * @param _servant + */ + public dynImpHandler(DynamicImplementation _servant) + { + servant = _servant; + } + + /** + * We cannot invoke properly without having parameter info. + * + * @throws BAD_OPERATION, always. + */ + public OutputStream _invoke(String method, InputStream input, + ResponseHandler handler + ) + { + throw new BAD_OPERATION(servant + " is not an InvokeHandler."); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuAdapterActivator.java b/gnu/CORBA/Poa/gnuAdapterActivator.java new file mode 100644 index 000000000..3019a2ae9 --- /dev/null +++ b/gnu/CORBA/Poa/gnuAdapterActivator.java @@ -0,0 +1,81 @@ +/* gnuAdapterActivator.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.LocalObject; +import org.omg.PortableServer.AdapterActivator; +import org.omg.PortableServer.POA; + +/** + * Defines a simple adapter activator. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuAdapterActivator + extends LocalObject + implements AdapterActivator +{ + /** + * Create a new POA on the parent, using the parent policy set + * from the suitable parent of grandparend and with independent + * POA manager (passing null to the createPOA). + * + * @param parent a parent. Either this parent or one of its + * grandparents must be gnuAbstractPOA, able to provide a + * policy set. + * + * @param child_name the name of the child being created. + * + * @return true on success or false if no gnuAbstractPOA + * found till the root poa. + */ + public boolean unknown_adapter(POA parent, String child_name) + { + try + { + POA n = parent.create_POA(child_name, null, policySets.rootPoa()); + n.the_POAManager().activate(); + } + catch (Exception ex) + { + return false; + } + return true; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuForwardRequest.java b/gnu/CORBA/Poa/gnuForwardRequest.java new file mode 100644 index 000000000..02fc42470 --- /dev/null +++ b/gnu/CORBA/Poa/gnuForwardRequest.java @@ -0,0 +1,90 @@ +/* gnuForwardRequest.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 gnu.CORBA.GIOP.ReplyHeader; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.portable.ObjectImpl; + +/** + * The class, indicating that the request should be forwarded to another + * target. We cannot use ForwardRequest because the exception is throws + * from methods that does not declare throwing it. Hence must be + * RuntimeException. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuForwardRequest + extends RuntimeException +{ + /** + * Use serialVersionUID (v1.4) for interoperability. + */ + private static final long serialVersionUID = -1L; + + /** + * The object reference, indicating the new location of the invocation target. + */ + public ObjectImpl forward_reference; + + /** + * This information shows if we use LOCATION_FORWARD or + * LOCATION_FORWARD_PERM in request. By defalult, LOCATION_FORWARD + * is always used. To use LOCATION_FORWARD_PERM, this exception should + * be thrown from the servant manager instead of ForwardRequest, + * with this field set to ReplyHeader.LOCATION_FORWARD_PERM. + */ + public byte forwarding_code = ReplyHeader.LOCATION_FORWARD; + + /** + * Create the ForwardRequest with explaining message and + * initialising the object reference to the given value. + * + * @param why a string, explaining, why this exception has been thrown. + * @param a_forward_reference a value for forward_reference. + */ + public gnuForwardRequest(org.omg.CORBA.Object a_forward_reference) + { + if (a_forward_reference instanceof ObjectImpl) + this.forward_reference = (ObjectImpl) a_forward_reference; + else + throw new BAD_PARAM("ObjectImpl expected"); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java b/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java new file mode 100644 index 000000000..a404486ce --- /dev/null +++ b/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java @@ -0,0 +1,80 @@ +/* gnuIdAssignmentPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID; +import org.omg.PortableServer.IdAssignmentPolicy; +import org.omg.PortableServer.IdAssignmentPolicyValue; + +/** + * Implementation of the id assignment policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuIdAssignmentPolicy + extends _PolicyImplBase + implements IdAssignmentPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuIdAssignmentPolicy(IdAssignmentPolicyValue v) + { + super(ID_ASSIGNMENT_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/IdAssignmentPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public IdAssignmentPolicyValue value() + { + return (IdAssignmentPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java b/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java new file mode 100644 index 000000000..2abd1f484 --- /dev/null +++ b/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java @@ -0,0 +1,80 @@ +/* gnuIdUniquenessPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.ID_UNIQUENESS_POLICY_ID; +import org.omg.PortableServer.IdUniquenessPolicy; +import org.omg.PortableServer.IdUniquenessPolicyValue; + +/** + * Implementation of the id uniqueness policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuIdUniquenessPolicy + extends _PolicyImplBase + implements IdUniquenessPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuIdUniquenessPolicy(IdUniquenessPolicyValue v) + { + super(ID_UNIQUENESS_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/IdUniquenessPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public IdUniquenessPolicyValue value() + { + return (IdUniquenessPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java b/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java new file mode 100644 index 000000000..1e539a2c4 --- /dev/null +++ b/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java @@ -0,0 +1,80 @@ +/* gnuImplicitActivationPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.IMPLICIT_ACTIVATION_POLICY_ID; +import org.omg.PortableServer.ImplicitActivationPolicy; +import org.omg.PortableServer.ImplicitActivationPolicyValue; + +/** + * Implementation of the implicit activation policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuImplicitActivationPolicy + extends _PolicyImplBase + implements ImplicitActivationPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuImplicitActivationPolicy(ImplicitActivationPolicyValue v) + { + super(IMPLICIT_ACTIVATION_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/ImplicitActivationPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public ImplicitActivationPolicyValue value() + { + return (ImplicitActivationPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuLifespanPolicy.java b/gnu/CORBA/Poa/gnuLifespanPolicy.java new file mode 100644 index 000000000..97b3f2d7a --- /dev/null +++ b/gnu/CORBA/Poa/gnuLifespanPolicy.java @@ -0,0 +1,80 @@ +/* gnuLifespanPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.LIFESPAN_POLICY_ID; +import org.omg.PortableServer.LifespanPolicy; +import org.omg.PortableServer.LifespanPolicyValue; + +/** + * The implementation of the life span policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuLifespanPolicy + extends _PolicyImplBase + implements LifespanPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuLifespanPolicy(LifespanPolicyValue v) + { + super(LIFESPAN_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/LifespanPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public LifespanPolicyValue value() + { + return (LifespanPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuPOA.java b/gnu/CORBA/Poa/gnuPOA.java new file mode 100644 index 000000000..1d9e83853 --- /dev/null +++ b/gnu/CORBA/Poa/gnuPOA.java @@ -0,0 +1,1615 @@ +/* gnuAbstractPOA.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 java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; + +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.OBJ_ADAPTER; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Policy; +import org.omg.CORBA.SetOverrideType; +import org.omg.CORBA.TRANSIENT; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableServer.AdapterActivator; +import org.omg.PortableServer.ForwardRequest; +import org.omg.PortableServer.IdAssignmentPolicy; +import org.omg.PortableServer.IdAssignmentPolicyValue; +import org.omg.PortableServer.IdUniquenessPolicy; +import org.omg.PortableServer.IdUniquenessPolicyValue; +import org.omg.PortableServer.ImplicitActivationPolicy; +import org.omg.PortableServer.ImplicitActivationPolicyValue; +import org.omg.PortableServer.LifespanPolicy; +import org.omg.PortableServer.LifespanPolicyValue; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.RequestProcessingPolicy; +import org.omg.PortableServer.RequestProcessingPolicyValue; +import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantActivator; +import org.omg.PortableServer.ServantLocator; +import org.omg.PortableServer.ServantManager; +import org.omg.PortableServer.ServantRetentionPolicy; +import org.omg.PortableServer.ServantRetentionPolicyValue; +import org.omg.PortableServer.ThreadPolicy; +import org.omg.PortableServer.ThreadPolicyValue; +import org.omg.PortableServer.POAManagerPackage.State; +import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.AdapterNonExistent; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import org.omg.PortableServer.POAPackage.NoServant; +import org.omg.PortableServer.POAPackage.ObjectAlreadyActive; +import org.omg.PortableServer.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantAlreadyActive; +import org.omg.PortableServer.POAPackage.ServantNotActive; +import org.omg.PortableServer.POAPackage.WrongAdapter; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; + +/** + * Our POA implementation. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuPOA + extends LocalObject + implements POA +{ + /** + * The active object map, mapping between object keys, objects and servants. + */ + public final activeObjectMap aom = new activeObjectMap(); + + /** + * The children of this POA. + */ + final ArrayList children = new ArrayList(); + + /** + * The name of this POA. + */ + final String name; + + /** + * The parent of this POA (null for the root POA). + */ + final POA parent; + + /** + * The ior key signature, indicating, that the ior key is encoded using + * internal agreements of this implementation (0x'free'). + */ + static final int SIGNATURE = 0x66726565; + + /** + * The adapter activator for this POA, null if no activator is set. + */ + AdapterActivator m_activator; + + /** + * The POA manager for this POA. + */ + POAManager m_manager; + + /** + * The servant manager (servant activator) for this POA. + */ + ServantActivator servant_activator; + + /** + * The servant manager (servant locator) for this POA. + */ + ServantLocator servant_locator; + + /** + * The default servant, if on is in use. + */ + Servant default_servant; + + /** + * The cached poa id value, computed once. + */ + private byte[] m_poa_id; + + /** + * The all policy values that apply to this POA. + * The used policy values are singletons, unique between policies. + */ + private final HashSet m_policies; + + /** + * An array of the set policies. + */ + Policy[] s_policies; + + /** + * The ORB, where the POA is connected. + */ + final ORB_1_4 m_orb; + + /** + * When true, the POA is being destroyed or is destroyed. + */ + boolean m_inDestruction; + + /** + * True if the active object map is used by this POA. + * The value is moved into separate boolean value due + * necessity of the frequent checks. + */ + public final boolean retain_servant; + + /** + * Create a new abstract POA. + * + * @param a_parent the parent of this POA. + * @param a_name a name for this POA. + * @param a_manager a manager for this POA. If null, a new + * {@link gnuPOAManager} will be instantiated. + * @param a_policies an array of policies that apply to this POA. + * @param an_orb an ORB for this POA. + */ + public gnuPOA(gnuPOA a_parent, String a_name, POAManager a_manager, + Policy[] a_policies, ORB_1_4 an_orb + ) + throws InvalidPolicy + { + // Add default policies. + Policy[] all_policies = policySets.withDefault(a_policies); + + name = a_name; + parent = a_parent; + m_orb = an_orb; + + if (a_manager != null) + m_manager = a_manager; + else + m_manager = new gnuPOAManager(); + + if (m_manager instanceof gnuPOAManager) + { + gnuPOAManager g = (gnuPOAManager) m_manager; + g.addPoa(this); + } + + m_policies = new HashSet(all_policies.length); + + s_policies = new Policy[ all_policies.length ]; + for (int i = 0; i < s_policies.length; i++) + { + s_policies [ i ] = all_policies [ i ].copy(); + m_policies.add(((vPolicy) s_policies [ i ]).getValue()); + } + + retain_servant = applies(ServantRetentionPolicyValue.RETAIN); + + validatePolicies(a_policies); + } + + /** + * Wait while at least one of the threads in this POA is actively + * processing one of requests. + */ + public void waitWhileRunning() + { + // First pause. + long time = 1; + + // Maximal duration between checks. + long max = 500; + + boolean runs; + + do + { + runs = m_orb.currents.has(this); + + if (runs) + { + // Avoid taking CPU resources + // from the thread that is running. + try + { + Thread.sleep(time); + time = time * 2; + if (time > max) + time = max; + } + catch (InterruptedException ex) + { + } + } + } + while (runs); + } + + /** + * Etherealize all objects, associated with this POA. Invoked from the + * {@link gnuPOAManager} only if it is known that the servant_activator + * holds non-null value. + */ + protected void etherealizeAll() + { + if (servant_activator == null) + return; + + ArrayList keys = new ArrayList(); + keys.addAll(aom.keySet()); + + byte[] key; + activeObjectMap.Obj obj; + boolean last; + for (int i = 0; i < keys.size(); i++) + { + key = (byte[]) keys.get(i); + obj = aom.get(key); + + if (obj.poa == this) + { + aom.remove(key); + + if (!obj.isDeactiveted()) + { + // Check if the servant still stays under the other key. + last = aom.findServant(obj.servant) == null; + servant_activator.etherealize(obj.key, this, obj.servant, true, + last + ); + } + } + } + } + + /** + * Create an instance of the POA with the given features. + * This method is not responsible for duplicate checking + * or adding the returned instance to any possible table. + * + * @param child_name the name of the poa being created. + * @param manager the poa manager (never null). + * @param policies the array of policies. + * @param an_orb the ORB for this POA. + * + * @return the created POA. + * + * @throws InvalidPolicy for conflicting or otherwise invalid policies.| + */ + protected POA createPoaInstance(String child_name, POAManager a_manager, + Policy[] policies, ORB_1_4 an_orb + ) + throws InvalidPolicy + { + POAManager some_manager = + a_manager == null ? new gnuPOAManager() : a_manager; + + if (some_manager instanceof gnuPOAManager) + { + ((gnuPOAManager) some_manager).addPoa(this); + } + + return new gnuPOA(this, child_name, some_manager, policies, an_orb); + } + + /** + * Check if the given policy value applies to this POA. + * + * @param policy_value a policy value to check. The policy values are + * singletons and unique between the different policies, so the policy + * type is not passed. + * + * @return true if the policy value applies, false otherwise. + */ + public final boolean applies(java.lang.Object policy_value) + { + return m_policies.contains(policy_value); + } + + /** + * Check for the presence of the required policy. + * + * @param policy_value a policy value to check. + * + * @throws WrongPolicy if the required policy value is not applicable. + */ + public final void required(java.lang.Object policy_value) + throws WrongPolicy + { + if (!applies(policy_value)) + throw new WrongPolicy(policy_value + " policy required."); + } + + /** + * Check for the absence of the given policy. + * + * @param policy_value a policy value to check. + * + * @throws WrongPolicy if the passed policy value is applicable. + */ + public final void excluding(java.lang.Object policy_value) + throws WrongPolicy + { + if (applies(policy_value)) + throw new WrongPolicy(policy_value + " policy applies."); + } + + /** + * Find and optionally activate the child POA with the given name. + * + * @param poa_name the name of the POA to find. + * @param activate_it if the child with the specified name is not found + * or inactive and this parameter is true, the target POA activator is + * invoked to activate that child. If this succeeds, that child POA + * is returned. + * + * @throws AdapterNonExistent if no active child with the given name + * is found and one of the following is true: + * a) the target POA has no associated + * {@link AdapterActivator}. b) that activator fails to activate the + * child POA. c) <code>activate_id</code> = false. + */ + public POA find_POA(String poa_name, boolean activate_it) + throws AdapterNonExistent + { + POA child; + for (int i = 0; i < children.size(); i++) + { + child = (POA) children.get(i); + if (child.the_name().equals(poa_name)) + return child; + } + + if (activate_it && m_activator != null) + { + boolean activated = m_activator.unknown_adapter(this, poa_name); + if (!activated) + throw new AdapterNonExistent(poa_name + " activation failed."); + + // Tha activator should add the child to the childrent table. + for (int i = 0; i < children.size(); i++) + { + child = (POA) children.get(i); + if (child.the_name().equals(poa_name)) + return child; + } + throw new AdapterNonExistent(poa_name + " not created. "); + } + else + throw new AdapterNonExistent(poa_name); + } + + /** + * Generate the Object Id for the given servant and add the servant to + * the Active Object Map using this Id a a key. If the servant + * activator is set, its incarnate method will be called. + * + * @param a_servant a servant that would serve the object with the + * returned Object Id. If null is passed, under apporoprate policies the + * servant activator is invoked. + * + * @return the generated objert Id for the given servant. + * + * @throws ServantAlreadyActive if this servant is already in the + * Active Object Map and the UNIQUE_ID policy applies. + * + * @throws WrongPolicy if the required policies SYSTEM_ID and RETAIN + * do not apply to this POA. + */ + public byte[] activate_object(Servant a_servant) + throws ServantAlreadyActive, WrongPolicy + { + checkDiscarding(); + required(ServantRetentionPolicyValue.RETAIN); + required(IdAssignmentPolicyValue.SYSTEM_ID); + + activeObjectMap.Obj exists = aom.findServant(a_servant); + + if (exists != null) + { + if (exists.isDeactiveted()) + { + // If exists but deactivated, activate and return + // the existing key. + exists.setDeactivated(false); + incarnate(exists, exists.key, a_servant, false); + return exists.key; + } + else if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) + throw new ServantAlreadyActive(); + + // It multiple ids are allowed, exit block allowing repetetive + // activations. + } + + byte[] object_key = activeObjectMap.getFreeId(); + servantDelegate delegate = new servantDelegate(a_servant, this, object_key); + connectDelegate(object_key, delegate); + return object_key; + } + + /** + * Add the given servant to the Active Object Map as a servant for the + * object with the provided Object Id. If the servant activator is + * set, its incarnate method will be called. + * + * @param an_Object_Id an object id for the given object. + * @param a_servant a servant that will serve the object with the given + * Object Id. If null is passed, under apporoprate policies the + * servant activator is invoked. + * + * @throws ObjectAlreadyActive if the given object id is already in the + * Active Object Map. + * @throws ServantAlreadyActive if the UNIQUE_ID policy applies and + * this servant is already in use. + * @throws WrongPolicy if the required RETAIN policy does not apply to + * this POA. + * @throws BAD_PARAM if the passed object id is invalid due any reason. + */ + public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant) + throws ServantAlreadyActive, ObjectAlreadyActive, + WrongPolicy + { + activate_object_with_id(an_Object_Id, a_servant, false); + } + + /** + * Same as activate_object_with_id, but permits gnuForwardRequest + * forwarding exception. This is used when the activation is called + * from the remote invocation context and we have possibility + * to return the forwarding message. + */ + public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant, + boolean use_forwarding + ) + throws ServantAlreadyActive, ObjectAlreadyActive, + WrongPolicy + { + checkDiscarding(); + required(ServantRetentionPolicyValue.RETAIN); + + // If the UNIQUE_ID applies, the servant being passed must not be + // already active. + if (applies(IdUniquenessPolicyValue.UNIQUE_ID)) + { + activeObjectMap.Obj sx = aom.findServant(a_servant, false); + if (sx != null) + throw new ServantAlreadyActive(); + } + + activeObjectMap.Obj exists = aom.get(an_Object_Id); + if (exists != null) + { + if (exists.servant == null) + { + locateServant(an_Object_Id, a_servant, exists, use_forwarding); + exists.setDeactivated(false); + } + else if (exists.isDeactiveted()) + { + exists.setDeactivated(false); + incarnate(exists, an_Object_Id, a_servant, use_forwarding); + } + else + throw new ObjectAlreadyActive(); + } + else + { + servantDelegate delegate = + new servantDelegate(a_servant, this, an_Object_Id); + connectDelegate(an_Object_Id, delegate); + } + } + + /** + * Locate the servant for this object Id and connect it to ORB. + * + * @param an_Object_Id the object id. + * @param a_servant the servant (may be null). + * @param exists an existing active object map entry. + * @param use_forwarding allow to throw the gnuForwardRequest + * if the activator throws ForwardRequest. + * + * @throws OBJ_ADAPTER minor 4 if the servant cannot be located + * (the required servant manager may be missing). + */ + private void locateServant(byte[] an_Object_Id, Servant a_servant, + activeObjectMap.Obj exists, boolean use_forwarding + ) + throws InternalError + { + // An object was created with create_reference. + gnuServantObject object = (gnuServantObject) exists.object; + if (servant_activator != null) + { + exists.setServant(incarnate(exists, an_Object_Id, a_servant, + use_forwarding + ) + ); + } + else if (default_servant != null) + { + exists.setServant(default_servant); + } + if (exists.servant == null) + { + exists.setServant(a_servant); + } + if (exists.servant == null) + { + throw new OBJ_ADAPTER("no servant", 4, CompletionStatus.COMPLETED_NO); + } + + servantDelegate delegate = + new servantDelegate(exists.servant, this, an_Object_Id); + exists.servant._set_delegate(delegate); + object.setServant(exists.servant); + connect_to_orb(an_Object_Id, delegate.object); + } + + /** + * Deactivate object with the given id. + * + * The deactivated object will continue to process requests that arrived + * before decativation. If this POA has the associated + * servant manager, a {@link ServantActivatorOperations#etherealize} is + * immediately invoked on the passed id. + * + * @throws WrongPolicy if the required RETAIN policy does not apply to + * this POA. + */ + public void deactivate_object(byte[] the_Object_Id) + throws ObjectNotActive, WrongPolicy + { + required(ServantRetentionPolicyValue.RETAIN); + + activeObjectMap.Obj exists = aom.get(the_Object_Id); + + if (exists == null || exists.isDeactiveted()) + throw new ObjectNotActive(); + + exists.setDeactivated(true); + + // Check if this servant is serving something else. + aom.remove(the_Object_Id); + + activeObjectMap.Obj other = aom.findServant(exists.servant, false); + + boolean remaining = other != null; + + aom.put(exists); + + if (servant_activator != null) + servant_activator.etherealize(the_Object_Id, this, exists.servant, false, + remaining + ); + } + + /** + * Create the object reference, encapsulating the given repository Id and + * the Object Id, generated by this POA. The returned object will not be + * activated by default and may be activated on the first invocation by + * the servant manager (if it is set and if policies are applicable). + * + * @param a_repository_id the repository id for the given object, can + * be null if to be requested from the servant later. + * + * @throws WrongPolicy if the required SYSTEM_ID policy does not apply to + * this POA. + */ + public org.omg.CORBA.Object create_reference(String a_repository_id) + throws WrongPolicy + { + required(IdAssignmentPolicyValue.SYSTEM_ID); + return create_reference_with_id(activeObjectMap.getFreeId(), a_repository_id); + } + + /** + * <p> + * Create the object reference, encapsulating the given repository Id and + * the given Object Id. The returned object will <i>not</i> be + * activated by default and may be activated on the first invocation by + * the servant manager (if the IMPLICIT_ACTIVATION policy applies). + * + * @param an_object_id the object id for the object being created. If this + * POA uses the SYSTEM_ID policy, the portable application should only + * pass the ids, generated by this POA. + * + * @param a_repository_id the repository id for the object being created, + * can be null if this information should be later requested from the + * servant. + */ + public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id, + String a_repository_id + ) + { + String[] ids; + if (a_repository_id == null) + ids = null; + else + ids = new String[] { a_repository_id }; + + // Check maybe such object is already activated. + activeObjectMap.Obj e = aom.get(an_object_id); + + Servant servant; + if (e == null) + { + servant = null; + } + else + { + servant = e.servant; + e.setDeactivated(false); + } + + gnuServantObject object = + new gnuServantObject(ids, an_object_id, this, m_orb); + object._set_delegate(new LocalDelegate(object, this, an_object_id)); + aom.add(object.Id, object, servant, this); + connect_to_orb(an_object_id, object); + + return object; + } + + /** + * Creates a new POA as a child of the target POA. + * + * @param child_name the name of the child POA being created. + * @param manager the manager that will control the new POA. If this parameter + * is null, a new POA manager is created and associated with the new POA. + * + * @param policies the policies, applicable for the parent POA. Policies + * are <i>not</i> inherited from the parent POA. + * + * @return an newly created POA. The POA will be intially in the holding + * state and must be activated to start processing requests. + * + * @throws AdapterAlreadyExists if the child with the given child_name + * already exists for the current POA. + * @throws InvalidPolicy if the policies conflict with each other or are + * otherwise inappropriate. + * + * @see #the_children() + */ + public POA create_POA(String child_name, POAManager manager, Policy[] policies) + throws AdapterAlreadyExists, InvalidPolicy + { + POA child; + for (int i = 0; i < children.size(); i++) + { + child = (POA) children.get(i); + if (child.the_name().equals(child_name)) + throw new AdapterAlreadyExists(name + "/" + child_name); + } + + POA poa = createPoaInstance(child_name, manager, policies, m_orb); + children.add(poa); + return poa; + } + + /** + * Returns a default servant for this POA. + * + * @return a servant that will be used for requests for + * which no servant is found in the Active Object Map. + * + * @throws NoServant if there is no default servant associated with this POA. + * @throws WrongPolicy if the USE_DEFAULT_SERVANT policy is not active. + */ + public Servant get_servant() + throws NoServant, WrongPolicy + { + required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); + if (default_servant == null) + throw new NoServant(); + return default_servant; + } + + /** + * Sets the default servant for this POA. + * + * @param a_servant a servant that will be used for requests for + * which no servant is found in the Active Object Map. + * + * @throws WrongPolicy if the USE_DEFAULT_SERVANT policy is not active. + */ + public void set_servant(Servant a_servant) + throws WrongPolicy + { + required(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); + default_servant = a_servant; + } + + /** + * Set a servant manager for this POA. + * + * @param a servant manager being set. If the RETAIN policy applies, the + * manager must implement a {@link ServantActivator}. If the NON_RETAIN + * policy applies, the manager must implement a {@link ServantLocator}. + * + * @throws WrongPolicy if the required USE_SERVANT_MANAGER policy does not + * apply to this POA. + * + * @throws OBJ_ADAPTER minor code 4 if the passed manager does not + * implement the required interface ({@link ServantActivator}, + * {@link ServantLocator}). The POA, that has the RETAIN policy uses + * servant managers that are ServantActivators. When the POA has the + * NON_RETAIN policy it uses servant managers that are ServantLoacators. + * + * @throws BAD_INV_ORDER minor code 6 if the method is called more than once + * on the same POA. The manager can be set only once. + */ + public void set_servant_manager(ServantManager a_manager) + throws WrongPolicy + { + required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); + if (servant_activator != null || servant_locator != null) + throw new BAD_INV_ORDER("Setting manager twice for " + name, 6, + CompletionStatus.COMPLETED_NO + ); + + if (applies(ServantRetentionPolicyValue.RETAIN)) + { + if (a_manager instanceof ServantActivator) + servant_activator = (ServantActivator) a_manager; + else + throw new OBJ_ADAPTER("RETAIN requires ServantActivator", 4, + CompletionStatus.COMPLETED_NO + ); + } + else if (applies(ServantRetentionPolicyValue.NON_RETAIN)) + { + if (a_manager instanceof ServantLocator) + servant_locator = (ServantLocator) a_manager; + else + throw new OBJ_ADAPTER("NON_RETAIN requires ServantLocator", 4, + CompletionStatus.COMPLETED_NO + ); + } + else + throw new WrongPolicy("No servant retention policy is specified."); + } + + /** + * Get the servant manager, associated with this POA. + * + * @return the associated servant manager or null if it has + * been previously set. + * + * @throws WrongPolicy if the required USE_SERVANT_MANAGER policy does not + * apply to this POA. + */ + public ServantManager get_servant_manager() + throws WrongPolicy + { + required(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); + + if (servant_activator != null) + return servant_activator; + else + return servant_locator; + } + + /** + * Get the unique Id of the POA in the process in which it is created. + * This Id is needed by portable interceptors. The id is unique + * for the life span of the POA in the process. For persistent + * POAs, if a POA is created in the same path with the same name as + * another POA, these POAs are identical have the same id. All transient + * POAs are assumed unique. + */ + public byte[] id() + { + if (m_poa_id != null) + return m_poa_id; + else + { + cdrBufOutput buffer = new cdrBufOutput(); + POA p = this; + while (p != null) + { + buffer.write_string(p.the_name()); + p = p.the_parent(); + } + m_poa_id = buffer.buffer.toByteArray(); + return m_poa_id; + } + } + + /** + * Returns the reference to the active object with the given Id. + * + * @param the_Object_Id the object id. + * + * @throws ObjectNotActive if there is no active object with such Id + * in the scope of this POA. + * @throws WrongPolicy if the required RETAIN policy does not apply to + * this POA. + */ + public org.omg.CORBA.Object id_to_reference(byte[] the_Object_Id) + throws ObjectNotActive, WrongPolicy + { + required(ServantRetentionPolicyValue.RETAIN); + + activeObjectMap.Obj ref = aom.get(the_Object_Id); + if (ref == null) + throw new ObjectNotActive(); + else + return ref.object; + } + + /** + * Returns the servant that serves the active object with the given Id. + * + * @param the_Object_Id the object id. + * + * @throws ObjectNotActive if there is no active object with such Id or + * it is not currently active. + * @throws WrongPolicy. This method requires either RETAIN or + * USE_DEFAULT_SERVANT policies and reaises the WrongPolicy if none of them + * apply to this POA. + */ + public Servant id_to_servant(byte[] the_Object_Id) + throws ObjectNotActive, WrongPolicy + { + if (applies(ServantRetentionPolicyValue.RETAIN)) + { + activeObjectMap.Obj ref = aom.get(the_Object_Id); + if (ref == null || ref.isDeactiveted()) + { + if (default_servant != null) + return default_servant; + else + throw new ObjectNotActive(); + } + else if (ref.servant != null) + return ref.servant; + else if (default_servant != null) + return default_servant; + else + throw new ObjectNotActive(); + } + else if (default_servant != null) + { + return default_servant; + } + else + throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required."); + } + + /** + * Returns the Object Id, encapsulated in the given object reference. + * + * @param the_Object the object that has been previously created with this + * POA. It need not be active. + * + * @throws WrongAdapter if the passed object is not known for this POA. + * @throws WrongPolicy never (declared for the future extensions only). + */ + public byte[] reference_to_id(org.omg.CORBA.Object the_Object) + throws WrongAdapter, WrongPolicy + { + activeObjectMap.Obj ref = aom.findObject(the_Object); + if (ref == null) + throw new WrongAdapter(); + return ref.key; + } + + /** + * Returns the servant that is serving this object. + * + * @return if the RETAIN policy applies and the object is in the Active + * Object Map, the method returns the servant, associated with this object. + * Otherwise, if the USE_DEFAULT_SERVANT policy applies, the method returns + * the default servant (if one was set). + * + * @throws ObjectNotActive if none of the conditions above are satisfied. + * @throws WrongAdapter if the object reference was not created with this POA. + * @throws WrongPolicy. This method requires either RETAIN or + * USE_DEFAULT_SERVANT policies and reaises the WrongPolicy if none of them + * apply to this POA. + */ + public Servant reference_to_servant(org.omg.CORBA.Object the_Object) + throws ObjectNotActive, WrongPolicy, + WrongAdapter + { + if (applies(ServantRetentionPolicyValue.RETAIN)) + { + activeObjectMap.Obj ref = aom.findObject(the_Object); + if (ref == null) + throw new WrongAdapter(); + else if (ref.isDeactiveted() || ref.servant == null) + { + if (default_servant != null) + return default_servant; + else + throw new ObjectNotActive(); + } + else + return ref.servant; + } + else if (default_servant != null) + { + return default_servant; + } + else + throw new WrongPolicy("Either RETAIN or USE_DEFAULT_SERVANT required."); + } + + /** + * Returns the id of the object, served by the given servant + * (assuming that the servant serves only one object). + * The id is found in one of the following ways. + * <ul> + * <li>If the POA has both the RETAIN and the UNIQUE_ID policy and + * the specified servant is active, the method return the Object Id associated + * with that servant. + * </li><li> + * If the POA has both the RETAIN and the IMPLICIT_ACTIVATION policy and + * either the POA has the MULTIPLE_ID policy or the specified servant is + * inactive, the method activates the servant using a POA-generated Object Id + * and the Interface Id associated with the servant, and returns that + * Object Id. + * </li> + * <li>If the POA has the USE_DEFAULT_SERVANT policy, the servant specified + * is the default servant, and the method is being invoked in the context of + * executing a request on the default servant, the method returns the + * ObjectId associated with the current invocation. + * </li> + * </ul> + * @throws ServantNotActive in all cases, not listed in the list above. + * @throws WrongPolicy The method requres USE_DEFAULT_SERVANT policy or + * a combination of the RETAIN policy and either the UNIQUE_ID or + * IMPLICIT_ACTIVATION policies and throws the WrongPolicy if these conditions + * are not satisfied. + */ + public byte[] servant_to_id(Servant the_Servant) + throws ServantNotActive, WrongPolicy + { + if (applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) || + applies(ServantRetentionPolicyValue.RETAIN) && + ( + applies(IdUniquenessPolicyValue.UNIQUE_ID) || + applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) + ) + ) + { + activeObjectMap.Obj ref = null; + if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) + ref = aom.findServant(the_Servant); + if (ref == null && + applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) + ) + { + // Try to activate. + try + { + return activate_object(the_Servant); + } + catch (ServantAlreadyActive ex) + { + // Either it shuld not be or the policy allows multiple ids. + throw new InternalError(); + } + } + if (ref == null) + throw new ServantNotActive(); + else + return ref.key; + } + else + throw new WrongPolicy("(RETAIN and UNIQUE ID) " + + "or USE_DEFAULT_SERVANT required." + ); + } + + /** + * <p>Converts the given servant to the object reference. + * The servant will serve all methods, invoked on the returned object. + * The returned object reference can be passed to the remote client, + * enabling remote invocations. + * </p><p> + * If the specified servant is active, it is returned. Otherwise, + * if the POA has the IMPLICIT_ACTIVATION policy the method activates + * the servant. In this case, if the servant activator is set, + * the {@link ServantActivatorOperations#incarnate} method will be called. + * </p> + * + * @throws ServantNotActive if the servant is inactive and no + * IMPLICIT_ACTIVATION policy applies. + * @throws WrongPolicy This method needs the RETAIN policy and either the + * UNIQUE_ID or IMPLICIT_ACTIVATION policies. + * + * @return the object, exposing the given servant in the context of this POA. + */ + public org.omg.CORBA.Object servant_to_reference(Servant the_Servant) + throws ServantNotActive, + WrongPolicy + { + required(ServantRetentionPolicyValue.RETAIN); + + activeObjectMap.Obj exists = null; + + if (!applies(IdUniquenessPolicyValue.MULTIPLE_ID)) + exists = aom.findServant(the_Servant); + + if (exists != null) + { + if (exists.isDeactiveted()) + { + if (applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)) + { + checkDiscarding(); + exists.setDeactivated(false); + incarnate(exists, exists.key, the_Servant, false); + } + else + throw new ServantNotActive(); + } + else + return exists.object; + } + if (exists == null && + applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) + ) + { + checkDiscarding(); + + byte[] object_key = activeObjectMap.getFreeId(); + + servantDelegate delegate = + new servantDelegate(the_Servant, this, object_key); + connectDelegate(object_key, delegate); + + return delegate.object; + } + else + throw new ServantNotActive(); + } + + /** + * Incarnate in cases when request forwarding is not expected + * because the servant must be provided by the servant activator. + * + * @param x the aom entry, where the object is replaced by + * value, returned by servant activator (if not null). + * + * @param key the object key. + * + * @param a_servant the servant that was passed as a parameter in the + * activation method. + * + * @param use_forwarding if true, the gnuForwardRequest is throw + * under the forwarding exception (for remote client). Otherwise, the + * request is internally redirected (for local invocation). + */ + private Servant incarnate(activeObjectMap.Obj x, byte[] object_key, + Servant a_servant, boolean use_forwarding + ) + { + if (servant_activator != null) + { + Servant servant; + try + { + servant = servant_activator.incarnate(object_key, this); + } + catch (ForwardRequest ex) + { + if (use_forwarding) + throw new gnuForwardRequest(ex.forward_reference); + else + servant = + ForwardedServant.create((ObjectImpl) ex.forward_reference); + } + if (servant != null && x != null) + x.setServant(servant); + if (servant == null && x != null) + servant = x.servant; + return servant; + } + else if (a_servant != null) + { + x.setServant(a_servant); + return a_servant; + } + else if (x.servant != null) + { + return x.servant; + } + else if (default_servant != null) + { + x.setServant(default_servant); + return x.servant; + } + else + throw new BAD_INV_ORDER("No servant given and the servant activator not set"); + } + + /** + * Return the POA manager, associated with this POA. + * + * @return the associated POA manager (always available). + */ + public POAManager the_POAManager() + { + return m_manager; + } + + /** + * Returns the adapter activator, associated with this POA. + * The newly created POA has no activator (null would be + * returned). The ORB root POA also initially has no activator. + * + * @return tha adapter activator or null if this POA has no + * associated adapter activator. + */ + public AdapterActivator the_activator() + { + return m_activator; + } + + /** + * Set the adapter activator for this POA. + * + * @param the activator being set. + */ + public void the_activator(AdapterActivator an_activator) + { + m_activator = an_activator; + } + + /** + * The children of this POA. + * + * @return the array of all childs for this POA. + */ + public POA[] the_children() + { + POA[] poas = new POA[ children.size() ]; + for (int i = 0; i < poas.length; i++) + { + poas [ i ] = (POA) children.get(i); + } + return poas; + } + + /** + * Return the name of this POA. + * + * @return the name of POA, relative to its parent. + */ + public String the_name() + { + return name; + } + ; + + /** + * Return the parent of this POA. + * + * @return the parent POA or <code>null</code> if this is a root POA. + */ + public POA the_parent() + { + return parent; + } + + /** {@inheritDoc} */ + public IdAssignmentPolicy create_id_assignment_policy(IdAssignmentPolicyValue a_value) + { + return new gnuIdAssignmentPolicy(a_value); + } + + /** {@inheritDoc} */ + public IdUniquenessPolicy create_id_uniqueness_policy(IdUniquenessPolicyValue a_value) + { + return new gnuIdUniquenessPolicy(a_value); + } + + /** {@inheritDoc} */ + public ImplicitActivationPolicy create_implicit_activation_policy(ImplicitActivationPolicyValue a_value) + { + return new gnuImplicitActivationPolicy(a_value); + } + + /** {@inheritDoc} */ + public LifespanPolicy create_lifespan_policy(LifespanPolicyValue a_value) + { + return new gnuLifespanPolicy(a_value); + } + + /** {@inheritDoc} */ + public RequestProcessingPolicy create_request_processing_policy(RequestProcessingPolicyValue a_value) + { + return new gnuRequestProcessingPolicy(a_value); + } + + /** {@inheritDoc} */ + public ServantRetentionPolicy create_servant_retention_policy(ServantRetentionPolicyValue a_value) + { + return new gnuServantRetentionPolicy(a_value); + } + + /** {@inheritDoc} */ + public ThreadPolicy create_thread_policy(ThreadPolicyValue a_value) + { + return new gnuThreadPolicy(a_value); + } + + /** + * <p> Destroy this POA and all descendant POAs. The destroyed POAs can be + * later re-created via {@link AdapterActivator} or by invoking + * {@link #create_POA}. + * This differs from {@link PoaManagerOperations#deactivate} that does + * not allow recreation of the deactivated POAs. After deactivation, + * recreation is only possible if the POAs were later destroyed. + * </p><p> + * The remote invocation on the target, belonging to the POA that is + * currently destroyed return the remote exception ({@link TRANSIENT}, + * minor code 4). + * </p> + * @param etherealize_objects if true, and POA has RETAIN policy, and the + * servant manager is available, the servant manager method + * {@link ServantActivatorOperations#etherealize} is called for each + * <i>active</i> object in the Active Object Map. This method should not + * try to access POA being destroyed. If <code>destroy</code> is called + * multiple times before the destruction completes, + * the etherialization should be invoked only once. + * + * @param wait_for_completion if true, the method waits till the POA being + * destroyed completes all current requests and etherialization. If false, + * the method returns immediately. + */ + public void destroy(boolean etherealize_objects, boolean wait_for_completion) + { + if (wait_for_completion) + waitWhileRunning(); + + // Put the brake instead of manager, preventing the subsequent + // requests. + gnuPOAManager g = new gnuPOAManager(); + g.state = State.INACTIVE; + m_manager = g; + + // Disconnect from parent. + if (parent instanceof gnuPOA) + { + ((gnuPOA) parent).children.remove(this); + } + + unregisterFromManager(); + + // Disconnect from the ORB all objects, registered with this POA. + ArrayList keys = new ArrayList(); + keys.addAll(aom.keySet()); + + byte[] key; + activeObjectMap.Obj obj; + for (int i = 0; i < keys.size(); i++) + { + key = (byte[]) keys.get(i); + obj = aom.get(key); + if (obj.poa == this) + m_orb.disconnect(obj.object); + } + + m_orb.identityDestroyed(this); + + if (etherealize_objects && servant_activator != null && !m_inDestruction) + { + etherealizeAll(); + } + m_inDestruction = true; + + POA[] ch = the_children(); + for (int i = 0; i < ch.length; i++) + { + ch [ i ].destroy(etherealize_objects, wait_for_completion); + } + } + + /** + * Destroy this POA if it has not been destroyed, destroys it. + */ + protected void finalize() + throws java.lang.Throwable + { + if (!m_inDestruction) + destroy(false, false); + } + + /** + * Remove self from the manager list. + */ + private void unregisterFromManager() + { + if (m_manager instanceof gnuPOAManager) + { + gnuPOAManager p = (gnuPOAManager) m_manager; + p.removePOA(this); + } + } + + /** + * Get the policy of the given type, associated with this POA. + * + * @param a_policy_type a type of the requested policy. + * @return a policy of the given type, applyting to this POA. + * + * @throws org.omg.CORBA.BAD_PARAM if the policy of this type has not + * been specified for this POA. + */ + public Policy _get_policy(int a_policy_type) + throws org.omg.CORBA.BAD_PARAM + { + for (int i = 0; i < s_policies.length; i++) + { + if (s_policies [ i ].policy_type() == a_policy_type) + return s_policies [ i ].copy(); + } + throw new BAD_PARAM("No policy type " + a_policy_type); + } + + /** + * Get the copy of the policy array. + */ + public Policy[] getPolicyArray() + { + Policy[] r = new Policy[ s_policies.length ]; + for (int i = 0; i < s_policies.length; i++) + { + r [ i ] = s_policies [ i ].copy(); + } + return r; + } + + /** + * The POAs cannot be created by this method. + * + * @specnote this is also not possible in Suns jdk at least till 1.4. + * + * @throws NO_IMPLEMENT always. + */ + public org.omg.CORBA.Object _set_policy_override(Policy[] policies, + SetOverrideType how + ) + { + throw new NO_IMPLEMENT("Use createPOA instead."); + } + + /** + * Get the ORB, where this POA is connected. + */ + public ORB orb() + { + return m_orb; + } + + /** + * Connect the given delegate under the given key, also calling + * incarnate. + */ + private void connectDelegate(byte[] object_key, servantDelegate delegate) + { + aom.add(delegate); + connect_to_orb(object_key, delegate.object); + if (servant_activator != null) + incarnate(null, object_key, delegate.servant, false); + } + + /** + * Check if the POA is not in a discarding mode. The activation + * operations are forbidded in discarding mode. + * + * @throws TRANSIENT if the POA is in discarding mode. + */ + private void checkDiscarding() + throws TRANSIENT + { + if (m_manager.get_state() == State.DISCARDING) + throw new TRANSIENT("Discarding mode", 1, CompletionStatus.COMPLETED_MAYBE); + } + + /** + * Connect the given delegate object to orb. + */ + protected void connect_to_orb(byte[] an_Object_Id, org.omg.CORBA.Object object) + { + if (applies(ThreadPolicyValue.SINGLE_THREAD_MODEL)) + m_orb.connect_1_thread(object, toIORKey(an_Object_Id), this); + else + m_orb.connect(object, toIORKey(an_Object_Id)); + } + + /** + * Returns the representation of this POA tree. + */ + public String toString() + { + StringBuffer b = new StringBuffer(name); + + if (children.size() != 0) + { + b.append(" ("); + + for (int i = 0; i < children.size(); i++) + { + b.append(children.get(i)); + if (i < children.size() - 2) + b.append(", "); + } + b.append(")"); + } + return b.toString(); + } + + /** + * Check if the policy set is valid. + */ + protected boolean validatePolicies(Policy[] a) + throws InvalidPolicy + { + if (applies(ServantRetentionPolicyValue.NON_RETAIN)) + { + if (!applies(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT) && + !applies(RequestProcessingPolicyValue.USE_SERVANT_MANAGER) + ) + { + short p = 0; + for (short i = 0; i < a.length; i++) + { + if (a [ i ].policy_type() == SERVANT_RETENTION_POLICY_ID.value) + p = i; + } + throw new InvalidPolicy("NON_RETAIN requires either " + + "USE_DEFAULT_SERVANT or USE_SERVANT_MANAGER", + p + ); + } + } + return true; + } + + /** + * Recursively searches for the given object in the POA tree. + */ + public activeObjectMap.Obj findObject(org.omg.CORBA.Object object) + { + activeObjectMap.Obj h = aom.findObject(object); + if (h != null) + return h; + else + { + for (int i = 0; i < children.size(); i++) + { + h = ((gnuPOA) children.get(i)).findObject(object); + if (h != null) + return h; + } + } + return h; + } + + /** + * Recursively searches for the given key in the POA tree. + * @param ior_key the key, ecapsulating both object + * and poa ids. + * @return + */ + public activeObjectMap.Obj findKey(byte[] object_id, byte[] poa_id) + { + activeObjectMap.Obj h = null; + if (Arrays.equals(poa_id, id())) + h = aom.get(object_id); + if (h != null) + return h; + else + { + for (int i = 0; i < children.size(); i++) + { + h = ((gnuPOA) children.get(i)).findKey(object_id, poa_id); + if (h != null) + return h; + } + } + return h; + } + + /** + * Parses the given key, extracts poa and object id and searches + * for such reference. + */ + public activeObjectMap.Obj findIorKey(byte[] ior_key) + { + cdrBufInput in = new cdrBufInput(ior_key); + int signature = in.read_long(); + if (signature != SIGNATURE) + return null; + + byte[] id = in.read_sequence(); + byte[] poa = in.read_sequence(); + return findKey(id, poa); + } + + /** + * Converts the object Id into the IOR key. IOR key must be + * unique in the scope of the ORB, and Ids only in the scope of POA. + * Hence the IOR key includes the POA identifiers. + */ + public byte[] toIORKey(byte[] object_id) + { + cdrBufOutput buffer = new cdrBufOutput(); + buffer.write_long(SIGNATURE); + buffer.write_sequence(object_id); + buffer.write_sequence(id()); + return buffer.buffer.toByteArray(); + } + + /** + * Extracts the object id from the ior key. + * + * @param ior_key + * + * @return the encapsulated object ior key or null if + * this ior key either refers a different POA or encoding signature + * mismatch. + */ + public byte[] idFormIor(byte[] ior_key) + { + cdrBufInput in = new cdrBufInput(ior_key); + int signature = in.read_long(); + if (signature != SIGNATURE) + return null; + + byte[] object_id = in.read_sequence(); + byte[] poa_id = in.read_sequence(); + if (Arrays.equals(poa_id, id())) + return object_id; + else + return null; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuPOAManager.java b/gnu/CORBA/Poa/gnuPOAManager.java new file mode 100644 index 000000000..6c1b5644f --- /dev/null +++ b/gnu/CORBA/Poa/gnuPOAManager.java @@ -0,0 +1,225 @@ +/* gnuPOAManager.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.BAD_INV_ORDER; +import org.omg.CORBA.LocalObject; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAManagerPackage.AdapterInactive; +import org.omg.PortableServer.POAManagerPackage.State; + +import java.util.HashSet; +import java.util.Iterator; + +/** + * The implementation of the POA manager. The manager is a controlled + * switch that can change its states in response to the method calls + * and throw exceptions if the requested change is invalid. It is possible + * to check the state this switch. It does not do anything else. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuPOAManager + extends LocalObject + implements POAManager +{ + /** + * The POAs, controlled by this manager. The members must be instances of + * the gnuAbstractPOA. + */ + HashSet POAs = new HashSet(); + + /** + * The state of the manager. The newly created manager is always + * in the holding state. + */ + State state = State.HOLDING; + + /** + * Get the state of the POA manager. + */ + public State get_state() + { + return state; + } + + /** + * Turns the associated POAs into active state, allowing them to receive + * and process requests. + * + * @throws if the POAs are in the inactive state. If once inactivated, + * the POA cannot be activated again. This method can only be called + * to leave the holding or discarding state. + */ + public void activate() + throws AdapterInactive + { + if (state != State.INACTIVE) + state = State.ACTIVE; + else + throw new AdapterInactive(); + } + + /** + * Turns the associated POAs into holding state. In this state, the POAs + * queue incoming requests but do not process them. + * + * @param wait_for_completion if true, the method call suspends the current + * thread till POAs complete the requests they are currently processing. If + * false, the method returns immediately. + + * @throws AdapterInactive if the POAs are in the inactive state. + */ + public void hold_requests(boolean wait_for_completion) + throws AdapterInactive + { + if (state != State.INACTIVE) + state = State.HOLDING; + else + throw new AdapterInactive(); + if (wait_for_completion) + waitForIdle(); + } + + /** + * + * Turns the asociated POAs into inactive state. The POAs in the incative + * state will reject new requests. If the POA is once inactivated, it + * cannot be activated again. The operation is used when + * the associated POAs are to be shut down. + * + * @param etherealize_objects if true, the servant managers of the + * associated POAs, having RETAIN and USE_SERVANT_MANAGER policies, + * will receive a call of {@link ServantActivatorOperations#etherealize}. + * + * @param wait_for_completion if true, the method call suspends the current + * thread till POAs complete the requests they are currently processing. If + * false, the method returns immediately. + * + * @throws AdapterInactive if the POAs are already in the inactive state. + * + * @see POAOperations#destroy + */ + public void deactivate(boolean etherealize_objects, + boolean wait_for_completion + ) + throws AdapterInactive + { + if (state == State.INACTIVE) + throw new AdapterInactive("Repetetive inactivation"); + state = State.INACTIVE; + if (wait_for_completion) + waitForIdle(); + + Iterator iter = POAs.iterator(); + while (iter.hasNext()) + { + gnuPOA poa = (gnuPOA) iter.next(); + + // If the servant activator is non null, this means it has been + // set - hence the policies are appropriate. + if (poa.servant_activator != null) + poa.etherealizeAll(); + } + } + + /** + * Turns the associated POAs into discaring state. In this state, the POAs + * discard the incoming requests. This mode is used in situations when + * the server is flooded with requests. The client receives remote exception + * ({@link org.omg.CORBA.TRANSIENT}, minor code 1). + * + * @param wait_for_completion if true, the method call suspends the current + * thread till POAs complete the requests they are currently processing. If + * false, the method returns immediately. + + * @throws AdapterInactive if the POAs are in the inactive state. + */ + public void discard_requests(boolean wait_for_completion) + throws AdapterInactive + { + if (state != State.INACTIVE) + state = State.DISCARDING; + else + throw new AdapterInactive(); + if (wait_for_completion) + waitForIdle(); + } + + /** + * Suspend the current thread while at least one of the associated POA is + * actively processing some requests. The method assumes that the POAs + * are not accepting the <i>new</i> requests due manager state. + * + * @throws BAD_INV_ORDER if the POAs are in the active state. + */ + public void waitForIdle() + { + if (state == State.ACTIVE) + throw new BAD_INV_ORDER("The state is active"); + + Iterator iter = POAs.iterator(); + while (iter.hasNext()) + { + gnuPOA poa = (gnuPOA) iter.next(); + poa.waitWhileRunning(); + } + } + + /** + * Add the POA that will be controlled by this manager. + * + * @param poa the POA. + */ + public void addPoa(gnuPOA poa) + { + POAs.add(poa); + } + + /** + * Remove the POA, releasing it from the control of this manager. + * Called in POA finaliser. + * + * @param poa the POA to remove. + */ + public void removePOA(gnuPOA poa) + { + POAs.remove(poa); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuPoaCurrent.java b/gnu/CORBA/Poa/gnuPoaCurrent.java new file mode 100644 index 000000000..927d02fe3 --- /dev/null +++ b/gnu/CORBA/Poa/gnuPoaCurrent.java @@ -0,0 +1,179 @@ +/* gnuPoaCurrent.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.CurrentHelper; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableServer.Current; +import org.omg.PortableServer.CurrentOperations; +import org.omg.PortableServer.CurrentPackage.NoContext; +import org.omg.PortableServer.POA; + +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; + +/** + * Supports the "Poa current" concept, providing the id and poa of + * the object currently being served. There is only one instance + * of this class per ORB. It maintains a thread to information map. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuPoaCurrent + extends ObjectImpl + implements Current +{ + /** + * The table, mapping threads to records. + */ + private TreeMap threads = new TreeMap(); + + /** + * Get the array of POA current repository ids. + * + * @return a single member array, containing value, returned + * by the {@link CurrentHelper#id}, normally + * "IDL:omg.org/PortableServer/Current:2.3". + */ + public String[] _ids() + { + return new String[] { CurrentHelper.id() }; + } + + /** + * Get the object id, associated with the thread currently being served. + * + * @throws NoContext if the current thread is not associated with any + * object. + */ + public byte[] get_object_id() + throws NoContext + { + CurrentOperations r; + synchronized (threads) + { + r = (CurrentOperations) threads.get(Thread.currentThread().getName()); + } + if (r != null) + return r.get_object_id(); + else + throw new NoContext(Thread.currentThread().getName()); + } + + /** + * Get the object POA, associated with the thread currently being served. + * + * @throws NoContext if the current thread is not associated with any + * object. + */ + public POA get_POA() + throws NoContext + { + CurrentOperations r; + synchronized (threads) + { + r = (CurrentOperations) threads.get(Thread.currentThread().getName()); + } + if (r != null) + return r.get_POA(); + else + throw new NoContext(Thread.currentThread().getName()); + } + + /** + * Add the entry to the map. + */ + public void put(Thread t, CurrentOperations record) + { + synchronized (threads) + { + threads.put(t.getName(), record); + } + } + + /** + * Check if this Poa has some running threads. + */ + public boolean has(POA poa) + { + synchronized (threads) + { + Iterator iter = threads.entrySet().iterator(); + while (iter.hasNext()) + { + Map.Entry item = (Map.Entry) iter.next(); + try + { + if (((CurrentOperations) item.getValue()).get_POA() == poa) + { + return true; + } + } + catch (NoContext ex) + { + throw new InternalError(); + } + } + } + return false; + } + + /** + * Check if this thread is registered. + */ + public boolean has(Thread t) + { + synchronized (threads) + { + return threads.containsKey(t.getName()); + } + } + + /** + * Remove the entry from the map. + */ + public void remove(Thread t) + { + synchronized (threads) + { + threads.remove(t.getName()); + } + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java b/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java new file mode 100644 index 000000000..5bbcd1321 --- /dev/null +++ b/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java @@ -0,0 +1,80 @@ +/* gnuRequestProcessingPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID; +import org.omg.PortableServer.RequestProcessingPolicy; +import org.omg.PortableServer.RequestProcessingPolicyValue; + +/** + * The implementation of the request processing policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuRequestProcessingPolicy + extends _PolicyImplBase + implements RequestProcessingPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuRequestProcessingPolicy(RequestProcessingPolicyValue v) + { + super(REQUEST_PROCESSING_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/RequestProcessingPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public RequestProcessingPolicyValue value() + { + return (RequestProcessingPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuServantObject.java b/gnu/CORBA/Poa/gnuServantObject.java new file mode 100644 index 000000000..f096104f9 --- /dev/null +++ b/gnu/CORBA/Poa/gnuServantObject.java @@ -0,0 +1,594 @@ +/* gnuServantObject.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 gnu.CORBA.IOR_Delegate; +import gnu.CORBA.IOR_contructed_object; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.OBJ_ADAPTER; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.TRANSIENT; +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; +import org.omg.PortableServer.CurrentOperations; +import org.omg.PortableServer.DynamicImplementation; +import org.omg.PortableServer.ForwardRequest; +import org.omg.PortableServer.ImplicitActivationPolicyValue; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAManagerPackage.State; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; +import org.omg.PortableServer.ServantRetentionPolicyValue; +import org.omg.PortableServer.portable.Delegate; + +import java.util.Arrays; + +/** + * Represents a CORBA object, being locally served by the associated + * servant. The calls to the object are forwarded to the calls to the + * servant. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuServantObject + extends ObjectImpl + implements org.omg.CORBA.Object, InvokeHandler, CurrentOperations +{ + /** + * The associated servant that must also implement the + * {@link InvokeHandler} interface. This value can be temporary + * null if the object was created using + * POA.create_reference or POA.create_reference_with_id, private to force + * always to use {@link setServant}. + */ + private Servant servant; + + /** + * The Id of this object. + */ + public final byte[] Id; + + /** + * The poa that takes care about this object. + */ + public final gnuPOA poa; + + /** + * The POA manager, used to control the work of this object. + */ + public final POAManager manager; + + /** + * The orb. + */ + public final ORB_1_4 orb; + + /** + * The object repository ids, if they were specified separately. + * Normally, the ids are requested from the servant. + */ + public final String[] repository_ids; + + /** + * Create an object with no connected servant. The servant must be + * set later. + * + * @param a_repository_ids an array of repository ids, can be null + * (then ids will be requested from the servant). + * @param an_id the object id. + * @param a_poa the POA. + */ + public gnuServantObject(String[] a_repository_ids, byte[] an_id, + gnuPOA a_poa, ORB_1_4 an_orb + ) + { + repository_ids = a_repository_ids; + Id = an_id; + manager = a_poa.the_POAManager(); + poa = a_poa; + orb = an_orb; + } + + /** + * Create a servant object, associated with the passed servant. + * + * @param a_servant a servant, serving this object. + * @param an_id an Object Id for this object. + * + * @throws BAD_PARAM if the passed servant is not an + * {@link InvokeHandler}. + */ + public gnuServantObject(Servant a_servant, byte[] an_id, ORB_1_4 an_orb, + gnuPOA a_poa + ) + { + Id = an_id; + setServant(a_servant); + poa = a_poa; + if (poa != null) + manager = poa.the_POAManager(); + else + manager = null; + repository_ids = null; + orb = an_orb; + } + + /** + * Set a servant, if it has not been previously set. + * + * @param a_servant a servant to set, can be null to indicate + * the necessity for the subsequent activation. + * + * @throws BAD_PARAM if the passed servant is not an + * {@link InvokeHandler} or {@link DynamicImplementation} and also + * not null. + */ + public void setServant(Servant a_servant) + { + if (a_servant != null && !(a_servant instanceof InvokeHandler) && + !(a_servant instanceof DynamicImplementation) + ) + + throw new BAD_PARAM("Must be either InvokeHandler or " + + "DynamicImplementation, but is " + a_servant + ); + servant = a_servant; + } + + /** + * Returns the associated servant. + */ + public Servant getServant() + { + return servant; + } + + /** + * Return the associated invocation handler. + */ + public InvokeHandler getHandler(String operation, CookieHolder cookie, + boolean forwarding_allowed + ) + throws gnuForwardRequest + { + if (servant != null) + return servantToHandler(servant); + else + { + // Use servant locator to locate the servant. + if (poa.servant_locator != null) + { + try + { + servant = + poa.servant_locator.preinvoke(Id, poa, operation, cookie); + return servantToHandler(servant); + } + catch (ForwardRequest forw_ex) + { + if (forwarding_allowed) + throw new gnuForwardRequest(forw_ex.forward_reference); + else + { + servant = + ForwardedServant.create(forw_ex.forward_reference); + return servantToHandler(servant); + } + } + } + else + // Use servant activator to locate the servant. + if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && + poa.applies(ServantRetentionPolicyValue.RETAIN) + ) + { + try + { + poa.activate_object_with_id(Id, servant, forwarding_allowed); + servant = poa.id_to_servant(Id); + return servantToHandler(servant); + } + catch (gnuForwardRequest forwarded) + { + throw forwarded; + } + catch (Exception ex) + { + ex.printStackTrace(); + + BAD_OPERATION bad = + new BAD_OPERATION("Unable to activate", 0x5004, + CompletionStatus.COMPLETED_NO + ); + bad.initCause(ex); + throw bad; + } + } + else if (poa.default_servant != null) + { + servant = poa.default_servant; + return servantToHandler(servant); + } + + // No servant and no servant manager - throw exception. + else + throw new BAD_OPERATION("Unable to activate", 0x5002, + CompletionStatus.COMPLETED_NO + ); + } + } + + /** + * Convert the servant to invocation handler. + */ + public InvokeHandler servantToHandler(Servant servant) + { + if (servant instanceof InvokeHandler) + return (InvokeHandler) servant; + else if (servant instanceof DynamicImplementation) + return new dynImpHandler((DynamicImplementation) servant); + else + throw new BAD_OPERATION(servant + " must be either InvokeHandler or " + + "POA DynamicImplementation" + ); + } + + /** + * Create a servant object, associated with the passed servant. + * Requests the object id from the servant. Depending on the + * policies of the servants POA, the calls are eithe not + * synchronized or synchronized on POA or ORB. + * + * @param a_servant a servant, serving this object. + * @param an_id an Object Id for this object. + */ + public gnuServantObject(Servant a_servant, gnuPOA poa) + { + this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), poa); + } + + /** + * Delegates call to servant, passing the poa and Id. + */ + public String[] _ids() + { + if (repository_ids == null) + return getServant()._all_interfaces(poa, Id); + else + return repository_ids; + } + + /** + * Gets a string representation. + */ + public String toString() + { + StringBuffer b = new StringBuffer("Servant object ("); + for (int i = 0; i < Id.length; i++) + { + b.append(Integer.toHexString(Id [ i ] & 0xFF)); + b.append(' '); + } + b.append(')'); + return b.toString(); + } + + /** + * Always returns true. + */ + public boolean _is_local() + { + return true; + } + + /** + * Check if this object could be named by the given repository id. + * @param idl_id the repository id to check. + * + * @return true if it is one of the possible repository ids of this + * object. + */ + public boolean _is_a(String idl_id) + { + String[] maybe = _ids(); + for (int i = 0; i < maybe.length; i++) + { + if (maybe [ i ].equals(idl_id)) + return true; + } + return false; + } + + /** + * Get an ORB, associated with the servant of this object. + * @return + */ + public ORB _orb() + { + return getServant()._orb(); + } + + /** + * Handle the invocation (delegates to servant). + * + * @throws TRANSIENT minor 0x535503e9 if the POA is in discarding mode. + * @throws OBJ_ADAPTER minor 0x535503ea if the POA is inactivated. + * @throws OBJECT_NOT_EXISTS minor 0x535503ec if this object is + * inactivated. + * + * @specnote see {@link POAManagerOperations} for specnotes about + * the minor codes. + */ + public OutputStream _invoke(String method, InputStream input, + ResponseHandler r_handler + ) + throws SystemException + { + try + { + CookieHolder cookie = null; + activeObjectMap.Obj self = poa.aom.get(Id); + + if (poa.servant_locator != null) + { + // If the servant locator is in use, it is always responsible + // for providing the servant. + self.servant = servant = null; + cookie = new CookieHolder(); + } + else if (self != null && self.isDeactiveted()) + { + if (poa.applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) && + poa.servant_activator != null + ) + { + // Reset the servant, forcing the subsequent activation. + servant = null; + } + else + throw new OBJECT_NOT_EXIST("Object deactivated", 0x535503ec, + CompletionStatus.COMPLETED_NO + ); + } + + InvokeHandler handler = getHandler(method, cookie, true); + + Delegate d = null; + + try + { + d = servant._get_delegate(); + orb.currents.put(Thread.currentThread(), this); + } + catch (Exception ex) + { + // In some cases exception is thrown if the delegate is not set. + } + if (d instanceof servantDelegate) + { + // If the delegate is already set, check maybe we can + // reuse the existing instance. + if (((servantDelegate) d).object != this) + servant._set_delegate(new servantDelegate(servant, poa, Id)); + } + else + { + servant._set_delegate(new servantDelegate(servant, poa, Id)); + } + + try + { + switch (manager.get_state().value()) + { + case State._ACTIVE : + return handler._invoke(method, input, r_handler); + + case State._HOLDING : + + // The holding mode is implemented + // relying on the holding capabilites of the network + // support (if any). + // TODO FIXME in more recent CORBA applications, the client + // ORB can free the connection and wait for a server side + // notification about the completed request. Implement this. + int sleep = 5; + int max = 500; + + // Wait till the state will be switched into some other + // mode. + while (manager.get_state().value() == State._HOLDING) + { + try + { + Thread.sleep(sleep); + if (sleep < max) + sleep = max; + } + catch (InterruptedException ex) + { + } + } + + // Handle another mode. + return _invoke(method, input, r_handler); + + case State._DISCARDING : + throw new TRANSIENT("Discarding mode", 0x535503e9, + CompletionStatus.COMPLETED_NO + ); + + case State._INACTIVE : + throw new OBJ_ADAPTER("POA deactivated", 0x535503ea, + CompletionStatus.COMPLETED_NO + ); + + default : + throw new InternalError(); // No more states. + } + } + finally + { + if (poa.servant_locator != null) + { + poa.servant_locator.postinvoke(Id, poa, method, cookie.value, + servant + ); + servant = null; + } + } + } + finally + { + orb.currents.remove(Thread.currentThread()); + } + } + + /** + * Compare with another object for equality, comparing the + * object keys. + */ + public boolean equals(java.lang.Object other) + { + if (other instanceof gnuServantObject) + { + gnuServantObject o = (gnuServantObject) other; + + return Arrays.equals(o.Id, Id); + } + else + return false; + } + + /** + * Get the hash code, based on the object key. + */ + public int hashCode() + { + long s = 0; + int v = 1; + for (int i = 0; i < Id.length; i++) + { + s += Id [ i ] * v; + if (s > Integer.MAX_VALUE) + { + s = s % Integer.MAX_VALUE; + v = 1; + } + v = v * 8; + } + return (int) (s % Integer.MAX_VALUE); + } + + /** + * Get the object id. + */ + public byte[] get_object_id() + { + return Id; + } + + /** + * Get POA. + */ + public POA get_POA() + { + return poa; + } + + /** + * Returns without action. + */ + public void _release() + { + } + + /** + * Returns without action. + */ + public void _releaseReply(InputStream stream) + { + } + + /** + * Checks if this object is equivalent to another instance. + * These objects are assumed equal if they are connected to the + * same orb and poa under the same Id, regardless of they + * delegates. + * + * @param another instance to check. + * @return + */ + public boolean _is_equivalent(org.omg.CORBA.Object other) + { + if (other instanceof gnuServantObject) + { + gnuServantObject g = (gnuServantObject) other; + return orb == g.orb && poa == g.poa && Arrays.equals(Id, g.Id); + } + else if (other instanceof IOR_contructed_object) + { + IOR_contructed_object ir = ((IOR_contructed_object) other); + try + { + IOR_Delegate ird = (IOR_Delegate) ir._get_delegate(); + byte[] ior_id = poa.idFormIor(ird.getIor().key); + if (ior_id != null && Arrays.equals(ior_id, Id)) + return true; + else + return false; + } + catch (Exception ex) + { + // Non - typical delegate or very specific subclass of + // IOR_constructed_object. + return super._is_equivalent(other); + } + } + return super._is_equivalent(other); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/gnuServantRetentionPolicy.java b/gnu/CORBA/Poa/gnuServantRetentionPolicy.java new file mode 100644 index 000000000..009e70e1b --- /dev/null +++ b/gnu/CORBA/Poa/gnuServantRetentionPolicy.java @@ -0,0 +1,80 @@ +/* gnuServantRetentionPolicy.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 gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID; +import org.omg.PortableServer.ServantRetentionPolicy; +import org.omg.PortableServer.ServantRetentionPolicyValue; + +/** + * The implementation of the servant retention policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuServantRetentionPolicy + extends _PolicyImplBase + implements ServantRetentionPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuServantRetentionPolicy(ServantRetentionPolicyValue v) + { + super(SERVANT_RETENTION_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/ServantRetentionPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public ServantRetentionPolicyValue value() + { + return (ServantRetentionPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/CDR/uncObjectOutputStream.java b/gnu/CORBA/Poa/gnuThreadPolicy.java index 3aa8582bb..f42ebefb3 100644 --- a/gnu/CORBA/CDR/uncObjectOutputStream.java +++ b/gnu/CORBA/Poa/gnuThreadPolicy.java @@ -1,4 +1,4 @@ -/* uncObjectOutputStream.java -- +/* gnuThreadPolicy.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -36,38 +36,45 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -package gnu.CORBA.CDR; +package gnu.CORBA.Poa; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.OutputStream; +import gnu.CORBA._PolicyImplBase; + +import org.omg.PortableServer.THREAD_POLICY_ID; +import org.omg.PortableServer.ThreadPolicy; +import org.omg.PortableServer.ThreadPolicyValue; /** - * The Uncloseable Object Output Stream is used in cases when - * it is necessary to write the data and leave the stream opened. + * The implementation of the thread policy. * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class uncObjectOutputStream - extends ObjectOutputStream +public class gnuThreadPolicy + extends _PolicyImplBase + implements ThreadPolicy, vPolicy { /** - * Delegate call to super class constructor. + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. */ - public uncObjectOutputStream(OutputStream out) - throws IOException + public gnuThreadPolicy(ThreadPolicyValue v) { - super(out); + super(THREAD_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/ThreadPolicy:1.0" + ); } /** - * Do not close, just flush. - * - * @throws IOException if the flush() throws it. + * Get the value for the policy that was passed in a constructor. */ - public void close() - throws IOException + public ThreadPolicyValue value() { - flush(); + return (ThreadPolicyValue) getValue(); } }
\ No newline at end of file diff --git a/gnu/CORBA/Poa/policySets.java b/gnu/CORBA/Poa/policySets.java new file mode 100644 index 000000000..eb688467a --- /dev/null +++ b/gnu/CORBA/Poa/policySets.java @@ -0,0 +1,128 @@ +/* policySets.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.Policy; +import org.omg.PortableServer.IdAssignmentPolicyValue; +import org.omg.PortableServer.IdUniquenessPolicyValue; +import org.omg.PortableServer.ImplicitActivationPolicyValue; +import org.omg.PortableServer.LifespanPolicyValue; +import org.omg.PortableServer.RequestProcessingPolicyValue; +import org.omg.PortableServer.ServantRetentionPolicyValue; +import org.omg.PortableServer.ThreadPolicyValue; + +import java.util.ArrayList; + +/** + * Contains the frequently uset POA policy sets. The policy + * arrays are package private for security reasons, the cloned + * copies are returned. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class policySets +{ + /** + * The default policy set, as defined in OMG specs. This is also + * the policy set for the root POA. + */ + private static final vPolicy[] rootPOASet = + new vPolicy[] + { + new gnuThreadPolicy(ThreadPolicyValue.ORB_CTRL_MODEL), + new gnuLifespanPolicy(LifespanPolicyValue.TRANSIENT), + new gnuIdUniquenessPolicy(IdUniquenessPolicyValue.UNIQUE_ID), + new gnuIdAssignmentPolicy(IdAssignmentPolicyValue.SYSTEM_ID), + new gnuServantRetentionPolicy(ServantRetentionPolicyValue.RETAIN), + new gnuRequestProcessingPolicy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY), + new gnuImplicitActivationPolicy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION) + }; + + /** + * Return the policy set, applicable for the root POA, as defined + * in OMG specs. + */ + public static Policy[] rootPoa() + { + Policy[] p = new Policy[ rootPOASet.length ]; + System.arraycopy(rootPOASet, 0, p, 0, p.length); + return p; + } + + /** + * Convert the potentially incomplete policy array into array, containing + * the complete policy set. + * + * @param policies the policy list, may be incomplete (even zero size). + * + * @return the complete policy array. The missing, but needed policies + * are added with they default values. + */ + public static Policy[] withDefault(Policy[] policies) + { + ArrayList current = new ArrayList(rootPOASet.length); + Policy p_default; + boolean specified; + + for (int i = 0; i < rootPOASet.length; i++) + { + p_default = rootPOASet [ i ]; + specified = false; + ForThis: + for (int j = 0; j < policies.length; j++) + { + if (policies [ j ].policy_type() == p_default.policy_type()) + { + specified = true; + current.add(policies [ j ]); + break ForThis; + } + } + if (!specified) + current.add(p_default.copy()); + } + + Policy[] complete = new Policy[ current.size() ]; + for (int i = 0; i < complete.length; i++) + { + complete [ i ] = (Policy) current.get(i); + } + return complete; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/Poa/servantDelegate.java b/gnu/CORBA/Poa/servantDelegate.java new file mode 100644 index 000000000..1825db386 --- /dev/null +++ b/gnu/CORBA/Poa/servantDelegate.java @@ -0,0 +1,235 @@ +/* servantDelegate.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 gnu.CORBA.Unexpected; + +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.Object; +import org.omg.PortableServer.CurrentPackage.NoContext; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAHelper; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.portable.Delegate; + +/** + * The implementation of the servant delegate for the locally existing + * servant.The associated servant that must also implement the + * {@link InvokeHandler} interface. Each servant requires a separate + * instance of this delegate and can serve a single object only. + * Hence the fields are final, but the delegate is typically reused + * unless the same servant is connected to different objects. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class servantDelegate + implements Delegate +{ + /** + * The servant, associated with this object. + */ + final Servant servant; + + /** + * The servant (not object) id. + */ + final byte[] servant_id; + + /** + * The POA, where the servant is connected. + */ + final gnuPOA poa; + + /** + * The object, exposed as an object, served by this servant. + */ + final gnuServantObject object; + + /** + * Create the delegat for the servant that will be connected to the + * given poa. The method is normally called from inside of gnuPOA. + * The constructor sets the newly created delegate as the delegate to this + * servant by calling Servant._set_delegate. + * + * @param a_poa the poa. + * @param a_servant the servant. + * @param a_servant_id the servant id. + */ + public servantDelegate(Servant a_servant, gnuPOA a_poa, byte[] a_servant_id) + { + poa = a_poa; + servant = a_servant; + servant_id = a_servant_id; + servant._set_delegate(this); + object = + new gnuServantObject(servant, servant_id, (ORB_1_4) servant._orb(), a_poa); + object._set_delegate(new LocalDelegate(object, poa, a_servant_id)); + } + + /** + * Check if this object could be named by the given repository id. + * @param idl_id the repository id to check. + * + * @return true if it is one of the possible repository ids of this + * object. + */ + public boolean is_a(Servant a_servant, String idl_id) + { + same(a_servant); + + String[] maybe = object.repository_ids; + if (maybe == null) + maybe = servant._all_interfaces(poa, object.Id); + for (int i = 0; i < maybe.length; i++) + { + if (maybe [ i ].equals(idl_id)) + return true; + } + return false; + } + + /** + * Return the ORB's default POA. + */ + public POA default_POA(Servant a_servant) + { + same(a_servant); + try + { + return POAHelper.narrow(orb(a_servant).resolve_initial_references("RootPOA")); + } + catch (InvalidName ex) + { + throw new Unexpected(ex); + } + } + + /** + * Get ORB. + */ + public ORB orb(Servant a_servant) + { + same(a_servant); + return poa.orb(); + } + + /** + * Get the object, exposing the servant. + */ + public Object this_object(Servant a_servant) + { + same(a_servant); + try + { + return poa.aom.get(poa.m_orb.currents.get_object_id()).object; + } + catch (NoContext ex) + { + return object; + } + } + + /** + * Not supported. + * + * @specnote Same as for Sun up till 1.5 inclusive. + */ + public Object get_interface_def(Servant a_servant) + { + same(a_servant); + throw new NO_IMPLEMENT(); + } + + /** + * Get the Id of the object being currently served. + */ + public byte[] object_id(Servant a_servant) + { + same(a_servant); + try + { + byte[] id = poa.m_orb.currents.get_object_id(); + return id; + } + catch (NoContext ex) + { + // TODO remove from mature code, this is a debug statement. + // The message should not appear during tests. + System.out.println("Not ok with object id"); + return object.Id; + } + } + + /** + * Always returns false; + */ + public boolean non_existent(Servant a_servant) + { + same(a_servant); + return false; + } + + /** + * Return the associated POA. + */ + public POA poa(Servant a_servant) + { + same(a_servant); + try + { + return poa.m_orb.currents.get_POA(); + } + catch (NoContext ex) + { + return poa; + } + } + + /** + * Checks if the passed servant is the same as the servant, associated with + * this delegate. This class requires a single servant per delegate. + */ + void same(Servant some_servant) + { + if (servant != some_servant) + throw new InternalError("Only one servant per delegate is supported."); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/CDR/uncObjectInputStream.java b/gnu/CORBA/Poa/vPolicy.java index b912f5d2c..9e45b56d7 100644 --- a/gnu/CORBA/CDR/uncObjectInputStream.java +++ b/gnu/CORBA/Poa/vPolicy.java @@ -1,4 +1,4 @@ -/* uncObjectInputStream.java -- +/* vPolicy.java -- Copyright (C) 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -36,35 +36,27 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -package gnu.CORBA.CDR; +package gnu.CORBA.Poa; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; +import org.omg.CORBA.Policy; /** - * An object input stream that cannot be closed. Used in cases where - * it represents only part of the input data. + * The Classpath implementation of the policy, providing the policy + * value and the code of the policy type. * - * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -public class uncObjectInputStream - extends ObjectInputStream +public interface vPolicy + extends Policy { /** - * Delegate call to super class constructor. + * Get the value of this policy */ - public uncObjectInputStream(InputStream in) - throws IOException - { - super(in); - } + java.lang.Object getValue(); /** - * Do not close the stream, return without action. + * Get the integer code of this policy value. */ - public void close() - { - // Do nothing. - } + int getCode(); + }
\ No newline at end of file diff --git a/gnu/CORBA/Restricted_ORB.java b/gnu/CORBA/Restricted_ORB.java index e2e7e7e93..801154e20 100644 --- a/gnu/CORBA/Restricted_ORB.java +++ b/gnu/CORBA/Restricted_ORB.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -49,18 +49,19 @@ 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.UnionMember; - -import org.omg.CORBA.ORBPackage.InvalidName; 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; /** @@ -80,7 +81,7 @@ import java.util.Properties; * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public class Restricted_ORB - extends ORB + extends org.omg.CORBA_2_3.ORB { /** * The singleton instance of this ORB. @@ -88,6 +89,11 @@ public class Restricted_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. */ @@ -104,7 +110,9 @@ public class Restricted_ORB /** {@inheritDoc} */ public Any create_any() { - return new gnuAny(); + gnuAny any = new gnuAny(); + any.setOrb(this); + return any; } /** {@inheritDoc} */ @@ -410,4 +418,46 @@ public class Restricted_ORB { no(); } + + /** + * Register the value factory under the given repository id. + */ + public ValueFactory register_value_factory(String repository_id, + ValueFactory factory + ) + { + factories.put(repository_id, factory); + return factory; + } + + /** + * Unregister the value factroy. + */ + public void unregister_value_factory(String id) + { + factories.remove(id); + } + + /** + * Look for the value factory for the value, having the given repository id. + * The implementation checks for the registered value factories first. + * If none found, it tries to load and instantiate the class, mathing the + * given naming convention. If this faild, null is returned. + * + * @param repository_id a repository id. + * + * @return a found value factory, null if none. + */ + public ValueFactory lookup_value_factory(String repository_id) + { + ValueFactory f = (ValueFactory) factories.get(repository_id); + if (f != null) + return f; + + f = (ValueFactory) ObjectCreator.createObject(repository_id, "DefaultFactory"); + if (f != null) + factories.put(repository_id, f); + + return f; + } }
\ No newline at end of file diff --git a/gnu/CORBA/ServiceDetailHolder.java b/gnu/CORBA/ServiceDetailHolder.java index 8073350a0..e8786374a 100644 --- a/gnu/CORBA/ServiceDetailHolder.java +++ b/gnu/CORBA/ServiceDetailHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/ServiceRequestAdapter.java b/gnu/CORBA/ServiceRequestAdapter.java index f584eb7a3..7f40fc84d 100644 --- a/gnu/CORBA/ServiceRequestAdapter.java +++ b/gnu/CORBA/ServiceRequestAdapter.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -53,10 +53,11 @@ 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. + * This class supports invocation using ServerRequest. When possible, + * it is better to use the {@link ObjectImpl#_invoke} rather than + * working via ServerRequest. However since 1.4 the ServerRequest is + * involved into POA machinery making this type of call is sometimes + * inavoidable. * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ @@ -86,13 +87,13 @@ public class ServiceRequestAdapter } /** - * The old style invocation using the currently deprecated server - * request class. + * Make an invocation. * * @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. + * @param result the result holder with the set suitable streamable. + * Using this parameter only increase the performance. It can be + * null if the return type is void or unknown. */ public static void invoke(ServerRequest request, InvokeHandler target, Streamable result @@ -133,12 +134,20 @@ public class ServiceRequestAdapter else { if (result != null) - { - result._read(in); - gnuAny r = new gnuAny(); - r.insert_Streamable(result); - request.set_result(r); - }; + { + // Use the holder for the return value, if provided. + result._read(in); + + gnuAny r = new gnuAny(); + r.insert_Streamable(result); + request.set_result(r); + } + else + { + // Use the universal holder otherwise. + gnuAny r = new gnuAny(); + r.insert_Streamable(new streamReadyHolder(in)); + } // Unpack the arguments for (int i = 0; i < args.count(); i++) diff --git a/gnu/CORBA/SetOverrideTypeHolder.java b/gnu/CORBA/SetOverrideTypeHolder.java index d1fcc18f3..12b4b9f0c 100644 --- a/gnu/CORBA/SetOverrideTypeHolder.java +++ b/gnu/CORBA/SetOverrideTypeHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/Simple_delegate.java b/gnu/CORBA/Simple_delegate.java index 662dfef18..5eabc7da8 100644 --- a/gnu/CORBA/Simple_delegate.java +++ b/gnu/CORBA/Simple_delegate.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -195,13 +195,40 @@ public class Simple_delegate } /** - * Only returns true if the objects are equal ('=='). + * Returns true if the objects are the same of have + * the same delegate set. All objects in this implementation + * have a separate delegate. */ public boolean is_equivalent(org.omg.CORBA.Object target, org.omg.CORBA.Object other ) { - return target == other; + if (target == other) + return true; + if ((target instanceof ObjectImpl) && other instanceof ObjectImpl) + { + try + { + org.omg.CORBA.portable.Delegate a = + ((ObjectImpl) target)._get_delegate(); + org.omg.CORBA.portable.Delegate b = + ((ObjectImpl) other)._get_delegate(); + if (a == b) + { + return true; + } + if (a != null && b != null) + { + return a.equals(b); + } + } + catch (Exception ex) + { + // Unable to get one of the delegates. + return false; + } + } + return false; } /** @@ -246,4 +273,4 @@ public class Simple_delegate { throw new InternalError(); } -} +}
\ No newline at end of file diff --git a/gnu/CORBA/SocketRepository.java b/gnu/CORBA/SocketRepository.java new file mode 100644 index 000000000..70bceadf5 --- /dev/null +++ b/gnu/CORBA/SocketRepository.java @@ -0,0 +1,93 @@ +/* SocketRepository.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import java.net.Socket; + +import java.util.HashMap; + +/** + * This class caches the opened sockets that are reused during the + * frequent calls. Otherwise, some CORBA applications may spend + * up to 90 % of the working time just for closing and opening the sockets. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class SocketRepository +{ + /** + * The socket map. + */ + private static HashMap sockets = new HashMap(); + + /** + * Put a socket. + * + * @param key as socket key. + * + * @param s a socket. + */ + public static void put_socket(Object key, Socket s) + { + sockets.put(key, s); + } + + /** + * Get a socket. + * + * @param key a socket key. + * + * @return an opened socket for reuse, null if no such + * available or it is closed. + */ + public static Socket get_socket(Object key) + { + Socket s = (Socket) sockets.get(key); + if (s != null && s.isClosed()) + { + sockets.remove(key); + return null; + } + else + { + sockets.remove(key); + return s; + } + } +}
\ No newline at end of file diff --git a/gnu/CORBA/TypeCodeHelper.java b/gnu/CORBA/TypeCodeHelper.java index 163ebbeb9..c74227542 100644 --- a/gnu/CORBA/TypeCodeHelper.java +++ b/gnu/CORBA/TypeCodeHelper.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/Unexpected.java b/gnu/CORBA/Unexpected.java index f030d4dfc..89fb7e7b9 100644 --- a/gnu/CORBA/Unexpected.java +++ b/gnu/CORBA/Unexpected.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/Version.java b/gnu/CORBA/Version.java index 64ef01853..84f40bf4f 100644 --- a/gnu/CORBA/Version.java +++ b/gnu/CORBA/Version.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/WCharHolder.java b/gnu/CORBA/WCharHolder.java index baa768fdf..23f0ad100 100644 --- a/gnu/CORBA/WCharHolder.java +++ b/gnu/CORBA/WCharHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/WStringHolder.java b/gnu/CORBA/WStringHolder.java index 84ffcae96..c9e8e3323 100644 --- a/gnu/CORBA/WStringHolder.java +++ b/gnu/CORBA/WStringHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/_PolicyImplBase.java b/gnu/CORBA/_PolicyImplBase.java new file mode 100644 index 000000000..d9ff9d648 --- /dev/null +++ b/gnu/CORBA/_PolicyImplBase.java @@ -0,0 +1,231 @@ +/* _PolicyImplBase.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.Policy; +import org.omg.CORBA.PolicyHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.InvokeHandler; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; + +/** + * The server side implementation base for the {@link Policy}. + * + * @specnote The java 1.4 API does not define the server side policy + * implementation base, but it defines the policy client side stub. + * As these two classes always work together, and even no separate testing is + * possible, the required implementation base is provided in gnu.CORBA + * namespace. Sun will probably include they base in the future java APIs. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class _PolicyImplBase + extends ObjectImpl + implements Policy, InvokeHandler +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The policy repository ids. + */ + private final String[] ids; + + /** + * The type of this policy. + */ + private final int type; + + /** + * The value of this policy. The value object is never the same + * for different policies. + */ + private final java.lang.Object value; + + /** + * The policy integer code, written in request to write + * the policy value. + */ + private final int policyCode; + + /** + * Create the new policy of the given type, having the given value. + * For security reasons, the method is kept package private. + * + * @param p_type the type of this policy. + * @param p_value the value of this policy. + * @param p_code the integer code of this policy. + * @param p_idl the policy IDL type string. The {@link #_ids()} + * will return array, first line being this string and another + * being PolicyHelper.id(). + */ + public _PolicyImplBase(int p_type, java.lang.Object p_value, int p_code, + String p_idl + ) + { + type = p_type; + value = p_value; + policyCode = p_code; + ids = new String[] { p_idl, PolicyHelper.id() }; + } + + /** + * Get the integer code of the type of this policy. + */ + public final int policy_type() + { + return type; + } + + /** + * Return the list of repository ids. + */ + public final String[] _ids() + { + return ids; + } + + /** + * Call the required method. + */ + public final OutputStream _invoke(String method, InputStream input, + ResponseHandler rh + ) + { + OutputStream output = null; + + if (method.equals("destroy")) + { + // The "destroy" has been invoked. + destroy(); + output = rh.createReply(); + } + else if (method.equals("copy")) + { + // The "copy" has been invoked. + org.omg.CORBA.Object returns = copy(); + output = rh.createReply(); + output.write_Object(this); + } + else if (method.equals("policy_type")) + { + // The "policy_type" has been invoked. + int returns = policy_type(); + output = rh.createReply(); + output.write_long(returns); + } + else if (method.equals("value")) + { + // The "value" can be invoked on the children types + // and must return an integer, representing the policy value + // (CORBA enumeration). + output = rh.createReply(); + output.write_long(policyCode); + } + else + throw new BAD_OPERATION(method, 0, CompletionStatus.COMPLETED_MAYBE); + + return output; + } + + /** + * Get the value of this policy + */ + public final java.lang.Object getValue() + { + return value; + } + + /** + * Get the integer code of this policy value. + */ + public final int getCode() + { + return policyCode; + } + + /** + * Returns without action. It is a work of garbage collector + * to remove the unused objects. + */ + public final void destroy() + { + } + + /** + * Returns the string representation of the given policy. + */ + public final String toString() + { + return value.toString(); + } + + /** + * Create a copy of this policy. The object is not mutable, so + * <code>this</code> can be returned. + * + * @return <code>this</code> + */ + public Policy copy() + { + return this; + } + + /** + * Use the value to get a hash code. + */ + public int hashCode() + { + return getValue().hashCode(); + } + + /** + * Check the values for equality. + */ + public boolean equals(Object x) + { + return x == null ? false : getValue().equals(x); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/aliasTypeCode.java b/gnu/CORBA/aliasTypeCode.java index a211b641f..884663101 100644 --- a/gnu/CORBA/aliasTypeCode.java +++ b/gnu/CORBA/aliasTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/binaryReply.java b/gnu/CORBA/binaryReply.java index 6d3c19291..71afa3776 100644 --- a/gnu/CORBA/binaryReply.java +++ b/gnu/CORBA/binaryReply.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/bufferedResponseHandler.java b/gnu/CORBA/bufferedResponseHandler.java index 03745a03a..e7f00baeb 100644 --- a/gnu/CORBA/bufferedResponseHandler.java +++ b/gnu/CORBA/bufferedResponseHandler.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/cdrEncapsCodec.java b/gnu/CORBA/cdrEncapsCodec.java new file mode 100644 index 000000000..699c6f76a --- /dev/null +++ b/gnu/CORBA/cdrEncapsCodec.java @@ -0,0 +1,356 @@ +/* cdrEncapsCodec.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import gnu.CORBA.CDR.cdrBufInput; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.CDR.cdrOutput; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UserException; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecPackage.FormatMismatch; +import org.omg.IOP.CodecPackage.InvalidTypeForEncoding; +import org.omg.IOP.CodecPackage.TypeMismatch; + +/** + * The local {@link Codec} implementation for ENCODING_CDR_ENCAPS + * encoding. This is a local implementation; the remote side should + * have its own Codec of this kind. + * + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class cdrEncapsCodec + extends LocalObject + implements Codec +{ + /** + * The default version of encoding, used in parameterless constructor. + */ + private static final Version DEFAULT_VERSION = new Version(1, 2); + + /** + * If set to true, no wide string or wide character is allowed (GIOP 1.0). + */ + private final boolean noWide; + + /** + * The version of this encoding. + */ + private final Version version; + + /** + * The associated ORB. + */ + protected final ORB orb; + + /** + * If true, this Codec writes the record length (as int) in the beginning + * of the record. This indicator is part of the formal OMG standard, but it is + * missing in Sun's implementation. Both Suns's and this Codec detects + * the indicator, if present, but can also decode data where this information + * is missing. If the length indicator is missing, the first four bytes in + * Suns encoding are equal to 0 (Big Endian marker). + */ + private boolean lengthIndicator = true; + + /** + * Create an instance of this Codec, encoding following the given version. + */ + public cdrEncapsCodec(ORB _orb, Version _version) + { + orb = _orb; + version = _version; + noWide = version.until_inclusive(1, 0); + } + + /** + * Return the array of repository ids for this object. + * + * @return { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }, always. + */ + public String[] _ids() + { + return new String[] { "IDL:gnu/CORBA/cdrEnapsCodec:1.0" }; + } + + /** + * Decode the contents of the byte array into Any. + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode(byte[] them) + throws FormatMismatch + { + cdrBufInput input = createInput(them); + cdrBufInput encapsulation = createEncapsulation(them, input); + + TypeCode type = encapsulation.read_TypeCode(); + + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new FormatMismatch(ex.getMessage()); + } + + return readAny(type, encapsulation); + } + + private cdrBufInput createEncapsulation(byte[] them, cdrBufInput input) + { + cdrBufInput encapsulation; + + if ((them [ 0 ] | them [ 1 ] | them [ 2 ] | them [ 3 ]) == 0) + { + // Skip that appears to be the always present Big Endian marker. + encapsulation = input; + input.read_short(); + } + else + encapsulation = input.read_encapsulation(); + return encapsulation; + } + + /** {@inheritDoc} */ + public byte[] encode(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + cdrBufOutput output = createOutput(that); + + // cdrBufOutput has internal support for this encoding. + cdrOutput encapsulation = output.createEncapsulation(); + + try + { + TypeCodeHelper.write(encapsulation, that.type()); + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Decode the value, stored in the byte array, into Any, assuming, + * that the byte array holds the data structure, defined by the + * given typecode. + * + * The byte array may have the optional four byte length indicator + * in the beginning. If these four bytes are zero, it is assumed, + * that no length indicator is present. + */ + public Any decode_value(byte[] them, TypeCode type) + throws FormatMismatch, TypeMismatch + { + try + { + checkTypePossibility("", type); + } + catch (InvalidTypeForEncoding ex) + { + throw new TypeMismatch(ex.getMessage()); + } + + cdrBufInput input = createInput(them); + cdrBufInput encapsulation = createEncapsulation(them, input); + return readAny(type, encapsulation); + } + + /** + * Read an Any from the given stream. + * + * @param type a type of the Any to read. + * @param input the encapsulation stream. + */ + private Any readAny(TypeCode type, cdrBufInput encapsulation) + throws MARSHAL + { + gnuAny a = new gnuAny(); + a.setOrb(orb); + + // cdrBufInput has internal support for this encoding. + a.read_value(encapsulation, type); + return a; + } + + /** {@inheritDoc} */ + public byte[] encode_value(Any that) + throws InvalidTypeForEncoding + { + checkTypePossibility("", that.type()); + + cdrBufOutput output = createOutput(that); + + cdrOutput encapsulation = output.createEncapsulation(); + + try + { + that.write_value(encapsulation); + + encapsulation.close(); + output.close(); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; + } + return output.buffer.toByteArray(); + } + + /** + * Create the CDR output stream for writing the given Any. + * The cdrBufOutput has internal support for encapsulation encodings. + * + * @param that the Any that will be written. + * + * @return the stream. + * + * @throws InvalidTypeForEncoding if that Any cannot be written under the + * given version. + */ + private cdrBufOutput createOutput(Any that) + throws InvalidTypeForEncoding + { + cdrBufOutput output = new cdrBufOutput(); + output.setOrb(orb); + output.setVersion(version); + return output; + } + + /** + * Checks if the given type can be encoded. Currently only checks for wide + * strings and wide chars for GIOP 1.0. + * + * @param t a typecode to chek. + * + * @throws InvalidTypeForEncoding if the typecode is not valid for the given + * version. + */ + private void checkTypePossibility(String name, TypeCode t) + throws InvalidTypeForEncoding + { + if (noWide) + { + try + { + int kind = t.kind().value(); + + if (kind == TCKind._tk_wchar || kind == TCKind._tk_wstring) + throw new InvalidTypeForEncoding(name + " wide char in " + + version + ); + else if (kind == TCKind._tk_alias || kind == TCKind._tk_array || + kind == TCKind._tk_sequence + ) + checkTypePossibility("Array member", t.content_type()); + + else if (kind == TCKind._tk_struct || kind == TCKind._tk_union) + { + for (int i = 0; i < t.member_count(); i++) + { + checkTypePossibility(t.member_name(i), t.member_type(i)); + } + } + } + catch (UserException ex) + { + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; + } + } + } + + /** + * Create the CDR input stream for reading the given byte array. + * + * @param them a byte array to read. + * + * @return the stream. + */ + private cdrBufInput createInput(byte[] them) + { + cdrBufInput input = new cdrBufInput(them); + input.setOrb(orb); + input.setVersion(version); + return input; + } + + /** + * Check if the Codec writes the length indicator. + */ + public boolean hasLengthIndicator() + { + return lengthIndicator; + } + + /** + * Sets if the Codec must write the record length in the beginning of the + * array. Encodings both with and without that indicator are understood + * both by Suns and this codec, but the OMG specification seems requiring + * it. The default behavior is to use the length indicator. + * + * @param use_lengthIndicator + */ + public void setUseLengthIndicator(boolean use_lengthIndicator) + { + lengthIndicator = use_lengthIndicator; + } +}
\ No newline at end of file diff --git a/gnu/CORBA/corbaArrayList.java b/gnu/CORBA/corbaArrayList.java index 7d531c092..1690f0583 100644 --- a/gnu/CORBA/corbaArrayList.java +++ b/gnu/CORBA/corbaArrayList.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/fixedTypeCode.java b/gnu/CORBA/fixedTypeCode.java index 4d09e043d..ec88c22be 100644 --- a/gnu/CORBA/fixedTypeCode.java +++ b/gnu/CORBA/fixedTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/generalTypeCode.java b/gnu/CORBA/generalTypeCode.java index 222e7afb3..3b7914878 100644 --- a/gnu/CORBA/generalTypeCode.java +++ b/gnu/CORBA/generalTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -62,7 +62,7 @@ public class generalTypeCode /** * Indicates that the field value has not been previously set. */ - protected static int UNSET = -Integer.MIN_VALUE; + protected static int UNSET = Integer.MIN_VALUE; /** * The kinds for that the length() must return 0 even if it diff --git a/gnu/CORBA/gnuAny.java b/gnu/CORBA/gnuAny.java index 7997265df..a48c50d61 100644 --- a/gnu/CORBA/gnuAny.java +++ b/gnu/CORBA/gnuAny.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -68,6 +68,8 @@ 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; @@ -279,9 +281,19 @@ public class gnuAny { try { - return ((ValueBaseHolder) has).value; + 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 (ClassCastException ex) + catch (Exception ex) { return new BAD_OPERATION("Value type expected"); } diff --git a/gnu/CORBA/gnuCodecFactory.java b/gnu/CORBA/gnuCodecFactory.java new file mode 100644 index 000000000..8b71baf14 --- /dev/null +++ b/gnu/CORBA/gnuCodecFactory.java @@ -0,0 +1,95 @@ +/* gnuCodecFactory.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.*; +import org.omg.CORBA.LocalObject; +import org.omg.IOP.*; +import org.omg.IOP.Codec; +import org.omg.IOP.CodecFactory; +import org.omg.IOP.CodecFactoryPackage.UnknownEncoding; +import org.omg.IOP.Encoding; + +/** + * A simple implementation of the Codec factory, able to return the + * standard Codec's. Only ENCODING_CDR_ENCAPS encoding is supported. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuCodecFactory + extends LocalObject + implements CodecFactory +{ + /** + * The associated ORB. + */ + private final ORB orb; + + /** + * Create a new instance of the this factory, associated with the given ORB. + */ + public gnuCodecFactory(ORB an_orb) + { + orb = an_orb; + } + + /** + * Creates the Codec for the given encoding. + * + * @param for_encoding the encoding for that the Codec must be created. + * + * @return the suitable Codec. + * + * @throws UnknownEncoding if the encoding is not a ENCODING_CDR_ENCAPS. + */ + public Codec create_codec(Encoding for_encoding) + throws UnknownEncoding + { + if (for_encoding.format != ENCODING_CDR_ENCAPS.value) + throw new UnknownEncoding("Only ENCODING_CDR_ENCAPS is " + + "supported by this factory." + ); + + return new cdrEncapsCodec(orb, + new Version(for_encoding.major_version, + for_encoding.minor_version + ) + ); + } +}
\ No newline at end of file diff --git a/gnu/CORBA/gnuContext.java b/gnu/CORBA/gnuContext.java index 533d7026b..baa9fc804 100644 --- a/gnu/CORBA/gnuContext.java +++ b/gnu/CORBA/gnuContext.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuContextList.java b/gnu/CORBA/gnuContextList.java index 5375e8b59..2a26437de 100644 --- a/gnu/CORBA/gnuContextList.java +++ b/gnu/CORBA/gnuContextList.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuEnvironment.java b/gnu/CORBA/gnuEnvironment.java index f470c95c0..ba02e3b19 100644 --- a/gnu/CORBA/gnuEnvironment.java +++ b/gnu/CORBA/gnuEnvironment.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuExceptionList.java b/gnu/CORBA/gnuExceptionList.java index 55a9cc19e..b684ec928 100644 --- a/gnu/CORBA/gnuExceptionList.java +++ b/gnu/CORBA/gnuExceptionList.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuNVList.java b/gnu/CORBA/gnuNVList.java index e423df3b4..e436c332c 100644 --- a/gnu/CORBA/gnuNVList.java +++ b/gnu/CORBA/gnuNVList.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuNamedValue.java b/gnu/CORBA/gnuNamedValue.java index eda91df2c..6e3c271c9 100644 --- a/gnu/CORBA/gnuNamedValue.java +++ b/gnu/CORBA/gnuNamedValue.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/gnuRequest.java b/gnu/CORBA/gnuRequest.java index 745b350d5..cbff17f69 100644 --- a/gnu/CORBA/gnuRequest.java +++ b/gnu/CORBA/gnuRequest.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -51,25 +51,27 @@ import org.omg.CORBA.ARG_OUT; import org.omg.CORBA.Any; import org.omg.CORBA.BAD_INV_ORDER; import org.omg.CORBA.Bounds; +import org.omg.CORBA.CompletionStatus; import org.omg.CORBA.Context; import org.omg.CORBA.ContextList; import org.omg.CORBA.Environment; import org.omg.CORBA.ExceptionList; import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_RESOURCES; import org.omg.CORBA.NVList; import org.omg.CORBA.NamedValue; import org.omg.CORBA.ORB; import org.omg.CORBA.Request; import org.omg.CORBA.SystemException; import org.omg.CORBA.TypeCode; -import org.omg.CORBA.UserException; +import org.omg.CORBA.UnknownUserException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.BindException; import java.net.Socket; -import org.omg.CORBA.UnknownUserException; /** * The implementation of the CORBA request. @@ -86,9 +88,23 @@ public class gnuRequest public static Version MAX_SUPPORTED = new Version(1, 2); /** - * The request reading buffer size. + * The initial pause that the Request makes when + * the required port is not available. + */ + public static int PAUSE_INITIAL = 50; + + /** + * The number of repretetive attempts to get a required + * port, if it is not immediately available. */ - public static final int READ_BUFFER_SIZE = 2048; + public static int PAUSE_STEPS = 12; + + /** + * The maximal pausing interval between two repetetive attempts. + * The interval doubles after each unsuccessful attempt, but + * will not exceed this value. + */ + public static int PAUSE_MAX = 1000; /** * The empty byte array. @@ -196,6 +212,11 @@ public class gnuRequest } /** + * Used when redirecting request to another target. + */ + gnuRequest redirected; + + /** * Get the IOR data, sufficient to find the invocation target. * * @return the IOR data. @@ -648,9 +669,54 @@ public class gnuRequest // Now the message size is available. header.message_size = request_part.buffer.size(); + Socket socket = null; + + java.lang.Object key = ior.Internet.host + ":" + ior.Internet.port; + + synchronized (SocketRepository.class) + { + socket = SocketRepository.get_socket(key); + } + try { - Socket socket = new Socket(ior.Internet.host, ior.Internet.port); + long pause = PAUSE_INITIAL; + + if (socket == null) + { + // The BindException may be thrown under very heavy parallel + // load. For some time, just wait, exceptiong the socket to free. + Open: + for (int i = 0; i < PAUSE_STEPS; i++) + { + try + { + socket = new Socket(ior.Internet.host, ior.Internet.port); + break Open; + } + catch (BindException ex) + { + try + { + // Expecting to free a socket via finaliser. + System.gc(); + Thread.sleep(pause); + pause = pause * 2; + if (pause > PAUSE_MAX) + pause = PAUSE_MAX; + } + catch (InterruptedException iex) + { + } + } + } + } + + if (socket == null) + throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port + + " in use" + ); + socket.setKeepAlive(true); OutputStream socketOutput = socket.getOutputStream(); @@ -674,16 +740,37 @@ public class gnuRequest { n += socketInput.read(r, n, r.length - n); } - socketInput.close(); return new binaryReply(orb, response_header, r); } else return EMPTY; } - catch (IOException ex1) + catch (IOException io_ex) + { + MARSHAL m = + new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" + + ior.Internet.port, 10000 + ior.Internet.port, + CompletionStatus.COMPLETED_NO + ); + m.initCause(io_ex); + throw m; + } + finally { - ex1.printStackTrace(); - return null; + try + { + if (socket != null && !socket.isClosed()) + { + socket.setSoTimeout(Functional_ORB.TANDEM_REQUESTS); + SocketRepository.put_socket(key, socket); + } + } + catch (IOException scx) + { + InternalError ierr = new InternalError(); + ierr.initCause(scx); + throw ierr; + } } } @@ -754,8 +841,6 @@ public class gnuRequest // The stream must be aligned sinve v1.2, but only once. boolean align = response.header.version.since_inclusive(1, 2); - boolean moved_permanently = false; - switch (rh.reply_status) { case ReplyHeader.NO_EXCEPTION : @@ -843,16 +928,21 @@ public class gnuRequest } catch (IOException ex) { - throw new MARSHAL(ex + " while reading the forwarding info"); + new MARSHAL("Cant read forwarding info", 5103, + CompletionStatus.COMPLETED_NO + ); } setIor(forwarded); + // Repeat with the forwarded information. p_invoke(); return; default : - throw new MARSHAL("Unknow reply status: " + rh.reply_status); + throw new MARSHAL("Unknow reply status", 8100 + rh.reply_status, + CompletionStatus.COMPLETED_NO + ); } } @@ -864,10 +954,10 @@ public class gnuRequest * * @throws MARSHAL if the attempt to write the parameters has failde. */ - private void write_parameter_buffer(MessageHeader header, - cdrBufOutput request_part - ) - throws MARSHAL + protected void write_parameter_buffer(MessageHeader header, + cdrBufOutput request_part + ) + throws MARSHAL { try { @@ -891,8 +981,10 @@ public class gnuRequest * * @throws MARSHAL if the attempt to write the parameters has failde. */ - private void write_parameters(MessageHeader header, cdrBufOutput request_part) - throws MARSHAL + protected void write_parameters(MessageHeader header, + cdrBufOutput request_part + ) + throws MARSHAL { // Align after 1.2, but only once. boolean align = header.version.since_inclusive(1, 2); @@ -919,7 +1011,9 @@ public class gnuRequest } catch (Bounds ex) { - throw new MARSHAL("Unable to write method arguments to CDR output."); + InternalError ierr = new InternalError(); + ierr.initCause(ex); + throw ierr; } } -} +}
\ No newline at end of file diff --git a/gnu/CORBA/holderFactory.java b/gnu/CORBA/holderFactory.java index 17e0a68e5..177797a9c 100644 --- a/gnu/CORBA/holderFactory.java +++ b/gnu/CORBA/holderFactory.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 @@ -177,7 +177,6 @@ public class holderFactory } catch (Exception ex) { - ex.printStackTrace(); return null; } } diff --git a/gnu/CORBA/primitiveArrayTypeCode.java b/gnu/CORBA/primitiveArrayTypeCode.java index 6a4864033..7e2beebc9 100644 --- a/gnu/CORBA/primitiveArrayTypeCode.java +++ b/gnu/CORBA/primitiveArrayTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. + 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 diff --git a/gnu/CORBA/primitiveTypeCode.java b/gnu/CORBA/primitiveTypeCode.java index d240c9aee..1fa5cd09f 100644 --- a/gnu/CORBA/primitiveTypeCode.java +++ b/gnu/CORBA/primitiveTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. + 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 diff --git a/gnu/CORBA/recordTypeCode.java b/gnu/CORBA/recordTypeCode.java index 1e34b9aa3..8f2ecde7d 100644 --- a/gnu/CORBA/recordTypeCode.java +++ b/gnu/CORBA/recordTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/recursiveTypeCode.java b/gnu/CORBA/recursiveTypeCode.java index 1fbae2401..6bc672e6e 100644 --- a/gnu/CORBA/recursiveTypeCode.java +++ b/gnu/CORBA/recursiveTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/streamReadyHolder.java b/gnu/CORBA/streamReadyHolder.java index db35495c0..a777bd555 100644 --- a/gnu/CORBA/streamReadyHolder.java +++ b/gnu/CORBA/streamReadyHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/streamRequest.java b/gnu/CORBA/streamRequest.java index 5b63ca88e..a0f7eb099 100644 --- a/gnu/CORBA/streamRequest.java +++ b/gnu/CORBA/streamRequest.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/stringTypeCode.java b/gnu/CORBA/stringTypeCode.java index 40adffaff..27aa119f3 100644 --- a/gnu/CORBA/stringTypeCode.java +++ b/gnu/CORBA/stringTypeCode.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/stubFinder.java b/gnu/CORBA/stubFinder.java index 3aff84133..77efd0047 100644 --- a/gnu/CORBA/stubFinder.java +++ b/gnu/CORBA/stubFinder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/typeNamer.java b/gnu/CORBA/typeNamer.java index ec3cf6e97..8b701015e 100644 --- a/gnu/CORBA/typeNamer.java +++ b/gnu/CORBA/typeNamer.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 diff --git a/gnu/CORBA/universalHolder.java b/gnu/CORBA/universalHolder.java index 1a5226c3e..6d8b77472 100644 --- a/gnu/CORBA/universalHolder.java +++ b/gnu/CORBA/universalHolder.java @@ -15,8 +15,8 @@ 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., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. +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 |