diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2005-09-23 19:36:46 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2005-09-23 19:36:46 +0000 |
commit | 9b044d19517541c95681d35a92dbc81e6e21d94f (patch) | |
tree | b2c2abf473309eac532cafbad81b20f3270ff45f /libjava/classpath/gnu/CORBA | |
parent | acff2da93c917c21aca570e2a41ee613c2b32c2e (diff) | |
download | gcc-9b044d19517541c95681d35a92dbc81e6e21d94f.tar.gz |
Initial revision
From-SVN: r104578
Diffstat (limited to 'libjava/classpath/gnu/CORBA')
58 files changed, 15278 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java b/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java new file mode 100644 index 00000000000..0c787ddc2df --- /dev/null +++ b/libjava/classpath/gnu/CORBA/CDR/noHeaderInput.java @@ -0,0 +1,166 @@ +/* noHeaderInput.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 org.omg.CORBA.CustomMarshal; +import org.omg.CORBA.DataInputStream; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.portable.BoxedValueHelper; +import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.portable.ValueFactory; + +import java.io.Serializable; + +/** + * Substitutes the main stream in factories when the header is already + * behind. Overrides methods that may be invoked from the factory, + * forcing not to read the header if called first time on this stream. + * + * This stream reverts to default behavior if one or more call are + * made (reading value types that are nested fields of the value type). + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +class noHeaderInput + extends cdrBufInput + implements DataInputStream +{ + /** + * If true, this is not the first call. + */ + boolean notFirst; + + /** + * Create an instance, reading from the given buffer. + */ + public noHeaderInput(byte[] buffer) + { + super(buffer); + } + + /** + * Read when knowning the class instance. + */ + public Serializable read_value(Class clz) + { + if (notFirst) + return super.read_value(clz); + else + { + try + { + notFirst = true; + return read_value((Serializable) clz.newInstance()); + } + catch (Exception ex) + { + MARSHAL m = new MARSHAL("Unable to create an instance"); + m.initCause(ex); + throw m; + } + } + } + + /** + * Tries to read using boxed value helper. + */ + public Serializable read_value(BoxedValueHelper helper) + { + if (notFirst) + return super.read_value(helper); + else + { + notFirst = true; + return helper.read_value(this); + } + } + + /** + * Tries to locate a factory using repository id. + */ + public Serializable read_value(String repository_id) + { + if (notFirst) + return super.read_value(repository_id); + else + { + notFirst = true; + + ValueFactory factory = + ((org.omg.CORBA_2_3.ORB) orb()).lookup_value_factory(repository_id); + if (factory == null) + throw new MARSHAL("No factory"); + return factory.read_value(this); + } + } + + /** + * Try to read when having an unitialised value. + */ + public Serializable read_value(Serializable value) + { + if (notFirst) + return super.read_value(value); + else + { + notFirst = true; + + // The user-defines io operations are implemented. + if (value instanceof CustomMarshal) + { + CustomMarshal marsh = (CustomMarshal) value; + try + { + marsh.unmarshal((DataInputStream) this); + } + catch (ClassCastException ex) + { + Vio.incorrect_plug_in(ex); + } + } + else + // The IDL-generated io operations are implemented. + if (value instanceof Streamable) + { + ((Streamable) value)._read(this); + } + return value; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java b/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java new file mode 100644 index 00000000000..47176c4b589 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/abstractDynAny.java @@ -0,0 +1,177 @@ +/* abstractDynAny.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.typeNamer; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; + +import java.io.Serializable; + +/** + * The top of our DynAny implementation, this class provides ORB that is + * required to create anys and factory that is required to initialise DynAnys. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class abstractDynAny + extends LocalObject + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The "initial final_type" that can be an alias of the known final_type. + */ + public TypeCode official_type; + + /** + * The "basic" final_type to that the final_type finally evaluates. + */ + public final TypeCode final_type; + + /** + * The DynAny factory, required in initializations. + */ + public final gnuDynAnyFactory factory; + + /** + * The ORB, to that this DynAny belongs. + */ + public final ORB orb; + + /** + * The minor code, indicating the error, related to work with non - GNU + * Classpath DynAny. + */ + short MINOR = 8148; + + /** + * The message about the empty structure or exception. + */ + static final String EMPTY = "Empty structure with no fields."; + + /** + * The message about the structure or exception size mismatch. + */ + static final String SIZE = "Size mismatch."; + + /** + * The message about the content of this DynAny being equal to + * <code>null</code> + */ + static final String ISNULL = "The content is null"; + + /** + * The change value listener. + */ + valueChangedListener listener; + + /** + * Create the abstract dyn any. + */ + public abstractDynAny(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + official_type = oType; + final_type = aType; + factory = aFactory; + orb = anOrb; + } + + /** + * Get the typecode. + */ + public TypeCode type() + { + return official_type; + } + + /** + * Create the Any. + */ + public Any createAny() + { + return orb.create_any(); + } + + /** + * The "value changed" listener. + */ + protected void valueChanged() + { + if (listener != null) + listener.changed(); + } + + /** + * Check the type. + */ + void checkType(TypeCode expected, TypeCode actual) + throws TypeMismatch + { + if (!expected.equal(actual)) + throw new TypeMismatch(typeMismatch(expected, actual)); + } + + /** + * Format "Type mismatch" string. + */ + String typeMismatch(TypeCode expected, TypeCode actual) + { + return typeNamer.nameIt(expected) + " expected " + + typeNamer.nameIt(actual); + } + + /** + * Format "size mismatch" string. + */ + String sizeMismatch(int here, int other) + { + return "Size mismatch, " + other + " (expected " + here + ")"; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java b/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java new file mode 100644 index 00000000000..8d8b7a559b1 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/abstractRecord.java @@ -0,0 +1,405 @@ +/* abstractRecord.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; +import gnu.CORBA.holderFactory; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.TypeCodePackage.Bounds; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynStruct; +import org.omg.DynamicAny.DynValueCommonOperations; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameValuePair; + +import java.io.Serializable; + +import java.lang.reflect.Field; + +/** + * A shared base for both dynamic structure an dynamic value final_type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class abstractRecord + extends anyDivideable + implements DynAny, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + String[] fNames; + + /** + * Creates the structure with the given typecode. + * + * @param fields The DynAny's, representing the fields of the structure. + */ + public abstractRecord(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + } + + /** @inheritDoc */ + public TCKind current_member_kind() + throws TypeMismatch, InvalidValue + { + if (array.length == 0) + throw new TypeMismatch(EMPTY); + try + { + return final_type.member_type(pos).kind(); + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + catch (Bounds e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** @inheritDoc */ + public String current_member_name() + throws TypeMismatch, InvalidValue + { + if (array.length == 0) + throw new TypeMismatch(EMPTY); + try + { + return final_type.member_name(pos); + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + catch (Bounds e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** + * Get content of the structure. This method must be defined on a different + * name because get_members_as_dyn_any() throws exception only in some of the + * supported interfaces. + */ + public NameDynAnyPair[] gnu_get_members_as_dyn_any() + { + NameDynAnyPair[] r = new NameDynAnyPair[ array.length ]; + for (int i = 0; i < r.length; i++) + { + try + { + r [ i ] = new NameDynAnyPair(fNames [ i ], array [ i ]); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + return r; + } + + /** + * Get content of the structure. This method must be defined on a different + * name because get_members_as_dyn_any() throws exception only in some of the + * supported interfaces. + */ + public NameValuePair[] gnu_get_members() + { + NameValuePair[] r = new NameValuePair[ array.length ]; + for (int i = 0; i < r.length; i++) + { + try + { + r [ i ] = new NameValuePair(fNames [ i ], array [ i ].to_any()); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + return r; + } + + /** + * Set members from the provided array. + */ + public void set_members_as_dyn_any(NameDynAnyPair[] value) + throws TypeMismatch, InvalidValue + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + + for (int i = 0; i < value.length; i++) + { + DynAny dynAny = value [ i ].value; + checkType(dynAny.type(), i); + checkName(value [ i ].id, i); + + array [ i ] = dynAny; + } + pos = 0; + } + + /** + * Check the name at the given position ("" matches everything). + */ + private void checkName(String xName, int i) + throws TypeMismatch + { + if (xName.length() > 0 && fNames [ i ].length() > 0) + if (!xName.equals(fNames [ i ])) + throw new TypeMismatch("Field name mismatch " + xName + " expected " + + fNames [ i ] + ); + } + + /** + * Check the type at the given position. + */ + private void checkType(TypeCode t, int i) + throws TypeMismatch + { + if (!array [ i ].type().equal(t)) + throw new TypeMismatch(typeMismatch(array [ i ].type(), t) + " field " + + i + ); + } + + /** + * Set members from the provided array. + */ + public void set_members(NameValuePair[] value) + throws TypeMismatch, InvalidValue + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + + for (int i = 0; i < value.length; i++) + { + Any any = value [ i ].value; + checkType(any.type(), i); + checkName(value [ i ].id, i); + + array [ i ].from_any(any); + } + pos = 0; + } + + /** @inheritDoc */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (from instanceof DynStruct) + { + try + { + set_members_as_dyn_any(((DynStruct) from).get_members_as_dyn_any()); + } + catch (InvalidValue e) + { + TypeMismatch t = new TypeMismatch("Invalid value"); + t.initCause(e); + throw t; + } + } + else + throw new TypeMismatch("Not a DynStruct"); + } + + /** + * Create a copy. + */ + public DynAny copy() + { + DynAny[] c = new DynAny[ array.length ]; + for (int i = 0; i < c.length; i++) + { + c [ i ] = array [ i ].copy(); + } + + abstractRecord d = newInstance(official_type, final_type, factory, orb); + d.array = c; + return d; + } + + /** + * Create a new instance when copying. + */ + protected abstract abstractRecord newInstance(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, + ORB anOrb + ); + + /** + * Done via reflection. + */ + public Any to_any() + { + try + { + Streamable sHolder = holderFactory.createHolder(official_type); + + Class sHolderClass = sHolder.getClass(); + Field sHolderValue = sHolderClass.getField("value"); + Class sClass = sHolderValue.getType(); + + Object structure = sClass.newInstance(); + Object member; + Any am; + Field vread; + Field vwrite; + Streamable memberHolder; + + for (int i = 0; i < array.length; i++) + { + am = array [ i ].to_any(); + memberHolder = am.extract_Streamable(); + vwrite = structure.getClass().getField(final_type.member_name(i)); + vread = memberHolder.getClass().getField("value"); + member = vread.get(memberHolder); + vwrite.set(structure, member); + } + + Any g = createAny(); + sHolderValue.set(sHolder, structure); + g.insert_Streamable(sHolder); + g.type(official_type); + return g; + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + + /** + * Done via reflection. + */ + public void from_any(Any an_any) + throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + try + { + Streamable s = an_any.extract_Streamable(); + if (s == null) + { + if (this instanceof DynValueCommonOperations) + { + ((DynValueCommonOperations) this).set_to_null(); + return; + } + else + throw new InvalidValue(ISNULL); + } + + Object structure = s.getClass().getField("value").get(s); + if (structure == null && (this instanceof DynValueCommonOperations)) + { + ((DynValueCommonOperations) this).set_to_null(); + return; + } + + Any member; + Streamable holder; + Object field; + TypeCode fType; + Field fField; + + for (int i = 0; i < array.length; i++) + { + fField = structure.getClass().getField(fNames [ i ]); + field = fField.get(structure); + fType = array [ i ].type(); + holder = holderFactory.createHolder(fType); + + member = createAny(); + holder.getClass().getField("value").set(holder, field); + member.insert_Streamable(holder); + member.type(fType); + + array [ i ].from_any(member); + } + + if (this instanceof DynValueCommonOperations) + ((DynValueCommonOperations) this).set_to_value(); + } + catch (InvalidValue v) + { + throw v; + } + catch (NoSuchFieldException ex) + { + TypeMismatch v = + new TypeMismatch("holder value does not match typecode"); + v.initCause(ex); + throw v; + } + catch (Exception ex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(ex); + throw t; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java b/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java new file mode 100644 index 00000000000..5f52c8078eb --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/anyDivideable.java @@ -0,0 +1,514 @@ +/* anyDivideable.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.typeNamer; + +import org.omg.CORBA.Any; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.UNKNOWN; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynValueCommon; + +import java.io.Serializable; + +/** + * Provides a base for DynAnys, having multiple components. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class anyDivideable + extends abstractDynAny + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The array of the components that in general case may have different + * final_type. + */ + protected DynAny[] array; + + /** + * The internal pointer. + */ + protected int pos = 0; + + public anyDivideable(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + } + + /** + * Advance forward. + */ + public boolean next() + { + pos++; + return array.length > pos; + } + + /** + * Set zero position. + */ + public void rewind() + { + pos = 0; + } + + /** + * Set a position. + */ + public boolean seek(int p) + { + pos = p; + return pos >= 0 && array.length > pos; + } + + /** + * Get the insertion point as DynAny. This method may throw exceptions if the + * current insertion point does not support reading or insertion of the + * primitive types. + * + * @return the focused component, from where the primitve value can be read or + * where it can be inserted. + * @throws InvalidValue if the primitive value cannot be inserted at the given + * point. + */ + protected DynAny focused() + throws InvalidValue, TypeMismatch + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ].component_count() == 0) + return array [ pos ]; + else + throw new TypeMismatch("Multiple coponents at " + pos); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + } + + /** {@inheritDoc} */ + public int component_count() + { + return array.length; + } + + /** + * Return the second (enclosed any) that is stored in the wrapped Any. + */ + public Any get_any() + throws TypeMismatch, InvalidValue + { + return focused().get_any(); + } + + /** {@inheritDoc} */ + public boolean get_boolean() + throws TypeMismatch, InvalidValue + { + return focused().get_boolean(); + } + + /** {@inheritDoc} */ + public char get_char() + throws TypeMismatch, InvalidValue + { + return focused().get_char(); + } + + /** {@inheritDoc} */ + public double get_double() + throws TypeMismatch, InvalidValue + { + return focused().get_double(); + } + + /** {@inheritDoc} */ + public float get_float() + throws TypeMismatch, InvalidValue + { + return focused().get_float(); + } + + /** {@inheritDoc} */ + public int get_long() + throws TypeMismatch, InvalidValue + { + return focused().get_long(); + } + + /** {@inheritDoc} */ + public long get_longlong() + throws TypeMismatch, InvalidValue + { + return focused().get_longlong(); + } + + /** {@inheritDoc} */ + public byte get_octet() + throws TypeMismatch, InvalidValue + { + return focused().get_octet(); + } + + /** {@inheritDoc} */ + public Object get_reference() + throws TypeMismatch, InvalidValue + { + return focused().get_reference(); + } + + /** {@inheritDoc} */ + public short get_short() + throws TypeMismatch, InvalidValue + { + return focused().get_short(); + } + + /** {@inheritDoc} */ + public String get_string() + throws TypeMismatch, InvalidValue + { + return focused().get_string(); + } + + /** {@inheritDoc} */ + public TypeCode get_typecode() + throws TypeMismatch, InvalidValue + { + return focused().get_typecode(); + } + + /** {@inheritDoc} */ + public int get_ulong() + throws TypeMismatch, InvalidValue + { + return focused().get_ulong(); + } + + /** {@inheritDoc} */ + public long get_ulonglong() + throws TypeMismatch, InvalidValue + { + return focused().get_ulonglong(); + } + + /** {@inheritDoc} */ + public short get_ushort() + throws TypeMismatch, InvalidValue + { + return focused().get_ushort(); + } + + /** {@inheritDoc} */ + public Serializable get_val() + throws TypeMismatch, InvalidValue + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ] instanceof DynValueCommon) + return array [ pos ].get_val(); + else + throw new TypeMismatch(); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + } + + /** {@inheritDoc} */ + public char get_wchar() + throws TypeMismatch, InvalidValue + { + return focused().get_wchar(); + } + + /** {@inheritDoc} */ + public String get_wstring() + throws TypeMismatch, InvalidValue + { + return focused().get_wstring(); + } + + /** {@inheritDoc} */ + public void insert_any(Any a_x) + throws TypeMismatch, InvalidValue + { + focused().insert_any(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_boolean(boolean a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_boolean(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_char(char a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_char(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_double(double a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_double(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_float(float a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_float(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_long(int a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_long(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_longlong(long a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_longlong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_octet(byte a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_octet(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_reference(Object a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_reference(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_short(short a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_short(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_string(String a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_string(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_typecode(TypeCode a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_typecode(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ulong(int a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ulong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ulonglong(long a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ulonglong(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_ushort(short a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_ushort(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_val(Serializable a_x) + throws InvalidValue, TypeMismatch + { + if (pos >= 0 && pos < array.length) + { + if (array [ pos ] instanceof DynValueCommon) + array [ pos ].insert_val(a_x); + else + throw new TypeMismatch(); + } + else + throw new InvalidValue("Out of bounds at " + pos + " valid 0.." + + (array.length - 1) + ); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_wchar(char a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_wchar(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public void insert_wstring(String a_x) + throws InvalidValue, TypeMismatch + { + focused().insert_wstring(a_x); + valueChanged(); + } + + /** {@inheritDoc} */ + public DynAny get_dyn_any() + throws TypeMismatch, InvalidValue + { + return focused().get_dyn_any(); + } + + /** {@inheritDoc} */ + public void insert_dyn_any(DynAny insert_it) + throws TypeMismatch, InvalidValue + { + focused().insert_dyn_any(insert_it); + } + + /** + * Get current component. + * + * @return current component or <code>null</code> if the pointer is out of + * bounds. + */ + public DynAny current_component() + throws TypeMismatch + { + if (array.length == 0) + throw new TypeMismatch("empty"); + return (pos >= 0 && pos < array.length) ? array [ pos ] : null; + } + + /** + * No action, cleanup is done by garbage collector in java. + */ + public void destroy() + { + } + + /** + * Involved in equal(DynAny). + */ + public abstract Any to_any() + throws TypeMismatch; + + /** + * Compares with other DynAny for equality. The final_type, array size and + * array members must match. + */ + public boolean equal(DynAny other) + { + try + { + if (!official_type.equal(other.type())) + return false; + else if (other instanceof anyDivideable) + { + anyDivideable x = (anyDivideable) other; + if (x.array.length != array.length) + return false; + + for (int i = 0; i < array.length; i++) + { + if (!array [ i ].equal(x.array [ i ])) + return false; + } + return true; + } + else if (other == null || other instanceof abstractDynAny) + return false; + else + return other.to_any().equal(to_any()); + } + catch (TypeMismatch e) + { + UNKNOWN u = new UNKNOWN(MINOR, CompletionStatus.COMPLETED_NO); + u.initCause(e); + throw u; + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java b/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java new file mode 100644 index 00000000000..b31a6b357f9 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/anyUndivideable.java @@ -0,0 +1,493 @@ +/* Undivideable.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import java.io.Serializable; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; + +/** + * Represent DynAny that has no internal components (DynEnum and so on). The + * methods, related to internal components, throw exceptions or return agreed + * values like null. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class anyUndivideable + extends abstractDynAny + implements Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Create a new instance with the given typecode. + */ + public anyUndivideable(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb) + { + super(oType, aType, aFactory, anOrb); + } + + /** + * There are no components. + * + * @return 0, always. + */ + public int component_count() + { + return 0; + } + + /** + * There is no current component. + * + * @throws TypeMismatch, always. + */ + public DynAny current_component() + throws TypeMismatch + { + throw new TypeMismatch("Not applicable"); + } + + /** + * Returns without action. + */ + public void destroy() + { + } + + /** + * Not in use. + */ + public Any get_any() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public boolean get_boolean() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public char get_char() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public double get_double() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public DynAny get_dyn_any() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public float get_float() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public int get_long() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public long get_longlong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public byte get_octet() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public Object get_reference() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public short get_short() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public String get_string() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public TypeCode get_typecode() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public int get_ulong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public long get_ulonglong() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public short get_ushort() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public Serializable get_val() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public char get_wchar() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public String get_wstring() + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_any(Any an_any) + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_boolean(boolean a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_char(char a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_double(double a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_dyn_any(DynAny insert_it) + throws TypeMismatch, InvalidValue + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_float(float a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_long(int a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_longlong(long a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_octet(byte a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_reference(Object a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_short(short a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_string(String a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_typecode(TypeCode a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ulong(int a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ulonglong(long a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_ushort(short a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_val(Serializable a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_wchar(char a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public void insert_wstring(String a_x) + throws InvalidValue, TypeMismatch + { + throw new TypeMismatch(); + } + + /** + * Not in use. + */ + public boolean next() + { + return false; + } + + /** + * Not in use. + */ + public void rewind() + { + } + + /** + * Not in use. + */ + public boolean seek(int p) + { + return false; + } + + /** + * Get the typecode of this enumeration. + */ + public TypeCode type() + { + return official_type; + } + + /** + * Compares with other DynAny for equality. + */ + public boolean equals(java.lang.Object other) + { + if (other instanceof DynAny) + return equal((DynAny) other); + else + return false; + } + + /** + * This depends on an object. + */ + public abstract boolean equal(DynAny other); + +} diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java new file mode 100644 index 00000000000..015628ebf90 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAny.java @@ -0,0 +1,945 @@ +/* gnuDynAny.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.OctetHolder; +import gnu.CORBA.Unexpected; +import gnu.CORBA.WCharHolder; +import gnu.CORBA.WStringHolder; +import gnu.CORBA.holderFactory; +import gnu.CORBA.typeNamer; +import gnu.CORBA.universalHolder; + +import org.omg.CORBA.Any; +import org.omg.CORBA.AnyHolder; +import org.omg.CORBA.BooleanHolder; +import org.omg.CORBA.CharHolder; +import org.omg.CORBA.DoubleHolder; +import org.omg.CORBA.FloatHolder; +import org.omg.CORBA.IntHolder; +import org.omg.CORBA.LongHolder; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.ObjectHolder; +import org.omg.CORBA.ShortHolder; +import org.omg.CORBA.StringHolder; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodeHolder; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.ValueBaseHolder; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; + +import java.io.IOException; +import java.io.Serializable; + +import java.util.Arrays; + +/** + * The primitive dynamic Any holds the value basic final_type that cannot be + * traversed. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynAny extends abstractDynAny implements DynAny, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The enclosed Streamable, holding the actual value. + */ + protected Streamable holder; + + /** + * Create DynAny providing the holder. + * + * @param a_holder + */ + public gnuDynAny(Streamable aHolder, TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + holder = aHolder; + } + + /** + * Assign the contents of the given {@link DynAny} to this DynAny. + * + * @param from the source to assign from. + */ + public void assign(DynAny from) throws TypeMismatch + { + checkType(official_type, from.type()); + + if (from instanceof gnuDynAny) + holder = ((gnuDynAny) from).holder; + else + holder = from.to_any().extract_Streamable(); + valueChanged(); + } + + /** + * Create a copy of this {@link DynAny} via buffer read/write. + */ + public DynAny copy() + { + if (holder != null) + { + cdrBufOutput buffer = new cdrBufOutput(); + holder._write(buffer); + + gnuDynAny other; + try + { + other = + new gnuDynAny((Streamable) (holder.getClass().newInstance()), + official_type, final_type, factory, orb + ); + } + catch (Exception e) + { + // Holder must have parameterless constructor. + throw new Unexpected(e); + } + other.holder._read(buffer.create_input_stream()); + return other; + } + else + { + return new gnuDynAny(null, official_type, final_type, factory, orb); + } + } + + /** + * Always returns <code>null</code>. + * + * @return <code>null</code>, always. + */ + public DynAny current_component() throws TypeMismatch + { + throw new TypeMismatch("Not applicable for " + + typeNamer.nameIt(final_type) + ); + } + + /** + * Returns without action, leaving all work to the garbage collector. + */ + public void destroy() + { + } + + /** + * Takes the passed parameter as the enclosed {@link Any} reference. + * + * @param an_any the {@link Any} that will be used as an enclosed reference. + * + * @throws TypeMismatch if the final_type of the passed Any is not the same as + * the final_type, currently stored in this Any. + */ + public void from_any(Any an_any) throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + + Streamable a_holder = an_any.extract_Streamable(); + if (a_holder == null) + { + throw new InvalidValue(ISNULL); + } + else if (a_holder instanceof universalHolder) + { + holder = holderFactory.createHolder(official_type); + if (holder == null) + holder = holderFactory.createHolder(final_type); + + if (holder == null) + holder = ((universalHolder) a_holder).Clone(); + else + { + InputStream in = an_any.create_input_stream(); + holder._read(in); + try + { + in.close(); + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + } + else + { + try + { + InputStream in = an_any.create_input_stream(); + holder = (Streamable) a_holder.getClass().newInstance(); + holder._read(in); + in.close(); + } + catch (Exception ex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(ex); + throw t; + } + } + valueChanged(); + } + + /** + * Return the second (enclosed any) that is stored in the wrapped Any. + */ + public Any get_any() throws TypeMismatch + { + try + { + return ((AnyHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public boolean get_boolean() throws TypeMismatch + { + try + { + return ((BooleanHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public char get_char() throws TypeMismatch + { + try + { + return ((CharHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public double get_double() throws TypeMismatch + { + try + { + return ((DoubleHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public float get_float() throws TypeMismatch + { + try + { + return ((FloatHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public int get_long() throws TypeMismatch + { + try + { + return ((IntHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public long get_longlong() throws TypeMismatch + { + try + { + return ((LongHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public byte get_octet() throws TypeMismatch + { + try + { + return ((OctetHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public Object get_reference() throws TypeMismatch + { + try + { + return ((ObjectHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public short get_short() throws TypeMismatch + { + try + { + return ((ShortHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public String get_string() throws TypeMismatch + { + try + { + return ((StringHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public TypeCode get_typecode() throws TypeMismatch + { + try + { + return ((TypeCodeHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public int get_ulong() throws TypeMismatch + { + check(TCKind.tk_ulong); + return get_long(); + } + + /** {@inheritDoc} */ + public long get_ulonglong() throws TypeMismatch + { + check(TCKind.tk_ulonglong); + return get_longlong(); + } + + /** {@inheritDoc} */ + public short get_ushort() throws TypeMismatch + { + check(TCKind.tk_ushort); + return get_short(); + } + + /** {@inheritDoc} */ + public Serializable get_val() throws TypeMismatch + { + try + { + return ((ValueBaseHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public char get_wchar() throws TypeMismatch + { + try + { + return ((WCharHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public String get_wstring() throws TypeMismatch + { + try + { + return ((WStringHolder) holder).value; + } + catch (ClassCastException cex) + { + TypeMismatch m = new TypeMismatch(); + m.initCause(cex); + throw m; + } + } + + /** {@inheritDoc} */ + public void insert_any(Any a_x) throws TypeMismatch, InvalidValue + { + try + { + if (a_x.type().kind().value() == TCKind._tk_null) + ((AnyHolder) holder).value = a_x; + else + { + OutputStream buf = a_x.create_output_stream(); + buf.write_any(a_x); + holder._read(buf.create_input_stream()); + buf.close(); + } + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + catch (MARSHAL m) + { + InvalidValue v = new InvalidValue(); + v.initCause(m); + throw v; + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** {@inheritDoc} */ + public void insert_boolean(boolean a_x) throws InvalidValue, TypeMismatch + { + try + { + ((BooleanHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_char(char a_x) throws InvalidValue, TypeMismatch + { + try + { + ((CharHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_double(double a_x) throws InvalidValue, TypeMismatch + { + try + { + ((DoubleHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_float(float a_x) throws InvalidValue, TypeMismatch + { + try + { + ((FloatHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_long(int a_x) throws InvalidValue, TypeMismatch + { + try + { + ((IntHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_longlong(long a_x) throws InvalidValue, TypeMismatch + { + try + { + ((LongHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_octet(byte a_x) throws InvalidValue, TypeMismatch + { + try + { + ((OctetHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_reference(Object a_x) throws InvalidValue, TypeMismatch + { + try + { + ((ObjectHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_short(short a_x) throws InvalidValue, TypeMismatch + { + try + { + ((ShortHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_string(String a_x) throws InvalidValue, TypeMismatch + { + try + { + if (a_x != null && + final_type.length() > 0 && + a_x.length() > final_type.length() + ) + throw new InvalidValue(a_x.length() + " exceeds bound, " + + final_type.length() + ); + ((StringHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_typecode(TypeCode a_x) throws InvalidValue, TypeMismatch + { + try + { + ((TypeCodeHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_ulong(int a_x) throws InvalidValue, TypeMismatch + { + try + { + ((IntHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_ulonglong(long a_x) throws InvalidValue, TypeMismatch + { + try + { + ((LongHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_ushort(short a_x) throws InvalidValue, TypeMismatch + { + try + { + ((ShortHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_val(Serializable a_x) throws InvalidValue, TypeMismatch + { + try + { + ((ValueBaseHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_wchar(char a_x) throws InvalidValue, TypeMismatch + { + try + { + ((WCharHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + } + + /** {@inheritDoc} */ + public void insert_wstring(String a_x) throws InvalidValue, TypeMismatch + { + try + { + if (a_x != null && + final_type.length() > 0 && + a_x.length() > type().length() + ) + throw new InvalidValue(a_x.length() + " exceeds bound, " + + final_type.length() + ); + ((WStringHolder) holder).value = a_x; + valueChanged(); + } + catch (ClassCastException cex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(cex); + throw t; + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + + /** + * The objects, enclosed inside this class, have only one component (self). + * + * @return false, always (no other action). + */ + public boolean next() + { + return false; + } + + /** + * Returns without action. + */ + public void rewind() + { + } + + /** + * This objects, stored in this wrapper, never have multiple internal + * components to seek. + * + * @return false, always (no other action). + */ + public boolean seek(int p) + { + return false; + } + + /** + * Returns the enclosed {@link Any}. + * + * @return the enclosed {@link Any}. + */ + public Any to_any() + { + Any a = createAny(); + a.insert_Streamable(holder); + a.type(official_type); + return a; + } + + /** {@inheritDoc} */ + public TypeCode type() + { + return official_type; + } + + /** + * Compute hashcode in a trivial way. + */ + protected int getHashCodeSimple(int maximum) + { + int h = super.hashCode() / 2; + if (h < 0) + h = -h; + return h % maximum; + } + + /** + * Inserts Any, contained in the parameter, into Any, contained in this + * DynAny. + */ + public void insert_dyn_any(DynAny d) throws TypeMismatch, InvalidValue + { + check(d.type().kind()); + + Any a = d.to_any(); + holder = a.extract_Streamable(); + valueChanged(); + } + + /** + * Checks for equality. The DynAnys are equal if the stored Anys are equal. + */ + public boolean equal(DynAny other) + { + if (other instanceof abstractDynAny) + { + if (other instanceof gnuDynAny) + { + gnuDynAny x = (gnuDynAny) other; + + if (!x.holder.getClass().equals(holder.getClass())) + return false; + + cdrBufOutput b1 = new cdrBufOutput(); + x.holder._write(b1); + + cdrBufOutput b2 = new cdrBufOutput(b1.buffer.size() + 10); + holder._write(b2); + + return Arrays.equals(b1.buffer.toByteArray(), + b2.buffer.toByteArray() + ); + } + else + return false; + } + if (other == null) + return false; + else if (other.component_count() != component_count() || + !official_type.equal(other.type()) + ) + return false; + else + return other.to_any().equal(to_any()); + } + + /** + * This final_type has no components. + * + * @return 0, always. + */ + public int component_count() + { + return 0; + } + + public DynAny get_dyn_any() throws TypeMismatch, InvalidValue + { + return new gnuDynAny(holder, official_type, final_type, factory, orb); + } + + private void check(TCKind t) throws TypeMismatch + { + if (t.value() != final_type.kind().value()) + throw new TypeMismatch(t.value() + "!=" + final_type.kind().value()); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java new file mode 100644 index 00000000000..dd1762890de --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynAnyFactory.java @@ -0,0 +1,356 @@ +/* gnuDynAnyFactory.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Poa.ORB_1_4; +import gnu.CORBA.Unexpected; +import gnu.CORBA.holderFactory; +import gnu.CORBA.typeNamer; + +import org.omg.CORBA.Any; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.UserException; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyFactory; +import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; +import org.omg.DynamicAny.DynArray; +import org.omg.DynamicAny.DynEnum; +import org.omg.DynamicAny.DynFixed; +import org.omg.DynamicAny.DynSequence; +import org.omg.DynamicAny.DynStruct; +import org.omg.DynamicAny.DynUnion; +import org.omg.DynamicAny.DynValue; +import org.omg.DynamicAny.DynValueBox; + +/** + * This class is returned by ORB when resolving + * initial reference "DynAnyFactory". + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynAnyFactory + extends LocalObject + implements DynAnyFactory +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The ORB, to that the factory belongs. + */ + final ORB_1_4 orb; + + /** + * Create a new factory, specifying the ORB to that the factory belongs. + * + * @param anOrb + */ + public gnuDynAnyFactory(ORB_1_4 anOrb) + { + orb = anOrb; + } + + /** + * Get the orb. + */ + public ORB_1_4 getOrb() + { + return orb; + } + + /** + * Create an initialised array. + */ + public DynArray create_array(TypeCode official, TypeCode type) + { + return new gnuDynArray(official, type, this, orb, true); + } + + /** + * Create an empty sequence. + */ + public DynSequence create_sequence(TypeCode official, TypeCode type) + { + return new gnuDynSequence(official, type, this, orb); + } + + /** + * Create structure. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynStruct create_structure(TypeCode official, TypeCode type) + { + return new gnuDynStruct(official, type, this, orb); + } + + /** + * Create union. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynUnion create_union(TypeCode official, TypeCode type) + { + try + { + return new gnuDynUnion(official, type, this, orb); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + + /** + * Create value. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynValue create_value(TypeCode official, TypeCode type) + { + return new gnuDynValue(official, type, this, orb); + } + + /** + * Create value box. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynValueBox create_value_box(TypeCode official, TypeCode type) + { + return new gnuDynValueBox(official, type, this, orb); + } + + /** + * Create enumeration. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynEnum create_enumeration(TypeCode official, TypeCode type) + { + return new gnuDynEnum(official, type, this, orb); + } + + /** + * Create fixed. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynFixed create_fixed(TypeCode official, TypeCode type) + { + return new gnuDynFixed(official, type, this, orb); + } + + /** + * Create alias. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynAny create_alias(TypeCode official, TypeCode type) + throws InconsistentTypeCode + { + try + { + return create_dyn_any_from_type_code(official, type.content_type()); + } + catch (BadKind e) + { + throw new Unexpected(e); + } + } + + /** + * Create the undivideable DynAny. + */ + public DynAny create_simple(TypeCode official, TypeCode type) + { + Streamable holder = holderFactory.createHolder(type); + return new gnuDynAny(holder, official, type, this, orb); + } + + /** + * Create the DynAny from typecode. + */ + public DynAny create_dyn_any_from_type_code(TypeCode type) + throws InconsistentTypeCode + { + return create_dyn_any_from_type_code(type, type); + } + + /** + * Create the DynAny from typecode. + * + * @param official the type that was originally passed as a parameter by user. + * May be alias of some other type. + * @param type the type into that the "official type" evaluates during alias + * resolving. Initially equal to "official type". + */ + public DynAny create_dyn_any_from_type_code(TypeCode official, TypeCode type) + throws InconsistentTypeCode + { + DynAny d; + try + { + switch (type.kind().value()) + { + case TCKind._tk_array : + return create_array(official, type); + + case TCKind._tk_sequence : + return create_sequence(official, type); + + case TCKind._tk_struct : + case TCKind._tk_except : + return create_structure(official, type); + + case TCKind._tk_union : + return create_union(official, type); + + case TCKind._tk_value : + return create_value(official, type); + + case TCKind._tk_value_box : + return create_value_box(official, type); + + case TCKind._tk_enum : + return create_enumeration(official, type); + + case TCKind._tk_fixed : + return create_fixed(official, type); + + case TCKind._tk_alias : + return create_alias(official, type); + + case TCKind._tk_null : + return new gnuDynAny(null, official, type, this, orb); + + case TCKind._tk_TypeCode : + d = create_simple(official, type); + d.insert_typecode(orb.get_primitive_tc(TCKind.tk_null)); + return d; + + case TCKind._tk_any : + d = create_simple(official, type); + + Any empty_any = orb.create_any(); + empty_any.type(orb.get_primitive_tc(TCKind.tk_null)); + d.insert_any(empty_any); + return d; + + case TCKind._tk_wstring : + d = create_simple(official, type); + d.insert_wstring(""); + return d; + + case TCKind._tk_string : + d = create_simple(official, type); + d.insert_string(""); + return d; + + case TCKind._tk_native : + case TCKind._tk_Principal : + case TCKind._tk_abstract_interface : + throw new InconsistentTypeCode("Following API, the " + + typeNamer.nameIt(type) + + " must not be supported." + ); + + default : + return create_simple(official, type); + } + } + catch (UserException uex) + { + InconsistentTypeCode it = new InconsistentTypeCode(); + it.initCause(uex); + throw it; + } + } + + /** + * Create the DynAny using the passed value as template and assign this value. + */ + public DynAny create_dyn_any(Any value) + throws InconsistentTypeCode + { + DynAny created = create_dyn_any_from_type_code(value.type()); + try + { + created.from_any(value); + } + catch (UserException uex) + { + InconsistentTypeCode t = new InconsistentTypeCode("Inconsistent Any"); + t.initCause(uex); + throw t; + } + catch (Exception e) + { + throw new Unexpected(e); + } + return created; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java new file mode 100644 index 00000000000..1c08496d423 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynArray.java @@ -0,0 +1,338 @@ +/* gnuDynArray.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; +import gnu.CORBA.holderFactory; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynArray; + +import java.io.Serializable; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; + +/** + * Provides support for dynamic array or sequence, where all members have the + * same final_type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynArray + extends anyDivideable + implements DynArray, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The component "official" type (may be alias). + */ + final TypeCode official_components; + + /** + * The component "final" type, after resolving any aliases. + */ + final TypeCode final_components; + + /** + * Creates new array. + * + * @param aType the final_type of array. + * @param aFactory the factory, used to initialise default values. + * @param orb the ORB to that this DynAny belongs. + * @param initialise_array if false, the array is not initialised in + * constructor. + * + * + * @throws BAD_PARAM if the passed typecode does not provide the length(). + */ + public gnuDynArray(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, + ORB anOrb, boolean initialise_array + ) + throws BAD_PARAM + { + super(oType, aType, aFactory, anOrb); + + try + { + official_components = final_type.content_type(); + + TypeCode component = official_components; + while (component.kind().value() == TCKind._tk_alias) + component = component.content_type(); + final_components = component; + + if (initialise_array) + { + array = new DynAny[ aType.length() ]; + for (int i = 0; i < array.length; i++) + { + array [ i ] = + factory.create_dyn_any_from_type_code(official_components); + } + } + } + catch (Exception e) + { + BAD_PARAM bad = new BAD_PARAM("Unable to initialise array"); + bad.initCause(e); + throw bad; + } + } + + /** + * Copy one DynAny into another. + */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (from instanceof DynArray && from.component_count() == array.length) + { + DynArray dyn = (DynArray) from; + array = dyn.get_elements_as_dyn_any(); + } + else + throw new TypeMismatch(); + } + + /** + * Create a copy. + */ + public DynAny copy() + { + DynAny[] c = new DynAny[ array.length ]; + for (int i = 0; i < c.length; i++) + { + c [ i ] = array [ i ].copy(); + } + + gnuDynArray d = + new gnuDynArray(official_type, final_type, factory, orb, false); + d.array = c; + return d; + } + + /** + * Get elements as array of anys. + */ + public Any[] get_elements() + { + Any[] r = new Any[ array.length ]; + for (int i = 0; i < r.length; i++) + r [ i ] = array [ i ].to_any(); + return r; + } + + /** {@inheritDoc} */ + public DynAny[] get_elements_as_dyn_any() + { + DynAny[] a = new DynAny[ array.length ]; + for (int i = 0; i < a.length; i++) + { + a [ i ] = array [ i ].copy(); + } + return a; + } + + /** + * Set elements when array of dyn anys is provided. This method can set nested + * data structures as an array components. + */ + public void set_elements_as_dyn_any(DynAny[] value) + throws InvalidValue, TypeMismatch + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + for (int i = 0; i < value.length; i++) + { + checkType(official_components, value [ i ].type()); + array [ i ].assign(value [ i ]); + } + pos = 0; + valueChanged(); + } + + /** + * Set elements when array of ordinary anys is provided. + */ + public void set_elements(Any[] value) + throws InvalidValue, TypeMismatch + { + if (value.length != array.length) + throw new InvalidValue(sizeMismatch(array.length, value.length)); + + for (int i = 0; i < value.length; i++) + { + checkType(official_components, value [ i ].type()); + try + { + array [ i ] = factory.create_dyn_any(value [ i ]); + } + catch (InconsistentTypeCode e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + pos = 0; + valueChanged(); + } + + /** + * Done via reflection. + */ + public Any to_any() + { + try + { + Streamable memberHolder = + holderFactory.createHolder(official_components); + + if (memberHolder == null) + memberHolder = holderFactory.createHolder(final_components); + + Class memberHolderClass = memberHolder.getClass(); + Class memberClass = memberHolderClass.getField("value").getType(); + + Object members = Array.newInstance(memberClass, array.length); + Object member; + Any am; + Field value = memberHolder.getClass().getField("value"); + + for (int i = 0; i < array.length; i++) + { + // Recursive call should support multidimensional arrays. + am = array [ i ].to_any(); + memberHolder = am.extract_Streamable(); + member = value.get(memberHolder); + Array.set(members, i, member); + } + + Streamable arrayHolder = holderFactory.createHolder(official_type); + arrayHolder.getClass().getField("value").set(arrayHolder, members); + + Any g = createAny(); + g.insert_Streamable(arrayHolder); + g.type(official_type); + return g; + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + + /** + * Done via reflection. + */ + public void from_any(Any an_any) + throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + try + { + Streamable s = an_any.extract_Streamable(); + Object members = s.getClass().getField("value").get(s); + + checkArrayValid(members); + + Any member; + Streamable holder; + Class holderClass = null; + + for (int i = 0; i < array.length; i++) + { + if (holderClass == null) + { + holder = holderFactory.createHolder(official_components); + if (holder == null) + holder = holderFactory.createHolder(final_components); + holderClass = holder.getClass(); + } + else + holder = (Streamable) holderClass.newInstance(); + + member = createAny(); + holder.getClass().getField("value").set(holder, + Array.get(members, i) + ); + member.insert_Streamable(holder); + member.type(official_components); + + // This may lead to recursion, supporting multidimensional + // arrays. + array [ i ].from_any(member); + } + } + catch (Exception ex) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(ex); + throw t; + } + valueChanged(); + } + + /** + * Check if array size is valid and (for sequences) resized + * if required. Called from from_any. + */ + protected void checkArrayValid(Object members) + throws TypeMismatch, InvalidValue + { + if (array.length != Array.getLength(members)) + throw new InvalidValue(sizeMismatch(array.length, Array.getLength(members))); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java new file mode 100644 index 00000000000..2fccc85c59d --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynEnum.java @@ -0,0 +1,244 @@ +/* gnuDynEnum.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.portable.InputStream; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynEnum; + +import java.io.IOException; + +import java.util.Arrays; + +/** + * Our implementation of dynamic enumeration. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynEnum extends anyUndivideable implements DynEnum +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The valid string values of the enumeration. Most of enumerations are short, + * counting 2-5 memebers. With so small number of memebers, it seems not + * reasonable to use hashtables. + */ + final String[] values; + + /** + * The current value of enum. + */ + int current; + + /** + * Create a new dyn enum from the given typecode. + */ + public gnuDynEnum(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, + ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + try + { + values = new String[ final_type.member_count() ]; + + for (int i = 0; i < values.length; i++) + { + values [ i ] = final_type.member_name(i); + } + } + catch (Exception e) + { + throw new BAD_PARAM("Not enum"); + } + } + + /** + * Create a clone of the given enum, sharing values and final_type. + */ + public gnuDynEnum(gnuDynEnum from) + { + super(from.official_type, from.final_type, from.factory, from.orb); + values = from.values; + } + + /** + * Assign the Enum from the passed value. The passed DynAny must hold the + * enumeration of exactly the same final_type. + */ + public void assign(DynAny from) throws TypeMismatch + { + checkType(official_type, from.type()); + if (!(from instanceof DynEnum)) + throw new TypeMismatch("Not a DynEnum"); + try + { + set_as_ulong(((DynEnum) from).get_as_ulong()); + } + catch (InvalidValue e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + + /** + * Copy this DynEnum. + */ + public DynAny copy() + { + gnuDynEnum other = new gnuDynEnum(this); + other.current = current; + return other; + } + + /** + * Compares for equality. + */ + public boolean equal(DynAny other) + { + if (other instanceof gnuDynEnum) + { + gnuDynEnum oe = (gnuDynEnum) other; + return current == oe.current && + (oe.values == values || Arrays.equals(values, oe.values)); + } + else if (other instanceof DynEnum) + { + DynEnum oe = (DynEnum) other; + return current == oe.get_as_ulong() && official_type.equal(oe.type()); + } + else + return false; + } + + /** + * Set value from any that must contain enumeration. + */ + public void from_any(Any an_any) throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + try + { + InputStream in = an_any.create_input_stream(); + set_as_ulong(in.read_long()); + in.close(); + } + catch (MARSHAL eof) + { + throw new InvalidValue(); + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } + + /** + * Get the value of this enumeration as string. + */ + public String get_as_string() + { + return values [ current ]; + } + + /** + * Get the value of this enumeration as int. + */ + public int get_as_ulong() + { + return current; + } + + /** + * Set the value of this enumeration as string. + */ + public void set_as_string(String value) throws InvalidValue + { + for (int i = 0; i < values.length; i++) + { + if (values [ i ].equals(value)) + { + current = i; + valueChanged(); + return; + } + } + throw new InvalidValue(value); + } + + /** + * Set the value of this enumeration as int. + */ + public void set_as_ulong(int value) throws InvalidValue + { + if (value < 0 || value >= values.length) + throw new InvalidValue(value + " not in [0.." + values.length); + else + { + current = value; + valueChanged(); + } + } + + /** + * Wrap the enumeration value into any. + */ + public Any to_any() + { + Any a = createAny(); + a.insert_long(current); + a.type(official_type); + return a; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java new file mode 100644 index 00000000000..39b00226245 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynFixed.java @@ -0,0 +1,252 @@ +/* gnuDynFixed.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynFixed; +import org.omg.DynamicAny.DynFixedOperations; + +import java.math.BigDecimal; + +/** + * Implements DynAny, holding CORBA <code>fixed</code>. This class is derived + * from gnuDynEnm to avoid repetetive inclusion of unused DynAny methods. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynFixed extends anyUndivideable implements DynFixed +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The default value, assigned in the new instance. + */ + static final BigDecimal ZERO = new BigDecimal("0.0"); + + /** + * The content of the dyn fixed, wrapped in this DynAny. + */ + BigDecimal value; + + /** + * The number of digits after the decimal point. + */ + final int scale; + + /** + * The number of digits. + */ + final int digits; + + /** + * Create a new instance of the dyn fixed. + */ + public gnuDynFixed(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + try + { + digits = final_type.fixed_digits(); + scale = final_type.fixed_scale(); + } + catch (Exception e) + { + throw new BAD_PARAM("Not a fixed"); + } + value = ZERO; + } + + /** + * Clone the current instance. + */ + public gnuDynFixed(gnuDynFixed from) + { + super(from.official_type, from.final_type, from.factory, from.orb); + digits = from.digits; + scale = from.scale; + value = from.value; + } + + /** + * Get the value of the wrapped dyn fixed, as string. + */ + public String get_value() + { + return value.toString(); + } + + /** + * Set the value. + */ + public boolean set_value(String fixed_value) + throws TypeMismatch, InvalidValue + { + // Count the digits till decimal point. + int digs = 0; + char c; + boolean leading0 = true; + Digs: + for (int i = 0; i < fixed_value.length(); i++) + { + c = fixed_value.charAt(i); + if (Character.isDigit(c)) + { + if (!(c == '0' && leading0)) + digs++; + if (c != '0') + leading0 = false; + } + else if (c == '.') + break Digs; + } + if (digs > (digits - scale)) + throw new InvalidValue("Too many digits: " + digs + " for " + digits + + "." + scale + ); + + try + { + value = new BigDecimal(fixed_value); + } + catch (NumberFormatException ex) + { + if (fixed_value.trim().length() == 0) + throw new InvalidValue("Empty string passed"); + + TypeMismatch inva = + new TypeMismatch("Not a number: '" + fixed_value + "'"); + inva.initCause(ex); + throw inva; + } + + valueChanged(); + return value.scale() <= scale; + } + + /** + * Assign the value from another BigDecimal. + */ + public void assign(DynAny from) throws TypeMismatch + { + checkType(official_type, from.type()); + + if (from instanceof gnuDynFixed) + { + gnuDynFixed other = (gnuDynFixed) from; + value = other.value; + } + else if (from instanceof DynFixedOperations) + { + value = new BigDecimal(((DynFixedOperations) from).get_value()); + } + else + throw new TypeMismatch("Not a DynFixed"); + valueChanged(); + } + + /** + * Create a copy. + */ + public DynAny copy() + { + return new gnuDynFixed(this); + } + + /** + * Compare for equality. + */ + public boolean equal(DynAny other) + { + if (other instanceof gnuDynFixed) + { + // Normally, this code would be executed. + return value.equals(((gnuDynFixed) other).value); + } + if (other instanceof DynFixedOperations) + { + // This may be involved when mixing implementations. + return ((DynFixedOperations) other).get_value().equals(get_value()); + } + else + return false; + } + + /** + * Set the value from Any (must hold <code>fixed</code> with the matching + * typecode.). + */ + public void from_any(Any an_any) throws TypeMismatch, InvalidValue + { + try + { + checkType(official_type, an_any.type()); + + value = an_any.extract_fixed(); + valueChanged(); + } + catch (BAD_OPERATION e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** + * Create and return Any, holding this DynFixed value. + */ + public Any to_any() + { + Any g = createAny(); + g.insert_fixed(value, official_type); + return g; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynSequence.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynSequence.java new file mode 100644 index 00000000000..cfa122f07d7 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynSequence.java @@ -0,0 +1,254 @@ +/* gnuDynSequence.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynSequence; + +import java.io.Serializable; + +import java.lang.reflect.*; + +public class gnuDynSequence + extends gnuDynArray + implements DynSequence, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The bound of the sequence, as defined in typecode. + */ + final int bound; + + /** + * Create a new gnuDynSequence with the given typecode. + * + * @throws BAD_PARAM if the passed typecode is probably not a sequence + * typecode. + */ + public gnuDynSequence(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + throws BAD_PARAM + { + super(oType, aType, aFactory, anOrb, false); + array = new DynAny[ 0 ]; + try + { + bound = final_type.length(); + } + catch (BadKind ex) + { + throw new Unexpected(ex); + } + } + + /** + * Get the length of the sequence. + */ + public int get_length() + { + return array.length; + } + + /** + * Resize the sequence, preserving components. + */ + public void set_length(int length) + throws InvalidValue + { + checkBound(length); + if (length == array.length) + return; // Nothing to do. + else if (length < array.length) + { + // Truncate. + DynAny[] d = new DynAny[ length ]; + for (int i = 0; i < d.length; i++) + d [ i ] = array [ i ]; + array = d; + } + else + { + // Expand. + DynAny[] d = new DynAny[ length ]; + for (int i = 0; i < array.length; i++) + d [ i ] = array [ i ]; + + for (int i = array.length; i < d.length; i++) + { + try + { + d [ i ] = + factory.create_dyn_any_from_type_code(official_components); + } + catch (InconsistentTypeCode e) + { + throw new Unexpected(e); + } + } + array = d; + } + valueChanged(); + } + + /** + * Copy one DynAny into another. + */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (from instanceof DynSequence) + { + DynSequence dyn = (DynSequence) from; + array = dyn.get_elements_as_dyn_any(); + } + else + throw new TypeMismatch(); + } + + /* + * Set the contenst of the sequence, resizing if required. + */ + public void set_elements_as_dyn_any(DynAny[] value) + throws InvalidValue, TypeMismatch + { + checkBound(value.length); + if (array.length != value.length) + set_length(value.length); + + for (int i = 0; i < value.length; i++) + { + checkType(official_components, value [ i ].type()); + array [ i ].assign(value [ i ]); + } + valueChanged(); + } + + /** + * Set the elements from array of Any's. + */ + public void set_elements(Any[] value) + throws InvalidValue, TypeMismatch + { + checkBound(value.length); + + DynAny[] prev = array; + + array = new DynAny[ value.length ]; + try + { + super.set_elements(value); + + // valueChanged() is called in super.set_elements(value). + } + + // On the problem, value does not change. + catch (TypeMismatch ex) + { + array = prev; + throw ex; + } + catch (InvalidValue ex) + { + array = prev; + throw ex; + } + catch (RuntimeException rex) + { + array = prev; + throw rex; + } + } + + /** + * Create a copy. + */ + public DynAny copy() + { + DynAny[] c = new DynAny[ array.length ]; + for (int i = 0; i < c.length; i++) + { + c [ i ] = array [ i ].copy(); + } + + gnuDynSequence d = + new gnuDynSequence(official_type, final_type, factory, orb); + d.array = c; + return d; + } + + /** + * Check the bound. + * + * @param x the value to check. + */ + void checkBound(int x) + throws InvalidValue + { + if (bound != 0) + if (x < 0 || x > bound) + throw new InvalidValue(x + " out of bounds, valid [0.." + bound + "]"); + } + + /** + * Check if array size is valid. Called from from_any. + */ + protected void checkArrayValid(Object members) + throws TypeMismatch, InvalidValue + { + checkBound(Array.getLength(members)); + if (get_length() != Array.getLength(members)) + set_length(Array.getLength(members)); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java new file mode 100644 index 00000000000..b086d6478cc --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynStruct.java @@ -0,0 +1,109 @@ +/* gnuDynStruct.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import java.io.Serializable; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.TypeCode; +import org.omg.DynamicAny.DynStruct; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameValuePair; +import gnu.CORBA.Unexpected; +import org.omg.DynamicAny.DynAny; + +/** + * Implementation of the DynStruct. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynStruct + extends abstractRecord + implements DynStruct, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Create an instance. + */ + public gnuDynStruct(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb) + { + super(oType, aType, aFactory, anOrb); + + // Initialise fields. + try + { + array = new DynAny[ final_type.member_count() ]; + fNames = new String[ array.length ]; + for (int i = 0; i < array.length; i++) + { + array [ i ] = + factory.create_dyn_any_from_type_code(final_type.member_type(i)); + fNames [ i ] = final_type.member_name(i); + } + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + + /** @inheritDoc */ + protected abstractRecord newInstance(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb) + { + return new gnuDynStruct(oType, aType, aFactory, anOrb); + } + + /** @inheritDoc */ + public NameDynAnyPair[] get_members_as_dyn_any() + { + return super.gnu_get_members_as_dyn_any(); + } + + /** @inheritDoc */ + public NameValuePair[] get_members() + { + return super.gnu_get_members(); + } +} diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java new file mode 100644 index 00000000000..ad41e24b6ae --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynUnion.java @@ -0,0 +1,439 @@ +/* gnuDynUnion.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; + +import org.omg.CORBA.Any; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynUnion; + +import java.io.Serializable; + +/** + * Implementation of DynUnion. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynUnion + extends anyDivideable + implements DynUnion, Serializable, valueChangedListener +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The discrimintor of this union. + */ + DynAny discriminator; + + /** + * The message string that occurs several times throwing exception. + */ + static String NOAM = "No active member"; + + /** + * Create a new instance with the given typecode. + * + * @param aType the final_type, must be final_type of the union. + */ + public gnuDynUnion(TypeCode oType, TypeCode aType, gnuDynAnyFactory aFactory, + ORB anOrb + ) + throws InconsistentTypeCode + { + super(oType, aType, aFactory, anOrb); + try + { + discriminator = + factory.create_dyn_any_from_type_code(final_type.discriminator_type()); + + ((abstractDynAny) discriminator).listener = this; + + if (final_type.default_index() >= 0) + set_to_default_member(); + else + set_to_no_active_member(); + } + catch (Exception ex) + { + InconsistentTypeCode inc = new InconsistentTypeCode("discriminator"); + inc.initCause(ex); + throw inc; + } + } + + /* + * (non-Javadoc) + * + * @see gnu.CORBA.DynAn.anyDivideable#to_any() + */ + public Any to_any() + { + Any a = createAny(); + OutputStream ou = a.create_output_stream(); + discriminator.to_any().write_value(ou); + if (array.length == 2) + array [ 1 ].to_any().write_value(ou); + a.read_value(ou.create_input_stream(), final_type); + return a; + } + + /** + * Assign from another identical structure. + */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (!(from instanceof DynUnion)) + throw new TypeMismatch("DynUnion required"); + else + { + try + { + DynUnion u = (DynUnion) from; + discriminator.assign(u.get_discriminator()); + if (u.has_no_active_member()) + { + if (array.length != 1) + array = new DynAny[] { discriminator }; + } + else + { + if (array.length != 2) + array = new DynAny[] { discriminator, u.member().copy() }; + else + array [ 1 ] = u.member().copy(); + } + } + catch (InvalidValue e) + { + throw new Unexpected(e); + } + } + valueChanged(); + } + + /** @inheritDoc */ + public DynAny copy() + { + try + { + gnuDynUnion other = + new gnuDynUnion(official_type, final_type, factory, orb); + other.discriminator = discriminator.copy(); + ((abstractDynAny) other.discriminator).listener = other; + if (array.length == 1) + { + other.array = new DynAny[] { other.discriminator }; + } + else + { + other.array = + new DynAny[] { other.discriminator, array [ 1 ].copy() }; + } + return other; + } + catch (InconsistentTypeCode ex) + { + throw new Unexpected(ex); + } + } + + /** + * Done via reading from stream. + */ + public void from_any(Any an_any) + throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + + Any adis = createAny(); + try + { + InputStream stream = an_any.create_input_stream(); + adis.read_value(stream, final_type.discriminator_type()); + + DynAny nd = factory.create_dyn_any(adis); + + set_discriminator(nd); + if (array.length == 2) + { + // Reusing the same Any <code>adis</code>. + adis.read_value(stream, array [ 1 ].type()); + array [ 1 ].from_any(adis); + } + } + catch (InconsistentTypeCode it) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(it); + throw t; + } + catch (MARSHAL m) + { + InvalidValue t = new InvalidValue(); + t.initCause(m); + throw t; + } + catch (BadKind b) + { + throw new Unexpected(b); + } + valueChanged(); + } + + /** @inheritDoc */ + public TCKind discriminator_kind() + { + return discriminator.type().kind(); + } + + /** @inheritDoc */ + public DynAny get_discriminator() + { + return discriminator; + } + + /** @inheritDoc */ + public boolean has_no_active_member() + { + return array.length == 1; + } + + /** @inheritDoc */ + public TCKind member_kind() + throws InvalidValue + { + return member().type().kind(); + } + + /** + * Get the name of the current variant of the union. + */ + public String member_name() + throws InvalidValue + { + if (array.length == 1) + throw new InvalidValue(NOAM); + try + { + Any da = discriminator.to_any(); + + + // Get the discriminator variant. + Variants: + for (int i = 0; i < final_type.member_count(); i++) + { + if (final_type.member_label(i).equal(da)) + return final_type.member_name(i); + } + throw new InvalidValue(NOAM); + } + catch (Exception e) + { + InvalidValue t = new InvalidValue("Err"); + t.initCause(e); + throw t; + } + } + + /** @inheritDoc */ + public DynAny member() + throws InvalidValue + { + if (array.length < 2) + throw new InvalidValue(NOAM); + else + return array [ 1 ]; + } + + /** + * Set the union discriminator. + */ + public void set_discriminator(DynAny aDiscriminator) + throws TypeMismatch + { + try + { + if (!aDiscriminator.type().equal(final_type.discriminator_type())) + throw new TypeMismatch("Wrong discriminator final_type for " + + final_type.name() + ); + + // Seting the same discriminator value again should not change + // the fields of the current member. + if (!discriminator.equal(aDiscriminator)) + { + discriminator.assign(aDiscriminator); + updateMember(); + } + else + { + pos = array.length == 2 ? 1 : 0; + } + } + catch (Exception e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + + /** + * Set to default member, if one exists. + */ + public void set_to_default_member() + throws TypeMismatch + { + try + { + int di = final_type.default_index(); + if (di < 0) + throw new TypeMismatch("Union " + final_type.name() + + "has no default index" + ); + + Any da = final_type.member_label(di); + discriminator.from_any(da); + updateMember(); + } + catch (TypeMismatch m) + { + // This one OK. + throw m; + } + catch (Exception e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + } + + /** @inheritDoc */ + public void set_to_no_active_member() + throws TypeMismatch + { + try + { + if (final_type.default_index() >= 0) + { + throw new TypeMismatch("Explicit default case defined."); + } + } + catch (BadKind ex) + { + // The default index is not set. + } + array = new DynAny[] { discriminator }; + valueChanged(); + } + + /** + * Update member, in accordance with discriminator value. + */ + public void updateMember() + throws TypeMismatch + { + try + { + Any da = discriminator.to_any(); + + + // Get the discriminator variant. + Variants: + for (int i = 0; i < final_type.member_count(); i++) + { + if (final_type.member_label(i).equal(da)) + { + array = + new DynAny[] + { + discriminator, + factory.create_dyn_any_from_type_code(final_type.member_type(i)) + }; + pos = 1; + valueChanged(); + return; + } + } + } + catch (Exception e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + + // Discrimintator does not point to valid member. + array = new DynAny[] { discriminator }; + pos = 0; + valueChanged(); + } + + /** + * Called when the discriminator is changed. + */ + public void changed() + { + try + { + updateMember(); + } + catch (TypeMismatch ex) + { + throw new Unexpected(ex); + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java new file mode 100644 index 00000000000..c2db9479785 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValue.java @@ -0,0 +1,382 @@ +/* gnuDynValue.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.VM_TRUNCATABLE; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ValueFactory; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynStruct; +import org.omg.DynamicAny.DynValue; +import org.omg.DynamicAny.DynValueCommon; +import org.omg.DynamicAny.DynValueOperations; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameValuePair; + +import java.io.Serializable; + +/** + * Implementation of DynValue. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynValue extends abstractRecord implements DynValue, + Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * If true, the value of this ValueType is set to null. + */ + boolean isNull; + + /** + * Create an instance. + */ + public gnuDynValue(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + + // Initialise fields. The array of fields also includes all inherited + // fields. + try + { + array = new DynAny[ final_type.member_count() ]; + fNames = new String[ array.length ]; + for (int i = 0; i < array.length; i++) + { + array [ i ] = + factory.create_dyn_any_from_type_code(final_type.member_type(i)); + fNames [ i ] = final_type.member_name(i); + } + + // Search of inherited members. + if (final_type.type_modifier() == VM_TRUNCATABLE.value) + { + TypeCode parent = final_type.concrete_base_type(); + DynAny ancestor = factory.create_dyn_any_from_type_code(parent); + + if (ancestor instanceof DynValue) + { + // Add members of ancestor in front of the curren members. + DynValue anc = (DynValue) ancestor; + anc.set_to_value(); + + NameDynAnyPair[] aar = anc.get_members_as_dyn_any(); + inheritFields(aar); + } + else if (ancestor instanceof DynStruct) + { + // Add members of ancestor in front of the curren members. + DynStruct anc = (DynStruct) ancestor; + NameDynAnyPair[] aar = anc.get_members_as_dyn_any(); + inheritFields(aar); + } + else + throw new BAD_PARAM("The parent of " + final_type.id() + ", " + + parent.id() + ", is not structure nor value." + ); + } + } + catch (Exception e) + { + throw new Unexpected(e); + } + + set_to_null(); + } + + /** + * Inherit the provided fields. + */ + private void inheritFields(NameDynAnyPair[] aar) + { + DynAny[] nArray = new DynAny[ array.length + aar.length ]; + String[] nNames = new String[ array.length + aar.length ]; + int p = 0; + for (int i = 0; i < aar.length; i++) + { + nArray [ p ] = aar [ i ].value; + nNames [ p ] = aar [ i ].id; + p++; + } + + for (int i = 0; i < array.length; i++) + { + nArray [ p ] = array [ i ]; + nNames [ p ] = fNames [ i ]; + p++; + } + + array = nArray; + fNames = nNames; + } + + /** @inheritDoc */ + public TCKind current_member_kind() throws TypeMismatch, InvalidValue + { + if (isNull) + throw new TypeMismatch(ISNULL); + else + return super.current_member_kind(); + } + ; + + /** @inheritDoc */ + public String current_member_name() throws TypeMismatch, InvalidValue + { + if (isNull) + throw new TypeMismatch(ISNULL); + else + return super.current_member_name(); + } + ; + + /** @inheritDoc */ + public NameDynAnyPair[] get_members_as_dyn_any() throws InvalidValue + { + if (isNull) + throw new InvalidValue(ISNULL); + return super.gnu_get_members_as_dyn_any(); + } + ; + + /** @inheritDoc */ + public NameValuePair[] get_members() throws InvalidValue + { + if (isNull) + throw new InvalidValue(ISNULL); + else + return super.gnu_get_members(); + } + ; + + /** @inheritDoc */ + public void set_members_as_dyn_any(NameDynAnyPair[] value) + throws TypeMismatch, InvalidValue + { + super.set_members_as_dyn_any(value); + isNull = false; + } + ; + + /** @inheritDoc */ + public void set_members(NameValuePair[] value) + throws TypeMismatch, InvalidValue + { + super.set_members(value); + isNull = false; + } + ; + + /** @inheritDoc */ + public boolean is_null() + { + return isNull; + } + + /** @inheritDoc */ + public void set_to_null() + { + isNull = true; + valueChanged(); + } + + /** @inheritDoc */ + public void set_to_value() + { + isNull = false; + valueChanged(); + } + + /** + * Create a new instance. + */ + protected abstractRecord newInstance(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + gnuDynValue v = new gnuDynValue(oType, aType, aFactory, anOrb); + if (isNull) + v.set_to_null(); + else + v.set_to_value(); + return v; + } + + /** + * Compare for equality, minding null values. + */ + public boolean equal(DynAny other) + { + if (other instanceof DynValueOperations) + { + DynValueCommon o = (DynValueCommon) other; + if (isNull) + return o.is_null() && o.type().equal(official_type); + else + return !o.is_null() && super.equal(other); + } + else + return false; + } + + /** + * Get the focused component, throwing exception if the current value is null. + */ + protected DynAny focused() throws InvalidValue, TypeMismatch + { + if (isNull) + throw new TypeMismatch(ISNULL); + else + return super.focused(); + } + + /** + * Convert into Any. + */ + public Any to_any() + { + if (isNull) + { + Any a0 = createAny(); + a0.type(orb.get_primitive_tc(TCKind.tk_null)); + return a0; + } + else + { + try + { + ValueFactory factory = + ((org.omg.CORBA_2_3.ORB) orb).lookup_value_factory(official_type.id()); + if (factory == null) + throw new MARSHAL("Factory for " + official_type.id() + + " not registered." + ); + + OutputStream out = orb.create_output_stream(); + + for (int i = 0; i < array.length; i++) + array [ i ].to_any().write_value(out); + + org.omg.CORBA_2_3.portable.InputStream in = + (org.omg.CORBA_2_3.portable.InputStream) out.create_input_stream(); + Serializable v = factory.read_value(in); + + Any g = createAny(); + g.type(official_type); + g.insert_Value(v, official_type); + + return g; + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + } + + /** @inheritDoc */ + public void assign(DynAny from) throws TypeMismatch + { + checkType(official_type, from.type()); + + if (from instanceof DynValue) + { + DynValue other = (DynValue) from; + if (other.is_null()) + set_to_null(); + else + { + set_to_value(); + try + { + DynValueOperations src = (DynValueOperations) from; + set_members_as_dyn_any(src.get_members_as_dyn_any()); + } + catch (InvalidValue e) + { + TypeMismatch t = new TypeMismatch("Invalid value"); + t.initCause(e); + throw t; + } + } + } + else + throw new TypeMismatch("Not a DynValue"); + } + + /** + * Get the number of components. + */ + public int component_count() + { + return isNull ? 0 : super.component_count(); + } + + /** {@inheritDoc} */ + public Serializable get_val() throws TypeMismatch, InvalidValue + { + return to_any().extract_Value(); + } + + /** {@inheritDoc} */ + public void insert_val(Serializable a_x) throws InvalidValue, TypeMismatch + { + Any a = to_any(); + a.insert_Value(a_x); + from_any(a); + valueChanged(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java new file mode 100644 index 00000000000..66e18f3b2fe --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/gnuDynValueBox.java @@ -0,0 +1,389 @@ +/* gnuDynValueBox.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +import gnu.CORBA.Unexpected; +import gnu.CORBA.holderFactory; + +import org.omg.CORBA.Any; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnyFactoryPackage.InconsistentTypeCode; +import org.omg.DynamicAny.DynAnyPackage.InvalidValue; +import org.omg.DynamicAny.DynAnyPackage.TypeMismatch; +import org.omg.DynamicAny.DynValueBox; +import org.omg.DynamicAny.DynValueBoxOperations; +import org.omg.DynamicAny.DynValueCommon; + +import java.io.Serializable; + +import java.lang.reflect.Field; + +/** + * Implementation of the DynValueBox. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuDynValueBox + extends anyDivideable + implements DynValueBox, Serializable +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The final_type of contents of this value box. + */ + final TypeCode content; + + /** + * The string for some TypeMismatch exceptions. + */ + String CONTENT = "Box content final_type mismatch"; + + /** + * Create a new instance of gnuDynValueBox. + */ + public gnuDynValueBox(TypeCode oType, TypeCode aType, + gnuDynAnyFactory aFactory, ORB anOrb + ) + { + super(oType, aType, aFactory, anOrb); + try + { + content = final_type.content_type(); + array = new DynAny[] { factory.create_dyn_any_from_type_code(content) }; + set_to_null(); + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + + /** @inheritDoc */ + public void assign(DynAny from) + throws TypeMismatch + { + checkType(official_type, from.type()); + if (from instanceof DynValueBoxOperations) + { + DynValueBoxOperations other = (DynValueBoxOperations) from; + if (other.is_null()) + set_to_null(); + else + { + DynAny inBox; + try + { + inBox = other.get_boxed_value_as_dyn_any(); + } + catch (InvalidValue e) + { + TypeMismatch t = new TypeMismatch("Invalid value"); + t.initCause(e); + throw t; + } + if (!content.equal(inBox.type())) + throw new TypeMismatch(CONTENT); + array = new DynAny[] { inBox.copy() }; + } + } + valueChanged(); + } + + /** @inheritDoc */ + public DynAny copy() + { + gnuDynValueBox other = + new gnuDynValueBox(official_type, final_type, factory, orb); + if (is_null()) + other.set_to_null(); + else + { + try + { + other.array = new DynAny[] { array [ 0 ].copy() }; + } + catch (Exception e) + { + throw new Unexpected(e); + } + } + return other; + } + + /** + * Returns null for null value, delegates to super. otherwise. + */ + public DynAny current_component() + throws TypeMismatch + { + if (is_null()) + return null; + else + return super.current_component(); + } + + /** + * Compare for equality, minding null values. + */ + public boolean equal(DynAny other) + { + if (other instanceof DynValueCommon) + { + DynValueCommon o = (DynValueCommon) other; + if (is_null()) + return o.is_null() && o.type().equal(official_type); + else + return !o.is_null() && super.equal(other); + } + else + return false; + } + + /** @inheritDoc */ + public void from_any(Any an_any) + throws TypeMismatch, InvalidValue + { + checkType(official_type, an_any.type()); + try + { + if (!an_any.type().content_type().equal(content)) + throw new InvalidValue(CONTENT); + } + catch (BadKind e) + { + TypeMismatch t = new TypeMismatch("Not a box"); + t.initCause(e); + throw t; + } + + Serializable s = an_any.extract_Value(); + if (s == null) + set_to_null(); + else + { + try + { + Streamable holder = holderFactory.createHolder(content); + Field v = holder.getClass().getField("value"); + v.set(holder, s); + + Any cont = createAny(); + cont.insert_Streamable(holder); + + array = new DynAny[] { factory.create_dyn_any(cont) }; + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + valueChanged(); + } + + /** @inheritDoc */ + public Any get_boxed_value() + throws InvalidValue + { + try + { + if (is_null()) + throw new InvalidValue(ISNULL); + else + return array [ 0 ].to_any(); + } + catch (Exception e) + { + InvalidValue t = new InvalidValue(); + t.initCause(e); + throw t; + } + } + + /** @inheritDoc */ + public DynAny get_boxed_value_as_dyn_any() + throws InvalidValue + { + if (is_null()) + throw new InvalidValue(ISNULL); + else + return array [ 0 ].copy(); + } + + /** {@inheritDoc} */ + public Serializable get_val() + throws TypeMismatch, InvalidValue + { + return to_any().extract_Value(); + } + + /** {@inheritDoc} */ + public void insert_val(Serializable a_x) + throws InvalidValue, TypeMismatch + { + Any a = to_any(); + a.insert_Value(a_x); + from_any(a); + valueChanged(); + } + + /** @inheritDoc */ + public boolean is_null() + { + return array.length == 0; + } + + /** @inheritDoc */ + public void set_boxed_value(Any boxIt) + throws TypeMismatch + { + if (!content.equal(boxIt.type())) + throw new TypeMismatch(CONTENT); + try + { + if (is_null()) + { + array = new DynAny[] { factory.create_dyn_any(boxIt) }; + } + else + { + array [ 0 ].from_any(boxIt); + } + } + catch (Exception e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + valueChanged(); + } + + /** @inheritDoc */ + public void set_boxed_value_as_dyn_any(DynAny boxIt) + throws TypeMismatch + { + if (!content.equal(boxIt.type())) + throw new TypeMismatch(CONTENT); + try + { + if (is_null()) + { + array = new DynAny[] { boxIt.copy() }; + } + else + { + array [ 0 ].assign(boxIt); + } + } + catch (Exception e) + { + TypeMismatch t = new TypeMismatch(); + t.initCause(e); + throw t; + } + valueChanged(); + } + + /** @inheritDoc */ + public void set_to_null() + { + array = new DynAny[ 0 ]; + valueChanged(); + } + + /** @inheritDoc */ + public void set_to_value() + { + try + { + if (array.length == 0) + { + array = + new DynAny[] { factory.create_dyn_any_from_type_code(content) }; + } + } + catch (InconsistentTypeCode e) + { + throw new Unexpected(e); + } + valueChanged(); + } + + /** @inheritDoc */ + public Any to_any() + { + Any a = createAny(); + + if (!is_null()) + { + try + { + Streamable holder; + if (array [ 0 ] instanceof gnuDynAny) + holder = ((gnuDynAny) array [ 0 ]).holder; + else + { + Any uan = array [ 0 ].to_any(); + holder = uan.extract_Streamable(); + } + + Field v = holder.getClass().getField("value"); + Serializable value = (Serializable) v.get(holder); + a.type(official_type); + a.insert_Value(value, content); + } + catch (Exception ex) + { + throw new Unexpected(ex); + } + } + else + a.type(orb.get_primitive_tc(TCKind.tk_null)); + return a; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java b/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java new file mode 100644 index 00000000000..94ddffbecf7 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAn/valueChangedListener.java @@ -0,0 +1,50 @@ +/* valueChangedListener.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.DynAn; + +/** + * An interface, able to receive notification about the change of value + * of some DynAny. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface valueChangedListener +{ + void changed(); +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/DynAnySeqHolder.java b/libjava/classpath/gnu/CORBA/DynAnySeqHolder.java new file mode 100644 index 00000000000..52d66d9e924 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/DynAnySeqHolder.java @@ -0,0 +1,116 @@ +/* DynAnySeqHolder.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.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.DynAny; +import org.omg.DynamicAny.DynAnySeqHelper; + +/** + * A holder for the sequence of {@link DynAny} + * ({@link DynAnySeq}). + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class DynAnySeqHolder + implements Streamable +{ + /** + * The stored array of <code>DynAny</code>. + */ + public DynAny[] value; + + /** + * Create the unitialised instance, leaving the value array + * with default <code>null</code> value. + */ + public DynAnySeqHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the array that will be assigned to + * the <code>value</code> array. + */ + public DynAnySeqHolder(DynAny[] initialValue) + { + value = initialValue; + } + + /** + * The method should read this object from the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _read(InputStream input) + { + value = DynAnySeqHelper.read(input); + } + + /** + * The method should write this object to the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _write(OutputStream output) + { + DynAnySeqHelper.write(output, value); + } + + /** + * Get the typecode of the DynAny. + */ + public org.omg.CORBA.TypeCode _type() + { + return DynAnySeqHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java b/libjava/classpath/gnu/CORBA/ForwardRequestHelper.java new file mode 100644 index 00000000000..c7fae5b061b --- /dev/null +++ b/libjava/classpath/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., 51 Franklin Street, Fifth Floor, Boston, MA +02110-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.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/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java b/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java new file mode 100644 index 00000000000..ba6c1f88d8f --- /dev/null +++ b/libjava/classpath/gnu/CORBA/GIOP/contextSupportingHeader.java @@ -0,0 +1,76 @@ +/* contextSupportingHeader.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA.GIOP; + +import org.omg.CORBA.BAD_INV_ORDER; + +/** + * A header, supporting the service contexts. Such header has a context field + * and methods for adding the new contexts. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public abstract class contextSupportingHeader +{ + + /** + * Empty array, indicating that no service context is available. + */ + protected static final ServiceContext[] NO_CONTEXT = new ServiceContext[0]; + + /** + * The context data. + */ + public ServiceContext[] service_context = NO_CONTEXT; + + /** + * Add service context to this header. + * + * @param context_to_add context to add. + * @param replace if true, the existing context with this ID is replaced. + * Otherwise, BAD_INV_ORDER is throwsn. + */ + public void addContext(org.omg.IOP.ServiceContext context_to_add, + boolean replace) + throws BAD_INV_ORDER + { + service_context = ServiceContext.add(service_context, context_to_add, + replace); + } +} diff --git a/libjava/classpath/gnu/CORBA/Interceptor/ClientRequestInterceptors.java b/libjava/classpath/gnu/CORBA/Interceptor/ClientRequestInterceptors.java new file mode 100644 index 00000000000..5c15e121d29 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/ClientRequestInterceptors.java @@ -0,0 +1,139 @@ +/* ClientRequestInterceptors.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.Interceptor; + +import org.omg.PortableInterceptor.ClientRequestInfo; +import org.omg.PortableInterceptor.ClientRequestInterceptor; +import org.omg.PortableInterceptor.ClientRequestInterceptorOperations; +import org.omg.PortableInterceptor.ForwardRequest; + +/** + * A block of the all registered ClientRequest interceptors. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ClientRequestInterceptors + implements ClientRequestInterceptorOperations +{ + /** + * The array of all registered ClientRequest interceptors. + */ + private final ClientRequestInterceptor[] interceptors; + + /** + * Create the interceptor pack with the registerend interceptor array, + * obtained from the registrator. + */ + public ClientRequestInterceptors(Registrator registrator) + { + interceptors = registrator.getClientRequestInterceptors(); + } + + /** @inheritDoc */ + public void receive_exception(ClientRequestInfo info) + throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].receive_exception(info); + } + } + + /** @inheritDoc */ + public void receive_other(ClientRequestInfo info) throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].receive_other(info); + } + } + + /** @inheritDoc */ + public void receive_reply(ClientRequestInfo info) + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].receive_reply(info); + } + } + + /** @inheritDoc */ + public void send_poll(ClientRequestInfo info) + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].send_poll(info); + } + } + + /** @inheritDoc */ + public void send_request(ClientRequestInfo info) throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].send_request(info); + } + } + + /** + * Call destroy on all registered interceptors. + */ + public void destroy() + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + interceptors [ i ].destroy(); + } + catch (Exception exc) + { + // OMG states we should ignore. + } + } + } + + /** + * Get the class name. + */ + public String name() + { + return getClass().getName(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/ForwardRequestHolder.java b/libjava/classpath/gnu/CORBA/Interceptor/ForwardRequestHolder.java new file mode 100644 index 00000000000..d9ced03a332 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/ForwardRequestHolder.java @@ -0,0 +1,106 @@ +/* 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.Interceptor; + +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.ForwardRequest; +import org.omg.PortableInterceptor.ForwardRequestHelper; + +/** + * 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); + } + + /** + * 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); + } + + /** + * Get the typecode of the ForwardRequest. + */ + public TypeCode _type() + { + return ForwardRequestHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java b/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java new file mode 100644 index 00000000000..88756988c92 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/IORInterceptors.java @@ -0,0 +1,109 @@ +/* IORInterceptors.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.Interceptor; + +import org.omg.PortableInterceptor.IORInfo; +import org.omg.PortableInterceptor.IORInterceptor; +import org.omg.PortableInterceptor.IORInterceptorOperations; + +/** + * A block of the all registered IOR interceptors. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class IORInterceptors implements IORInterceptorOperations +{ + /** + * The array of all registered IOR interceptors. + */ + private final IORInterceptor[] interceptors; + + /** + * Create the interceptor pack with the registerend interceptor array, + * obtained from the registrator. + */ + public IORInterceptors(Registrator registrator) + { + interceptors = registrator.getIORInterceptors(); + } + + /** + * Call this method for all registered interceptors. + */ + public void establish_components(IORInfo info) + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + interceptors [ i ].establish_components(info); + } + catch (Exception exc) + { + // OMG states we should ignore. + } + } + } + + /** + * Call destroy on all registered interceptors. + */ + public void destroy() + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + interceptors [ i ].destroy(); + } + catch (Exception exc) + { + // OMG states we should ignore. + } + } + } + + /** + * Get the class name. + */ + public String name() + { + return getClass().getName(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java b/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java new file mode 100644 index 00000000000..ff35cd0c85e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/Registrator.java @@ -0,0 +1,470 @@ +/* Registrator.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.Interceptor; + +import gnu.CORBA.Poa.ORB_1_4; +import gnu.CORBA.gnuCodecFactory; + +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.Object; +import org.omg.IOP.CodecFactory; +import org.omg.PortableInterceptor.ClientRequestInterceptor; +import org.omg.PortableInterceptor.IORInterceptor; +import org.omg.PortableInterceptor.Interceptor; +import org.omg.PortableInterceptor.ORBInitInfo; +import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName; +import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName; +import org.omg.PortableInterceptor.ORBInitializer; +import org.omg.PortableInterceptor.ORBInitializerOperations; +import org.omg.PortableInterceptor.PolicyFactory; +import org.omg.PortableInterceptor.ServerRequestInterceptor; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.TreeMap; + +/** + * Collects interceptors, references and factories into arrays during + * registration. As the class is security sensitive, the most of the fields are + * private. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class Registrator extends LocalObject implements ORBInitInfo +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The agreed properties prefix. + */ + public final static String m_prefix = + "org.omg.PortableInterceptor.ORBInitializerClass."; + + /** + * The initialization - time server request interceptors. + */ + private ArrayList m_server = new ArrayList(); + + /** + * The initialization - time client request interceptors. + */ + private ArrayList m_client = new ArrayList(); + + /** + * The initialization - time ior interceptors. + */ + private ArrayList m_ior = new ArrayList(); + + /** + * The policy factories. + */ + public Hashtable m_policyFactories = new Hashtable(); + + /** + * The registered references. To avoid exposing the ORB's references map, the + * are added by ORB from inside the ORB code. The ORB is responsible for + * taking them from this field between pre_init and post_init. + */ + public TreeMap m_references = new TreeMap(); + + /** + * The initializers. + */ + public ArrayList m_initializers = new ArrayList(); + + /** + * The ORB being intialised. + */ + final ORB_1_4 orb; + + /** + * The argument string array, passed to ORB.init. + */ + final String[] m_args; + + /** + * The codec factory. + */ + final gnuCodecFactory m_codecFactory; + + /** + * Create the interceptor collection from the given properties, using the + * agreed naming convention. + * + * @param orb the ORB being initialised. + * @param props the cumulated set of properties where the orb initializer + * pattern is searched. + * @param an_args the argument string array, passed to ORB.init. + */ + public Registrator(ORB_1_4 an_orb, Properties props, String[] an_args) + { + orb = an_orb; + m_args = an_args; + m_codecFactory = new gnuCodecFactory(orb); + checkProperties(props); + checkProperties(System.getProperties()); + checkFile("user.home", null); + checkFile("java.home", "lib"); + } + + /** + * Scan the given properties for the possible interceptors. + */ + private void checkProperties(Properties props) + { + if (props == null) + { + return; + } + + Enumeration names = props.propertyNames(); + java.lang.Object key; + String sk; + + while (names.hasMoreElements()) + { + key = names.nextElement(); + if (key != null) + { + sk = key.toString(); + if (sk.startsWith(m_prefix)) + { + try + { + String cn = sk.substring(m_prefix.length()); + Class iClass = Class.forName(cn); + ORBInitializer initializer = + (ORBInitializer) iClass.newInstance(); + m_initializers.add(initializer); + } + catch (Exception exc) + { + // OMG states we should not throw an exception, but + // this will help the user to detect his error + // in initialiser properties. Should never print during + // normal run. + System.err.println(sk + " failed"); + } + } + } + } + } + + /** + * Check if the property is defined in the existsting file orb.properties. + */ + private void checkFile(String dir, String subdir) + { + try + { + File f = new File(dir); + if (!f.exists()) + { + return; + } + + if (subdir != null) + { + f = new File(f, subdir); + } + f = new File(f, "orb.properties"); + + if (!f.exists()) + { + return; + } + + Properties p = new Properties(); + p.load(new BufferedInputStream(new FileInputStream(f))); + + checkProperties(p); + } + catch (IOException ex) + { + } + } + + /** + * Called by ORB as a pre_init for all initializers. + */ + public void pre_init() + { + Iterator iter = m_initializers.iterator(); + while (iter.hasNext()) + { + ORBInitializerOperations initializer = + (ORBInitializerOperations) iter.next(); + initializer.pre_init(this); + } + } + + /** + * Get the map of the registered references. The ORB calls this method to + * import the references into its references map. + */ + public Map getRegisteredReferences() + { + return m_references; + } + + /** + * Called by ORB as a post-init for all initializers. After this call, the + * interceptor sets are fixed and redundant information is discarded. + */ + public void post_init() + { + Iterator iter = m_initializers.iterator(); + while (iter.hasNext()) + { + ORBInitializerOperations initializer = + (ORBInitializerOperations) iter.next(); + initializer.post_init(this); + } + } + + public ServerRequestInterceptor[] getServerRequestInterceptors() + { + ServerRequestInterceptor[] iServer = + new ServerRequestInterceptor[ m_server.size() ]; + for (int i = 0; i < iServer.length; i++) + { + iServer [ i ] = (ServerRequestInterceptor) m_server.get(i); + } + return iServer; + } + + public ClientRequestInterceptor[] getClientRequestInterceptors() + { + ClientRequestInterceptor[] iClient = + new ClientRequestInterceptor[ m_client.size() ]; + for (int i = 0; i < iClient.length; i++) + { + iClient [ i ] = (ClientRequestInterceptor) m_client.get(i); + } + return iClient; + } + + public IORInterceptor[] getIORInterceptors() + { + IORInterceptor[] iIor = new IORInterceptor[ m_ior.size() ]; + for (int i = 0; i < iIor.length; i++) + { + iIor [ i ] = (IORInterceptor) m_ior.get(i); + } + return iIor; + } + + public void add_client_request_interceptor( + ClientRequestInterceptor interceptor + ) throws DuplicateName + { + add(m_client, interceptor); + } + + public void add_ior_interceptor(IORInterceptor interceptor) + throws DuplicateName + { + add(m_ior, interceptor); + } + + public void add_server_request_interceptor( + ServerRequestInterceptor interceptor + ) throws DuplicateName + { + add(m_server, interceptor); + } + + /** + * Allocate a new slot for request - specific records. + */ + public int allocate_slot_id() + { + return orb.icSlotSize++; + } + + /** + * Add the interceptor to the given collection. + * + * @param list the collection to add. + * @param interceptor the interceptor to add. + */ + private void add(ArrayList list, Interceptor interceptor) + throws DuplicateName + { + if (interceptor.name().length() > 0) + { + Iterator iter = list.iterator(); + Interceptor ic; + + while (iter.hasNext()) + { + ic = (Interceptor) iter.next(); + if (ic.name().equals(interceptor.name())) + { + throw new DuplicateName(interceptor.name()); + } + } + } + list.add(interceptor); + } + + /** + * Get string array, passed to ORB.init. + */ + public String[] arguments() + { + return m_args; + } + + /** + * Get the codec factory. + */ + public CodecFactory codec_factory() + { + return m_codecFactory; + } + + /** + * Get the ORB's id, currently using .toString. + */ + public String orb_id() + { + return "orb_" + orb; + } + + /** + * Register reference. + */ + public void register_initial_reference(String object_name, Object object) + throws InvalidName + { + if (object_name == null) + { + throw new InvalidName("null"); + } + else if (object_name.length() == 0) + { + throw new InvalidName("Empty string"); + } + else if (m_references.containsKey(object_name)) + { + throw new InvalidName(object_name); + } + else + { + m_references.put(object_name, object); + } + } + + /** + * Accumulates the policy factory map. + */ + public void register_policy_factory(int policy_type, + PolicyFactory policy_factory + ) + { + Integer it = new Integer(policy_type); + if (m_policyFactories.containsKey(it)) + { + throw new BAD_INV_ORDER( + "Repetetive registration of the policy factory for type " + + policy_type, + 16, + CompletionStatus.COMPLETED_NO + ); + } + m_policyFactories.put(it, policy_factory); + } + + /** + * Delegates to ORB. + */ + public org.omg.CORBA.Object resolve_initial_references(String object_name) + throws InvalidName + { + try + { + return orb.resolve_initial_references(object_name); + } + catch (org.omg.CORBA.ORBPackage.InvalidName e) + { + InvalidName in = new InvalidName(e.getMessage()); + in.initCause(e); + throw in; + } + } + + /** + * Check if any interceptors of this type were registered. + */ + public boolean hasClientRequestInterceptors() + { + return m_client.size() > 0; + } + + /** + * Check if any interceptors of this type were registered. + */ + public boolean hasServerRequestInterceptors() + { + return m_server.size() > 0; + } + + /** + * Check if any interceptors of this type were registered. + */ + public boolean hasIorInterceptors() + { + return m_ior.size() > 0; + } +} diff --git a/libjava/classpath/gnu/CORBA/Interceptor/ServerRequestInterceptors.java b/libjava/classpath/gnu/CORBA/Interceptor/ServerRequestInterceptors.java new file mode 100644 index 00000000000..4b9bede98eb --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/ServerRequestInterceptors.java @@ -0,0 +1,139 @@ +/* ServerRequestInterceptors.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.Interceptor; + +import org.omg.PortableInterceptor.ForwardRequest; +import org.omg.PortableInterceptor.ServerRequestInfo; +import org.omg.PortableInterceptor.ServerRequestInterceptor; +import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; + +/** + * A block of the all registered ServerRequest interceptors. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class ServerRequestInterceptors + implements ServerRequestInterceptorOperations +{ + /** + * The array of all registered ServerRequest interceptors. + */ + private final ServerRequestInterceptor[] interceptors; + + /** + * Create the interceptor pack with the registerend interceptor array, + * obtained from the registrator. + */ + public ServerRequestInterceptors(Registrator registrator) + { + interceptors = registrator.getServerRequestInterceptors(); + } + + /** @inheritDoc */ + public void receive_request_service_contexts(ServerRequestInfo info) + throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].receive_request_service_contexts(info); + } + } + + /** @inheritDoc */ + public void receive_request(ServerRequestInfo info) throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].receive_request(info); + } + } + + /** @inheritDoc */ + public void send_exception(ServerRequestInfo info) throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].send_exception(info); + } + } + + /** @inheritDoc */ + public void send_other(ServerRequestInfo info) throws ForwardRequest + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].send_other(info); + } + } + + /** @inheritDoc */ + public void send_reply(ServerRequestInfo info) + { + for (int i = 0; i < interceptors.length; i++) + { + interceptors [ i ].send_reply(info); + } + } + + /** + * Call destroy on all registered interceptors. + */ + public void destroy() + { + for (int i = 0; i < interceptors.length; i++) + { + try + { + interceptors [ i ].destroy(); + } + catch (Exception exc) + { + // OMG states we should ignore. + } + } + } + + /** + * Get the class name. + */ + public String name() + { + return getClass().getName(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuClientRequestInfo.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuClientRequestInfo.java new file mode 100644 index 00000000000..beb81c81f6c --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuClientRequestInfo.java @@ -0,0 +1,337 @@ +/* gnuClientRequestInfo.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.Interceptor; + +import gnu.CORBA.Unexpected; +import gnu.CORBA.gnuRequest; + +import org.omg.CORBA.ARG_IN; +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.INV_POLICY; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.NVList; +import org.omg.CORBA.ORB; +import org.omg.CORBA.ParameterMode; +import org.omg.CORBA.Policy; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.BadKind; +import org.omg.Dynamic.Parameter; +import org.omg.IOP.ServiceContext; +import org.omg.IOP.TaggedComponent; +import org.omg.IOP.TaggedProfile; +import org.omg.PortableInterceptor.ClientRequestInfo; +import org.omg.PortableInterceptor.InvalidSlot; + +/** + * Client request info. All requests on the client side in Classpath + * implementations are handled via gnuRequest class. This class holds the + * instance of the gnuRequest, accessing the request info this way. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuClientRequestInfo extends LocalObject + implements ClientRequestInfo +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The request structure, from that some methods take the needed information + * directly. The same request structure cannot be reused in parallel threads, + * the submission methods are synchronized. + */ + private final gnuRequest request; + + /** + * Provides possibility to set the wrapped thrown exception explicitly, where + * applicable. + */ + public Any m_wrapped_exception; + + /** + * Create the info on the given request. + */ + public gnuClientRequestInfo(gnuRequest a_request) + { + request = a_request; + } + + /** @inheritDoc */ + public void add_request_service_context(ServiceContext service_context, + boolean replace + ) + { + request.add_request_service_context(service_context, replace); + } + + /** @inheritDoc */ + public TaggedProfile effective_profile() + { + return request.effective_profile(); + } + + /** @inheritDoc */ + public org.omg.CORBA.Object effective_target() + { + return request.effective_target(); + } + + /** @inheritDoc */ + public TaggedComponent get_effective_component(int id) + throws BAD_PARAM + { + return request.get_effective_component(id); + } + + /** @inheritDoc */ + public TaggedComponent[] get_effective_components(int id) + throws BAD_PARAM + { + return request.get_effective_components(id); + } + + /** @inheritDoc */ + public Policy get_request_policy(int type) throws INV_POLICY + { + return request.get_request_policy(type); + } + + /** @inheritDoc */ + public String received_exception_id() + { + try + { + if (m_wrapped_exception != null) + { + return m_wrapped_exception.type().id(); + } + else + { + return request.received_exception_id(); + } + } + catch (BadKind e) + { + throw new Unexpected(e); + } + } + + /** @inheritDoc */ + public Any received_exception() + { + if (m_wrapped_exception != null) + { + return m_wrapped_exception; + } + else + { + return request.received_exception(); + } + } + + /** @inheritDoc */ + public org.omg.CORBA.Object target() + { + return request.target(); + } + + /** @inheritDoc */ + public Parameter[] arguments() + { + request.checkDii(); + + NVList args = request.arguments(); + Parameter[] p = new Parameter[ args.count() ]; + try + { + for (int i = 0; i < p.length; i++) + { + ParameterMode mode; + + switch (args.item(i).flags()) + { + case ARG_IN.value : + mode = ParameterMode.PARAM_IN; + break; + + case ARG_OUT.value : + mode = ParameterMode.PARAM_OUT; + break; + + case ARG_INOUT.value : + mode = ParameterMode.PARAM_INOUT; + break; + + default : + throw new Unexpected(); + } + + p [ i ] = new Parameter(args.item(i).value(), mode); + } + } + catch (Bounds e) + { + throw new Unexpected(e); + } + return p; + } + + /** @inheritDoc */ + public Any result() + { + request.checkDii(); + + Any rt = request.return_value(); + + if (rt == null) + { + ORB orb = request.orb(); + rt = orb.create_any(); + rt.type(orb.get_primitive_tc(TCKind.tk_void)); + return rt; + } + + return request.return_value(); + } + + /** @inheritDoc */ + public String[] contexts() + { + return request.ice_contexts(); + } + + /** @inheritDoc */ + public TypeCode[] exceptions() + { + request.checkDii(); + + ExceptionList ex = request.exceptions(); + TypeCode[] et = new TypeCode[ ex.count() ]; + try + { + for (int i = 0; i < et.length; i++) + { + et [ i ] = ex.item(i); + } + } + catch (Bounds e) + { + throw new Unexpected(e); + } + return et; + } + + /** @inheritDoc */ + public org.omg.CORBA.Object forward_reference() + { + return request.forward_reference(); + } + + /** @inheritDoc */ + public String[] operation_context() + { + return request.operation_context(); + } + + /** @inheritDoc */ + public Any get_slot(int id) throws InvalidSlot + { + return request.get_slot(id); + } + + /** @inheritDoc */ + public String operation() + { + return request.operation(); + } + + /** @inheritDoc */ + public short reply_status() + { + return request.reply_status(); + } + + /** @inheritDoc */ + public int request_id() + { + return request.request_id(); + } + + /** @inheritDoc */ + public boolean response_expected() + { + return request.response_expected(); + } + + /** + * Determines how far the request shall progress before control is returned to + * the client. However up till JDK 1.5 inclusive this method always returns + * SYNC_WITH_TRANSPORT. + * + * @return {@link org.omg.Messaging.SYNC_WITH_TRANSPORT.value (1), always. + * + * @specnote as defined in the Suns 1.5 JDK API. + */ + public short sync_scope() + { + return request.sync_scope(); + } + + /** @inheritDoc */ + public ServiceContext get_reply_service_context(int ctx_name) + throws BAD_PARAM + { + return request.get_reply_service_context(ctx_name); + } + + /** @inheritDoc */ + public ServiceContext get_request_service_context(int ctx_name) + throws BAD_PARAM + { + return request.get_request_service_context(ctx_name); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java new file mode 100644 index 00000000000..ee8af7fc0b4 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuIcCurrent.java @@ -0,0 +1,255 @@ +/* gnuIcCurrent.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.Interceptor; + +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.Poa.ORB_1_4; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_INV_ORDER; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableInterceptor.Current; +import org.omg.PortableInterceptor.CurrentHelper; +import org.omg.PortableInterceptor.InvalidSlot; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +/** + * Supports the "Interceptor current" concept, providing the slot value + * information for the current thread. When making the invocation, this + * information is copied to the Current, returned by ClientRequestInfo. + * + * 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 gnuIcCurrent extends ObjectImpl implements Current +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The ORB, controllin this Current. It provides data about the required size + * of the slot array. + */ + final ORB_1_4 orb; + + /** + * The table, mapping threads to records. + */ + private Hashtable threads = new Hashtable(); + + /** + * An empty array when no slots are defined, computed once. + */ + static final Any[] NO_SLOTS = new Any[ 0 ]; + + /** + * Create the IC current. + */ + public gnuIcCurrent(ORB_1_4 an_orb) + { + orb = an_orb; + } + + /** + * 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/PortableInterceptor/Current:1.0". + */ + public String[] _ids() + { + return new String[] { CurrentHelper.id() }; + } + + /** + * Add the entry to the map. + */ + public void put(Thread t, Any[] record) + { + synchronized (threads) + { + threads.put(t, record); + + // Remove non-running threads, avoiding memory leak. + if (threads.size() > 12) + { + Iterator it = threads.entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry e = (Map.Entry) it.next(); + Thread tx = (Thread) e.getKey(); + if (!tx.isAlive()) + { + it.remove(); + } + } + } + } + } + + /** + * Check if this thread is registered. + */ + public boolean has(Thread t) + { + synchronized (threads) + { + return threads.containsKey(t); + } + } + + /** + * Remove the entry from the map. + */ + public void remove(Thread t) + { + synchronized (threads) + { + threads.remove(t); + } + } + + /** + * Get array of all slots, as it is applicable for the current thread. If the + * slots were not previously allocated, they are allocated during this call. + */ + Any[] get_slots() + { + Any[] r; + synchronized (threads) + { + r = (Any[]) threads.get(Thread.currentThread()); + if (r == null) + { + r = new Any[ orb.icSlotSize ]; + + for (int i = 0; i < r.length; i++) + { + Any a = orb.create_any(); + a.type(orb.get_primitive_tc(TCKind.tk_null)); + r [ i ] = a; + } + + put(Thread.currentThread(), r); + } + return r; + } + } + + /** + * Get copu array of all slots, as it is applicable for the current thread. If + * the slots were not previously allocated, they are allocated during this + * call. + */ + public Any[] clone_slots() + { + if (orb.icSlotSize == 0) + { + return NO_SLOTS; + } + else + { + Any[] r = get_slots(); + Any[] copy = new Any[ r.length ]; + + cdrBufOutput buf = new cdrBufOutput(); + buf.setOrb(orb); + + for (int i = 0; i < copy.length; i++) + { + r [ i ].write_value(buf); + } + + InputStream input = buf.create_input_stream(); + + for (int i = 0; i < copy.length; i++) + { + copy [ i ] = orb.create_any(); + copy [ i ].read_value(input, r [ i ].type()); + } + + return copy; + } + } + + /** + * Get value for the slot with the given id. If the array of Currents has not + * been yet allocated for the current thread, it is allocated during the + * invocation of this method. + */ + public Any get_slot(int slot_id) throws InvalidSlot, BAD_INV_ORDER + { + try + { + return get_slots() [ slot_id ]; + } + catch (ArrayIndexOutOfBoundsException e) + { + throw new InvalidSlot("Slot " + slot_id); + } + } + + /** + * Set value for the slot with the given id. If the array of Currents has not + * been yet allocated for the current thread, it is allocated during the + * invocation of this method. + */ + public void set_slot(int slot_id, Any data) + throws InvalidSlot, BAD_INV_ORDER + { + try + { + get_slots() [ slot_id ] = data; + } + catch (ArrayIndexOutOfBoundsException e) + { + throw new InvalidSlot("Slot " + slot_id); + } + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java new file mode 100644 index 00000000000..1c406cb5e46 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuIorInfo.java @@ -0,0 +1,120 @@ +/* gnuIorInfo.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.Interceptor; + +import gnu.CORBA.IOR; +import gnu.CORBA.Poa.ORB_1_4; + +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.Policy; +import org.omg.IOP.TaggedComponent; +import org.omg.PortableInterceptor.IORInfo; +import org.omg.PortableServer.POA; + +/** + * Implements IORInfo. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuIorInfo extends LocalObject implements IORInfo +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * The ORB, to that the IOR is related. + */ + public final ORB_1_4 orb; + + /** + * The POA, to that IOR is related. + */ + public final POA poa; + + /** + * The IOR itself. + */ + private final IOR ior; + + /** + * Create an instance. + */ + public gnuIorInfo(ORB_1_4 an_orb, POA a_poa, IOR an_ior) + { + orb = an_orb; + poa = a_poa; + ior = an_ior; + } + + /** + * Add component to tje specified profile of this IOR. + */ + public void add_ior_component_to_profile(TaggedComponent tagged_component, + int profile_id + ) + { + ior.add_ior_component_to_profile(tagged_component, profile_id); + } + + /** + * Add component to all found profiles in this IOR. + */ + public void add_ior_component(TaggedComponent tagged_component) + { + ior.add_ior_component(tagged_component); + } + + /** + * Get the POA policy. + */ + public Policy get_effective_policy(int policy_type) + { + return poa._get_policy(policy_type); + } + + /** + * Return the state of the object POA. + */ + short state() + { + return (short) poa.the_POAManager().get_state().value(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java b/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java new file mode 100644 index 00000000000..5f75f76878a --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Interceptor/gnuServerRequestInfo.java @@ -0,0 +1,456 @@ +/* gnuServerRequestInfo.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.Interceptor; + +import gnu.CORBA.GIOP.ReplyHeader; +import gnu.CORBA.GIOP.RequestHeader; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.Poa.gnuServantObject; +import gnu.CORBA.Unexpected; +import gnu.CORBA.gnuRequest; + +import org.omg.CORBA.ARG_IN; +import org.omg.CORBA.ARG_INOUT; +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.Bounds; +import org.omg.CORBA.CompletionStatus; +import org.omg.CORBA.ExceptionList; +import org.omg.CORBA.INV_POLICY; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.NO_RESOURCES; +import org.omg.CORBA.NVList; +import org.omg.CORBA.Object; +import org.omg.CORBA.ParameterMode; +import org.omg.CORBA.Policy; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.Dynamic.Parameter; +import org.omg.IOP.ServiceContext; +import org.omg.Messaging.SYNC_WITH_TRANSPORT; +import org.omg.PortableInterceptor.InvalidSlot; +import org.omg.PortableInterceptor.ServerRequestInfo; + +/** + * Implementation of the ServerRequestInfo, associacted with gnuServantObject. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuServerRequestInfo extends LocalObject + implements ServerRequestInfo +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * A local object that will serve the invocation. + */ + final gnuServantObject m_object; + + /** + * A message that the given resource is not available using this metod of + * invocation. + */ + static final String not_available = + "The used invocation method provides" + "no access to this resource."; + + /** + * An array of slots. + */ + Any[] m_slots; + + /** + * The request header. + */ + public final RequestHeader m_request_header; + + /** + * The reply header. + */ + public final ReplyHeader m_reply_header; + + /** + * The forward reference, if applicable. + */ + public Object m_forward_reference; + + /** + * The thrown systen exception. + */ + public Exception m_sys_exception; + + /** + * The Any, containing the thrown user exception. + */ + public Any m_usr_exception; + + /** + * The associated request, if any. + */ + public gnuRequest m_request; + + /** + * Create a new instance at the time when it is known which object will serve + * the invocation. + * + * @param an_object a local object, connected to the local servant that will + * serve the invocation. + */ + public gnuServerRequestInfo(gnuServantObject an_object, + RequestHeader a_request_header, ReplyHeader a_reply_header + ) + { + m_object = an_object; + m_request_header = a_request_header; + m_reply_header = a_reply_header; + m_slots = new Any[ m_object.orb.icSlotSize ]; + reset(); + } + + /** + * Set the give slot. + */ + public void set_slot(int id, Any data) throws InvalidSlot + { + try + { + m_slots [ id ] = data; + } + catch (Exception e) + { + InvalidSlot ex = new InvalidSlot("Cannot set slot " + id); + ex.initCause(e); + throw ex; + } + } + + /** + * Get the given slot. + */ + public Any get_slot(int id) throws InvalidSlot + { + try + { + return m_slots [ id ]; + } + catch (Exception e) + { + InvalidSlot ex = new InvalidSlot("Cannot get slot " + id); + ex.initCause(e); + throw ex; + } + } + + /** + * Reset slot data. + */ + public void reset() + { + TypeCode tkNull = m_object.orb.get_primitive_tc(TCKind.tk_null); + for (int i = 0; i < m_slots.length; i++) + { + Any a = m_object.orb.create_any(); + a.type(tkNull); + m_slots [ i ] = a; + } + m_sys_exception = null; + m_usr_exception = null; + } + + /** + * Get the object id (not the object IOR key). + */ + public byte[] object_id() + { + return m_object.Id; + } + + /** + * Check if the target is an instance of the type, represented by the given + * repository Id. + */ + public boolean target_is_a(String id) + { + return m_object._is_a(id); + } + + /** + * Get the POA id. + */ + public byte[] adapter_id() + { + return m_object.poa.id(); + } + + /** + * Get the POA policy of the given type that applies to the object being + * served (request being handled). + */ + public Policy get_server_policy(int type) throws INV_POLICY + { + return m_object.poa._get_policy(type); + } + + /** + * Get the first member of the object repository id array. + */ + public String target_most_derived_interface() + { + return m_object._ids() [ 0 ]; + } + + /** + * Get the name of the operation being performed. + */ + public String operation() + { + if (m_request != null) + { + return m_request.operation(); + } + else + { + return m_request_header.operation; + } + } + + /** + * Not available. + */ + public TypeCode[] exceptions() + { + if (m_request == null) + { + throw new NO_RESOURCES(not_available, 1, + CompletionStatus.COMPLETED_MAYBE + ); + } + + m_request.checkDii(); + + ExceptionList ex = m_request.exceptions(); + TypeCode[] et = new TypeCode[ ex.count() ]; + try + { + for (int i = 0; i < et.length; i++) + { + et [ i ] = ex.item(i); + } + } + catch (Bounds e) + { + throw new Unexpected(e); + } + return et; + } + + /** + * Get reply status. + */ + public short reply_status() + { + return (short) m_reply_header.reply_status; + } + + /** + * Get request id. All local requests have request id = -1. + */ + public int request_id() + { + return m_request_header.request_id; + } + + /** + * Check if the client expected any response. + */ + public boolean response_expected() + { + return m_request_header.isResponseExpected(); + } + + /** @inheritDoc */ + public void add_reply_service_context(ServiceContext service_context, + boolean replace + ) + { + m_reply_header.addContext(service_context, replace); + } + + /** + * Get an exception, wrapped into Any. + */ + public Any sending_exception() + { + if (m_usr_exception != null) + { + return m_usr_exception; + } + else if (m_sys_exception != null) + { + Any a = m_object.orb.create_any(); + ObjectCreator.insertException(a, m_sys_exception); + return a; + } + else + { + return null; + } + } + + public org.omg.CORBA.Object forward_reference() + { + return m_forward_reference; + } + + /** @inheritDoc */ + public ServiceContext get_reply_service_context(int ctx_name) + throws BAD_PARAM + { + return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name, + m_reply_header.service_context + ); + } + + /** @inheritDoc */ + public ServiceContext get_request_service_context(int ctx_name) + throws BAD_PARAM + { + return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name, + m_request_header.service_context + ); + } + + /** + * Not available + */ + public String[] operation_context() + { + if (m_request == null) + { + throw new NO_RESOURCES(not_available); + } + else + { + return m_request.operation_context(); + } + } + + /** @inheritDoc */ + public Any result() + { + if (m_request == null) + { + throw new NO_RESOURCES(not_available); + } + else + { + return m_request.return_value(); + } + } + + /** @inheritDoc */ + public String[] contexts() + { + if (m_request == null) + { + throw new NO_RESOURCES(not_available); + } + else + { + return m_request.ice_contexts(); + } + } + + /** + * Always returns "with transport". + */ + public short sync_scope() + { + return SYNC_WITH_TRANSPORT.value; + } + + /** @inheritDoc */ + public Parameter[] arguments() + { + if (m_request == null) + { + throw new NO_RESOURCES(not_available); + } + + m_request.checkDii(); + + NVList args = m_request.arguments(); + Parameter[] p = new Parameter[ args.count() ]; + try + { + for (int i = 0; i < p.length; i++) + { + ParameterMode mode; + + switch (args.item(i).flags()) + { + case ARG_IN.value : + mode = ParameterMode.PARAM_IN; + break; + + case ARG_OUT.value : + mode = ParameterMode.PARAM_OUT; + break; + + case ARG_INOUT.value : + mode = ParameterMode.PARAM_INOUT; + break; + + default : + throw new Unexpected(); + } + + p [ i ] = new Parameter(args.item(i).value(), mode); + } + } + catch (Bounds e) + { + throw new Unexpected(e); + } + return p; + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NameDynAnyPairHolder.java b/libjava/classpath/gnu/CORBA/NameDynAnyPairHolder.java new file mode 100644 index 00000000000..6ceb9aae06f --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NameDynAnyPairHolder.java @@ -0,0 +1,115 @@ +/* NameDynAnyPairHolder.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.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameDynAnyPairHelper; + +/** + * A holder for the structure {@link NameDynAnyPair}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameDynAnyPairHolder + implements Streamable +{ + /** + * The stored NameDynAnyPair value. + */ + public NameDynAnyPair value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public NameDynAnyPairHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public NameDynAnyPairHolder(NameDynAnyPair initialValue) + { + value = initialValue; + } + + /** + * The method should read this object from the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _read(InputStream input) + { + value = NameDynAnyPairHelper.read(input); + } + + /** + * The method should write this object to the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _write(OutputStream output) + { + NameDynAnyPairHelper.write(output, value); + } + + /** + * Get the typecode of the NameDynAnyPair. + */ + public org.omg.CORBA.TypeCode _type() + { + return NameDynAnyPairHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NameDynAnyPairSeqHolder.java b/libjava/classpath/gnu/CORBA/NameDynAnyPairSeqHolder.java new file mode 100644 index 00000000000..71b6174c1ad --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NameDynAnyPairSeqHolder.java @@ -0,0 +1,115 @@ +/* NameDynAnyPairSeqHolder.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.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.NameDynAnyPair; +import org.omg.DynamicAny.NameDynAnyPairSeqHelper; + +/** + * A holder for the sequence of {@link NameDynAnyPair}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameDynAnyPairSeqHolder + implements Streamable +{ + /** + * The stored array of <code>NameDynAnyPair</code>. + */ + public NameDynAnyPair[] value; + + /** + * Create the unitialised instance, leaving the value array + * with default <code>null</code> value. + */ + public NameDynAnyPairSeqHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the array that will be assigned to + * the <code>value</code> array. + */ + public NameDynAnyPairSeqHolder(NameDynAnyPair[] initialValue) + { + value = initialValue; + } + + /** + * The method should read this object from the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _read(InputStream input) + { + value = NameDynAnyPairSeqHelper.read(input); + } + + /** + * The method should write this object to the CDR input stream, but + * (following the JDK 1.5 API) it does not. + * + * @param input a org.omg.CORBA.portable stream to read from. + * + * @specenote Sun throws the same exception. + * + * @throws MARSHAL always. + */ + public void _write(OutputStream output) + { + NameDynAnyPairSeqHelper.write(output, value); + } + + /** + * Get the typecode of the NameDynAnyPair. + */ + public org.omg.CORBA.TypeCode _type() + { + return NameDynAnyPairSeqHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NameValuePairHolder.java b/libjava/classpath/gnu/CORBA/NameValuePairHolder.java new file mode 100644 index 00000000000..9a939d5e337 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NameValuePairHolder.java @@ -0,0 +1,105 @@ +/* NameValuePairHolder.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.CORBA; + +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.NameValuePair; +import org.omg.DynamicAny.NameValuePairHelper; + +/** + * A holder for the structure {@link NameValuePair}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameValuePairHolder + implements Streamable +{ + /** + * The stored NameValuePair value. + */ + public NameValuePair value; + + /** + * Create the unitialised instance, leaving the value field + * with default <code>null</code> value. + */ + public NameValuePairHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the value that will be assigned to + * the <code>value</code> field. + */ + public NameValuePairHolder(NameValuePair 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 = NameValuePairHelper.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) + { + NameValuePairHelper.write(output, value); + } + + /** + * Get the typecode of the NameValuePair. + */ + public org.omg.CORBA.TypeCode _type() + { + return NameValuePairHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NameValuePairSeqHolder.java b/libjava/classpath/gnu/CORBA/NameValuePairSeqHolder.java new file mode 100644 index 00000000000..216d78e04c8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NameValuePairSeqHolder.java @@ -0,0 +1,105 @@ +/* NameValuePairSeqHolder.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.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.Streamable; +import org.omg.DynamicAny.NameValuePair; +import org.omg.DynamicAny.NameValuePairSeqHelper; + +/** + * A holder for the sequence of {@link NameValuePair}. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameValuePairSeqHolder + implements Streamable +{ + /** + * The stored array of <code>NameValuePair</code>. + */ + public NameValuePair[] value; + + /** + * Create the unitialised instance, leaving the value array + * with default <code>null</code> value. + */ + public NameValuePairSeqHolder() + { + } + + /** + * Create the initialised instance. + * @param initialValue the array that will be assigned to + * the <code>value</code> array. + */ + public NameValuePairSeqHolder(NameValuePair[] initialValue) + { + value = initialValue; + } + + /** + * Read the {@link value} array from the CDR stream. + * + * @param input the org.omg.CORBA.portable stream to read. + */ + public void _read(InputStream input) + { + value = NameValuePairSeqHelper.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) + { + NameValuePairSeqHelper.write(output, value); + } + + /** + * Get the typecode of the NameValuePair. + */ + public org.omg.CORBA.TypeCode _type() + { + return NameValuePairSeqHelper.type(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/NamingService/NameParser.java b/libjava/classpath/gnu/CORBA/NamingService/NameParser.java new file mode 100644 index 00000000000..f886cf93533 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/NamingService/NameParser.java @@ -0,0 +1,419 @@ +/* NameParser.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.CORBA.NamingService; + +import gnu.CORBA.Functional_ORB; +import gnu.CORBA.IOR; +import gnu.CORBA.Unexpected; +import gnu.CORBA.Version; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.DATA_CONVERSION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CORBA.portable.Delegate; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CosNaming.NamingContext; +import org.omg.CosNaming.NamingContextExtHelper; +import org.omg.CosNaming.NamingContextHelper; +import org.omg.CosNaming._NamingContextStub; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.StringTokenizer; + +/** + * Parses the alternative IOR representations into our IOR structure. + * + * TODO This parser currently supports only one address per target string. A + * string with the multiple addresses will be accepted, but only the last + * address will be taken into consideration. The fault tolerance is not yet + * implemented. + * + * The key string is filtered using {@link java.net.URLDecoder} that replaces + * the agreed escape sequences by the corresponding non alphanumeric characters. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class NameParser + extends snConverter +{ + /** + * The corbaloc prefix. + */ + public static final String pxCORBALOC = "corbaloc"; + + /** + * The corbaname prefix. + */ + public static final String pxCORBANAME = "corbaname"; + + /** + * The IOR prefix. + */ + public static final String pxIOR = "ior"; + + /** + * Marks iiop protocol. + */ + public static final String IIOP = "iiop"; + + /** + * Marks rir protocol. + */ + public static final String RIR = "rir"; + + /** + * The default port value, as specified in OMG documentation. + */ + public static final int DEFAULT_PORT = 2809; + + /** + * The default name. + */ + public static final String DEFAULT_NAME = "NameService"; + + /** + * The string to name converter, initialized on demand. + */ + static snConverter converter; + + /** + * The current position. + */ + int p; + + /** + * The address being parsed, splitted into tokens. + */ + String[] t; + + /** + * Parse CORBALOC. + * + * The expected format is: <br> + * 1. corbaloc:[iiop][version.subversion@]:host[:port]/key <br> + * 2. corbaloc:rir:[/key] <br> + * 3. corbaname:[iiop][version.subversion@]:host[:port]/key <br> + * 4. corbaname:rir:[/key] <br> + * + * Protocol defaults to IOP, the object key defaults to the NameService. + * + * @param corbaloc the string to parse. + * @param orb the ORB, needed to create IORs and resolve rir references. + * + * @return the resolved object. + */ + public synchronized org.omg.CORBA.Object corbaloc(String corbaloc, + Functional_ORB orb) + throws BAD_PARAM + { + boolean corbaname; + + // The alternative addresses, if given. + ArrayList alt_addr = new ArrayList(); + + // The version numbers with default values. + int major = 1; + int minor = 0; + + // The host address. + String host; + + // The port. + int port = DEFAULT_PORT; + + // The object key as string. + String key; + + StringTokenizer st = new StringTokenizer(corbaloc, ":@/.,#", true); + + t = new String[st.countTokens()]; + + for (int i = 0; i < t.length; i++) + { + t[i] = st.nextToken(); + } + + p = 0; + + if (t[p].startsWith(pxCORBANAME)) + corbaname = true; + else if (t[p].equalsIgnoreCase(pxCORBALOC)) + corbaname = false; + else if (t[p].equalsIgnoreCase(pxIOR)) + { + IOR ior = IOR.parse(corbaloc); + return orb.ior_to_object(ior); + } + else + throw new DATA_CONVERSION("Unsupported protocol: '" + t[p] + "'"); + + p++; + + if (!t[p++].equals(":")) + throw new BAD_PARAM("Syntax (':' expected after name prefix)"); + + // Check for rir: + if (t[p].equals(RIR)) + { + p++; + if (!t[p++].equals(":")) + throw new BAD_PARAM("':' expected after 'rir'"); + + key = readKey("/"); + + Object object; + try + { + object = orb.resolve_initial_references(key); + return corbaname ? resolve(object) : object; + } + catch (InvalidName e) + { + throw new BAD_PARAM("Unknown initial reference '" + key + "'"); + } + } + else + // Check for iiop. + if (t[p].equals(IIOP) || t[p].equals(":")) + { + IOR ior = new IOR(); + + Addresses: do + { // Read addresses. + if (t[p].equals(":")) + { + p++; + } + else + { + p++; + if (!t[p++].equals(":")) + throw new BAD_PARAM("':' expected after 'iiop'"); + // Check if version is present. + if (t[p + 1].equals(".")) + if (t[p + 3].equals("@")) + { + // Version info present. + try + { + major = Integer.parseInt(t[p++]); + } + catch (NumberFormatException e) + { + throw new BAD_PARAM("Major version number '" + + t[p - 1] + "'"); + } + p++; // '.' at this point. + try + { + minor = Integer.parseInt(t[p++]); + } + catch (NumberFormatException e) + { + throw new BAD_PARAM("Major version number '" + + t[p - 1] + "'"); + } + p++; // '@' at this point. + } + } + + ior.Internet.version = new Version(major, minor); + + // Then host data goes till '/' or ':'. + StringBuffer bhost = new StringBuffer(corbaloc.length()); + while (!t[p].equals(":") && !t[p].equals("/") && !t[p].equals(",")) + bhost.append(t[p++]); + + host = bhost.toString(); + + ior.Internet.host = host; + + if (t[p].equals(":")) + { + // Port specified. + p++; + try + { + port = Integer.parseInt(t[p++]); + } + catch (NumberFormatException e) + { + throw new BAD_PARAM("Invalid port '" + t[p - 1] + "'"); + } + } + + ior.Internet.port = port; + + // Id is not listed. + ior.Id = ""; + + if (t[p].equals(",")) + p++; + else + break Addresses; + } + while (true); + + key = readKey("/"); + ior.key = key.getBytes(); + + org.omg.CORBA.Object object = orb.ior_to_object(ior); + return corbaname ? resolve(object) : object; + } + + else + throw new DATA_CONVERSION("Unsupported protocol '" + t[p] + "'"); + } + + private org.omg.CORBA.Object resolve(org.omg.CORBA.Object object) + { + NamingContext ns; + String key = "?"; + try + { + if (object instanceof NamingContext) + ns = (NamingContext) object; + else + { + Delegate delegate = ((ObjectImpl) object)._get_delegate(); + ns = new _NamingContextStub(delegate); + } + } + catch (Exception ex) + { + BAD_PARAM bad = new BAD_PARAM("The CORBANAME target " + object + + " is not a NamingContext"); + bad.minor = 10; + bad.initCause(ex); + throw bad; + } + + if (converter == null) + converter = new snConverter(); + + try + { + key = readKey("#"); + object = ns.resolve(converter.toName(key)); + return object; + } + catch (Exception ex) + { + BAD_PARAM bad = new BAD_PARAM("Wrong CORBANAME '" + key + "'"); + bad.minor = 10; + bad.initCause(ex); + throw bad; + } + } + + private String readKey(String delimiter) + throws BAD_PARAM + { + if (p < t.length) + if (!t[p].equals(delimiter)) + { + if (t[p].equals("#")) + return DEFAULT_NAME; + else + throw new BAD_PARAM("'" + delimiter + "String' expected '" + t[p] + + "' found"); + } + + StringBuffer bKey = new StringBuffer(); + p++; + + while (p < t.length && !t[p].equals("#")) + bKey.append(t[p++]); + + if (bKey.length() == 0) + return DEFAULT_NAME; + + try + { + return URLDecoder.decode(bKey.toString(), "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + throw new Unexpected("URLDecoder does not support UTF-8", e); + } + } + + static NameParser n = new NameParser(); + + static void corbalocT(String ior, Functional_ORB orb) + { + System.out.println(ior); + System.out.println(n.corbaloc(ior, orb)); + System.out.println(); + } + + public static void main(String[] args) + { + try + { + Functional_ORB orb = (Functional_ORB) ORB.init(args, null); + corbalocT("corbaloc:iiop:1.3@155axyz.com/Prod/aTradingService", orb); + corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb); + corbalocT("corbaloc:iiop:355cxyz.com/Prod/cTradingService", orb); + corbalocT("corbaloc:iiop:2.7@255bxyz.com/Prod/bTradingService", orb); + corbalocT("corbaloc:iiop:355cxyz.com:7777/Prod/cTradingService", orb); + + corbalocT("corbaloc::556xyz.com:80/Dev/NameService", orb); + corbalocT("corbaloc:iiop:1.2@host1:3076/0", orb); + + corbalocT("corbaloc:rir:/NameService", orb); + corbalocT("corbaloc:rir:/", orb); + corbalocT("corbaloc:rir:", orb); + + corbalocT("corbaloc:rir:/NameService", orb); + corbalocT("corbaloc:rir:/", orb); + corbalocT("corbaloc:rir:", orb); + + corbalocT("corbaloc::555xyz.com,:556xyz.com:80/Dev/NameService", orb); + } + catch (BAD_PARAM e) + { + e.printStackTrace(System.out); + } + } +} diff --git a/libjava/classpath/gnu/CORBA/Poa/ForwardRequestHolder.java b/libjava/classpath/gnu/CORBA/Poa/ForwardRequestHolder.java new file mode 100644 index 00000000000..5e2455952d2 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java b/libjava/classpath/gnu/CORBA/Poa/ForwardedServant.java new file mode 100644 index 00000000000..2df378df6a4 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java b/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java new file mode 100644 index 00000000000..7af3369d2e8 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/LocalDelegate.java @@ -0,0 +1,382 @@ +/* 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.portable.RemarshalException; +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 #m_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 + { + try + { + 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 + { + LocalRequest lrq = (LocalRequest) sr.request; + return lrq.s_invoke(handler); + } + } + catch (gnuForwardRequest f) + { + try + { + return ((ObjectImpl) f.forward_reference)._invoke(f.forward_reference._request( + operation, + true + ) + ); + } + catch (RemarshalException e) + { + // Never thrown in this place by Classpath implementation. + throw new NO_IMPLEMENT(); + } + } + } + + public void releaseReply(org.omg.CORBA.Object target, InputStream input) + { + release(target); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java b/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java new file mode 100644 index 00000000000..a727499fce5 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/LocalRequest.java @@ -0,0 +1,684 @@ +/* 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.GIOP.v1_2.ReplyHeader; +import gnu.CORBA.GIOP.v1_2.RequestHeader; +import gnu.CORBA.Interceptor.gnuClientRequestInfo; +import gnu.CORBA.Interceptor.gnuServerRequestInfo; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.Unexpected; +import gnu.CORBA.gnuAny; +import gnu.CORBA.gnuRequest; +import gnu.CORBA.recordTypeCode; +import gnu.CORBA.streamReadyHolder; +import gnu.CORBA.streamRequest; + +import org.omg.CORBA.ARG_OUT; +import org.omg.CORBA.Any; +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.SystemException; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.UnknownUserException; +import org.omg.CORBA.UserException; +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.portable.ResponseHandler; +import org.omg.PortableInterceptor.ClientRequestInterceptorOperations; +import org.omg.PortableInterceptor.ForwardRequest; +import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; +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) + { + // Local request must be intercepted both by server and request + // interceptors. + boolean s_intercept = false; + ServerRequestInterceptorOperations s_interceptor = null; + gnuServerRequestInfo s_info = null; + + boolean c_intercept = false; + ClientRequestInterceptorOperations c_interceptor = null; + gnuClientRequestInfo c_info = null; + + try + { + if (poa.m_orb.iServer != null || poa.m_orb.iClient != null) + { + setORB(poa.m_orb); + + // These two are only needed with interceptors. + m_rqh = new RequestHeader(); + m_rqh.operation = m_operation; + m_rph = new ReplyHeader(); + + m_rqh.object_key = object.Id; + m_rph.request_id = m_rqh.request_id; + } + + if (poa.m_orb.iClient != null) + { + c_interceptor = poa.m_orb.iClient; + + c_info = new gnuClientRequestInfo(this); + c_intercept = true; + + c_interceptor.send_request(c_info); + + m_target = object; + } + + if (poa.m_orb.iServer != null) + { + s_interceptor = poa.m_orb.iServer; + + s_info = new gnuServerRequestInfo(object, m_rqh, m_rph); + s_info.m_request = this; + + s_intercept = true; + + s_interceptor.receive_request_service_contexts(s_info); + } + + 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); + } + + try + { + if (s_intercept) + { + s_interceptor.receive_request(s_info); + } + handler._invoke(m_operation, input, this); + + // Handler is casted into i_handler. + if ((s_intercept || c_intercept) && isExceptionReply()) + { + s_info.m_reply_header.reply_status = + ReplyHeader.USER_EXCEPTION; + m_rph.reply_status = ReplyHeader.USER_EXCEPTION; + + // Make Any, holding the user exception. + Any a = new gnuAny(); + OutputStream buf = getBuffer(); + InputStream in = buf.create_input_stream(); + String uex_idl = "unknown"; + try + { + in.mark(Integer.MAX_VALUE); + uex_idl = in.read_string(); + m_exception_id = uex_idl; + in.reset(); + } + catch (IOException e) + { + throw new Unexpected(e); + } + + try + { + UserException exception = + ObjectCreator.readUserException(uex_idl, in); + + m_environment.exception(exception); + ObjectCreator.insertWithHelper(a, exception); + } + catch (Exception e) + { + // Failed due any reason, insert without + // helper. + a.insert_Streamable(new streamReadyHolder( + buf.create_input_stream() + ) + ); + + recordTypeCode r = + new recordTypeCode(TCKind.tk_except); + r.setId(uex_idl); + r.setName(ObjectCreator.getDefaultName(uex_idl)); + } + + s_info.m_usr_exception = a; + c_info.m_wrapped_exception = a; + s_interceptor.send_exception(s_info); + c_interceptor.receive_exception(c_info); + } + else + { + if (s_intercept) + { + s_info.m_reply_header.reply_status = + ReplyHeader.NO_EXCEPTION; + s_interceptor.send_reply(s_info); + } + if (c_intercept) + { + m_rph.reply_status = ReplyHeader.NO_EXCEPTION; + c_interceptor.receive_reply(c_info); + } + } + } + catch (SystemException sys_ex) + { + if (s_intercept) + { + s_info.m_reply_header.reply_status = + ReplyHeader.SYSTEM_EXCEPTION; + s_info.m_sys_exception = sys_ex; + s_interceptor.send_exception(s_info); + } + + if (c_intercept) + { + m_rph.reply_status = ReplyHeader.SYSTEM_EXCEPTION; + + Any a = new gnuAny(); + if (ObjectCreator.insertSysException(a, sys_ex)) + { + c_info.m_wrapped_exception = a; + } + c_interceptor.receive_exception(c_info); + } + + throw sys_ex; + } + } + 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(); + } + + catch (ForwardRequest fex) + { + // May be thrown by interceptor. + if (s_intercept) + { + Forwarding: + while (true) + { + s_info.m_reply_header.reply_status = + ReplyHeader.LOCATION_FORWARD; + s_info.m_forward_reference = fex.forward; + try + { + s_interceptor.send_other(s_info); + break Forwarding; + } + catch (ForwardRequest fex2) + { + s_info.m_forward_reference = fex2.forward; + fex.forward = s_info.m_forward_reference; + } + } + } + + if (c_intercept) + { + this.m_rph.reply_status = ReplyHeader.LOCATION_FORWARD; + this.m_forwarding_target = fex.forward; + try + { + c_interceptor.receive_other(c_info); + } + catch (ForwardRequest fex2) + { + fex.forward = fex2.forward; + } + } + throw new gnuForwardRequest(fex.forward); + } + catch (gnuForwardRequest fex) + { + // May be thrown during activation. + // May be thrown during activation. + if (s_intercept) + { + Forwarding: + while (true) + { + s_info.m_reply_header.reply_status = + ReplyHeader.LOCATION_FORWARD; + s_info.m_forward_reference = fex.forward_reference; + try + { + s_interceptor.send_other(s_info); + break Forwarding; + } + catch (ForwardRequest fex2) + { + s_info.m_forward_reference = fex2.forward; + fex.forward_reference = (ObjectImpl) fex2.forward; + } + } + } + + if (c_intercept) + { + this.m_rph.reply_status = ReplyHeader.LOCATION_FORWARD; + this.m_forwarding_target = fex.forward_reference; + try + { + c_interceptor.receive_other(c_info); + } + catch (ForwardRequest fex2) + { + fex.forward_reference = (ObjectImpl) fex2.forward; + } + } + throw fex; + } + } + + /** + * 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/libjava/classpath/gnu/CORBA/Poa/LocalServerRequest.java b/libjava/classpath/gnu/CORBA/Poa/LocalServerRequest.java new file mode 100644 index 00000000000..6d0b39650c1 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java b/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java new file mode 100644 index 00000000000..d95bf2be8f6 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/ORB_1_4.java @@ -0,0 +1,256 @@ +/* ORB_1_4.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 gnu.CORBA.IOR; +import gnu.CORBA.Connected_objects.cObject; +import gnu.CORBA.DynAn.gnuDynAnyFactory; +import gnu.CORBA.Interceptor.ClientRequestInterceptors; +import gnu.CORBA.Interceptor.IORInterceptors; +import gnu.CORBA.Interceptor.Registrator; +import gnu.CORBA.Interceptor.ServerRequestInterceptors; +import gnu.CORBA.Interceptor.gnuIcCurrent; +import gnu.CORBA.Interceptor.gnuIorInfo; + +import org.omg.CORBA.Any; +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.Policy; +import org.omg.CORBA.PolicyError; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.PortableInterceptor.PolicyFactory; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAPackage.InvalidPolicy; + +import java.applet.Applet; +import java.util.Properties; + +/** + * 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 ("POA Current's"). + */ + public gnuPoaCurrent currents = new gnuPoaCurrent(); + + /** + * Maps the active threads to the interceptor data ("Interceptor Current's"). + */ + public gnuIcCurrent ic_current = new gnuIcCurrent(this); + + /** + * Creates dynamic anys. + */ + public gnuDynAnyFactory factory = new gnuDynAnyFactory(this); + + /** + * Calls the parent constructor and additionally puts the "RootPOA", + * "RootPOAManager", "POACurrent" and "DynAnyFactory" 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); + initial_references.put("DynAnyFactory", factory); + initial_references.put("PICurrent", ic_current); + } + + /** + * 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(); + } + + /** + * Do interceptor registration. + * + * @param properties the properties, between those names the agreed prefix + * "org.omg.PortableInterceptor.ORBInitializerClass." is searched. + * + * @param args the string array, passed to the ORB.init + */ + protected void registerInterceptors(Properties properties, String[] args) + { + Registrator registrator = new Registrator(this, properties, args); + + policyFactories = registrator.m_policyFactories; + + registrator.pre_init(); + initial_references.putAll(registrator.getRegisteredReferences()); + registrator.post_init(); + + if (registrator.hasIorInterceptors()) + iIor = new IORInterceptors(registrator); + + if (registrator.hasServerRequestInterceptors()) + iServer = new ServerRequestInterceptors(registrator); + + if (registrator.hasClientRequestInterceptors()) + iClient = new ClientRequestInterceptors(registrator); + + policyFactories = registrator.m_policyFactories; + } + + /** + * Create IOR and allow registered interceptors to add additional components. + */ + protected IOR createIOR(cObject ref) + throws BAD_OPERATION + { + IOR ior = super.createIOR(ref); + if (iIor != null) + { + activeObjectMap.Obj obj = rootPOA.findIorKey(ior.key); + + POA poa; + + // Null means that the object was connected to the ORB directly. + if (obj == null) + poa = rootPOA; + else + poa = obj.poa; + + gnuIorInfo info = new gnuIorInfo(this, poa, ior); + + // This may modify the ior. + iIor.establish_components(info); + } + return ior; + } + + /** + * Create policy using the previously registered factory. + */ + public Policy create_policy(int type, Any value) + throws PolicyError + { + Integer policy = new Integer(type); + + PolicyFactory forge = (PolicyFactory) policyFactories.get(policy); + if (forge == null) + throw new PolicyError("No factory registered for policy " + type, + (short) type); + else + return forge.create_policy(type, value); + } + + /** + * Set the parameters and then register interceptors. + */ + protected void set_parameters(Applet app, Properties props) + { + super.set_parameters(app, props); + registerInterceptors(props, new String[0]); + } + + /** + * Set the parameters and then register interceptors. + */ + protected void set_parameters(String[] para, Properties props) + { + super.set_parameters(para, props); + registerInterceptors(props, para); + } + +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java b/libjava/classpath/gnu/CORBA/Poa/activeObjectMap.java new file mode 100644 index 00000000000..1354ba9c5e1 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java b/libjava/classpath/gnu/CORBA/Poa/dynImpHandler.java new file mode 100644 index 00000000000..1cc3e131cd7 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java b/libjava/classpath/gnu/CORBA/Poa/gnuAdapterActivator.java new file mode 100644 index 00000000000..3019a2ae966 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuForwardRequest.java b/libjava/classpath/gnu/CORBA/Poa/gnuForwardRequest.java new file mode 100644 index 00000000000..02fc42470b3 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuIdAssignmentPolicy.java new file mode 100644 index 00000000000..a404486ce70 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuIdUniquenessPolicy.java new file mode 100644 index 00000000000..2abd1f4845f --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuImplicitActivationPolicy.java new file mode 100644 index 00000000000..1e539a2c4e0 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuLifespanPolicy.java new file mode 100644 index 00000000000..97b3f2d7a9b --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java b/libjava/classpath/gnu/CORBA/Poa/gnuPOA.java new file mode 100644 index 00000000000..1d9e838532a --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java b/libjava/classpath/gnu/CORBA/Poa/gnuPOAManager.java new file mode 100644 index 00000000000..6c1b5644f36 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuPoaCurrent.java b/libjava/classpath/gnu/CORBA/Poa/gnuPoaCurrent.java new file mode 100644 index 00000000000..927d02fe3d2 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuRequestProcessingPolicy.java new file mode 100644 index 00000000000..5bbcd1321b3 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java b/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java new file mode 100644 index 00000000000..1ad98d1cecd --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/gnuServantObject.java @@ -0,0 +1,802 @@ +/* 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.GIOP.ReplyHeader; +import gnu.CORBA.IOR_Delegate; +import gnu.CORBA.IOR_contructed_object; +import gnu.CORBA.Interceptor.gnuServerRequestInfo; +import gnu.CORBA.ObjectCreator; +import gnu.CORBA.Unexpected; +import gnu.CORBA.bufferedResponseHandler; +import gnu.CORBA.recordTypeCode; +import gnu.CORBA.streamReadyHolder; + +import org.omg.CORBA.Any; +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.TCKind; +import org.omg.CORBA.TRANSIENT; +import org.omg.CORBA.UserException; +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.PortableInterceptor.ForwardRequest; +import org.omg.PortableInterceptor.ServerRequestInterceptorOperations; +import org.omg.PortableServer.CurrentOperations; +import org.omg.PortableServer.DynamicImplementation; +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.io.IOException; + +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 (org.omg.PortableServer.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 a_servant) + { + if (a_servant instanceof InvokeHandler) + { + return (InvokeHandler) a_servant; + } + else if (a_servant instanceof DynamicImplementation) + { + return new dynImpHandler((DynamicImplementation) a_servant); + } + else + { + throw new BAD_OPERATION(a_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 a_poa) + { + this(a_servant, a_servant._object_id(), (ORB_1_4) a_servant._orb(), a_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 + { + boolean intercept = false; + ServerRequestInterceptorOperations interceptor = null; + gnuServerRequestInfo info = null; + bufferedResponseHandler i_handler = null; + + try + { + if (orb.iServer != null && + r_handler instanceof bufferedResponseHandler + ) + { + interceptor = orb.iServer; + + i_handler = (bufferedResponseHandler) r_handler; + + info = + new gnuServerRequestInfo(this, i_handler.request_header, + i_handler.reply_header + ); + intercept = true; + + interceptor.receive_request_service_contexts(info); + } + + 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 : + + OutputStream rt; + try + { + if (intercept) + { + interceptor.receive_request(info); + } + + rt = handler._invoke(method, input, r_handler); + + if (intercept) + { + // Handler is casted into i_handler. + if (i_handler.isExceptionReply()) + { + info.m_reply_header.reply_status = + ReplyHeader.USER_EXCEPTION; + + // Make Any, holding the user exception. + Any a = orb.create_any(); + OutputStream buf = i_handler.getBuffer(); + InputStream in = buf.create_input_stream(); + String uex_idl = "unknown"; + try + { + in.mark(Integer.MAX_VALUE); + uex_idl = in.read_string(); + in.reset(); + } + catch (IOException e) + { + throw new Unexpected(e); + } + + try + { + UserException exception = + ObjectCreator.readUserException(uex_idl, + in + ); + + ObjectCreator.insertWithHelper(a, + exception + ); + } + catch (Exception e) + { + // Failed due any reason, insert without + // helper. + a.insert_Streamable(new streamReadyHolder( + buf.create_input_stream() + ) + ); + + recordTypeCode r = + new recordTypeCode(TCKind.tk_except); + r.setId(uex_idl); + r.setName(ObjectCreator.getDefaultName( + uex_idl + ) + ); + } + + info.m_usr_exception = a; + interceptor.send_exception(info); + } + else + { + info.m_reply_header.reply_status = + ReplyHeader.NO_EXCEPTION; + interceptor.send_reply(info); + } + } + } + catch (SystemException sys_ex) + { + if (intercept) + { + info.m_reply_header.reply_status = + ReplyHeader.SYSTEM_EXCEPTION; + info.m_sys_exception = sys_ex; + interceptor.send_exception(info); + } + throw sys_ex; + } + + return rt; + + 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 + // as soon as JDK specification would allow bidirectional + // policy. + 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()); + } + } + catch (ForwardRequest fex) + { + // May be thrown by interceptor. + if (intercept) + { + Forwarding: + while (true) + { + info.m_reply_header.reply_status = + ReplyHeader.LOCATION_FORWARD; + info.m_forward_reference = fex.forward; + try + { + interceptor.send_other(info); + break Forwarding; + } + catch (ForwardRequest fex2) + { + info.m_forward_reference = fex2.forward; + fex.forward = info.m_forward_reference; + } + } + } + throw new gnuForwardRequest(fex.forward); + } + catch (gnuForwardRequest fex) + { + // May be thrown during activation. + if (intercept) + { + Forwarding: + while (true) + { + info.m_reply_header.reply_status = + ReplyHeader.LOCATION_FORWARD; + info.m_forward_reference = fex.forward_reference; + try + { + interceptor.send_other(info); + break Forwarding; + } + catch (ForwardRequest fex2) + { + info.m_forward_reference = fex2.forward; + fex.forward_reference = (ObjectImpl) fex2.forward; + } + } + } + throw fex; + } + } + + /** + * 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/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuServantRetentionPolicy.java new file mode 100644 index 00000000000..009e70e1b35 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java b/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java new file mode 100644 index 00000000000..f42ebefb363 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/gnuThreadPolicy.java @@ -0,0 +1,80 @@ +/* gnuThreadPolicy.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.THREAD_POLICY_ID; +import org.omg.PortableServer.ThreadPolicy; +import org.omg.PortableServer.ThreadPolicyValue; + +/** + * The implementation of the thread policy. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuThreadPolicy + extends _PolicyImplBase + implements ThreadPolicy, vPolicy +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1L; + + /** + * Create the policy. + * + * @param v a value for the policy. + */ + public gnuThreadPolicy(ThreadPolicyValue v) + { + super(THREAD_POLICY_ID.value, v, v.value(), + "IDL:org.omg/PortableServer/ThreadPolicy:1.0" + ); + } + + /** + * Get the value for the policy that was passed in a constructor. + */ + public ThreadPolicyValue value() + { + return (ThreadPolicyValue) getValue(); + } +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/Poa/policySets.java b/libjava/classpath/gnu/CORBA/Poa/policySets.java new file mode 100644 index 00000000000..eb688467ae7 --- /dev/null +++ b/libjava/classpath/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/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java b/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java new file mode 100644 index 00000000000..f59c01c6b3e --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/servantDelegate.java @@ -0,0 +1,232 @@ +/* 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) + { + 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/libjava/classpath/gnu/CORBA/Poa/vPolicy.java b/libjava/classpath/gnu/CORBA/Poa/vPolicy.java new file mode 100644 index 00000000000..9e45b56d7ee --- /dev/null +++ b/libjava/classpath/gnu/CORBA/Poa/vPolicy.java @@ -0,0 +1,62 @@ +/* vPolicy.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; + +/** + * The Classpath implementation of the policy, providing the policy + * value and the code of the policy type. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public interface vPolicy + extends Policy +{ + /** + * Get the value of this policy + */ + java.lang.Object getValue(); + + /** + * Get the integer code of this policy value. + */ + int getCode(); + +}
\ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/gnuValueHolder.java b/libjava/classpath/gnu/CORBA/gnuValueHolder.java new file mode 100644 index 00000000000..0b382648981 --- /dev/null +++ b/libjava/classpath/gnu/CORBA/gnuValueHolder.java @@ -0,0 +1,135 @@ +/* gnuValueHolder.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.Vio; + +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.ValueBaseHolder; +import org.omg.CORBA.portable.BoxedValueHelper; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; + +import java.io.Serializable; + +/** + * Boxed value holder that also remembers the value type and the value helper. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class gnuValueHolder + extends ValueBaseHolder +{ + /** + * The type code of the stored value. + */ + TypeCode type; + + /** + * The helper that could read and write fields of the boxed value. + */ + transient BoxedValueHelper helper; + + /** + * If true, the helper not available. + */ + transient boolean helper_NA; + + /** + * Create a new instance for the given value and given type. + */ + public gnuValueHolder(Serializable value, TypeCode a_type) + { + super(value); + type = a_type; + } + + /** + * Get the true type, as it was passed in the constructor. + */ + public TypeCode _type() + { + return type; + } + + /** + * Write content to the output stream. Tries to locate the + * corresponding helper class. + */ + public void _write(OutputStream output) + { + findHelper(); + if (helper == null) + super._write(output); + else + Vio.write(output, value, helper); + } + + /** + * Read, trying to locate helper, if possible. + */ + public void _read(InputStream input) + { + findHelper(); + if (helper == null) + super._read(input); + else + value = Vio.read(input, helper); + } + + /** + * Set the read and write methods. + */ + void findHelper() + { + if (helper != null || helper_NA) + return; + try + { + Class helperClass = + Class.forName(ObjectCreator.toHelperName(type.id())); + + helper = (BoxedValueHelper) helperClass.newInstance(); + } + catch (Exception ex) + { + helper_NA = true; + } + } +}
\ No newline at end of file |