diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-16 16:22:34 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2005-08-16 16:22:34 +0000 |
commit | 988ea14cc6a504c6d5c7b9bfcbc01ca2b0a4e432 (patch) | |
tree | 0ee0ebd2e7d7a1b0b00edf51b48286965b1b4fca /gnu | |
parent | e439fd75db6107e87660301775017154f05e1c06 (diff) | |
download | classpath-988ea14cc6a504c6d5c7b9bfcbc01ca2b0a4e432.tar.gz |
2005-08-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics-branch for 2005/08/07-2005/08/14.
Diffstat (limited to 'gnu')
97 files changed, 14746 insertions, 457 deletions
diff --git a/gnu/CORBA/CDR/Vio.java b/gnu/CORBA/CDR/Vio.java index 8f17bd2f5..d7a749dd6 100644 --- a/gnu/CORBA/CDR/Vio.java +++ b/gnu/CORBA/CDR/Vio.java @@ -46,6 +46,7 @@ import org.omg.CORBA.DataOutputStream; import org.omg.CORBA.MARSHAL; import org.omg.CORBA.NO_IMPLEMENT; import org.omg.CORBA.StringSeqHelper; +import org.omg.CORBA.portable.*; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.OutputStream; import org.omg.CORBA.portable.Streamable; @@ -55,6 +56,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.Method; + /** * A specialised class for reading and writing the value types. * @@ -222,7 +225,7 @@ public abstract class Vio throw new MARSHAL("Unable to instantiate the value type"); else { - read_instance(input, ox, value_tag); + read_instance(input, ox, value_tag, null); return (Serializable) ox; } } @@ -285,7 +288,7 @@ public abstract class Vio } } - read_instance(input, ox, value_tag); + read_instance(input, ox, value_tag, null); return (Serializable) ox; } catch (Exception ex) @@ -301,17 +304,22 @@ public abstract class Vio * an instance. * * @param input a stream to read from. - * @param value_instance an instance of the value. + * + * @param value_instance an pre-created instance of the value. If the + * helper is not null, this parameter is ignored an should be null. + * + * @param helper a helper to create an instance and read the object- + * specific part of the record. If the value_instance is used instead, + * this parameter should be null. * * @return the loaded value. * * @throws MARSHAL if the reading has failed due any reason. */ - public static Serializable read(InputStream input, Serializable value_instance) + public static Object read(InputStream input, Object value_instance, + Object helper + ) { - // Explicitly prevent the stream from closing as we may need - // to read the subsequent bytes as well. Stream may be auto-closed - // in its finalizer. try { int value_tag = input.read_long(); @@ -345,8 +353,9 @@ public abstract class Vio } } - read_instance(input, value_instance, value_tag); - return (Serializable) value_instance; + value_instance = + read_instance(input, value_instance, value_tag, helper); + return value_instance; } catch (Exception ex) { @@ -355,18 +364,43 @@ public abstract class Vio } /** + * Read using provided boxed value helper. This method expects + * the full value type header, followed by contents, that are + * delegated to the provided helper. It handles null. + * + * @param input the stream to read from. + * @param helper the helper that reads the type-specific part of + * the content. + * + * @return the value, created by the helper, or null if the + * header indicates that null was previously written. + */ + public static Serializable read(InputStream input, Object helper) + { + return (Serializable) read(input, null, helper); + } + + /** * Fill in the instance fields by the data from the input stream. * The method assumes that the value header, if any, is already * behind. The information from the stream is stored into the * passed ox parameter. * * @param input an input stream to read from. - * @param value a value type object, must be either Streamable or - * CustomMarshal. + * + * @param value a pre-instantiated value type object, must be either + * Streamable or CustomMarshal. If the helper is used, this parameter + * is ignored and should be null. + * + * @param value_tag the tag that must be read previously. + * @param helper the helper for read object specific part; may be + * null to read in using other methods. + * + * @return the value that was read. */ - public static void read_instance(InputStream input, Object value, - int value_tag - ) + private static Object read_instance(InputStream input, Object value, + int value_tag, Object helper + ) { try { @@ -377,7 +411,7 @@ public abstract class Vio // Read all chunks. int chunk_size = input.read_long(); - if (chunk_size <= 0) + if (chunk_size < 0) throw new MARSHAL("Invalid first chunk size " + chunk_size); byte[] r = new byte[ chunk_size ]; @@ -412,12 +446,29 @@ public abstract class Vio // More than one chunk was present. // Add the last chunk. bout.write(r, 0, n); - input = new cdrBufInput(bout.toByteArray()); + input = new noHeaderInput(bout.toByteArray()); } else { // Only one chunk was present. - input = new cdrBufInput(r); + input = new noHeaderInput(r); + } + } + else + { + if (input instanceof cdrBufInput) + { + // Highly probable case. + input = + new noHeaderInput(((cdrBufInput) input).buffer.getBuffer()); + } + else + { + cdrBufOutput bout = new cdrBufOutput(); + int c; + while ((c = input.read()) >= 0) + bout.write((byte) c); + input = new noHeaderInput(bout.buffer.toByteArray()); } } } @@ -447,6 +498,11 @@ public abstract class Vio { ((Streamable) value)._read(input); } + else if (helper instanceof BoxedValueHelper) + value = ((BoxedValueHelper) helper).read_value(input); + else if (helper instanceof ValueFactory) + value = + ((ValueFactory) helper).read_value((org.omg.CORBA_2_3.portable.InputStream) input); else // Stating the interfaces that the USER should use. @@ -462,6 +518,8 @@ public abstract class Vio if (eor >= 0) throw new MARSHAL("End of state marker has an invalid value " + eor); } + + return value; } /** @@ -527,7 +585,35 @@ public abstract class Vio if (value == null) output.write_long(vt_NULL); else - write_instance(output, value, id); + write_instance(output, value, id, null); + } + + /** + * Write standard value type header, followed by contents, produced + * by the boxed value helper. + * + * @param output the stream to write to. + * @param value the value to write, can be null. + * @param helper the helper that writes the value content if it is + * not null. + */ + public static void write(OutputStream output, Serializable value, + Object helper + ) + { + if (value == null) + output.write_long(vt_NULL); + else + { + String id; + + if (helper instanceof BoxedValueHelper) + id = ((BoxedValueHelper) helper).get_id(); + else + id = ""; + + write_instance(output, value, id, helper); + } } /** @@ -537,9 +623,11 @@ public abstract class Vio * @param output an output stream to write into. * @param value a value to write. * @param id a value repository id. + * @param helper a helper, writing object - specifica part. Can be null + * if the value should be written unsing other methods. */ private static void write_instance(OutputStream output, Serializable value, - String id + String id, Object helper ) { // This implementation always writes a single repository id. @@ -563,6 +651,11 @@ public abstract class Vio output.write_long(value_tag); output.write_string(id); + if (helper instanceof BoxedValueHelper) + { + ((BoxedValueHelper) helper).write_value(outObj, value); + } + else // User defince write method is present. if (value instanceof CustomMarshal) { @@ -580,11 +673,38 @@ public abstract class Vio ((Streamable) value)._write(outObj); } else + { + // Try to find helper via class loader. + boolean ok = false; + try + { + Class helperClass = Class.forName(ObjectCreator.toHelperName(id)); + + // It will be the helper for the encapsulated boxed value, not the + // for the global boxed value type itself. + Method write = + helperClass.getMethod("write", + new Class[] + { + org.omg.CORBA.portable.OutputStream.class, + value.getClass() + } + ); + write.invoke(null, new Object[] { outObj, value }); + ok = true; + } + catch (Exception ex) + { + ok = false; + } - // Stating the interfaces that the USER should use. - throw new MARSHAL("The " + value.getClass().getName() + - " must implement either StreamableValue or CustomValue." - ); + // Stating the interfaces that the USER should use. + if (!ok) + throw new MARSHAL("The " + value.getClass().getName() + + " must implement either StreamableValue" + + " or CustomValue." + ); + } if (USE_CHUNKING) { @@ -611,8 +731,8 @@ public abstract class Vio * * @throws NO_IMPLEMENT, always. */ - private static void incorrect_plug_in(Throwable ex) - throws NO_IMPLEMENT + static void incorrect_plug_in(Throwable ex) + throws NO_IMPLEMENT { NO_IMPLEMENT no = new NO_IMPLEMENT("Incorrect CORBA plug-in"); no.initCause(ex); diff --git a/gnu/CORBA/CDR/cdrInput.java b/gnu/CORBA/CDR/cdrInput.java index 859f93ae5..69f9c8c58 100644 --- a/gnu/CORBA/CDR/cdrInput.java +++ b/gnu/CORBA/CDR/cdrInput.java @@ -1180,7 +1180,8 @@ public abstract class cdrInput } // Discard the null terminator and, if needed, the endian marker. - return new String(s, p, n - nt - p); + String r = new String(s, p, n - nt - p); + return r; } catch (EOFException ex) { diff --git a/gnu/CORBA/CDR/cdrOutput.java b/gnu/CORBA/CDR/cdrOutput.java index 86ca3b1cb..36a00e132 100644 --- a/gnu/CORBA/CDR/cdrOutput.java +++ b/gnu/CORBA/CDR/cdrOutput.java @@ -99,7 +99,7 @@ public abstract class cdrOutput /** * The GIOP version. */ - protected Version giop = new Version(1, 0); + protected Version giop = new Version(1, 2); /** * The code set information. diff --git a/gnu/CORBA/CDR/noHeaderInput.java b/gnu/CORBA/CDR/noHeaderInput.java new file mode 100644 index 000000000..0c787ddc2 --- /dev/null +++ b/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/gnu/CORBA/DynAn/NameValuePairHolder.java b/gnu/CORBA/DynAn/NameValuePairHolder.java index 7afc81cd4..2558f5335 100644 --- a/gnu/CORBA/DynAn/NameValuePairHolder.java +++ b/gnu/CORBA/DynAn/NameValuePairHolder.java @@ -46,9 +46,8 @@ import org.omg.CORBA.portable.OutputStream; import org.omg.CORBA.portable.Streamable; /** - * The name-value pair holder. The {@link NameValuePair} has no standard - * holder defined, but it is needed to store the {@link NameValuePair} into - * {@link Any}. + * The name-value pair holder. The {@link NameValuePair} has no standard holder + * defined, but it is needed to store the {@link NameValuePair} into {@link Any}. * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ @@ -92,4 +91,4 @@ public class NameValuePairHolder { NameValuePairHelper.write(output, value); } -} +}
\ No newline at end of file diff --git a/gnu/CORBA/DynAn/abstractDynAny.java b/gnu/CORBA/DynAn/abstractDynAny.java new file mode 100644 index 000000000..47176c4b5 --- /dev/null +++ b/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/gnu/CORBA/DynAn/abstractRecord.java b/gnu/CORBA/DynAn/abstractRecord.java new file mode 100644 index 000000000..8d8b7a559 --- /dev/null +++ b/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/gnu/CORBA/DynAn/anyDivideable.java b/gnu/CORBA/DynAn/anyDivideable.java new file mode 100644 index 000000000..5f52c8078 --- /dev/null +++ b/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/gnu/CORBA/DynAn/anyUndivideable.java b/gnu/CORBA/DynAn/anyUndivideable.java new file mode 100644 index 000000000..b31a6b357 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynAny.java b/gnu/CORBA/DynAn/gnuDynAny.java new file mode 100644 index 000000000..a12706176 --- /dev/null +++ b/gnu/CORBA/DynAn/gnuDynAny.java @@ -0,0 +1,985 @@ +/* primitiveDynAny.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you 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.*; +import gnu.CORBA.CDR.cdrBufOutput; +import gnu.CORBA.OctetHolder; +import gnu.CORBA.Unexpected; +import gnu.CORBA.WCharHolder; +import gnu.CORBA.WStringHolder; +import gnu.CORBA.typeNamer; + +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.*; +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/gnu/CORBA/DynAn/gnuDynAnyFactory.java b/gnu/CORBA/DynAn/gnuDynAnyFactory.java new file mode 100644 index 000000000..dd1762890 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynArray.java b/gnu/CORBA/DynAn/gnuDynArray.java new file mode 100644 index 000000000..1c08496d4 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynEnum.java b/gnu/CORBA/DynAn/gnuDynEnum.java new file mode 100644 index 000000000..148d99375 --- /dev/null +++ b/gnu/CORBA/DynAn/gnuDynEnum.java @@ -0,0 +1,250 @@ +/* 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.*; + +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/gnu/CORBA/DynAn/gnuDynFixed.java b/gnu/CORBA/DynAn/gnuDynFixed.java new file mode 100644 index 000000000..13ec24e6c --- /dev/null +++ b/gnu/CORBA/DynAn/gnuDynFixed.java @@ -0,0 +1,257 @@ +/* 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.CORBA.TypeCodePackage.*; +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/gnu/CORBA/DynAn/gnuDynSequence.java b/gnu/CORBA/DynAn/gnuDynSequence.java new file mode 100644 index 000000000..cfa122f07 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynStruct.java b/gnu/CORBA/DynAn/gnuDynStruct.java new file mode 100644 index 000000000..b086d6478 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynUnion.java b/gnu/CORBA/DynAn/gnuDynUnion.java new file mode 100644 index 000000000..ad41e24b6 --- /dev/null +++ b/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/gnu/CORBA/DynAn/gnuDynValue.java b/gnu/CORBA/DynAn/gnuDynValue.java new file mode 100644 index 000000000..db37be016 --- /dev/null +++ b/gnu/CORBA/DynAn/gnuDynValue.java @@ -0,0 +1,395 @@ +/* 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.CompletionStatus; +import org.omg.CORBA.MARSHAL; +import org.omg.CORBA.NO_IMPLEMENT; +import org.omg.CORBA.ORB; +import org.omg.CORBA.TCKind; +import org.omg.CORBA.TypeCode; +import org.omg.CORBA.TypeCodePackage.*; +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/gnu/CORBA/DynAn/gnuDynValueBox.java b/gnu/CORBA/DynAn/gnuDynValueBox.java new file mode 100644 index 000000000..66e18f3b2 --- /dev/null +++ b/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/gnu/CORBA/DynAn/valueChangedListener.java b/gnu/CORBA/DynAn/valueChangedListener.java new file mode 100644 index 000000000..94ddffbec --- /dev/null +++ b/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/gnu/CORBA/DynAnySeqHolder.java b/gnu/CORBA/DynAnySeqHolder.java new file mode 100644 index 000000000..52d66d9e9 --- /dev/null +++ b/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/gnu/CORBA/NameDynAnyPairHolder.java b/gnu/CORBA/NameDynAnyPairHolder.java new file mode 100644 index 000000000..6ceb9aae0 --- /dev/null +++ b/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/gnu/CORBA/NameDynAnyPairSeqHolder.java b/gnu/CORBA/NameDynAnyPairSeqHolder.java new file mode 100644 index 000000000..71b6174c1 --- /dev/null +++ b/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/gnu/CORBA/NameValuePairHolder.java b/gnu/CORBA/NameValuePairHolder.java new file mode 100644 index 000000000..9a939d5e3 --- /dev/null +++ b/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/gnu/CORBA/NameValuePairSeqHolder.java b/gnu/CORBA/NameValuePairSeqHolder.java new file mode 100644 index 000000000..216d78e04 --- /dev/null +++ b/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/gnu/CORBA/Poa/ORB_1_4.java b/gnu/CORBA/Poa/ORB_1_4.java index 6302ddf12..00ca3bf76 100644 --- a/gnu/CORBA/Poa/ORB_1_4.java +++ b/gnu/CORBA/Poa/ORB_1_4.java @@ -39,6 +39,7 @@ exception statement from your version. */ package gnu.CORBA.Poa; import gnu.CORBA.Functional_ORB; +import gnu.CORBA.DynAn.gnuDynAnyFactory; import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.OBJECT_NOT_EXIST; @@ -62,10 +63,15 @@ public class ORB_1_4 * Maps the active threads to the invocation data ("Current's"). */ public gnuPoaCurrent currents = new gnuPoaCurrent(); + + /** + * Creates dynamic anys. + */ + public gnuDynAnyFactory factory = new gnuDynAnyFactory(this); /** - * Calls the parent constructor and additionally puts the "RootPOA" and - * "RootPOAManager" into initial references. + * Calls the parent constructor and additionally puts the "RootPOA", + * "RootPOAManager", "POACurrent" and "DynAnyFactory" into initial references. */ public ORB_1_4() { @@ -84,6 +90,7 @@ public class ORB_1_4 initial_references.put("RootPOA", rootPOA); initial_references.put("RootPOAManager", rootPOA.the_POAManager()); initial_references.put("POACurrent", currents); + initial_references.put("DynAnyFactory", factory); } /** diff --git a/gnu/CORBA/Restricted_ORB.java b/gnu/CORBA/Restricted_ORB.java index 801154e20..698c8b11e 100644 --- a/gnu/CORBA/Restricted_ORB.java +++ b/gnu/CORBA/Restricted_ORB.java @@ -240,13 +240,16 @@ public class Restricted_ORB } /** {@inheritDoc} */ - public TypeCode create_union_tc(String id, String name, TypeCode type, + public TypeCode create_union_tc(String id, String name, + TypeCode discriminator_type, UnionMember[] members ) { recordTypeCode r = new recordTypeCode(TCKind.tk_union); r.setId(id); r.setName(name); + r.setDiscriminator_type(discriminator_type); + r.setDefaultIndex(0); for (int i = 0; i < members.length; i++) { @@ -454,7 +457,9 @@ public class Restricted_ORB if (f != null) return f; - f = (ValueFactory) ObjectCreator.createObject(repository_id, "DefaultFactory"); + f = (ValueFactory) ObjectCreator.createObject(repository_id, + "DefaultFactory" + ); if (f != null) factories.put(repository_id, f); diff --git a/gnu/CORBA/fixedTypeCode.java b/gnu/CORBA/fixedTypeCode.java index ec88c22be..eb610417b 100644 --- a/gnu/CORBA/fixedTypeCode.java +++ b/gnu/CORBA/fixedTypeCode.java @@ -109,16 +109,12 @@ public class fixedTypeCode return number.unscaledValue().abs().toString().length(); } - public boolean equals(Object other) + /** + * Compare with other type code for equality. + */ + public boolean equal(TypeCode other) { - if (other == this) - { - return true; - } - if (!(other instanceof TypeCode)) - { - return false; - } + if (other == this) return true; try { TypeCode that = (TypeCode) other; diff --git a/gnu/CORBA/gnuAny.java b/gnu/CORBA/gnuAny.java index a48c50d61..7e5ef3351 100644 --- a/gnu/CORBA/gnuAny.java +++ b/gnu/CORBA/gnuAny.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.CORBA; +import gnu.CORBA.CDR.Vio; import gnu.CORBA.CDR.cdrBufInput; import gnu.CORBA.CDR.cdrBufOutput; @@ -63,6 +64,7 @@ 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.BoxedValueHelper; import org.omg.CORBA.portable.Streamable; import java.io.IOException; @@ -499,20 +501,33 @@ public class gnuAny } /** {@inheritDoc} */ - public void insert_Value(Serializable x, TypeCode typecode) + public void insert_Value(Serializable x, TypeCode c_typecode) { - type(typecode); - insert_Value(x); + if (typecode != null && typecode.kind() == TCKind.tk_value_box) + { + has = new gnuValueHolder(x, typecode); + } + else + { + type(typecode); + insert_Value(x); + } } /** {@inheritDoc} */ public void insert_Value(Serializable x) { - resetTypes(); - if (has instanceof ValueBaseHolder) - ((ValueBaseHolder) has).value = x; + if (typecode != null && typecode.kind() == TCKind.tk_value_box) + { + has = new gnuValueHolder(x, typecode); + } else - has = new ValueBaseHolder(x); + { + if (has instanceof ValueBaseHolder) + ((ValueBaseHolder) has).value = x; + else + has = new ValueBaseHolder(x); + } } /** @@ -748,15 +763,38 @@ public class gnuAny } } type(a_type); - has._read(input); - } - catch (BadKind ex) - { - throw new MARSHAL("Bad kind: " + ex.getMessage()); + + if (!(has instanceof universalHolder) && + (kind == TCKind._tk_value_box)) + { + // The streamable only contains operations for + // reading the value, not the value header. + Field vField = has.getClass().getField("value"); + + BoxedValueHelper helper; + + try + { + Class helperClass = + Class.forName(ObjectCreator.toHelperName(a_type.id())); + helper = (BoxedValueHelper) helperClass.newInstance(); + } + catch (Exception ex) + { + helper = null; + } + + Object content = Vio.read(input, helper); + vField.set(has, content); + } + else + has._read(input); } - catch (IOException ex) + catch (Exception ex) { - throw new MARSHAL("IO exception: " + ex.getMessage()); + MARSHAL m = new MARSHAL(); + m.initCause(ex); + throw m; } } @@ -790,6 +828,12 @@ public class gnuAny { if (has != null) has._write(output); + else + // These kinds support null. + if (xKind == TCKind._tk_null || xKind == TCKind._tk_objref || + xKind == TCKind._tk_value || xKind == TCKind._tk_value_box + ) + output.write_long(0); } /** @@ -806,16 +850,26 @@ public class gnuAny if (xKind >= 0) { if (xKind != kind) - throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + - " when stored " + typeNamer.nameIt(xKind) - ); + if (!( + xKind == TCKind._tk_alias && + has._type().kind().value() == kind + ) + ) + throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + + " when stored " + typeNamer.nameIt(xKind) + ); } else { if (type().kind().value() != kind) - throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + - " stored " + typeNamer.nameIt(type()) - ); + if (!( + type().kind().value() == TCKind._tk_alias && + has._type().kind().value() == kind + ) + ) + throw new BAD_OPERATION("Extracting " + typeNamer.nameIt(kind) + + " stored " + typeNamer.nameIt(type()) + ); } } diff --git a/gnu/CORBA/gnuValueHolder.java b/gnu/CORBA/gnuValueHolder.java new file mode 100644 index 000000000..0b3826489 --- /dev/null +++ b/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 diff --git a/gnu/CORBA/holderFactory.java b/gnu/CORBA/holderFactory.java index 177797a9c..159d22332 100644 --- a/gnu/CORBA/holderFactory.java +++ b/gnu/CORBA/holderFactory.java @@ -68,74 +68,76 @@ import org.omg.CORBA.UShortSeqHolder; import org.omg.CORBA.WCharSeqHolder; import org.omg.CORBA.WStringSeqHolder; import org.omg.CORBA.portable.Streamable; +import org.omg.CORBA.ObjectHolder; /** - * Creates the suitable holder for storing the value of the given - * type. + * Creates the suitable holder for storing the value of the given final_type. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ public class holderFactory { /** - * The array, sufficiently large to use any {@link TCKind}._tk* constant - * as an index. + * The array, sufficiently large to use any {@link TCKind}._tk* constant as + * an index. */ private static final Class[] holders; + private static final Class[] seqHolders; static - { - holders = new Class[ 32 ]; - holders [ TCKind._tk_Principal ] = PrincipalHolder.class; - holders [ TCKind._tk_TypeCode ] = TypeCodeHolder.class; - holders [ TCKind._tk_any ] = AnyHolder.class; - holders [ TCKind._tk_boolean ] = BooleanHolder.class; - holders [ TCKind._tk_char ] = CharHolder.class; - holders [ TCKind._tk_double ] = DoubleHolder.class; - holders [ TCKind._tk_float ] = FloatHolder.class; - holders [ TCKind._tk_fixed ] = FixedHolder.class; - holders [ TCKind._tk_long ] = IntHolder.class; - holders [ TCKind._tk_longdouble ] = DoubleHolder.class; - holders [ TCKind._tk_longlong ] = LongHolder.class; - holders [ TCKind._tk_octet ] = OctetHolder.class; - holders [ TCKind._tk_short ] = ShortHolder.class; - holders [ TCKind._tk_string ] = StringHolder.class; - holders [ TCKind._tk_ulong ] = IntHolder.class; - holders [ TCKind._tk_ulonglong ] = LongHolder.class; - holders [ TCKind._tk_ushort ] = ShortHolder.class; - holders [ TCKind._tk_wchar ] = WCharHolder.class; - holders [ TCKind._tk_wstring ] = WStringHolder.class; - - seqHolders = new Class[ 32 ]; - - seqHolders [ TCKind._tk_ulonglong ] = ULongLongSeqHolder.class; - seqHolders [ TCKind._tk_short ] = ShortSeqHolder.class; - seqHolders [ TCKind._tk_octet ] = OctetSeqHolder.class; - seqHolders [ TCKind._tk_any ] = AnySeqHolder.class; - seqHolders [ TCKind._tk_long ] = LongSeqHolder.class; - seqHolders [ TCKind._tk_longlong ] = LongLongSeqHolder.class; - seqHolders [ TCKind._tk_float ] = FloatSeqHolder.class; - seqHolders [ TCKind._tk_double ] = DoubleSeqHolder.class; - seqHolders [ TCKind._tk_char ] = CharSeqHolder.class; - seqHolders [ TCKind._tk_boolean ] = BooleanSeqHolder.class; - seqHolders [ TCKind._tk_wchar ] = WCharSeqHolder.class; - seqHolders [ TCKind._tk_ushort ] = UShortSeqHolder.class; - seqHolders [ TCKind._tk_ulong ] = ULongSeqHolder.class; - seqHolders [ TCKind._tk_string ] = StringSeqHolder.class; - seqHolders [ TCKind._tk_wstring ] = WStringSeqHolder.class; - } + { + holders = new Class[32]; + holders[TCKind._tk_Principal] = PrincipalHolder.class; + holders[TCKind._tk_TypeCode] = TypeCodeHolder.class; + holders[TCKind._tk_any] = AnyHolder.class; + holders[TCKind._tk_boolean] = BooleanHolder.class; + holders[TCKind._tk_char] = CharHolder.class; + holders[TCKind._tk_double] = DoubleHolder.class; + holders[TCKind._tk_float] = FloatHolder.class; + holders[TCKind._tk_fixed] = FixedHolder.class; + holders[TCKind._tk_long] = IntHolder.class; + holders[TCKind._tk_longdouble] = DoubleHolder.class; + holders[TCKind._tk_longlong] = LongHolder.class; + holders[TCKind._tk_octet] = OctetHolder.class; + holders[TCKind._tk_short] = ShortHolder.class; + holders[TCKind._tk_string] = StringHolder.class; + holders[TCKind._tk_ulong] = IntHolder.class; + holders[TCKind._tk_ulonglong] = LongHolder.class; + holders[TCKind._tk_ushort] = ShortHolder.class; + holders[TCKind._tk_wchar] = WCharHolder.class; + holders[TCKind._tk_wstring] = WStringHolder.class; + holders[TCKind._tk_objref] = ObjectHolder.class; + + seqHolders = new Class[32]; + + seqHolders[TCKind._tk_ulonglong] = ULongLongSeqHolder.class; + seqHolders[TCKind._tk_short] = ShortSeqHolder.class; + seqHolders[TCKind._tk_octet] = OctetSeqHolder.class; + seqHolders[TCKind._tk_any] = AnySeqHolder.class; + seqHolders[TCKind._tk_long] = LongSeqHolder.class; + seqHolders[TCKind._tk_longlong] = LongLongSeqHolder.class; + seqHolders[TCKind._tk_float] = FloatSeqHolder.class; + seqHolders[TCKind._tk_double] = DoubleSeqHolder.class; + seqHolders[TCKind._tk_char] = CharSeqHolder.class; + seqHolders[TCKind._tk_boolean] = BooleanSeqHolder.class; + seqHolders[TCKind._tk_wchar] = WCharSeqHolder.class; + seqHolders[TCKind._tk_ushort] = UShortSeqHolder.class; + seqHolders[TCKind._tk_ulong] = ULongSeqHolder.class; + seqHolders[TCKind._tk_string] = StringSeqHolder.class; + seqHolders[TCKind._tk_wstring] = WStringSeqHolder.class; + } /** - * Create a holder for storing the value of the given built-in type. - * This function returns the defined holders for the built-in primitive - * types and they sequences. + * Create a holder for storing the value of the given built-in final_type. This + * function returns the defined holders for the built-in primitive types and + * they sequences. * * @param t the typecode * - * @return an instance of the corresponding built-in holder of null - * if no such is defined for this type. The holder is created with a - * parameterless constructor. + * @return an instance of the corresponding built-in holder of null if no such + * is defined for this final_type. The holder is created with a parameterless + * constructor. */ public static Streamable createHolder(TypeCode t) { @@ -145,24 +147,23 @@ public class holderFactory int componentKind; Streamable holder = null; - Streamable component; - if (kind < holders.length && holders [ kind ] != null) - holder = (Streamable) holders [ kind ].newInstance(); + if (kind < holders.length && holders[kind] != null) + holder = (Streamable) holders[kind].newInstance(); if (holder != null) return holder; switch (kind) { - case TCKind._tk_sequence : - componentKind = t.content_type().kind().value(); - if (componentKind < seqHolders.length) - return (Streamable) seqHolders [ componentKind ].newInstance(); - break; - - default : - break; + case TCKind._tk_sequence: + componentKind = t.content_type().kind().value(); + if (componentKind < seqHolders.length) + return (Streamable) seqHolders[componentKind].newInstance(); + break; + + default: + break; } } catch (Exception ex) diff --git a/gnu/CORBA/typeNamer.java b/gnu/CORBA/typeNamer.java index 8b701015e..f790dc959 100644 --- a/gnu/CORBA/typeNamer.java +++ b/gnu/CORBA/typeNamer.java @@ -83,7 +83,7 @@ public class typeNamer new primitiveTypeCode(TCKind.tk_any), new primitiveTypeCode(TCKind.tk_TypeCode), new primitiveTypeCode(TCKind.tk_Principal), - new primitiveTypeCode(TCKind.tk_objref), + new recordTypeCode(TCKind.tk_objref), new primitiveTypeCode(TCKind.tk_struct), new primitiveTypeCode(TCKind.tk_union), new primitiveTypeCode(TCKind.tk_enum), @@ -104,6 +104,15 @@ public class typeNamer new primitiveTypeCode(TCKind.tk_abstract_interface) }; + static + { + // The Id of the "abstract object" is defined as empty string. + recordTypeCode object = + (recordTypeCode) primitveCodes [ TCKind._tk_objref ]; + object.setId(""); + object.setName("Object"); + } + /** * Get the primitive type code. * @@ -168,4 +177,4 @@ public class typeNamer return "type of kind '" + type.kind().value() + "'"; } } -} +}
\ No newline at end of file diff --git a/gnu/CORBA/universalHolder.java b/gnu/CORBA/universalHolder.java index 6d8b77472..c20dac442 100644 --- a/gnu/CORBA/universalHolder.java +++ b/gnu/CORBA/universalHolder.java @@ -60,7 +60,7 @@ import java.io.IOException; * * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */ -class universalHolder +public class universalHolder implements Streamable { /** @@ -71,7 +71,7 @@ class universalHolder /** * Create the universal holder that uses the given buffer to store the data. */ - universalHolder(cdrBufOutput buffer) + public universalHolder(cdrBufOutput buffer) { value = buffer; } @@ -154,4 +154,21 @@ class universalHolder { return value.create_input_stream(); } -} + + /** + * Clone. + */ + public universalHolder Clone() + { + try + { + cdrBufOutput nb = new cdrBufOutput(value.buffer.size()); + value.buffer.writeTo(nb); + return new universalHolder(nb); + } + catch (IOException ex) + { + throw new Unexpected(ex); + } + } +}
\ No newline at end of file diff --git a/gnu/classpath/debug/Component.java b/gnu/classpath/debug/Component.java index 3dfc8927b..242419ce4 100644 --- a/gnu/classpath/debug/Component.java +++ b/gnu/classpath/debug/Component.java @@ -110,6 +110,12 @@ public final class Component extends Level */ public static final Component X509 = new Component ("X.509", 6); + /** + * Trace access control policies, including the parsing of + * java.policy files. + */ + public static final Component POLICY = new Component ("POLICY", 7); + private final int startIndex; private final int endIndex; diff --git a/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java b/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java index c022dc537..3cf8592f4 100644 --- a/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java +++ b/gnu/classpath/jdwp/exception/JdwpInternalErrorException.java @@ -50,8 +50,13 @@ import gnu.classpath.jdwp.JdwpConstants; public class JdwpInternalErrorException extends JdwpException { - public JdwpInternalErrorException (Throwable cause) + public JdwpInternalErrorException(Throwable cause) { - super (JdwpConstants.Error.INTERNAL, cause); + super(JdwpConstants.Error.INTERNAL, cause); + } + + public JdwpInternalErrorException(String msg) + { + super(JdwpConstants.Error.INTERNAL, msg); } } diff --git a/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java new file mode 100644 index 000000000..fb5802794 --- /dev/null +++ b/gnu/classpath/jdwp/processor/ClassLoaderReferenceCommandSet.java @@ -0,0 +1,114 @@ +/* ClassLoaderReferenceCommandSet.java -- class to implement the + ClassLoaderReference Command Set + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.processor; + +import gnu.classpath.jdwp.IVirtualMachine; +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.IdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * A class representing the ClassLoaderReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ClassLoaderReferenceCommandSet implements CommandSet +{ + // Our hook into the jvm + private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); + + // Manages all the different ids that are assigned by jdwp + private final IdManager idMan = Jdwp.getIdManager(); + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + + // Although there's only a single command to choose from we still use + // a switch to maintain consistency with the rest of the CommandSets + try + { + switch (command) + { + case JdwpConstants.CommandSet.ClassLoaderReference.VISIBLE_CLASSES: + executeVisibleClasses(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ClassLoaderReference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + return true; + } + + public void executeVisibleClasses(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId oId = idMan.readId(bb); + ClassLoader cl = (ClassLoader) oId.getObject(); + ArrayList loadRequests = vm.getLoadRequests(cl); + os.writeInt(loadRequests.size()); + for (Iterator iter = loadRequests.iterator(); iter.hasNext();) + { + Class clazz = (Class)iter.next(); + ReferenceTypeId refId = idMan.getReferenceTypeId(clazz); + refId.writeTagged(os); + } + } + +} diff --git a/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java new file mode 100644 index 000000000..2d84abbbd --- /dev/null +++ b/gnu/classpath/jdwp/processor/ClassTypeCommandSet.java @@ -0,0 +1,228 @@ +/* ClassTypeCommandSet.java -- class to implement the ClassType + Command Set + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.processor; + +import gnu.classpath.jdwp.IVirtualMachine; +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidFieldException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.IdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.util.MethodResult; +import gnu.classpath.jdwp.util.Value; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.ByteBuffer; + +/** + * A class representing the ClassType Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ClassTypeCommandSet implements CommandSet +{ + // Our hook into the jvm + private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); + + // Manages all the different ids that are assigned by jdwp + private final IdManager idMan = Jdwp.getIdManager(); + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ClassType.SUPERCLASS: + executeSuperclass(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.SET_VALUES: + executeSetValues(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.INVOKE_METHOD: + executeInvokeMethod(bb, os); + break; + case JdwpConstants.CommandSet.ClassType.NEW_INSTANCE: + executeNewInstance(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in ClassType Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + return true; + } + + private void executeSuperclass(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + Class superClazz = clazz.getSuperclass(); + + ReferenceTypeId clazzId = idMan.getReferenceTypeId(superClazz); + clazzId.write(os); + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + + // We don't actually seem to need this... + Class clazz = refId.getType(); + + int numValues = bb.getInt(); + + for (int i = 0; i < numValues; i++) + { + ObjectId fieldId = idMan.readId(bb); + Field field = (Field) (fieldId.getObject()); + Object value = Value.getUntaggedObj(bb, field.getType()); + try + { + field.setAccessible(true); // Might be a private field + field.set(null, value); + } + catch (IllegalArgumentException ex) + { + throw new InvalidFieldException(ex); + } + catch (IllegalAccessException ex) + { // Since we set it as accessible this really shouldn't happen + throw new JdwpInternalErrorException(ex); + } + } + } + + private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + MethodResult mr = invokeMethod(bb); + + Object value = mr.getReturnedValue(); + Exception exception = mr.getThrownException(); + ObjectId eId = idMan.getId(exception); + + Value.writeTaggedValue(os, value); + eId.writeTagged(os); + } + + private void executeNewInstance(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + MethodResult mr = invokeMethod(bb); + + Object obj = mr.getReturnedValue(); + ObjectId oId = idMan.getId(obj); + Exception exception = mr.getThrownException(); + ObjectId eId = idMan.getId(exception); + + oId.writeTagged(os); + eId.writeTagged(os); + } + + /** + * Execute the static method and return the resulting MethodResult. + */ + private MethodResult invokeMethod(ByteBuffer bb) throws JdwpException, + IOException + { + ReferenceTypeId refId = idMan.readReferenceTypeId(bb); + Class clazz = refId.getType(); + + ObjectId tId = idMan.readId(bb); + Thread thread = (Thread) tId.getObject(); + + ObjectId mId = idMan.readId(bb); + Method method = (Method) mId.getObject(); + + int args = bb.getInt(); + Object[] values = new Object[args]; + + for (int i = 0; i < args; i++) + { + values[i] = Value.getObj(bb); + } + boolean suspendSuccess = false; + int invokeOpts = bb.getInt(); + try + { + if ((invokeOpts & JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) + != 0) + { + // We must suspend all running threads first + suspendSuccess = vm.suspendAllThreadsExcept(Thread.currentThread(). + getThreadGroup()); + } + MethodResult mr = vm.executeMethod(null, thread, clazz, method, values, + false); + if (suspendSuccess) + { // We must call resume if we suspended threads + suspendSuccess = false; + vm.resumeAllThreadsExcept(Thread.currentThread().getThreadGroup()); + } + return mr; + } + catch (Exception ex) + { + if (suspendSuccess) + { // We must call resume if we suspended threads + vm.resumeAllThreadsExcept(Thread.currentThread().getThreadGroup()); + } + throw new JdwpInternalErrorException(ex); + } + } +} diff --git a/gnu/classpath/jdwp/processor/EventRequestCommandSet.java b/gnu/classpath/jdwp/processor/EventRequestCommandSet.java new file mode 100644 index 000000000..b2eb2ea7b --- /dev/null +++ b/gnu/classpath/jdwp/processor/EventRequestCommandSet.java @@ -0,0 +1,208 @@ +/* EventRequestCommandSet.java -- class to implement the EventRequest Command + Set + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.processor; + +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.event.EventManager; +import gnu.classpath.jdwp.event.EventRequest; +import gnu.classpath.jdwp.event.filters.ClassExcludeFilter; +import gnu.classpath.jdwp.event.filters.ClassMatchFilter; +import gnu.classpath.jdwp.event.filters.ClassOnlyFilter; +import gnu.classpath.jdwp.event.filters.ConditionalFilter; +import gnu.classpath.jdwp.event.filters.CountFilter; +import gnu.classpath.jdwp.event.filters.ExceptionOnlyFilter; +import gnu.classpath.jdwp.event.filters.FieldOnlyFilter; +import gnu.classpath.jdwp.event.filters.IEventFilter; +import gnu.classpath.jdwp.event.filters.InstanceOnlyFilter; +import gnu.classpath.jdwp.event.filters.LocationOnlyFilter; +import gnu.classpath.jdwp.event.filters.StepFilter; +import gnu.classpath.jdwp.event.filters.ThreadFilter; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.IdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ReferenceTypeId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Iterator; + +/** + * A class representing the EventRequest Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class EventRequestCommandSet implements CommandSet +{ + // Manages all the different ids that are assigned by jdwp + private final IdManager idMan = Jdwp.getIdManager(); + + // The Event Manager + private final EventManager evMan = Jdwp.getDefault().getEventManager(); + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.EventRequest.SET: + executeSet(bb, os); + break; + case JdwpConstants.CommandSet.EventRequest.CLEAR: + executeClear(bb, os); + break; + case JdwpConstants.CommandSet.EventRequest.CLEAR_ALL_BREAKPOINTS: + executeClearAllBreakpoints(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in EventRequest Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + return true; + } + + private void executeSet(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + byte eventKind = bb.get(); + byte suspendPolicy = bb.get(); + int modifiers = bb.getInt(); + + EventRequest eventReq = new EventRequest(eventKind, suspendPolicy); + IEventFilter filter = null; + ReferenceTypeId refId; + for (int i = 0; i < modifiers; i++) + { + byte modKind = bb.get(); + switch (modKind) + { + case 1: + filter = new CountFilter(bb.getInt()); + break; + case 2: + filter = new ConditionalFilter(idMan.readId(bb)); + break; + case 3: + filter = new ThreadFilter((ThreadId) idMan.readId(bb)); + break; + case 4: + filter = new ClassOnlyFilter(idMan.readReferenceTypeId(bb)); + break; + case 5: + filter = new ClassMatchFilter(JdwpString.readString(bb)); + break; + case 6: + filter = new ClassExcludeFilter(JdwpString.readString(bb)); + break; + case 7: + filter = new LocationOnlyFilter(new Location(bb)); + break; + case 8: + long id = bb.getLong(); + if (id == 0) + refId = null; + else + refId = idMan.readReferenceTypeId(bb); + boolean caught = (bb.get() == 0) ? false : true; + boolean unCaught = (bb.get() == 0) ? false : true; + filter = new ExceptionOnlyFilter(refId, caught, unCaught); + break; + case 9: + refId = idMan.readReferenceTypeId(bb); + ReferenceTypeId fieldId = idMan.readReferenceTypeId(bb); + filter = new FieldOnlyFilter(refId, fieldId); + break; + case 10: + ObjectId tid = idMan.readId(bb); + int size = bb.getInt(); + int depth = bb.getInt(); + filter = new StepFilter(tid, size, depth); + break; + case 11: + ObjectId oid = idMan.readId(bb); + filter = new InstanceOnlyFilter(oid.getObject()); + break; + default: + throw new NotImplementedException("modKind " + modKind + + " is not implemented."); + } + eventReq.addFilter(filter); + } + evMan.requestEvent(eventReq); + os.writeInt(eventReq.getId()); + + } + + private void executeClear(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + byte eventKind = bb.get(); + int requestId = bb.getInt(); + EventRequest request = evMan.getRequest(eventKind, requestId); + evMan.deleteRequest(request); + } + + private void executeClearAllBreakpoints(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + Iterator evReqIter = evMan.getAllRequests(EventRequest.EVENT_BREAKPOINT); + while (evReqIter.hasNext()) + { + EventRequest evReq = (EventRequest) evReqIter.next(); + evMan.deleteRequest(evReq); + } + } + +} diff --git a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java index 56980eecd..31f629ffe 100644 --- a/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java +++ b/gnu/classpath/jdwp/processor/ObjectReferenceCommandSet.java @@ -1,4 +1,4 @@ -/* ObjectReferenceCommandSet.java -- lass to implement the ObjectReference +/* ObjectReferenceCommandSet.java -- class to implement the ObjectReference Command Set Copyright (C) 2005 Free Software Foundation @@ -50,7 +50,7 @@ import gnu.classpath.jdwp.id.IdManager; import gnu.classpath.jdwp.id.ObjectId; import gnu.classpath.jdwp.id.ReferenceTypeId; import gnu.classpath.jdwp.util.Value; -import gnu.classpath.jdwp.util.MethodInvoker; +import gnu.classpath.jdwp.util.MethodResult; import java.io.DataOutputStream; import java.io.IOException; @@ -232,14 +232,14 @@ public class ObjectReferenceCommandSet implements CommandSet nonVirtual = true; else nonVirtual = false; - MethodInvoker vmi = new MethodInvoker(vm); - vmi.executeMethod(obj, thread, clazz, method, values, nonVirtual); - Object value = vmi.getReturnedValue(); - ObjectId exceptionId = vmi.getExceptionId(); + MethodResult mr = vm.executeMethod(obj, thread, clazz, method, values, nonVirtual); + Object value = mr.getReturnedValue(); + Exception exception = mr.getThrownException(); + ObjectId eId = idMan.getId(exception); Value.writeTaggedValue(os, value); - exceptionId.writeTagged(os); + eId.writeTagged(os); } private void executeDisableCollection(ByteBuffer bb, DataOutputStream os) diff --git a/gnu/classpath/jdwp/processor/StackFrameCommandSet.java b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java new file mode 100644 index 000000000..97315c0e8 --- /dev/null +++ b/gnu/classpath/jdwp/processor/StackFrameCommandSet.java @@ -0,0 +1,164 @@ +/* StackFrameCommandSet.java -- class to implement the StackFrame Command Set + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.processor; + +import gnu.classpath.jdwp.VMFrame; +import gnu.classpath.jdwp.IVirtualMachine; +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.IdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.util.Value; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * A class representing the StackFrame Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class StackFrameCommandSet implements CommandSet +{ + // Our hook into the jvm + private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); + + // Manages all the different ids that are assigned by jdwp + private final IdManager idMan = Jdwp.getIdManager(); + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + boolean keepRunning = true; + try + { + switch (command) + { + case JdwpConstants.CommandSet.StackFrame.GET_VALUES: + executeGetValues(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.SET_VALUES: + executeSetValues(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.THIS_OBJECT: + executeThisObject(bb, os); + break; + case JdwpConstants.CommandSet.StackFrame.POP_FRAMES: + executePopFrames(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in Stack Frame Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + return true; + } + + private void executeGetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId tId = idMan.readId(bb); + Thread thread = (Thread) tId.getObject(); + + // Although Frames look like other ids they are not. First they are not + // ObjectIds since they don't exist in the users code. Storing them as an + // ObjectId would mean they could be garbage collected since no one else + // has a reference to them. Furthermore they are not ReferenceTypeIds since + // these are held permanently and we want these to be held only as long as + // the Thread is suspended. + VMFrame frame = vm.getVMFrame(thread, bb); + int slots = bb.getInt(); + os.writeInt(slots); // Looks pointless but this is the protocol + for (int i = 0; i < slots; i++) + { + int slot = bb.getInt(); + byte sig = bb.get(); + Object val = frame.getValue(slot); + Value.writeTaggedValue(os, val); + } + } + + private void executeSetValues(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId tId = idMan.readId(bb); + Thread thread = (Thread) tId.getObject(); + + VMFrame frame = vm.getVMFrame(thread, bb); + + int slots = bb.getInt(); + for (int i = 0; i < slots; i++) + { + int slot = bb.getInt(); + Object value = Value.getObj(bb); + frame.setValue(slot, value); + } + } + + private void executeThisObject(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ObjectId tId = idMan.readId(bb); + Thread thread = (Thread) tId.getObject(); + + VMFrame frame = vm.getVMFrame(thread, bb); + + Object thisObject = frame.getObject(); + Value.writeTaggedValue(os, thisObject); + } + + private void executePopFrames(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // This command is optional, determined by VirtualMachines CapabilitiesNew + // so we'll leave it till later to implement + throw new NotImplementedException("Command PopFrames not implemented."); + } +} diff --git a/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java b/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java new file mode 100644 index 000000000..871096960 --- /dev/null +++ b/gnu/classpath/jdwp/processor/ThreadReferenceCommandSet.java @@ -0,0 +1,251 @@ +/* ThreadReferenceCommandSet.java -- class to implement the ThreadReference + Command Set Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.processor; + +import gnu.classpath.jdwp.VMFrame; +import gnu.classpath.jdwp.IVirtualMachine; +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.JdwpConstants; +import gnu.classpath.jdwp.exception.InvalidObjectException; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; +import gnu.classpath.jdwp.id.IdManager; +import gnu.classpath.jdwp.id.ObjectId; +import gnu.classpath.jdwp.id.ThreadId; +import gnu.classpath.jdwp.util.JdwpString; +import gnu.classpath.jdwp.util.Location; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +/** + * A class representing the ThreadReference Command Set. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class ThreadReferenceCommandSet implements CommandSet +{ + // Our hook into the jvm + private final IVirtualMachine vm = Jdwp.getIVirtualMachine(); + + // Manages all the different ids that are assigned by jdwp + private final IdManager idMan = Jdwp.getIdManager(); + + public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) + throws JdwpException + { + try + { + switch (command) + { + case JdwpConstants.CommandSet.ThreadReference.NAME: + executeName(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.SUSPEND: + executeSuspend(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.RESUME: + executeResume(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.STATUS: + executeStatus(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.THREAD_GROUP: + executeThreadGroup(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.FRAMES: + executeFrames(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.FRAME_COUNT: + executeFrameCount(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.OWNED_MONITORS: + executeOwnedMonitors(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.CURRENT_CONTENDED_MONITOR: + executeCurrentContendedMonitor(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.STOP: + executeStop(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.INTERRUPT: + executeInterrupt(bb, os); + break; + case JdwpConstants.CommandSet.ThreadReference.SUSPEND_COUNT: + executeSuspendCount(bb, os); + break; + default: + throw new NotImplementedException("Command " + command + + " not found in Thread Reference Command Set."); + } + } + catch (IOException ex) + { + // The DataOutputStream we're using isn't talking to a socket at all + // So if we throw an IOException we're in serious trouble + throw new JdwpInternalErrorException(ex); + } + return true; + } + + private void executeName(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + JdwpString.writeString(os, thread.getName()); + } + + private void executeSuspend(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + vm.suspendThread(thread); + } + + private void executeResume(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + vm.suspendThread(thread); + } + + private void executeStatus(ByteBuffer bb, DataOutputStream os) + throws InvalidObjectException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + int threadStatus = vm.getThreadStatus(thread); + // There's only one possible SuspendStatus... + int suspendStatus = JdwpConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED; + + os.writeInt(threadStatus); + os.writeInt(suspendStatus); + } + + private void executeThreadGroup(ByteBuffer bb, DataOutputStream os) + throws InvalidObjectException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + ThreadGroup group = thread.getThreadGroup(); + ObjectId groupId = idMan.getId(group); + groupId.write(os); + } + + private void executeFrames(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + int startFrame = bb.getInt(); + int length = bb.getInt(); + + ArrayList frames = vm.getVMFrames(thread, startFrame, length); + os.writeInt(frames.size()); + for (int i = 0; i < frames.size(); i++) + { + VMFrame frame = (VMFrame) frames.get(i); + os.writeLong(frame.getId()); + Location loc = frame.getLocation(); + loc.write(os); + } + } + + private void executeFrameCount(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + + int frameCount = vm.getFrameCount(thread); + os.writeInt(frameCount); + } + + private void executeOwnedMonitors(ByteBuffer bb, DataOutputStream os) + throws JdwpException + { + // This command is optional, determined by VirtualMachines CapabilitiesNew + // so we'll leave it till later to implement + throw new NotImplementedException( + "Command OwnedMonitors not implemented."); + } + + private void executeCurrentContendedMonitor(ByteBuffer bb, + DataOutputStream os) + throws JdwpException + { + // This command is optional, determined by VirtualMachines CapabilitiesNew + // so we'll leave it till later to implement + throw new NotImplementedException( + "Command CurrentContentedMonitors not implemented."); + } + + private void executeStop(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + ObjectId exception = idMan.readId(bb); + vm.stopThread(thread, (Exception) exception.getObject()); + } + + private void executeInterrupt(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + thread.interrupt(); + } + + private void executeSuspendCount(ByteBuffer bb, DataOutputStream os) + throws JdwpException, IOException + { + ThreadId tid = (ThreadId) idMan.readId(bb); + Thread thread = (Thread) tid.getObject(); + int suspendCount = vm.getSuspendCount(thread); + os.writeInt(suspendCount); + } +} diff --git a/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java b/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java index 32b987817..938e1e060 100644 --- a/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java +++ b/gnu/classpath/jdwp/processor/VirtualMachineCommandSet.java @@ -144,9 +144,9 @@ public class VirtualMachineCommandSet implements CommandSet case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES_WITH_GENERIC: executeAllClassesWithGeneric(bb, os); break; - default: - break; + throw new NotImplementedException("Command " + command + + " not found in VirtualMachine Command Set."); } } catch (IOException ex) @@ -246,7 +246,7 @@ public class VirtualMachineCommandSet implements CommandSet int numThreads = root.activeCount(); Thread allThreads[] = new Thread[numThreads]; - root.enumerate(allThreads, true); + root.enumerate(allThreads); // We need to loop through for the true count since some threads may have // been destroyed since we got diff --git a/gnu/classpath/jdwp/util/LineTable.java b/gnu/classpath/jdwp/util/LineTable.java new file mode 100644 index 000000000..90d460ff3 --- /dev/null +++ b/gnu/classpath/jdwp/util/LineTable.java @@ -0,0 +1,96 @@ +/* LineTable.java -- A class representing a Line Table for a method + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A class representing a Line Table for a method. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class LineTable +{ + + private final long start; + private final long end; + private final int[] lineNum; + private final long[] lineCI; + private final int lines; + + /** + * Construct a line table with the given parameters. + * + * @param start lowest code index for method, -1 if native + * @param end highest code index for method, -1 if native + * @param lines number of entries in line table + * @param lineCI code indexes for entries in line tables (of length lines) + * @param lineNum line numbers for in line tables (of length lines) + */ + public LineTable(long start, long end, int lines, long lineCI[], + int lineNum[]) + { + this.start = start; + this.end = end; + this.lines = lines; + this.lineCI = lineCI; + this.lineNum = lineNum; + } + + /** + * Writes this line table to the given DataOutputStream. + * + * @param os the stream to write it to + * @throws IOException + */ + public void write(DataOutputStream os) + throws IOException + { + os.writeLong(start); + os.writeLong(end); + os.writeInt(lines); + for (int i = 0; i < lines; i++) + { + os.writeLong(lineCI[i]); + os.writeInt(lineNum[i]); + } + } +} diff --git a/gnu/classpath/jdwp/util/Location.java b/gnu/classpath/jdwp/util/Location.java new file mode 100644 index 000000000..1c13c5eb6 --- /dev/null +++ b/gnu/classpath/jdwp/util/Location.java @@ -0,0 +1,116 @@ +/* Location.java -- class to read/write JDWP locations + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +import gnu.classpath.jdwp.Jdwp; +import gnu.classpath.jdwp.exception.JdwpException; +import gnu.classpath.jdwp.id.ClassReferenceTypeId; +import gnu.classpath.jdwp.id.ObjectId; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Method; +import java.nio.ByteBuffer; + +/** + * A class to read/write JDWP locations. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class Location +{ + + private ClassReferenceTypeId crti; + + private int index; + + private byte tag; + + private ObjectId mid; + + /** + * Create a location with the given parameters. + * + * @param tag the type of construct the location is in + * @param clazz the class the location is in + * @param meth the Method + * @param index location in the method + * @throws JdwpException + */ + public Location(byte tag, Class clazz, Method meth, int index) + throws JdwpException + { + this.tag = tag; + this.crti = + (ClassReferenceTypeId) Jdwp.getIdManager().getReferenceTypeId(clazz); + this.mid = Jdwp.getIdManager().getId(meth); + this.index = index; + } + + /** + * Read a location from the given bytebuffer, consists of a TAG (byte), + * followed by a ReferenceTypeId, a MethodId and an index (int). + * + * @param bb this holds the location + * @throws IOException + * @throws JdwpException + */ + public Location(ByteBuffer bb) throws IOException, JdwpException + { + this.tag = bb.get(); + this.crti = + (ClassReferenceTypeId) Jdwp.getIdManager().readReferenceTypeId(bb); + this.mid = Jdwp.getIdManager().readId(bb); + this.index = bb.getInt(); + } + + /** + * Write the given location to an output stream. + * + * @param os stream to write to + * @throws IOException + */ + public void write(DataOutputStream os) throws IOException + { + os.writeByte(tag); + crti.write(os); + mid.write(os); + os.writeInt(index); + } +} diff --git a/gnu/classpath/jdwp/util/MethodResult.java b/gnu/classpath/jdwp/util/MethodResult.java new file mode 100644 index 000000000..fd1d5cac4 --- /dev/null +++ b/gnu/classpath/jdwp/util/MethodResult.java @@ -0,0 +1,76 @@ +/* MethodResult.java -- class to wrap around values returned from a Method call + in the VM + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +/** + * A class to wrap around values returned from a Method call in the VM. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class MethodResult +{ + // The Object returned by the executing method + private Object returnedValue; + + // Any Exception that was thrown by the executing method + private Exception thrownException; + + public Object getReturnedValue() + { + return returnedValue; + } + + public void setReturnedValue(Object returnedValue) + { + this.returnedValue = returnedValue; + } + + public Exception getThrownException() + { + return thrownException; + } + + public void setThrownException(Exception thrownException) + { + this.thrownException = thrownException; + } + +} diff --git a/gnu/classpath/jdwp/util/Value.java b/gnu/classpath/jdwp/util/Value.java index de7194dc7..a4bd9b946 100644 --- a/gnu/classpath/jdwp/util/Value.java +++ b/gnu/classpath/jdwp/util/Value.java @@ -43,6 +43,7 @@ import gnu.classpath.jdwp.JdwpConstants; import gnu.classpath.jdwp.exception.InvalidFieldException; import gnu.classpath.jdwp.exception.JdwpException; import gnu.classpath.jdwp.exception.JdwpInternalErrorException; +import gnu.classpath.jdwp.exception.NotImplementedException; import gnu.classpath.jdwp.id.ObjectId; import java.io.DataOutputStream; @@ -65,7 +66,7 @@ public class Value * @throws InvalidFieldException */ public static void writeUntaggedValue(DataOutputStream os, Object obj) - throws InvalidFieldException, IOException + throws JdwpException, IOException { writeValue(os, obj, false); } @@ -79,7 +80,7 @@ public class Value * @throws InvalidFieldException */ public static void writeTaggedValue(DataOutputStream os, Object obj) - throws InvalidFieldException, IOException + throws JdwpException, IOException { writeValue(os, obj, true); } @@ -96,7 +97,7 @@ public class Value */ private static void writeValue(DataOutputStream os, Object obj, boolean tagged) - throws IOException, InvalidFieldException + throws IOException, JdwpException { Class clazz = obj.getClass(); if (clazz.isPrimitive()) @@ -156,7 +157,8 @@ public class Value } else { // This shouldn't be possible - throw new InvalidFieldException("Field has invalid primitive!"); + throw new JdwpInternalErrorException( + "Field has invalid primitive!"); } } else @@ -235,7 +237,8 @@ public class Value return new byte[0]; else { // This shouldn't be possible - throw new InvalidFieldException("Field has invalid primitive!"); + throw new JdwpInternalErrorException( + "Field has invalid primitive!"); } } else @@ -291,7 +294,8 @@ public class Value ObjectId oid = Jdwp.getIdManager().readId(bb); return oid.getObject(); default: - throw new JdwpInternalErrorException("Could not find TAG:" + tag); + throw new NotImplementedException("Tag " + tag + + " is not implemented."); } } } diff --git a/gnu/classpath/jdwp/util/VariableTable.java b/gnu/classpath/jdwp/util/VariableTable.java new file mode 100644 index 000000000..3fb3bba90 --- /dev/null +++ b/gnu/classpath/jdwp/util/VariableTable.java @@ -0,0 +1,110 @@ +/* VariableTable.java -- A class representing a Variable Table for a method + Copyright (C) 2005 Free Software Foundation + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package gnu.classpath.jdwp.util; + +import java.io.DataOutputStream; +import java.io.IOException; + +/** + * A class representing a Variable Table for a method. + * + * @author Aaron Luchko <aluchko@redhat.com> + */ +public class VariableTable +{ + + private final long argCnt; + + private final long slots; + + private final long[] lineCI; + + private int[] slot; + + private int[] lengths; + + private String[] sigs; + + private String[] names; + + /** + * Make a new variable table with the given values. + * + * @param argCnt number of words used by arguments in this frame + * @param slots number of variables + * @param lineCI first code index of given variable (size slots) + * @param names name of given variable (size slots) + * @param sigs signature of given variable (size slots) + * @param lengths size of region where variable is active (size slots) + * @param slot index of variable in this frame (size slots) + */ + public VariableTable(int argCnt, int slots, long lineCI[], String names[], + String sigs[], int lengths[], int slot[]) + { + this.argCnt = argCnt; + this.slots = slots; + this.lineCI = lineCI; + this.names = names; + this.sigs = sigs; + this.lengths = lengths; + this.slot = slot; + } + + /** + * Writes this line table to the given DataOutputStream. + * + * @param os the stream to write it to + * @throws IOException + */ + public void write(DataOutputStream os) throws IOException + { + os.writeLong(argCnt); + os.writeLong(slots); + for (int i = 0; i < slots; i++) + { + os.writeLong(lineCI[i]); + JdwpString.writeString(os, names[i]); + JdwpString.writeString(os, sigs[i]); + os.writeInt(lengths[i]); + os.writeInt(slot[i]); + } + } + +} diff --git a/gnu/java/awt/ClasspathToolkit.java b/gnu/java/awt/ClasspathToolkit.java index 5fb444f98..1d25cc1da 100644 --- a/gnu/java/awt/ClasspathToolkit.java +++ b/gnu/java/awt/ClasspathToolkit.java @@ -92,14 +92,6 @@ public abstract class ClasspathToolkit extends Toolkit { /** - * A map from URLs to previously loaded images, used by {@link - * #getImage(java.net.URL)}. For images that were loaded via a path - * to an image file, the map contains a key with a file URL. - */ - private HashMap imageCache; - - - /** * Returns a shared instance of the local, platform-specific * graphics environment. * @@ -109,59 +101,6 @@ public abstract class ClasspathToolkit */ public abstract GraphicsEnvironment getLocalGraphicsEnvironment(); - - /** - * Determines the current size of the default, primary screen. - * - * @throws HeadlessException if the local graphics environment is - * headless, which means that no screen is attached and no user - * interaction is allowed. - */ - public Dimension getScreenSize() - { - DisplayMode mode; - - // getDefaultScreenDevice throws HeadlessException if the - // local graphics environment is headless. - mode = GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDisplayMode(); - - return new Dimension(mode.getWidth(), mode.getHeight()); - } - - - /** - * Determines the current color model of the default, primary - * screen. - * - * @see GraphicsEnvironment#getDefaultScreenDevice() - * @see java.awt.GraphicsDevice#getDefaultConfiguration() - * @see java.awt.GraphicsConfiguration#getColorModel() - * - * @throws HeadlessException if the local graphics environment is - * headless, which means that no screen is attached and no user - * interaction is allowed. - */ - public ColorModel getColorModel() - { - // getDefaultScreenDevice throws HeadlessException if the - // local graphics environment is headless. - return GraphicsEnvironment.getLocalGraphicsEnvironment() - .getDefaultScreenDevice().getDefaultConfiguration() - .getColorModel(); - } - - /** - * Retrieves the metrics for rendering a font on the screen. - * - * @param font the font whose metrics are requested. - */ - public FontMetrics getFontMetrics(Font font) - { - return ((ClasspathFontPeer) font.getPeer ()).getFontMetrics (font); - } - - /** * Acquires an appropriate {@link ClasspathFontPeer}, for use in * classpath's implementation of {@link java.awt.Font}. @@ -185,8 +124,8 @@ public abstract class ClasspathToolkit * Creates a {@link Font}, in a platform-specific manner. * * The default implementation simply constructs a {@link Font}, but some - * toolkits may wish to override this, to return {@link Font} subclasses which - * implement {@link java.awt.font.OpenType} or + * toolkits may wish to override this, to return {@link Font} subclasses + * which implement {@link java.awt.font.OpenType} or * {@link java.awt.font.MultipleMaster}. */ public Font getFont (String name, Map attrs) @@ -194,7 +133,6 @@ public abstract class ClasspathToolkit return new Font (name, attrs); } - /** * Creates a font, reading the glyph definitions from a stream. * @@ -223,137 +161,6 @@ public abstract class ClasspathToolkit */ public abstract Font createFont(int format, InputStream stream); - - /** - * Returns an image from the specified file, which must be in a - * recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>This method maintains a cache for images. If an image has been - * loaded from the same path before, the cached copy will be - * returned. The implementation may hold cached copies for an - * indefinite time, which can consume substantial resources with - * large images. Users are therefore advised to use {@link - * #createImage(java.lang.String)} instead. - * - * <p>The default implementation creates a file URL for the - * specified path and invokes {@link #getImage(URL)}. - * - * @param path A path to the image file. - * - * @return IllegalArgumentException if <code>path</code> does not - * designate a valid path. - */ - public Image getImage(String path) - { - try - { - return getImage(new File(path).toURL()); - } - catch (MalformedURLException muex) - { - throw (IllegalArgumentException) new IllegalArgumentException(path) - .initCause(muex); - } - } - - - /** - * Loads an image from the specified URL. The image data must be in - * a recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>This method maintains a cache for images. If an image has been - * loaded from the same URL before, the cached copy will be - * returned. The implementation may hold cached copies for an - * indefinite time, which can consume substantial resources with - * large images. Users are therefore advised to use {@link - * #createImage(java.net.URL)} instead. - * - * @param url the URL from where the image is read. - */ - public Image getImage(URL url) - { - Image result; - - synchronized (this) - { - // Many applications never call getImage. Therefore, we lazily - // create the image cache when it is actually needed. - if (imageCache == null) - imageCache = new HashMap(); - else - { - result = (Image) imageCache.get(url); - if (result != null) - return result; - } - - // The createImage(URL) method, which is specified by - // java.awt.Toolkit, is not implemented by this abstract class - // because it is platform-dependent. Once Classpath has support - // for the javax.imageio package, it might be worth considering - // that toolkits provide native stream readers. Then, the class - // ClasspathToolkit could provide a general implementation that - // delegates the image format parsing to javax.imageio. - result = createImage(url); - - // It is not clear whether it would be a good idea to use weak - // references here. The advantage would be reduced memory - // consumption, since loaded images would not be kept - // forever. But on VMs that frequently perform garbage - // collection (which includes VMs with a parallel or incremental - // collector), the image might frequently need to be re-loaded, - // possibly over a slow network connection. - imageCache.put(url, result); - - return result; - } - } - - - /** - * Returns an image from the specified file, which must be in a - * recognized format. The set of recognized image formats may vary - * from toolkit to toolkit. - * - * <p>A new image is created every time this method gets called, - * even if the same path has been passed before. - * - * <p>The default implementation creates a file URL for the - * specified path and invokes {@link #createImage(URL)}. - * - * @param path A path to the file to be read in. - */ - public Image createImage(String path) - { - try - { - // The abstract method createImage(URL) is defined by - // java.awt.Toolkit, but intentionally not implemented by - // ClasspathToolkit because it is platform specific. - return createImage(new File(path).toURL()); - } - catch (MalformedURLException muex) - { - throw (IllegalArgumentException) new IllegalArgumentException(path) - .initCause(muex); - } - } - - /** - * Creates an ImageProducer from the specified URL. The image is assumed - * to be in a recognised format. If the toolkit does not implement the - * image format or the image format is not recognised, null is returned. - * This default implementation is overriden by the Toolkit implementations. - * - * @param url URL to read image data from. - */ - public ImageProducer createImageProducer(URL url) - { - return null; - } - public abstract RobotPeer createRobot (GraphicsDevice screen) throws AWTException; @@ -365,15 +172,8 @@ public abstract class ClasspathToolkit */ public abstract EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w); - /** - * Used to register ImageIO SPIs provided by the toolkit. - */ - - public void registerImageIOSpis(IIORegistry reg) - { - } - public abstract boolean nativeQueueEmpty(); public abstract void wakeNativeQueue(); public abstract void iterateNativeQueue(EventQueue locked, boolean block); } + diff --git a/gnu/java/awt/peer/gtk/GtkButtonPeer.java b/gnu/java/awt/peer/gtk/GtkButtonPeer.java index ab5df9f46..a8b746ce2 100644 --- a/gnu/java/awt/peer/gtk/GtkButtonPeer.java +++ b/gnu/java/awt/peer/gtk/GtkButtonPeer.java @@ -46,6 +46,9 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.peer.ButtonPeer; +// A composite widget. GtkButtons have transparent backgrounds. An +// AWT Button is opaque. To compensate, a GtkButtonPeer is a +// GtkButton packed in a GtkEventBox. public class GtkButtonPeer extends GtkComponentPeer implements ButtonPeer { @@ -61,6 +64,11 @@ public class GtkButtonPeer extends GtkComponentPeer native void gtkWidgetRequestFocus (); native void setNativeBounds (int x, int y, int width, int height); + // Because this is a composite widget, we need to retrieve the + // GtkButton's preferred dimensions, not the enclosing + // GtkEventBox's. + native void gtkWidgetGetPreferredDimensions (int[] dim); + public GtkButtonPeer (Button b) { super (b); diff --git a/gnu/java/awt/peer/gtk/GtkComponentPeer.java b/gnu/java/awt/peer/gtk/GtkComponentPeer.java index a7aea091d..e272bfafc 100644 --- a/gnu/java/awt/peer/gtk/GtkComponentPeer.java +++ b/gnu/java/awt/peer/gtk/GtkComponentPeer.java @@ -85,7 +85,7 @@ public class GtkComponentPeer extends GtkGenericPeer boolean isInRepaint; - Timer repaintTimer = new Timer (true); + static final Timer repaintTimer = new Timer (true); /* this isEnabled differs from Component.isEnabled, in that it knows if a parent is disabled. In that case Component.isEnabled @@ -418,6 +418,9 @@ public class GtkComponentPeer extends GtkGenericPeer public void setBounds (int x, int y, int width, int height) { + int new_x = x; + int new_y = y; + Component parent = awtComponent.getParent (); // Heavyweight components that are children of one or more @@ -438,8 +441,8 @@ public class GtkComponentPeer extends GtkGenericPeer i = ((Container) parent).getInsets (); - x += parent.getX () + i.left; - y += parent.getY () + i.top; + new_x += parent.getX () + i.left; + new_y += parent.getY () + i.top; parent = parent.getParent (); } @@ -448,18 +451,22 @@ public class GtkComponentPeer extends GtkGenericPeer // placing a heavyweight component in a Window. if (parent instanceof Window && !lightweightChild) { - Insets insets = ((Window) parent).getInsets (); GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer (); + // important: we want the window peer's insets here, not the + // window's, since user sub-classes of Window can override + // getInset and we only want to correct for the frame borders, + // not for any user-defined inset values + Insets insets = peer.getInsets (); + int menuBarHeight = 0; if (peer instanceof GtkFramePeer) menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight (); - // Convert from Java coordinates to GTK coordinates. - setNativeBounds (x - insets.left, y - insets.top + menuBarHeight, - width, height); + new_x = x - insets.left; + new_y = y - insets.top + menuBarHeight; } - else - setNativeBounds (x, y, width, height); + + setNativeBounds (new_x, new_y, width, height); } void setCursor () @@ -671,4 +678,9 @@ public class GtkComponentPeer extends GtkGenericPeer { backBuffer.flush(); } + + public String toString () + { + return "peer of " + awtComponent.toString(); + } } diff --git a/gnu/java/awt/peer/gtk/GtkLabelPeer.java b/gnu/java/awt/peer/gtk/GtkLabelPeer.java index fdd5fd15f..3d099e9ca 100644 --- a/gnu/java/awt/peer/gtk/GtkLabelPeer.java +++ b/gnu/java/awt/peer/gtk/GtkLabelPeer.java @@ -41,6 +41,9 @@ package gnu.java.awt.peer.gtk; import java.awt.Label; import java.awt.peer.LabelPeer; +// A composite widget. GtkLabels have transparent backgrounds. An +// AWT Label is opaque. To compensate, a GtkLabelPeer is a GtkLabel +// packed in a GtkEventBox. public class GtkLabelPeer extends GtkComponentPeer implements LabelPeer { @@ -51,6 +54,10 @@ public class GtkLabelPeer extends GtkComponentPeer public native void setText(String text); native void setNativeBounds (int x, int y, int width, int height); + // Because this is a composite widget, we need to retrieve the + // GtkLabel's preferred dimensions, not the enclosing GtkEventBox's. + native void gtkWidgetGetPreferredDimensions (int[] dim); + void create () { Label label = (Label) awtComponent; diff --git a/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java b/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java index 79eeaf9ba..a1a1cbd6d 100644 --- a/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java +++ b/gnu/java/awt/peer/gtk/GtkMenuBarPeer.java @@ -77,4 +77,9 @@ public class GtkMenuBarPeer extends GtkMenuComponentPeer } public native void delMenu(int index); + + public void addMenu (Menu m) + { + // FIXME: implement + } } diff --git a/gnu/java/awt/peer/gtk/GtkMenuPeer.java b/gnu/java/awt/peer/gtk/GtkMenuPeer.java index 80332dd6a..fabcf1f09 100644 --- a/gnu/java/awt/peer/gtk/GtkMenuPeer.java +++ b/gnu/java/awt/peer/gtk/GtkMenuPeer.java @@ -100,4 +100,9 @@ public class GtkMenuPeer extends GtkMenuItemPeer } public native void delItem(int index); + + public void addSeparator() + { + // FIXME: implement + } } diff --git a/gnu/java/awt/peer/gtk/GtkToolkit.java b/gnu/java/awt/peer/gtk/GtkToolkit.java index 69901102f..951a7c32e 100644 --- a/gnu/java/awt/peer/gtk/GtkToolkit.java +++ b/gnu/java/awt/peer/gtk/GtkToolkit.java @@ -121,6 +121,9 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit portableNativeSync = 0; // false gtkInit(portableNativeSync); + + // Register ImageIO SPIs + GdkPixbufDecoder.registerSpis( IIORegistry.getDefaultInstance() ); } public GtkToolkit () @@ -641,11 +644,6 @@ public class GtkToolkit extends gnu.java.awt.ClasspathToolkit return new GdkRobotPeer (screen); } - public void registerImageIOSpis(IIORegistry reg) - { - GdkPixbufDecoder.registerSpis(reg); - } - public native boolean nativeQueueEmpty(); public native void wakeNativeQueue(); public native void iterateNativeQueue(EventQueue locked, boolean block); diff --git a/gnu/java/awt/peer/qt/MainQtThread.java b/gnu/java/awt/peer/qt/MainQtThread.java new file mode 100644 index 000000000..24082f643 --- /dev/null +++ b/gnu/java/awt/peer/qt/MainQtThread.java @@ -0,0 +1,84 @@ +/* MainQtThread.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +/** + * This Thread is the main Qt thread. + * + * It doesn't appear to do much here, since all custom code executed by + * this thread is injected into Qt's main event loop through the (native) + * MainThreadInterface class. + */ +public class MainQtThread extends Thread +{ + long QApplicationPointer; + long mainThreadInterface; + String theme; + private boolean running; + + public MainQtThread( String theme ) + { + this.theme = theme; + running = false; + } + + public boolean isRunning() + { + return running; + } + + /** + * Creates the QApplication + */ + public native long init(String theme); + + /** + * Runs the QApplication (doesn't return.) + */ + public native void exec(long ptr); + + public void run() + { + QApplicationPointer = init(theme); + running = true; + exec(QApplicationPointer); + } + +} + + diff --git a/gnu/java/awt/peer/qt/NativeWrapper.java b/gnu/java/awt/peer/qt/NativeWrapper.java new file mode 100644 index 000000000..706e0df6c --- /dev/null +++ b/gnu/java/awt/peer/qt/NativeWrapper.java @@ -0,0 +1,43 @@ +/* NativeWrapper.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +public class NativeWrapper +{ + protected long nativeObject; +} diff --git a/gnu/java/awt/peer/qt/QMatrix.java b/gnu/java/awt/peer/qt/QMatrix.java new file mode 100644 index 000000000..428cda173 --- /dev/null +++ b/gnu/java/awt/peer/qt/QMatrix.java @@ -0,0 +1,73 @@ +/* QMatrix.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.geom.AffineTransform; + +/** + * A simple wrapper class for a QMatrix, + * interfacing it to an AffineTransform. + */ +public class QMatrix extends NativeWrapper +{ + + public QMatrix( AffineTransform t ) + { + double[] matrix = new double[6]; + t.getMatrix( matrix ); + init( matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5] ); + } + + private native void init(double m00, double m10, double m01, double m11, + double m02, double m12 ); + + private native double[] getMatrix(); + + public AffineTransform getTransform() + { + return new AffineTransform( getMatrix() ); + } + + public native void dispose(); + + public void finalize() + { + dispose(); + } +} + diff --git a/gnu/java/awt/peer/qt/QPainterPath.java b/gnu/java/awt/peer/qt/QPainterPath.java new file mode 100644 index 000000000..8d176a156 --- /dev/null +++ b/gnu/java/awt/peer/qt/QPainterPath.java @@ -0,0 +1,141 @@ +/* QPainterPath.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.PathIterator; +import java.awt.geom.GeneralPath; + +/** + * A simple wrapper class for a QPainterPath, + * createable from an AWT Shape + */ +public class QPainterPath extends NativeWrapper +{ + QPainterPath() + { + } + + public QPainterPath( Shape s ) + { + PathIterator pi = s.getPathIterator( new AffineTransform() ); + double[] coords = new double[6]; + + init( pi.getWindingRule() ); + + while( !pi.isDone() ) + { + switch( pi.currentSegment(coords) ) + { + case PathIterator.SEG_MOVETO: + moveTo( coords[0], coords[1] ); + break; + + case PathIterator.SEG_CLOSE: + close(); + break; + + case PathIterator.SEG_LINETO: + lineTo( coords[0], coords[1] ); + break; + + case PathIterator.SEG_QUADTO: + quadTo( coords[0], coords[1], coords[2], coords[3] ); + break; + + case PathIterator.SEG_CUBICTO: + cubicTo( coords[0], coords[1], + coords[2], coords[3], + coords[4], coords[5] ); + break; + } + pi.next(); + } + } + + /** + * Constructor for rectangles. + */ + public QPainterPath( double x, double y, double w, double h ) + { + init(PathIterator.WIND_EVEN_ODD); + moveTo( x, y ); + lineTo( x + w, y ); + lineTo( x + w, y + h ); + lineTo( x , y + h ); + lineTo( x, y ); + close(); + } + + /** + * Constructor for lines. + */ + public QPainterPath( double x1, double y1, double x2, double y2, boolean s ) + { + init(PathIterator.WIND_EVEN_ODD); + moveTo( x1, y1 ); + lineTo( x2, y2 ); + } + + /** + * Returns the QPainterPath as a GeneralPath + */ + public native GeneralPath getPath(); + + private native void init(int windingRule); + + private native void moveTo(double x, double y); + + private native void close(); + + private native void lineTo(double x, double y); + + private native void quadTo(double x1, double y1, double x2, double y2); + + private native void cubicTo(double x1, double y1, double x2, double y2, + double x3, double y3); + + public native void dispose(); + + public void finalize() + { + dispose(); + } +} + diff --git a/gnu/java/awt/peer/qt/QPen.java b/gnu/java/awt/peer/qt/QPen.java new file mode 100644 index 000000000..ec41015ed --- /dev/null +++ b/gnu/java/awt/peer/qt/QPen.java @@ -0,0 +1,71 @@ +/* QPen.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Stroke; +import java.awt.BasicStroke; + +/** + * A simple wrapper class for a QPen, + * interfacing it to an BasicStroke. + */ +public class QPen extends NativeWrapper +{ + + public QPen( Stroke stroke ) + { + if( !( stroke instanceof BasicStroke ) ) + throw new IllegalArgumentException("Not a basic stroke."); + + BasicStroke s = (BasicStroke)stroke; + if(s.getDashArray() != null) + throw new IllegalArgumentException("Can't handle dashed strokes."); + + init(s.getLineWidth(), s.getEndCap(), s.getLineJoin(), s.getMiterLimit()); + } + + private native void init(double width, int cap, int join, double miterlimit); + + public native void dispose(); + + public void finalize() + { + dispose(); + } +} + diff --git a/gnu/java/awt/peer/qt/QtAudioClip.java b/gnu/java/awt/peer/qt/QtAudioClip.java new file mode 100644 index 000000000..8d2ec5706 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtAudioClip.java @@ -0,0 +1,104 @@ +/* QtAudioClip.java -- Qt implementation of the applet AudioClip interface + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.applet.AudioClip; +import java.io.File; +import java.io.IOException; +import java.awt.Toolkit; + +/** + * Implementation of the applet AudioClip interface on a Qt + * QSound object. + */ +public class QtAudioClip extends NativeWrapper implements AudioClip +{ + private static Toolkit t = null; + + public QtAudioClip(String filename) + { + checkForQt(); + File f = new File(filename); + try + { + String fn = f.getCanonicalPath(); + loadClip( fn ); + } + catch(IOException e) + { + } + } + + private native void loadClip(String filename); + + private native void play(boolean looped); + + private native boolean isAvailable(); + + /** + * Checks that Qt and sound is available. + */ + private void checkForQt() + { + if( t == null ) + t = Toolkit.getDefaultToolkit(); + if( !( t instanceof QtToolkit) ) + throw new IllegalStateException("This requires Qt peers."); + } + + // *************** Public methods ******************* + + public void loop() + { + play( true ); + } + + public void play() + { + play( false ); + } + + public native void stop(); + + public native void dispose(); + + public void finalize() + { + dispose(); + } +} diff --git a/gnu/java/awt/peer/qt/QtButtonPeer.java b/gnu/java/awt/peer/qt/QtButtonPeer.java new file mode 100644 index 000000000..3dd607b19 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtButtonPeer.java @@ -0,0 +1,79 @@ +/* QtButtonPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Button; +import java.awt.event.ActionEvent; +import java.awt.peer.ButtonPeer; + +public class QtButtonPeer extends QtComponentPeer implements ButtonPeer +{ + public QtButtonPeer( QtToolkit kit, Button owner ) + { + super( kit, owner ); + } + + public native void init(); + + protected void setup() + { + super.setup(); + setLabel( ((Button)owner).getLabel() ); + } + + /** + * Callback for button click events + */ + void fireClick(int modifiers) + { + ActionEvent e = new ActionEvent(owner, + ActionEvent.ACTION_PERFORMED, + ((Button)owner).getActionCommand(), + System.currentTimeMillis(), + (modifiers & 0x2FF)); + QtToolkit.eventQueue.postEvent(e); + } + + // ************ Public methods ********************* + + public native void setLabel( String label ); +} + + + + diff --git a/gnu/java/awt/peer/qt/QtCanvasPeer.java b/gnu/java/awt/peer/qt/QtCanvasPeer.java new file mode 100644 index 000000000..2367cd066 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtCanvasPeer.java @@ -0,0 +1,65 @@ +/* QtCanvasPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.peer.CanvasPeer; + +public class QtCanvasPeer extends QtComponentPeer implements CanvasPeer +{ + public QtCanvasPeer( QtToolkit kit, Canvas owner ) + { + super( kit, owner ); + } + + public native void init(); + + protected void setup() + { + super.setup(); + } + + /** + * Overloaded, because a Canvas doesn't have a preferred size. + */ + public Dimension getPreferredSize() + { + return owner.getSize(); + } +} diff --git a/gnu/java/awt/peer/qt/QtCheckboxPeer.java b/gnu/java/awt/peer/qt/QtCheckboxPeer.java new file mode 100644 index 000000000..788e08ee1 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtCheckboxPeer.java @@ -0,0 +1,114 @@ +/* QtCheckboxPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Rectangle; +import java.awt.Checkbox; +import java.awt.CheckboxGroup; +import java.awt.event.ItemEvent; +import java.awt.peer.CheckboxPeer; +import java.util.WeakHashMap; + +public class QtCheckboxPeer extends QtComponentPeer implements CheckboxPeer +{ + private CheckboxGroup group; + + // Map QButtonGroup<->CheckboxGroup + private static WeakHashMap groupMap; + + static + { + groupMap = new WeakHashMap(); + } + + public QtCheckboxPeer( QtToolkit kit, Checkbox owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setCheckboxGroup( ((Checkbox)owner).getCheckboxGroup() ); + setLabel( ((Checkbox)owner).getLabel() ); + setState( ((Checkbox)owner).getState() ); + } + + private void fireToggle(boolean checked) + { + if (group == null) + ((Checkbox)owner).setState( checked ); + else + if ( checked ) + group.setSelectedCheckbox((Checkbox)owner); + + int sel = checked ? ItemEvent.SELECTED : ItemEvent.DESELECTED; + ItemEvent e = new ItemEvent((Checkbox)owner, + ItemEvent.ITEM_STATE_CHANGED, + ((Checkbox)owner).getLabel(), + sel); + QtToolkit.eventQueue.postEvent(e); + } + + // ************ Public methods ********************* + + public void setCheckboxGroup( CheckboxGroup group ) + { + if(this.group == group) + return; + + // if we change from a checkbox to a radio button or vice versa + if((this.group == null) != (group == null)) + { + this.group = group; + callInit(); + setup(); + } + + this.group = group; + } + + public native void setLabel( String label ); + + public native void setState( boolean state ); + +} + + diff --git a/gnu/java/awt/peer/qt/QtChoicePeer.java b/gnu/java/awt/peer/qt/QtChoicePeer.java new file mode 100644 index 000000000..30674b36e --- /dev/null +++ b/gnu/java/awt/peer/qt/QtChoicePeer.java @@ -0,0 +1,95 @@ +/* QtChoicePeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Choice; +import java.awt.event.ItemEvent; +import java.awt.peer.ChoicePeer; + +public class QtChoicePeer extends QtComponentPeer implements ChoicePeer +{ + public QtChoicePeer( QtToolkit kit, Choice owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + + Choice c = (Choice) owner; + int n = c.getItemCount(); + for ( int i = 0; i < n ; i++ ) + add( c.getItem( i ), i ); + select( c.getSelectedIndex() ); + } + + private void fireChoice( int index ) + { + ((Choice)owner).select( index ); + ItemEvent e = new ItemEvent((Choice)owner, + ItemEvent.ITEM_STATE_CHANGED, + ((Choice)owner).getItem(index), + ItemEvent.SELECTED); + QtToolkit.eventQueue.postEvent(e); + } + + // ************ Public methods ********************* + + public native void add( String item, int index ); + + public void addItem( String item, int index ) + { + add(item, index); + } + + public native void remove( int index ); + + public void removeAll() + { + int n = ((Choice)owner).getItemCount(); + for (int i = 0; i < n; i++) + remove( i ); + } + + public native void select( int index ); +} + + diff --git a/gnu/java/awt/peer/qt/QtComponentGraphics.java b/gnu/java/awt/peer/qt/QtComponentGraphics.java new file mode 100644 index 000000000..4f3803dc6 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtComponentGraphics.java @@ -0,0 +1,125 @@ +/* QtComponentGraphics.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Color; +import java.awt.GraphicsConfiguration; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.Paint; + +/** + * QtComponentPainter is a Graphics2D context for painting directly to AWT + * components. They require an existing QPainter object (the one passed into + * the native paint method), and are created there (ONLY). + * + * Since this context does direct on-screen drawing it is NOT thread-safe, + * and should NOT be used outside the thread in which it was created. + * + * In other words, + * this is intended for use by QtComponentPeer.paintEvent() only. + * + */ +public class QtComponentGraphics extends QtGraphics +{ + private QtComponentPeer peer; + + /** + * Creates a new ComponentGraphics from an *existing* QPainter object. + * + * @param ptr the pointer to the QPainter object. + */ + public QtComponentGraphics(long ptr, QtComponentPeer component) + { + nativeObject = ptr; + peer = component; + + Rectangle r = component.owner.getBounds(); + r.setLocation(0, 0); + initialClip = r; + + currentAlpha = 1.0; + Color c = component.owner.getBackground(); + if(c == null) + setBackground(Color.white); + else + setBackground( c ); + + c = component.owner.getForeground(); + if(c == null) + setColor( Color.black ); + else + setColor( c ); + + setup(); + setClip( initialClip ); + } + + /** + * Copying constructor + */ + QtComponentGraphics( QtComponentGraphics g ) + { + super( g ); // Slalom is fun + } + + public Graphics create() + { + return new QtComponentGraphics( this ); + } + + /** + * This is a tricky one + */ + public void copyArea(int x, int y, int width, int height, + int dx, int dy) + { + // FIXME + } + + /** + * Returns the GraphicsConfiguration of the context component. + */ + public GraphicsConfiguration getDeviceConfiguration() + { + return peer.getGraphicsConfiguration(); + } +} + + diff --git a/gnu/java/awt/peer/qt/QtComponentPeer.java b/gnu/java/awt/peer/qt/QtComponentPeer.java new file mode 100644 index 000000000..bfebdfdd4 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtComponentPeer.java @@ -0,0 +1,714 @@ +/* QtComponentPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.AWTEvent; +import java.awt.AWTException; +import java.awt.BufferCapabilities; +import java.awt.Component; +import java.awt.Container; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Image; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.KeyboardFocusManager; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.peer.ComponentPeer; +import java.awt.image.ColorModel; +import java.awt.image.VolatileImage; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.event.ComponentEvent; // 100% +import java.awt.event.FocusEvent; // 100% +import java.awt.event.InputEvent; // (abstract) +import java.awt.event.KeyEvent; // 2/3 +import java.awt.event.MouseEvent; // 70%? +import java.awt.event.PaintEvent; // Yup. +import java.awt.event.WindowEvent; // 2/ 12 +import java.util.Timer; +import java.util.TimerTask; + +public class QtComponentPeer extends NativeWrapper implements ComponentPeer +{ + + /** + * Popup trigger button, may differ between platforms + */ + protected static final int POPUP_TRIGGER = 3; + + /** + * The toolkit which manufactured this peer. + */ + protected QtToolkit toolkit; + + /** + * The component which owns this peer. + */ + Component owner; + + /** + * Timestamp of last MouseMotionEvent. + */ + private long lastMME; + + /** + * Classpath updates our eventMask. + */ + private long eventMask; + + /** + * if the thing has mouse motion listeners or not. + */ + private boolean hasMotionListeners; + + /** + * The component's double buffer for off-screen drawing. + */ + private QtImage backBuffer; + + /** + * Stores if the backBuffer is dirty or not + */ + private boolean dirtyBackBuffer; + + protected long qtApp; + + private boolean settingUp; + + QtComponentPeer( QtToolkit kit, Component owner ) + { + this.owner = owner; + this.toolkit = kit; + qtApp = QtToolkit.guiThread.QApplicationPointer; + nativeObject = 0; + callInit(); // Calls the init method FROM THE MAIN THREAD. + setup(); + hasMotionListeners = false; + } + + protected native void callInit(); + + /** + * Init does the creation of native widgets, it is therefore + * called from the main thread. (the constructor waits for this to happen.) + */ + protected void init() + { + } + + protected void setup() + { + settingUp = true; + if (owner != null) + { +// if (owner.getBackground() != null) +// setBackground(owner.getBackground()); +// else + owner.setBackground(getNativeBackground()); + + if (owner.getForeground() != null) + setForeground(owner.getForeground()); + else + setForeground( Color.black ); + + if (owner.getCursor() != null) + if (owner.getCursor().getType() != Cursor.DEFAULT_CURSOR) + setCursor(owner.getCursor()); + + if (owner.getFont() != null) + setFont(owner.getFont()); + + setEnabled( owner.isEnabled() ); + setVisible( owner.isVisible() ); + + Rectangle r = owner.getBounds(); + setBounds( r.x, r.y, r.width, r.height ); + if( drawableComponent() ) + backBuffer = new QtImage( r.width, r.height ); + else + backBuffer = null; + dirtyBackBuffer = true; + } + settingUp = false; + } + + native void QtUpdate(); + native void QtUpdateArea(int x, int y, int w, int h); + private synchronized native void disposeNative(); + private native void setGround(int r, int g, int b, boolean isForeground); + private native void setBoundsNative(int x, int y, int width, int height); + private native void setCursor(int ctype); + private native Color getNativeBackground(); + private native void setFontNative(QtFontPeer fp); + private native int whichScreen(); + + private boolean drawableComponent() + { + return ((this instanceof QtContainerPeer && + !(this instanceof QtScrollPanePeer)) || + (this instanceof QtCanvasPeer)); + } + + // ************ Event methods ********************* + + /** + * Window closing event + */ + protected void closeEvent() + { + if (owner instanceof Window) + { + WindowEvent e = new WindowEvent((Window)owner, + WindowEvent.WINDOW_CLOSING); + QtToolkit.eventQueue.postEvent(e); + } + } + + protected void enterEvent(int modifiers, int x, int y, int dummy) + { + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_ENTERED, + System.currentTimeMillis(), + (modifiers & 0x2FF), x, y, 0, false); + QtToolkit.eventQueue.postEvent(e); + } + + protected void focusInEvent() + { + FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_GAINED); + QtToolkit.eventQueue.postEvent(e); + } + + protected void focusOutEvent() + { + FocusEvent e = new FocusEvent(owner, FocusEvent.FOCUS_LOST); + QtToolkit.eventQueue.postEvent(e); + } + + protected void keyPressEvent(int modifiers, int code, int unicode, int dummy) + { + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager (); + KeyEvent e = new KeyEvent(owner, + KeyEvent.KEY_PRESSED, + System.currentTimeMillis(), + modifiers, code, (char)(unicode & 0xFFFF), + KeyEvent.KEY_LOCATION_UNKNOWN); + if (!manager.dispatchEvent (e)) + QtToolkit.eventQueue.postEvent(e); + } + + protected void keyReleaseEvent(int modifiers, int code, int unicode, int dummy) + { + KeyEvent e = new KeyEvent(owner, + KeyEvent.KEY_RELEASED, + System.currentTimeMillis(), + modifiers, code, (char)(unicode & 0xFFFF), + KeyEvent.KEY_LOCATION_UNKNOWN); + QtToolkit.eventQueue.postEvent(e); + } + + protected void leaveEvent(int modifiers, int x, int y, int dummy) + { + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_EXITED, + System.currentTimeMillis(), + (modifiers & 0x2FF), x, y, 0, false); + QtToolkit.eventQueue.postEvent(e); + } + + // FIXME: Coalesce press-release events into clicks. + protected void mouseDoubleClickEvent( int modifiers, int x, int y, int clickCount) + { + if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) + return; + int button = 0; + if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == + InputEvent.BUTTON1_DOWN_MASK) button = 1; + if((modifiers & InputEvent.BUTTON2_DOWN_MASK) == + InputEvent.BUTTON2_DOWN_MASK) button = 2; + if((modifiers & InputEvent.BUTTON3_DOWN_MASK) == + InputEvent.BUTTON3_DOWN_MASK) button = 3; + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_CLICKED, + System.currentTimeMillis(), + (modifiers & 0x2FF), x, y, clickCount, + false, button); + QtToolkit.eventQueue.postEvent(e); + } + + protected void mouseMoveEvent( int modifiers, int x, int y, int clickCount) + { + if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) + return; + + long timeStamp = System.currentTimeMillis(); + if( timeStamp - lastMME > 100 ) + hasMotionListeners = (owner.getMouseMotionListeners().length > 0); + if( hasMotionListeners ) + { + int button = 0; + if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == + InputEvent.BUTTON1_DOWN_MASK) button = 1; + if((modifiers & InputEvent.BUTTON2_DOWN_MASK) == + InputEvent.BUTTON2_DOWN_MASK) button = 2; + if((modifiers & InputEvent.BUTTON3_DOWN_MASK) == + InputEvent.BUTTON3_DOWN_MASK) button = 3; + + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_MOVED, + timeStamp, + (modifiers & 0x2FF), x, y, clickCount, + false, button); + QtToolkit.eventQueue.postEvent(e); + } + lastMME = timeStamp; + } + + protected void mousePressEvent( int modifiers, int x, int y, int clickCount) + { + // if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) + // return; + int button = 0; + if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == + InputEvent.BUTTON1_DOWN_MASK) button = 1; + if((modifiers & InputEvent.BUTTON2_DOWN_MASK) == + InputEvent.BUTTON2_DOWN_MASK) button = 2; + if((modifiers & InputEvent.BUTTON3_DOWN_MASK) == + InputEvent.BUTTON3_DOWN_MASK) button = 3; + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_PRESSED, + System.currentTimeMillis(), + (modifiers & 0x2FF), x, y, clickCount, + ( button == POPUP_TRIGGER ), + button); + QtToolkit.eventQueue.postEvent(e); + } + + protected void mouseReleaseEvent( int modifiers, int x, int y, int clickCount) + { + if( (eventMask & AWTEvent.MOUSE_EVENT_MASK) == 0 ) + return; + int button = 0; + if((modifiers & InputEvent.BUTTON1_DOWN_MASK) == + InputEvent.BUTTON1_DOWN_MASK) button = 1; + if((modifiers & InputEvent.BUTTON2_DOWN_MASK) == + InputEvent.BUTTON2_DOWN_MASK) button = 2; + if((modifiers & InputEvent.BUTTON3_DOWN_MASK) == + InputEvent.BUTTON3_DOWN_MASK) button = 3; + + MouseEvent e = new MouseEvent(owner, + MouseEvent.MOUSE_RELEASED, + System.currentTimeMillis(), + (modifiers & 0x2FF), x, y, clickCount, + false, button); + QtToolkit.eventQueue.postEvent(e); + } + + protected void moveEvent() + { + ComponentEvent e = new ComponentEvent(owner, + ComponentEvent.COMPONENT_MOVED); + QtToolkit.eventQueue.postEvent(e); + } + + protected void paintEvent(QtGraphics g) + { + if (backBuffer != null) + { + if (dirtyBackBuffer) + { + backBuffer.clear(); + Graphics2D bbg = (Graphics2D)backBuffer.getGraphics(); + owner.paint(bbg); + bbg.dispose(); + dirtyBackBuffer = false; + } + backBuffer.drawPixels(g, 0, 0, 0, 0, 0, false ); + } + } + + protected void resizeEvent(int oldWidth, int oldHeight, + int width, int height) + { + dirtyBackBuffer = true; + if( drawableComponent() ) + backBuffer = new QtImage(width, height); + owner.setSize(width, height); + ComponentEvent e = new ComponentEvent(owner, + ComponentEvent.COMPONENT_RESIZED); + QtToolkit.eventQueue.postEvent(e); + } + + protected void showEvent() + { + if (owner instanceof Window) + { + WindowEvent e = new WindowEvent((Window)owner, + WindowEvent.WINDOW_OPENED); + QtToolkit.eventQueue.postEvent(e); + } + else + { + ComponentEvent e = new ComponentEvent(owner, + ComponentEvent.COMPONENT_SHOWN); + QtToolkit.eventQueue.postEvent(e); + } + } + + protected void hideEvent() + { + ComponentEvent e = new ComponentEvent(owner, + ComponentEvent.COMPONENT_HIDDEN); + QtToolkit.eventQueue.postEvent(e); + } + + private native Dimension getMinimumSizeNative(); + + private native Dimension getPreferredSizeNative(); + + // ************ Public methods ********************* + + /** Classpath-specific method */ + public void setEventMask(long x) + { + eventMask = x; + } + + + public boolean canDetermineObscurity() + { + return true; + } + + public int checkImage(Image img, + int w, + int h, + ImageObserver o) + { + return toolkit.checkImage(img, w, h, o); + } + + public void createBuffers(int numBuffers, BufferCapabilities caps) + throws AWTException + { + // FIXME + } + + public Image createImage(ImageProducer producer) + { + return toolkit.createImage(producer); + } + + public Image createImage(int width, int height) + { + return new QtImage(width, height); + } + + public void coalescePaintEvent(PaintEvent e) + { + // FIXME + } + + public VolatileImage createVolatileImage(int w, int h) + { + return new QtVolatileImage( w, h ); + } + + public void destroyBuffers() + { + // FIXME + } + + public void disable() + { + setEnabled(false); + } + + public void dispose() + { + disposeNative(); + } + + public void enable() + { + setEnabled(true); + } + + public void finalize() + { + dispose(); + } + + public void flip(BufferCapabilities.FlipContents contents) + { + // FIXME + } + + public Image getBackBuffer() + { + return backBuffer; + } + + public ColorModel getColorModel() + { + return toolkit.getColorModel(); + } + + public FontMetrics getFontMetrics(Font font) + { + return new QtFontMetrics( font, getGraphics() ); + } + + public Graphics getGraphics() + { + if( backBuffer == null) + { + Rectangle r = owner.getBounds(); + backBuffer = new QtImage( r.width, r.height ); + } + dirtyBackBuffer = true; + return backBuffer.getGraphics(); + } + + public GraphicsConfiguration getGraphicsConfiguration() + { + int id = whichScreen(); // get the ID of the screen the widget is on. + GraphicsDevice[] devs = QtToolkit.graphicsEnv.getScreenDevices(); + return devs[id].getDefaultConfiguration(); + } + + public native Point getLocationOnScreen(); + + public Dimension getMinimumSize() + { + Dimension d = getMinimumSizeNative(); + if(d == null) + return new Dimension(0, 0); + return d; + } + + public Dimension getPreferredSize() + { + Dimension d = getPreferredSizeNative(); + if(d == null) + return owner.getSize(); + return d; + } + + public Toolkit getToolkit() + { + return toolkit; + } + + public native boolean handlesWheelScrolling(); + + public void hide() + { + setVisible(false); + } + + public native boolean isFocusable(); + + public boolean isFocusTraversable() + { + // FIXME + return false; + } + + public native boolean isObscured(); + + public Dimension minimumSize() + { + return getMinimumSize(); + } + + public Dimension preferredSize() + { + return getPreferredSize(); + } + + public native void requestFocus(); + + public boolean requestFocus (Component source, boolean bool1, + boolean bool2, long x) + { + // FIXME + return true; + } + + public void reshape(int x, + int y, + int width, + int height) + { + dirtyBackBuffer = true; + setBounds( x, y, width, height ); + } + + public void setBackground(Color c) + { + if(c == null && !settingUp) + return; + setGround(c.getRed(), c.getGreen(), c.getBlue(), false); + } + + public void setBounds(int x, int y, int width, int height) + { + if(width > 0 && height > 0) + backBuffer = new QtImage(width, height); + setBoundsNative(x, y, width, height); + } + + public void setCursor(Cursor cursor) + { + if (cursor != null) + setCursor(cursor.getType()); + } + + public native void setEnabled(boolean b); + + public void setFont(Font f) + { + if( f == null || f.getPeer() == null) + throw new IllegalArgumentException("Null font."); + setFontNative( (QtFontPeer)f.getPeer() ); + } + + public void setForeground(Color c) + { + if(c == null && !settingUp) + return; + setGround(c.getRed(), c.getGreen(), c.getBlue(), true); + } + + public native void setVisible(boolean b); + + public void show() + { + setVisible(true); + } + + public void handleEvent (AWTEvent e) + { + int eventID = e.getID(); + switch (eventID) + { + case ComponentEvent.COMPONENT_SHOWN: + case PaintEvent.PAINT: + case PaintEvent.UPDATE: + dirtyBackBuffer = true; + QtUpdate(); + break; + case KeyEvent.KEY_PRESSED: + // FIXME + break; + case KeyEvent.KEY_RELEASED: + // FIXME + break; + } + } + + public void paint(Graphics g) + { + // We don't need to do anything here. + } + + public boolean prepareImage(Image img, + int w, + int h, + ImageObserver o) + { + return toolkit.prepareImage(img, w, h, o); + } + + public void print(Graphics g) + { + // FIXME + } + + /** + * Schedules a timed repaint. + */ + public void repaint(long tm, + int x, + int y, + int width, + int height) + { + Timer t = new Timer(); + t.schedule(new RepaintTimerTask(x, y, width, height), tm); + } + + /** + * Update the cursor (note that setCursor is usually not called) + */ + public void updateCursorImmediately() + { + if (owner.getCursor() != null) + setCursor(owner.getCursor().getType()); + } + + /** + * Timed repainter + */ + private class RepaintTimerTask extends TimerTask + { + private int x, y, w, h; + RepaintTimerTask(int x, int y, int w, int h) + { + this.x=x; + this.y=y; + this.w=w; + this.h=h; + } + public void run() + { + QtUpdateArea(x, y, w, h); + } + } + +} diff --git a/gnu/java/awt/peer/qt/QtContainerPeer.java b/gnu/java/awt/peer/qt/QtContainerPeer.java new file mode 100644 index 000000000..25b5c1786 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtContainerPeer.java @@ -0,0 +1,97 @@ +/* QtContainerPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Component; +import java.awt.Insets; +import java.awt.peer.ContainerPeer; + +public class QtContainerPeer extends QtComponentPeer implements ContainerPeer +{ + public QtContainerPeer( QtToolkit kit, Component owner ) + { + super( kit, owner ); + } + + protected void init() + { + } + + protected void setup() + { + super.setup(); + } + + // ************ Public methods ********************* + public void beginLayout() + { + } + + public void beginValidate() + { + } + + public void endLayout() + { + // FIXME + QtUpdate(); + } + + public void endValidate() + { + } + + public Insets getInsets() + { + return new Insets(0, 0, 0, 0); + } + + public Insets insets() + { + return getInsets(); + } + + public boolean isPaintPending() + { + // FIXME etc. + return false; + } +} + + + diff --git a/gnu/java/awt/peer/qt/QtDialogPeer.java b/gnu/java/awt/peer/qt/QtDialogPeer.java new file mode 100644 index 000000000..0da2e4ebc --- /dev/null +++ b/gnu/java/awt/peer/qt/QtDialogPeer.java @@ -0,0 +1,75 @@ +/* QtDialogPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Dialog; +import java.awt.MenuBar; +import java.awt.Rectangle; +import java.awt.peer.DialogPeer; + +public class QtDialogPeer extends QtWindowPeer implements DialogPeer +{ + public QtDialogPeer( QtToolkit kit, Dialog owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setTitle( ((Dialog)owner).getTitle() ); + setResizable( ((Dialog)owner).isResizable() ); + setModal( ((Dialog)owner).isModal() ); + } + + native void setModal(boolean modal); + + private native void setBoundsNative(int x, int y, int width, int height, boolean fixed); + + // ************ Public methods ********************* + + public native void setResizable (boolean resizeable); + + public void setBounds(int x, int y, int width, int height) + { + setBoundsNative(x, y, width, height, + !((Dialog)owner).isResizable()); + } +} diff --git a/gnu/java/awt/peer/qt/QtFileDialogPeer.java b/gnu/java/awt/peer/qt/QtFileDialogPeer.java new file mode 100644 index 000000000..4937031aa --- /dev/null +++ b/gnu/java/awt/peer/qt/QtFileDialogPeer.java @@ -0,0 +1,84 @@ +/* QtFileDialogPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.FileDialog; +import java.io.FilenameFilter; +import java.awt.peer.FileDialogPeer; + +public class QtFileDialogPeer extends QtDialogPeer implements FileDialogPeer +{ + public QtFileDialogPeer( QtToolkit kit, FileDialog owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setMode( ((FileDialog)owner).getMode() ); + } + + /** + * Sets load or save mode + */ + private native void setMode(int mode); + + private void fileDialogDone(String path, String filename) + { + } + + // ************ Public methods ********************* + public void setFile (String file) + { + // FIXME + } + + public void setDirectory (String dir) + { + // FIXME + } + + public void setFilenameFilter (FilenameFilter ff) + { + // FIXME + } +} + diff --git a/gnu/java/awt/peer/qt/QtFontMetrics.java b/gnu/java/awt/peer/qt/QtFontMetrics.java new file mode 100644 index 000000000..e403239e9 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtFontMetrics.java @@ -0,0 +1,128 @@ +/* QtFontMetrics.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.geom.Rectangle2D; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.font.LineMetrics; + +public class QtFontMetrics extends FontMetrics +{ + + private long nativeObject; + private QtFontPeer peer; + + public QtFontMetrics( Font f ) + { + super( f ); + if(f.getPeer() == null || !(f.getPeer() instanceof QtFontPeer)) + throw new IllegalArgumentException("Invalid Font object."); + peer = (QtFontPeer) f.getPeer(); + init( peer ); + } + + public QtFontMetrics( Font f, Graphics g ) + { + super( f ); + if(f.getPeer() == null || !(f.getPeer() instanceof QtFontPeer)) + throw new IllegalArgumentException("Invalid Font object."); + if( !(g instanceof QtGraphics) ) + throw new IllegalArgumentException("Invalid graphics object."); + peer = (QtFontPeer) f.getPeer(); + initGraphics(peer, (QtGraphics)g ); + } + + QtFontMetrics( QtFontPeer f, Graphics g ) + { + super( null ); + if( !(g instanceof QtGraphics) ) + throw new IllegalArgumentException("Invalid graphics object."); + peer = f; + initGraphics(peer, (QtGraphics)g ); + } + + public QtFontMetrics( QtFontPeer fp ) + { + super( (Font)null ); + peer = fp; + init( peer ); + } + + private native void init(QtFontPeer fp); + + private native void initGraphics(QtFontPeer fp, QtGraphics g); + + private native void dispose(); + + native Rectangle2D getStringBounds(String s); + + // ****************** Package private *************************** + + native boolean canDisplay( char c ); + + // ****************** Public methods **************************** + + public native int getAscent(); + + public native int getDescent(); + + public native int getHeight(); + + public native int getLeading(); + + public native int getMaxAdvance(); + + public native int charWidth(char c); + + public int charsWidth(char[] chars, int off, int len) + { + return stringWidth( new String(chars, off, len) ); + } + + public native int stringWidth(String str); + + public Rectangle2D getStringBounds(String str, Graphics context) + { + QtFontMetrics fm = new QtFontMetrics(peer, context); + return fm.getStringBounds( str ); + } +} diff --git a/gnu/java/awt/peer/qt/QtFontPeer.java b/gnu/java/awt/peer/qt/QtFontPeer.java new file mode 100644 index 000000000..ce63577a8 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtFontPeer.java @@ -0,0 +1,207 @@ +/* QtFontPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.geom.Rectangle2D; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.font.LineMetrics; +import java.text.CharacterIterator; +import java.util.Locale; +import java.util.Map; +import java.awt.peer.FontPeer; + +import gnu.java.awt.peer.ClasspathFontPeer; + +public class QtFontPeer extends ClasspathFontPeer +{ + // Pointer to native QFont structure. + private long nativeObject; + private QtFontMetrics metrics; + + + public QtFontPeer (String name, int style) + { + this(name, style, 12); + } + + public QtFontPeer (String name, int style, int size) + { + super(name, style, size); + init(); + } + + public QtFontPeer (String name, Map attributes) + { + super(name, attributes); + init(); + } + + public void init() + { + if(this.familyName == null) + throw new IllegalArgumentException("null family name"); + if(this.familyName.equals("Helvetica")) + this.familyName = "sans serif"; + create(this.familyName, this.style, (int)this.size); + metrics = new QtFontMetrics(this); + } + + /** + * Creates the QFont object. + */ + private native void create(String name, int style, int size); + + /** + * Destroys the QFont. + */ + public native void dispose(); + + + // ****************** ClasspathFontPeer Methods. + + public boolean canDisplay (Font font, char c) + { + return metrics.canDisplay( c ); + } + + public int canDisplayUpTo (Font font, CharacterIterator i, + int start, int limit) + { + int index = start; + char c = i.setIndex( index ); + while( index <= limit ) + { + if(!canDisplay(font, c)) + return index; + index++; + c = i.next(); + } + return -1; + } + + public String getSubFamilyName (Font font, Locale locale) + { + throw new UnsupportedOperationException(); + } + + public String getPostScriptName (Font font) + { + throw new UnsupportedOperationException(); + } + + public int getNumGlyphs (Font font) + { + throw new UnsupportedOperationException(); + } + + public int getMissingGlyphCode (Font font) + { + throw new UnsupportedOperationException(); + } + + public byte getBaselineFor (Font font, char c) + { + throw new UnsupportedOperationException(); + } + + public String getGlyphName (Font font, int glyphIndex) + { + throw new UnsupportedOperationException(); + } + + public GlyphVector createGlyphVector (Font font, + FontRenderContext frc, + CharacterIterator ci) + { + throw new UnsupportedOperationException(); + } + + public GlyphVector createGlyphVector (Font font, + FontRenderContext ctx, + int[] glyphCodes) + { + throw new UnsupportedOperationException(); + } + + public GlyphVector layoutGlyphVector (Font font, + FontRenderContext frc, + char[] chars, int start, + int limit, int flags) + { + throw new UnsupportedOperationException(); + } + + public FontMetrics getFontMetrics (Font font) + { + return new QtFontMetrics( this ); + } + + public boolean hasUniformLineMetrics (Font font) + { + throw new UnsupportedOperationException(); + } + + public LineMetrics getLineMetrics (Font font, + CharacterIterator ci, + int begin, int limit, + FontRenderContext rc) + { + throw new UnsupportedOperationException(); + } + + public Rectangle2D getMaxCharBounds (Font font, + FontRenderContext rc) + { + throw new UnsupportedOperationException(); + } + + public Rectangle2D getStringBounds (Font font, + CharacterIterator ci, + int begin, int limit, + FontRenderContext frc) + { + int index = begin; + String s = "" + ci.setIndex( index ); + while( index++ <= limit ) + s = s + ci.next(); + return metrics.getStringBounds(s); + } +} diff --git a/gnu/java/awt/peer/qt/QtFramePeer.java b/gnu/java/awt/peer/qt/QtFramePeer.java new file mode 100644 index 000000000..56f6132e5 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtFramePeer.java @@ -0,0 +1,137 @@ +/* QtFramePeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Frame; +import java.awt.Image; +import java.awt.Insets; +import java.awt.MenuBar; +import java.awt.Rectangle; +import java.awt.peer.FramePeer; + +public class QtFramePeer extends QtWindowPeer implements FramePeer +{ + private int theState; // FIXME + + long frameObject; + + public QtFramePeer( QtToolkit kit, Frame owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setTitle( ((Frame)owner).getTitle() ); + } + + private native void setIcon(QtImage image); + + private native void setMaximizedBounds(int w, int h); + + private native void setMenu(QtMenuBarPeer mb); + + private native int menuBarHeight(); + + // ************ Public methods ********************* + + public void destroy() + { + dispose(); + } + + public int getState() + { + // FIXME + return theState; + } + + public Insets getInsets() + { + int mbHeight; + if( ((Frame)owner).getMenuBar() != null ) + mbHeight = menuBarHeight(); + else + mbHeight = 0; + + // FIXME : more accurate? + return new Insets(0, 0, mbHeight, 0); + } + + public void setIconImage(Image im) + { + if (im instanceof QtImage) + setIcon ((QtImage)im); + // FIXME + } + + public void setMaximizedBounds(Rectangle rect) + { + // FIXME + } + + public void setMenuBar(MenuBar mb) + { + if( mb != null) + { + QtMenuBarPeer mbpeer = (QtMenuBarPeer)mb.getPeer(); + if( mbpeer != null) + { + mbpeer.addMenus(); + setMenu( mbpeer ); + } + } + else + setMenu( null ); + } + + public void setResizable(boolean resizeable) + { + // FIXME + } + + public void setState(int s) + { + theState = s; + // FIXME + } + +} diff --git a/gnu/java/awt/peer/qt/QtGraphics.java b/gnu/java/awt/peer/qt/QtGraphics.java new file mode 100644 index 000000000..8fada89a0 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtGraphics.java @@ -0,0 +1,699 @@ +/* QtGraphics.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.AlphaComposite; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Composite; +import java.awt.GradientPaint; +import java.awt.GraphicsConfiguration; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.Rectangle; +import java.awt.Paint; +import java.awt.Polygon; +import java.awt.Shape; +import java.awt.Stroke; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.AffineTransform; +import java.awt.geom.PathIterator; +import java.awt.geom.Arc2D; +import java.awt.geom.Ellipse2D; +import java.awt.geom.Line2D; +import java.awt.geom.Rectangle2D; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.BufferedImageOp; +import java.awt.image.ImageObserver; +import java.awt.image.RenderedImage; +import java.awt.image.renderable.RenderableImage; + +import java.text.AttributedCharacterIterator; +import java.text.CharacterIterator; +import java.util.Map; + +/** + * QtGraphics is an abstract implementation of Graphics2D over a QPainter + * object. This is to be subclassed for different drawing contexts, + * which may have different requirements. + */ +public abstract class QtGraphics extends Graphics2D +{ + /** + * Native QPainter pointer. + */ + protected long nativeObject; + + private static final AffineTransform identity = new AffineTransform(); + + // Graphics state + protected Font font; // Current font. + protected Color color, bgcolor; // Current color and background color. + protected Shape clip; // Current clipping area. + protected Shape initialClip; // Initial clip bounds + protected AffineTransform xform; // Current transform + protected Stroke currentStroke; // the current stroke + protected boolean nativeStroking; // whether we're using Qt's stroking or not + protected Composite composite; // current composite operator + protected double currentAlpha; // current alpha + protected Paint currentPaint; // current paint + protected RenderingHints renderingHints; // the rendering hints. + + /** + * Owner Graphics, used by subcontext created by create() + * to avoid GC of the original context. + */ + Graphics parent; + + /** + * Do-nothing constructor. + */ + QtGraphics() + { + } + + /** + * Copying constructor - used by copy() and subclasses. + */ + QtGraphics(QtGraphics parent) + { + cloneNativeContext( parent ); + setFont( parent.getFont() ); + setAlpha( parent.currentAlpha ); + setBackground( parent.getBackground() ); + setColor( parent.getColor() ); + setClip( (initialClip = parent.getClip()) ); + setTransform( parent.getTransform() ); + setStroke( parent.getStroke() ); + setComposite( parent.getComposite() ); + setPaint( parent.getPaint() ); + setRenderingHints( parent.getRenderingHints() ); + } + + /** + * Set up some generic defaults. + */ + protected void setup() + { + font = new Font ("Dialog", Font.PLAIN, 12); + setTransform( identity ); + setStroke( new BasicStroke() ); + renderingHints = new RenderingHints( null ); + } + + public synchronized native void delete(); + public synchronized native void dispose(); + + // ********************** etc ******************************* + + private void resetClip() + { + AffineTransform current = getTransform(); + setTransform( identity ); + setClip( initialClip ); + setTransform( current ); + } + + // NOTE: Image here must be a QImage or wrapper! + protected native void initImage(Image image); + + // Creates a new native QPainter object on the same context. + private native void cloneNativeContext( QtGraphics parent ); + private native void setColor(int r, int g, int b, int a); + private native void drawNative( QPainterPath p ); + private native void fillNative( QPainterPath p ); + private native void setClipNative( QPainterPath p ); + private native void setClipRectNative( int x, int y, int w, int h ); + private native void intersectClipNative( QPainterPath p ); + private native void intersectClipRectNative( int x, int y, int w, int h ); + private native void setQtTransform(QMatrix m); + private native void setNativeStroke(QPen p); + private native void setNativeComposite(int alphaMode); + private native void drawStringNative(String string, double x, double y); + private native void setLinearGradient(int r1, int g1, int b1, + int r2, int g2, int b2, + double x1, double y1, + double x2, double y2, boolean cyclic); + private native void setAlphaNative(double alpha); + private native void setFontNative(QtFontPeer font); + private native QPainterPath getClipNative(); + + private void setAlpha(double alpha) + { + currentAlpha = alpha; + setAlphaNative(currentAlpha); + } + + // ************ Public methods ********************* + + /** + * Context-sensitive methods are declared abstract. + */ + public abstract Graphics create(); + + public abstract void copyArea(int x, int y, int width, int height, + int dx, int dy); + + public abstract GraphicsConfiguration getDeviceConfiguration(); + + + public Color getColor() + { + return new Color(color.getRed(), color.getGreen(), color.getBlue()); + } + + public void setColor(Color c) + { + this.color = c; + int alpha = (int)(c.getAlpha() * currentAlpha); + setColor(c.getRed(), c.getGreen(), c.getBlue(), alpha); + } + + public void setBackground(Color color) + { + bgcolor = new Color(color.getRed(), color.getGreen(), color.getBlue()); + } + + public Color getBackground() + { + return new Color(bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue()); + } + + public void setPaintMode() + { + } + + public void setXORMode(Color color) + { + // FIXME + } + + public boolean hit(Rectangle rect, Shape s, boolean onStroke) + { + if( onStroke ) + { + Shape stroked = currentStroke.createStrokedShape( s ); + return stroked.intersects( (double)rect.x, (double)rect.y, + (double)rect.width, (double)rect.height ); + } + return s.intersects( (double)rect.x, (double)rect.y, + (double)rect.width, (double)rect.height ); + } + + // ******************* Font *********************** + public Font getFont() + { + return font; + } + + public void setFont(Font font) + { + this.font = font; + if(font.getPeer() != null && font.getPeer() instanceof QtFontPeer) + setFontNative( (QtFontPeer)font.getPeer() ); + } + + public FontMetrics getFontMetrics(Font font) + { + return new QtFontMetrics(font, this); + } + + // ***************** Clipping ********************* + + /** + * Intersects the current clip with the shape + */ + public void clip(Shape s) + { + intersectClipNative( new QPainterPath( s ) ); + } + + public void clipRect(int x, int y, int width, int height) + { + intersectClipRectNative( x, y, width, height ); + } + + public void setClip(int x, int y, int width, int height) + { + setClipRectNative( x, y, width, height ); + } + + public Shape getClip() + { + return getClipNative().getPath(); + } + + public native Rectangle getClipBounds(); + + /** + * Sets the clip + */ + public void setClip(Shape clip) + { + if (clip == null) + resetClip(); + else + setClipNative(new QPainterPath( clip )); + } + + // ***************** Drawing primitives ********************* + + public void draw(Shape s) + { + if( nativeStroking ) + drawNative( new QPainterPath(s) ); + else + fillNative( new QPainterPath( currentStroke.createStrokedShape( s ) ) ); + } + + public void fill(Shape s) + { + fillNative( new QPainterPath(s) ); + } + + public void drawLine(int x1, int y1, int x2, int y2) + { + if( nativeStroking ) + drawNative( new QPainterPath((double)x1, (double)y1, (double)x2, (double)y2, true) ); + else + draw( new Line2D.Double((double)x1, (double)y1, (double)x2, (double)y2) ); + } + + public void drawRect(int x, int y, int width, int height) + { + if( nativeStroking ) + drawNative( new QPainterPath((double)x, (double)y, + (double)width, (double)height) ); + else + fillNative( new QPainterPath + ( currentStroke.createStrokedShape + (new Rectangle2D.Double + ((double)x, (double)y, + (double)width, (double)height) ) ) ); + } + + public void fillRect(int x, int y, int width, int height) + { + fillNative( new QPainterPath( x, y, width, height ) ); + } + + public void clearRect(int x, int y, int width, int height) + { + Color c = color; + setColor( bgcolor ); // FIXME + fillRect( x, y, width, height ); + setColor( c ); + } + + public void drawRoundRect(int x, int y, int width, int height, + int arcWidth, int arcHeight) + { + draw( new RoundRectangle2D.Double(x, y, width, height, + arcWidth, arcHeight) ); + } + + public void fillRoundRect(int x, int y, int width, int height, + int arcWidth, int arcHeight) + { + fill( new RoundRectangle2D.Double(x, y, width, height, + arcWidth, arcHeight) ); + } + + public void drawOval(int x, int y, int width, int height) + { + draw( new Ellipse2D.Double((double)x, (double)y, + (double)width, (double)height) ); + } + + public void fillOval(int x, int y, int width, int height) + { + fill( new Ellipse2D.Double(x, y, width, height) ); + } + + public void drawArc(int x, int y, int width, int height, + int arcStart, int arcAngle) + { + draw( new Arc2D.Double(x, y, width, height, arcStart, arcAngle, + Arc2D.OPEN) ); + } + + public void fillArc(int x, int y, int width, int height, + int arcStart, int arcAngle) + { + fill( new Arc2D.Double(x, y, width, height, arcStart, arcAngle, + Arc2D.CHORD) ); + } + + public void drawPolyline(int xPoints[], int yPoints[], int npoints) + { + for( int i = 0; i < npoints - 1; i++) + drawLine(xPoints[i], yPoints[i], xPoints[i + 1], yPoints[i + 1]); + } + + public void drawPolygon(int xPoints[], int yPoints[], int npoints) + { + draw( new Polygon(xPoints, yPoints, npoints) ); + } + + public void fillPolygon(int xPoints[], int yPoints[], int npoints) + { + fill( new Polygon(xPoints, yPoints, npoints) ); + } + + public native void fill3DRect(int x, int y, int width, int height, boolean raised); + + public native void draw3DRect(int x, int y, int width, int height, boolean raised); + + // *********************** Text rendering ************************* + + public void drawString(String string, int x, int y) + { + drawStringNative(string, (double)x, (double)y); + } + + public void drawString(String string, float x, float y) + { + drawStringNative(string, (double)x, (double)y); + } + + public void drawString (AttributedCharacterIterator ci, int x, int y) + { + // FIXME - to something more correct ? + String s = ""; + for(char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) + s += c; + drawString(s, x, y); + } + + public void drawString(AttributedCharacterIterator ci, + float x, float y) + { + // FIXME - to something more correct ? + String s = ""; + for(char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) + s += c; + drawString(s, x, y); + } + + public void drawGlyphVector(GlyphVector v, float x, float y) + { + throw new RuntimeException("Not implemented"); + } + + // ******************* Image drawing ****************************** + public boolean drawImage(Image image, + AffineTransform Tx, + ImageObserver obs) + { + if (image instanceof QtImage) + return ((QtImage)image).drawImage(this, new QMatrix( Tx ), obs); + + return (new QtImage(image.getSource())).drawImage(this, + new QMatrix( Tx ), + obs); + } + + public boolean drawImage(Image image, int x, int y, Color bgcolor, + ImageObserver observer) + { + if (image instanceof QtImage) + return ((QtImage)image).drawImage (this, x, y, bgcolor, observer); + return (new QtImage(image.getSource())).drawImage (this, x, y, + bgcolor, observer); + } + + public boolean drawImage(Image image, + int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + Color bgcolor, ImageObserver observer) + { + if (image instanceof QtImage) + return ((QtImage)image).drawImage(this, dx1, dy1, dx2, dy2, + sx1, sy1, sx2, sy2, bgcolor, observer); + + return (new QtImage(image.getSource())).drawImage(this, dx1, dy1, + dx2, dy2, + sx1, sy1, sx2, sy2, + bgcolor, observer); + } + + public boolean drawImage(Image image, int x, int y, + int width, int height, Color bgcolor, + ImageObserver observer) + { + if (image instanceof QtImage) + return ((QtImage)image).drawImage (this, x, y, width, height, + bgcolor, observer); + return (new QtImage(image.getSource())).drawImage (this, x, y, + width, height, + bgcolor, observer); + } + + public boolean drawImage(Image image, int x, int y, int width, int height, + ImageObserver observer) + { + return drawImage(image, x, y, width, height, null, observer); + } + + public boolean drawImage(Image image, int x, int y, ImageObserver observer) + { + return drawImage(image, x, y, null, observer); + } + + public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) + { + return drawImage(image, dx1, dy1, dx2, dy2, + sx1, sy1, sx2, sy2, null, observer); + } + + // *********************** Transform methods ************************* + public AffineTransform getTransform() + { + return new AffineTransform( xform ); + } + + public void setTransform(AffineTransform Tx) + { + xform = new AffineTransform( Tx ); + setQtTransform( new QMatrix( xform ) ); + } + + public void rotate(double theta) + { + xform.rotate( theta ); + setQtTransform( new QMatrix( xform ) ); + } + + public void rotate(double theta, double x, double y) + { + xform.rotate(theta, x, y); + setQtTransform( new QMatrix( xform ) ); + } + + public void scale(double sx, double sy) + { + xform.scale(sx, sy); + setQtTransform( new QMatrix( xform ) ); + } + + public void shear(double shx, double shy) + { + xform.shear(shx, shy); + setQtTransform( new QMatrix( xform ) ); + } + + public void transform(AffineTransform Tx) + { + xform.concatenate( Tx ); + setQtTransform( new QMatrix( xform ) ); + } + + public void translate(double tx, double ty) + { + xform.translate( tx, ty ); + setQtTransform( new QMatrix( xform ) ); + } + + public void translate(int x, int y) + { + translate((double)x, (double)y); + } + + // *************** Stroking, Filling, Compositing ***************** + public void setStroke(Stroke s) + { + try // ..to convert the stroke into a native one. + { + QPen pen = new QPen( s ); + nativeStroking = true; + setNativeStroke( pen ); + setColor( color ); + } + catch (IllegalArgumentException e) + { + nativeStroking = false; + } + currentStroke = s; + } + + public Stroke getStroke() + { // FIXME: return copy? + return currentStroke; + } + + public void setComposite(Composite comp) + { + if( comp == null) + { + setNativeComposite( AlphaComposite.SRC_OVER ); + return; + } + + if( comp instanceof AlphaComposite ) + { + if( ((AlphaComposite)comp).getRule() != AlphaComposite.XOR ) + setAlpha( ((AlphaComposite)comp).getAlpha() ); + setNativeComposite( ((AlphaComposite)comp).getRule() ); + composite = comp; + } + else + throw new UnsupportedOperationException("We don't support custom"+ + " composites yet."); + } + + public Composite getComposite() + { + return composite; + } + + public void setPaint(Paint p) + { + if( p == null ) + return; + + // FIXME + currentPaint = p; + if( p instanceof GradientPaint ) + { + GradientPaint lg = (GradientPaint)p; + setLinearGradient(lg.getColor1().getRed(), lg.getColor1().getGreen(), + lg.getColor1().getBlue(), lg.getColor2().getRed(), + lg.getColor2().getGreen(), lg.getColor2().getBlue(), + lg.getPoint1().getX(), lg.getPoint1().getY(), + lg.getPoint2().getX(), lg.getPoint2().getY(), + lg.isCyclic() ); + return; + } + if( p instanceof Color ) + { + setColor((Color) p); + return; + } + throw new UnsupportedOperationException("We don't support custom"+ + " paints yet."); + } + + public Paint getPaint() + { + // FIXME + return currentPaint; + } + + // ********************** Rendering Hints ************************* + + public void addRenderingHints(Map hints) + { + renderingHints.putAll( hints ); + } + + public Object getRenderingHint(RenderingHints.Key hintKey) + { + return renderingHints.get( hintKey ); + } + + public RenderingHints getRenderingHints() + { + return new RenderingHints( renderingHints ); + } + + public void setRenderingHints(Map hints) + { + renderingHints = new RenderingHints( hints ); + updateRenderingHints(); + } + + public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) + { + renderingHints.put( hintKey, hintValue ); + updateRenderingHints(); + } + + private void updateRenderingHints() + { + // FIXME - update native settings. + } + + ////////////////////////////// unimplemented ///////////////////// + + public FontRenderContext getFontRenderContext() + { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void drawRenderableImage(RenderableImage image, AffineTransform xform) + { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void drawRenderedImage(RenderedImage image, AffineTransform xform) + { + throw new UnsupportedOperationException("Not implemented yet"); + } + + public void drawImage(BufferedImage image, BufferedImageOp op, int x, int y) + { + throw new UnsupportedOperationException("Not implemented yet"); + } +} + diff --git a/gnu/java/awt/peer/qt/QtGraphicsEnvironment.java b/gnu/java/awt/peer/qt/QtGraphicsEnvironment.java new file mode 100644 index 000000000..142b140cf --- /dev/null +++ b/gnu/java/awt/peer/qt/QtGraphicsEnvironment.java @@ -0,0 +1,108 @@ +/* QtGraphicsEnvironment.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.image.BufferedImage; +import java.util.Locale; + +public class QtGraphicsEnvironment extends GraphicsEnvironment +{ + QtToolkit toolkit; + GraphicsDevice[] screens; + + public QtGraphicsEnvironment (QtToolkit tk) + { + super(); + toolkit = tk; + // Get the number of screens from Qt. + int n = toolkit.numScreens(); + + /** + * Create the screen device objects + */ + screens = new GraphicsDevice[ n ]; + for(int i = 0; i < n; i++) + screens[ i ] = new QtScreenDevice( i ); + } + + public Font[] getAllFonts () + { + String[] fonts = getAvailableFontFamilyNames(); + Font[] fontObjs = new Font[fonts.length]; + for( int i = 0; i < fonts.length; i++) + fontObjs[i] = new Font(fonts[i], Font.PLAIN, 12); + return fontObjs; + } + + public String[] getAvailableFontFamilyNames() + { + return toolkit.getFontList(); + } + + public String[] getAvailableFontFamilyNames(Locale l) + { + return getAvailableFontFamilyNames(); + } + + public GraphicsDevice getDefaultScreenDevice () + { + return screens[ toolkit.defaultScreen() ]; + } + + public Graphics2D createGraphics (BufferedImage image) + { + return (Graphics2D)image.getGraphics(); + } + + public GraphicsDevice[] getScreenDevices() + { + return screens; + } + + public QtToolkit getToolkit() + { + return toolkit; + } +} + + diff --git a/gnu/java/awt/peer/qt/QtImage.java b/gnu/java/awt/peer/qt/QtImage.java new file mode 100644 index 000000000..6289f2825 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtImage.java @@ -0,0 +1,588 @@ +/* QtImage.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Graphics; +import java.awt.Color; +import java.awt.Image; +import java.awt.image.ColorModel; +import java.awt.image.DirectColorModel; +import java.awt.image.MemoryImageSource; +import java.awt.image.ImageConsumer; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.io.File; +import java.io.IOException; +import java.io.ByteArrayOutputStream; +import java.io.BufferedInputStream; +import java.net.URL; +import java.util.Hashtable; +import java.util.Vector; + +/** + * QtImage - wraps a QImage + * + */ +public class QtImage extends Image +{ + int width = -1, height = -1; + + /** + * Properties. + */ + Hashtable props; + + /** + * Loaded or not flag, for asynchronous compatibility. + */ + boolean isLoaded; + + /** + * Pointer to the QImage + */ + long nativeObject; + + /** + * Observer queue. + */ + Vector observers; + + /** + * Error flag for loading. + */ + boolean errorLoading; + + /** + * Original source, if created from an ImageProducer. + */ + ImageProducer source; + + /* + * The 32-bit AARRGGBB format the uses. + */ + static ColorModel nativeModel = new DirectColorModel(32, + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + + /** + * Clears the image to RGBA 0 + */ + public native void clear(); + + /** + * Returns a copy of the pixel data as a java array. + */ + private native int[] getPixels(); + + /** + * Sets the pixel data from a java array. + */ + private native void setPixels(int[] pixels); + + /** + * Loads an image + */ + private native boolean loadImage(String name); + + /** + * Loads an image from data. + */ + private native boolean loadImageFromData(byte[] data); + + /** + * Allocates a QImage + */ + private native void createImage(); + + /** + * Frees the above. + */ + private synchronized native void freeImage(); + + /** + * Sets the image to scaled copy of src image. hints are rendering hints. + */ + private native void createScaledImage(QtImage src, int hints); + + /** + * Draws the image optionally composited. + */ + native void drawPixels (QtGraphics gc, + int bg_red, int bg_green, int bg_blue, + int x, int y, + boolean composite); + /** + * Draws the image, optionally scaled and composited. + */ + private native void drawPixelsScaled (QtGraphics gc, + int bg_red, int bg_green, int bg_blue, + int x, int y, int width, int height, + boolean composite); + + /** + * Draws the image transformed. + */ + private native void drawPixelsTransformed (QtGraphics gc, QMatrix transform); + + /** + * Draws the image scaled flipped and optionally composited. + */ + private native void drawPixelsScaledFlipped (QtGraphics gc, + int bg_red, int bg_green, + int bg_blue, + boolean flipX, boolean flipY, + int srcX, int srcY, + int srcWidth, int srcHeight, + int dstX, int dstY, + int dstWidth, int dstHeight, + boolean composite); + + /** + * Creates the image from an ImageProducer. May result in an error image. + */ + public QtImage (ImageProducer producer) + { + isLoaded = false; + observers = new Vector(); + source = producer; + errorLoading = false; + if( producer != null ) + source.startProduction(new QtImageConsumer(this, source)); + } + + /** + * Creates the image from a URL. May result in an error image. + */ + public QtImage (URL url) + { + isLoaded = false; + observers = new Vector(); + errorLoading = false; + ByteArrayOutputStream baos = new ByteArrayOutputStream( 5000 ); + try + { + BufferedInputStream bis = new BufferedInputStream(url.openStream()); + + byte[] buf = new byte[5000]; + int n = 0; + + while ( (n = bis.read( buf )) != -1 ) + baos.write(buf, 0, n); + bis.close(); + } + catch(IOException e) + { + throw new IllegalArgumentException("Couldn't load image."); + } + if ( loadImageFromData( baos.toByteArray() ) != true ) + throw new IllegalArgumentException("Couldn't load image."); + + isLoaded = true; + observers = null; + props = new Hashtable(); + } + + /** + * Constructs a QtImage by loading a given file. + * + * @throws IllegalArgumentException if the image could not be loaded. + */ + public QtImage (String filename) + { + File f = new File(filename); + observers = null; + props = new Hashtable(); + try + { + String fn = f.getCanonicalPath(); + if (loadImage( fn ) != true) + { + errorLoading = true; + isLoaded = false; + return; + } + } + catch(IOException e) + { + errorLoading = true; + isLoaded = false; + return; + } + + errorLoading = false; + isLoaded = true; + } + + /** + * Constructs a QtImage from a byte array of an image file. + * + * @throws IllegalArgumentException if the image could not be loaded. + */ + public QtImage (byte[] data) + { + if (loadImageFromData(data) != true) + throw new IllegalArgumentException("Couldn't load image."); + + isLoaded = true; + observers = null; + errorLoading = false; + props = new Hashtable(); + } + + /** + * Constructs an empty QtImage. + */ + public QtImage (int width, int height) + { + this.width = width; + this.height = height; + props = new Hashtable(); + isLoaded = true; + observers = null; + errorLoading = false; + createImage(); + clear(); + } + + /** + * Constructs a scaled version of the src bitmap, using Qt + */ + private QtImage (QtImage src, int width, int height, int hints) + { + this.width = width; + this.height = height; + props = new Hashtable(); + isLoaded = true; + observers = null; + errorLoading = false; + + createScaledImage(src, hints); + } + + /** + * Callback from the image consumer. + */ + public void setImage(int width, int height, + int[] pixels, Hashtable properties) + { + this.width = width; + this.height = height; + props = (properties != null) ? properties : new Hashtable(); + + if (width <= 0 || height <= 0 || pixels == null) + { + errorLoading = true; + return; + } + + isLoaded = true; + deliver(); + createImage(); + setPixels(pixels); + } + + // java.awt.Image methods //////////////////////////////////////////////// + + public int getWidth (ImageObserver observer) + { + if (addObserver(observer)) + return -1; + + return width; + } + + public int getHeight (ImageObserver observer) + { + if (addObserver(observer)) + return -1; + + return height; + } + + public Object getProperty (String name, ImageObserver observer) + { + if (addObserver(observer)) + return UndefinedProperty; + + Object value = props.get (name); + return (value == null) ? UndefinedProperty : value; + } + + /** + * Returns the source of this image. + */ + public ImageProducer getSource () + { + if (!isLoaded) + return null; + return new MemoryImageSource(width, height, nativeModel, getPixels(), + 0, width); + } + + /** + * Creates a Graphics context for this image. + */ + public Graphics getGraphics () + { + if (!isLoaded) + return null; + + return new QtImageGraphics(this); + } + + /** + * Returns a scaled instance of this image. + */ + public Image getScaledInstance(int width, + int height, + int hints) + { + if (width <= 0 || height <= 0) + throw new IllegalArgumentException("Width and height of scaled bitmap"+ + "must be >= 0"); + + return new QtImage(this, width, height, hints); + } + + /** + * If the image is loaded and comes from an ImageProducer, + * regenerate the image from there. + * + * I have no idea if this is ever actually used. Since QtImage can't be + * instantiated directly, how is the user to know if it was created from + * an ImageProducer or not? + */ + public synchronized void flush () + { + if (isLoaded && source != null) + { + observers = new Vector(); + isLoaded = false; + freeImage(); + source.startProduction(new QtImageConsumer(this, source)); + } + } + + public void finalize() + { + if (isLoaded) + freeImage(); + } + + public void dispose() + { + finalize(); + } + + /** + * Returns the image status, used by QtToolkit + */ + public int checkImage (ImageObserver observer) + { + if (addObserver(observer)) + { + if (errorLoading == true) + return ImageObserver.ERROR; + else + return 0; + } + + return ImageObserver.ALLBITS | ImageObserver.WIDTH | ImageObserver.HEIGHT; + } + + // Drawing methods //////////////////////////////////////////////// + + /** + * Draws an image with eventual scaling/transforming. + */ + public boolean drawImage (QtGraphics g, QMatrix matrix, + ImageObserver observer) + { + if (addObserver(observer)) + return false; + + drawPixelsTransformed (g, matrix); + + return true; + } + + /** + * Draws an image to the QtGraphics context, at (x,y) with optional + * compositing with a background color. + */ + public boolean drawImage (QtGraphics g, int x, int y, + Color bgcolor, ImageObserver observer) + { + if (addObserver(observer)) + return false; + + if(bgcolor != null) + drawPixels(g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), x, y, true); + else + drawPixels(g, 0, 0, 0, x, y, false); + + return true; + } + + /** + * Draws an image to the QtGraphics context, at (x,y) scaled to + * width and height, with optional compositing with a background color. + */ + public boolean drawImage (QtGraphics g, int x, int y, int width, int height, + Color bgcolor, ImageObserver observer) + { + if (addObserver(observer)) + return false; + + if(bgcolor != null) + drawPixelsScaled(g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), x, y, width, height, true); + else + drawPixelsScaled(g, 0, 0, 0, x, y, width, height, false); + + return true; + } + + /** + * Draws an image with eventual scaling/transforming. + */ + public boolean drawImage (QtGraphics g, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + Color bgcolor, ImageObserver observer) + { + if (addObserver(observer)) + return false; + + boolean flipX = (dx1 > dx2)^(sx1 > sx2); + boolean flipY = (dy1 > dy2)^(sy1 > sy2); + int dstWidth = Math.abs (dx2 - dx1); + int dstHeight = Math.abs (dy2 - dy1); + int srcWidth = Math.abs (sx2 - sx1); + int srcHeight = Math.abs (sy2 - sy1); + int srcX = (sx1 < sx2) ? sx1 : sx2; + int srcY = (sy1 < sy2) ? sy1 : sy2; + int dstX = (dx1 < dx2) ? dx1 : dx2; + int dstY = (dy1 < dy2) ? dy1 : dy2; + + // Clipping. This requires the dst to be scaled as well, + if (srcWidth > width) + { + dstWidth = (int)((double)dstWidth*((double)width/(double)srcWidth)); + srcWidth = width - srcX; + } + + if (srcHeight > height) + { + dstHeight = (int)((double)dstHeight*((double)height/(double)srcHeight)); + srcHeight = height - srcY; + } + + if (srcWidth + srcX > width) + { + dstWidth = (int)((double)dstWidth * (double)(width - srcX)/(double)srcWidth); + srcWidth = width - srcX; + } + + if (srcHeight + srcY > height) + { + dstHeight = (int)((double)dstHeight * (double)(width - srcY)/(double)srcHeight); + srcHeight = height - srcY; + } + + if ( srcWidth <= 0 || srcHeight <= 0 || dstWidth <= 0 || dstHeight <= 0) + return true; + + if(bgcolor != null) + drawPixelsScaledFlipped (g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), + flipX, flipY, + srcX, srcY, + srcWidth, srcHeight, + dstX, dstY, + dstWidth, dstHeight, + true); + else + drawPixelsScaledFlipped (g, 0, 0, 0, flipX, flipY, + srcX, srcY, srcWidth, srcHeight, + dstX, dstY, dstWidth, dstHeight, + false); + return true; + } + + public native void copyArea(int x, int y, int width, int height, + int dx, int dy); + + // Private methods //////////////////////////////////////////////// + + /** + * Delivers notifications to all queued observers. + */ + private void deliver() + { + int flags = ImageObserver.HEIGHT | + ImageObserver.WIDTH | + ImageObserver.PROPERTIES | + ImageObserver.ALLBITS; + + if (observers != null) + for(int i=0; i < observers.size(); i++) + ((ImageObserver)observers.elementAt(i)). + imageUpdate(this, flags, 0, 0, width, height); + + observers = null; + } + + /** + * Adds an observer, if we need to. + * @return true if an observer was added. + */ + private boolean addObserver(ImageObserver observer) + { + if (!isLoaded) + { + if(observer != null) + if (!observers.contains (observer)) + observers.addElement (observer); + return true; + } + return false; + } +} diff --git a/gnu/java/awt/peer/qt/QtImageConsumer.java b/gnu/java/awt/peer/qt/QtImageConsumer.java new file mode 100644 index 000000000..aec0671f8 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtImageConsumer.java @@ -0,0 +1,154 @@ +/* QtImageConsumer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Graphics; +import java.awt.Image; +import java.awt.image.ColorModel; +import java.awt.image.DirectColorModel; +import java.awt.image.ImageConsumer; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.util.Hashtable; +import java.util.Vector; + +/** + * Helper class to QtImage. Sits and gathers pixels for a QtImage and then + * calls QtImage.setImage(). + * + * @author Sven de Marothy + */ +public class QtImageConsumer implements ImageConsumer +{ + private QtImage target; + private int width, height; + private Hashtable properties; + private int[] pixelCache = null; + private ImageProducer source; + + public QtImageConsumer(QtImage target, ImageProducer source) + { + this.target = target; + this.source = source; + } + + public synchronized void imageComplete (int status) + { + source.removeConsumer(this); + target.setImage(width, height, pixelCache, properties); + } + + public synchronized void setColorModel (ColorModel model) + { + // This method is to inform on what the most used color model + // in the image is, for optimization reasons. We ignore this + // information. + } + + public synchronized void setDimensions (int width, int height) + { + pixelCache = new int[width*height]; + + this.width = width; + this.height = height; + } + + public synchronized void setHints (int flags) + { + // This method informs us in which order the pixels are + // delivered, for progressive-loading support, etc. + // Since we wait until it's all loaded, we can ignore the hints. + } + + public synchronized void setPixels (int x, int y, int width, int height, + ColorModel cm, byte[] pixels, + int offset, int scansize) + { + setPixels (x, y, width, height, cm, convertPixels (pixels), offset, + scansize); + } + + public synchronized void setPixels (int x, int y, int width, int height, + ColorModel cm, int[] pixels, + int offset, int scansize) + { + if (pixelCache == null) + return; // Not sure this should ever happen. + + if (cm.equals(QtImage.nativeModel)) + for (int i = 0; i < height; i++) + System.arraycopy (pixels, offset + (i * scansize), + pixelCache, (y + i) * this.width + x, + width); + else + { + for (int i = 0; i < height; i++) + for (int j = 0; j < width; j++) + { + // get in AARRGGBB and convert to AABBGGRR + int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]); + byte b = (byte)(pix & 0xFF); + byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF); + pix &= 0xFF00FF00; + pix |= ((b & 0xFF) << 16); + pix |= (r & 0xFF); + pixelCache[(y + i) * this.width + x + j] = pix; + } + } + } + + /** + * This is an old method, no idea if it's correct. + */ + private int[] convertPixels (byte[] pixels) + { + int ret[] = new int[pixels.length]; + + for (int i = 0; i < pixels.length; i++) + ret[i] = pixels[i] & 0xFF; + + return ret; + } + + public synchronized void setProperties (Hashtable props) + { + this.properties = props; + } +} + + diff --git a/gnu/java/awt/peer/qt/QtImageGraphics.java b/gnu/java/awt/peer/qt/QtImageGraphics.java new file mode 100644 index 000000000..1f866a489 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtImageGraphics.java @@ -0,0 +1,139 @@ +/* QtImageGraphics.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Color; +import java.awt.GraphicsConfiguration; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Paint; +import java.awt.Rectangle; +import java.util.Stack; + +/** + * QtComponentPainter is a Graphics2D context for painting to QtImage and + * QtVolatileImages. + */ +public class QtImageGraphics extends QtGraphics +{ + Image parentImage; + Stack owners; + QtImageGraphics topParent; + + public QtImageGraphics(Image image) + { + if(!( image instanceof QtVolatileImage || image instanceof QtImage)) + throw new IllegalArgumentException("Cannot create QtImageGraphics for a non-QImage context."); + + owners = new Stack(); + owners.push(this); + topParent = null; + int w, h; + if(image instanceof QtImage) + { + w = ((QtImage)image).width; + h = ((QtImage)image).height; + } + else + { + w = ((QtVolatileImage)image).width; + h = ((QtVolatileImage)image).height; + } + + initImage( image ); + parentImage = image; + initialClip = new Rectangle( 0, 0, w, h ); + setClip( initialClip ); + setBackground(Color.white); // fixme + currentAlpha = 1.0; + setColor(Color.black); + setup(); + } + + /** + * Copying constructor + */ + QtImageGraphics( QtImageGraphics g ) + { + super( g ); + parentImage = g.parentImage; + if( g.topParent == null ) + topParent = g; + else + topParent = g.topParent; + topParent.owners.push( this ); + } + + public void dispose() + { + while(!owners.empty()) + ((QtImageGraphics)owners.pop()).delete(); + } + + + /** + * Create a copy of this context. + */ + public Graphics create() + { + return new QtImageGraphics( this ); + } + + /** + * Copy an area. + */ + public void copyArea(int x, int y, int width, int height, + int dx, int dy) + { + if(parentImage instanceof QtImage) + ((QtImage)parentImage).copyArea(x, y, width, height, dx, dy); + else + ((QtVolatileImage)parentImage).copyArea(x, y, width, height, dx, dy); + } + + /** + * Returns the GraphicsConfiguration of the context component. + */ + public GraphicsConfiguration getDeviceConfiguration() + { + throw new UnsupportedOperationException("Not implemented yet"); + } +} + + diff --git a/gnu/java/awt/peer/qt/QtLabelPeer.java b/gnu/java/awt/peer/qt/QtLabelPeer.java new file mode 100644 index 000000000..6e9c0734b --- /dev/null +++ b/gnu/java/awt/peer/qt/QtLabelPeer.java @@ -0,0 +1,62 @@ +/* QtLabelPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Label; +import java.awt.peer.LabelPeer; + +public class QtLabelPeer extends QtComponentPeer implements LabelPeer +{ + public QtLabelPeer( QtToolkit kit, Label owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setText( ((Label)owner).getText() ); + setAlignment( ((Label)owner).getAlignment() ); + } + + public native void setAlignment( int alignment ); + + public native void setText( String label ); +} diff --git a/gnu/java/awt/peer/qt/QtListPeer.java b/gnu/java/awt/peer/qt/QtListPeer.java new file mode 100644 index 000000000..0ea00ca4c --- /dev/null +++ b/gnu/java/awt/peer/qt/QtListPeer.java @@ -0,0 +1,139 @@ +/* QtListPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Dimension; +import java.awt.List; +import java.awt.peer.ListPeer; + +public class QtListPeer extends QtComponentPeer implements ListPeer +{ + public QtListPeer( QtToolkit kit, List owner ) + { + super( kit, owner ); + } + + public native void init(); + + protected void setup() + { + super.setup(); + List o = (List)owner; + String[] items = o.getItems(); + setMultipleMode(o.isMultipleMode()); + for (int i = 0; i < items.length; i++) + add(items[i], i); + int[] selected = o.getSelectedIndexes(); + for (int i = 0; i < selected.length; i++) + select(selected[i]); + } + + private native void select(int index, boolean selected); + + // ************ Public methods ********************* + + public native void add(String item, int index); + + public void addItem(String item, int index) + { + add(item, index); + } + + public void clear() + { + removeAll(); + } + + /** + * Deletes items from the starting index to the ending index (inclusive). + */ + public native void delItems(int start_index, int end_index); + + public void deselect(int index) + { + select(index, false); + } + + public native int[] getSelectedIndexes(); + + public native void makeVisible(int index); + + public Dimension minimumSize(int s) + { + return getMinimumSize(s); + } + + public Dimension preferredSize(int s) + { + return getPreferredSize(s); + } + + public void removeAll() + { + delItems(0, ((List)owner).getItemCount() - 1); + } + + public void select(int index) + { + select(index, true); + } + + /** + * Sets multiple-selection mode. + * WONTFIX: QAbstractItemView::MultiSelection does not work as it should + * in Qt 4.0.0, Trolltech bug reporter says this will be fixed in 4.1.0. + */ + public native void setMultipleMode(boolean multi); + + public void setMultipleSelections(boolean multi) + { + setMultipleMode(multi); + } + + public Dimension getPreferredSize(int s) + { + // FIXME + return getPreferredSize(); + } + + public Dimension getMinimumSize(int s) + { + // FIXME + return getMinimumSize(); + } +} diff --git a/gnu/java/awt/peer/qt/QtMenuBarPeer.java b/gnu/java/awt/peer/qt/QtMenuBarPeer.java new file mode 100644 index 000000000..7c71da01e --- /dev/null +++ b/gnu/java/awt/peer/qt/QtMenuBarPeer.java @@ -0,0 +1,103 @@ +/* QtMenuBarPeer.java -- Qt peer for a menu bar. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.peer.MenuBarPeer; +import java.util.Vector; + +public class QtMenuBarPeer extends QtMenuComponentPeer implements MenuBarPeer +{ + public QtMenuBarPeer( QtToolkit kit, MenuBar owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + } + + /** + * Recurses the menubar adding menus (and menu items), + * called from the Frame peer. + */ + void addMenus() + { + MenuBar o = (MenuBar)owner; + int help = (o.getHelpMenu() != null) ? 1 : 0; + for (int i = 0; i < o.getMenuCount() - help; i++) + addMenu( o.getMenu(i) ); + if(o.getHelpMenu() != null) + addHelpMenu( o.getHelpMenu() ); + } + + private native void addMenu( QtMenuPeer mp ); + + private native void addHelpMenu( QtMenuPeer mp ); + + private native void delMenu( QtMenuPeer mp ); + + // ************ Public methods ********************* + + public void addMenu( Menu m ) + { + if (m.getPeer() == null) + return; // throw null pointer exception? illegalstateexception? + ((QtMenuPeer)m.getPeer()).addItems(); + addMenu( (QtMenuPeer)m.getPeer() ); + } + + public void addHelpMenu( Menu m ) + { + if (m.getPeer() == null) + return; + ((QtMenuPeer)m.getPeer()).addItems(); + addHelpMenu( (QtMenuPeer)m.getPeer() ); + } + + public void delMenu( int index ) + { + Menu m = ((MenuBar)owner).getMenu( index ); + if(m != null) + delMenu( (QtMenuPeer)m.getPeer() ); + } +} + diff --git a/gnu/java/awt/peer/qt/QtMenuComponentPeer.java b/gnu/java/awt/peer/qt/QtMenuComponentPeer.java new file mode 100644 index 000000000..b6344fe42 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtMenuComponentPeer.java @@ -0,0 +1,77 @@ +/* QtMenuComponentPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.MenuComponent; +import java.awt.peer.MenuComponentPeer; + +public class QtMenuComponentPeer extends NativeWrapper + implements MenuComponentPeer +{ + protected QtToolkit toolkit; + protected MenuComponent owner; + + public QtMenuComponentPeer( QtToolkit kit, MenuComponent owner ) + { + this.toolkit = kit; + this.owner = owner; + nativeObject = 0; + callInit(); + setup(); + } + + protected native void callInit(); + + protected void init() + { + } + + protected void setup() + { + } + + public void finalize() + { + dispose(); + } + + // ************ Public methods ********************* + + public native void dispose(); + +} diff --git a/gnu/java/awt/peer/qt/QtMenuItemPeer.java b/gnu/java/awt/peer/qt/QtMenuItemPeer.java new file mode 100644 index 000000000..5baf74029 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtMenuItemPeer.java @@ -0,0 +1,100 @@ +/* QtMenuItemPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.CheckboxMenuItem; +import java.awt.event.ActionEvent; +import java.awt.peer.MenuItemPeer; +import java.awt.peer.CheckboxMenuItemPeer; + +public class QtMenuItemPeer extends QtMenuComponentPeer + implements MenuItemPeer, CheckboxMenuItemPeer +{ + public QtMenuItemPeer( QtToolkit toolkit, MenuItem owner ) + { + super(toolkit, owner); + } + + protected void init() + { + String label = ((MenuItem)owner).getLabel(); + create(label, label.equals("-"), (owner instanceof CheckboxMenuItem)); + } + + protected void setup() + { + } + + private native void create(String label, boolean isSeperator, boolean isCheckable); + + public void finalize() + { + dispose(); + } + + public native void dispose(); + + private void fireClick() + { + ActionEvent e = new ActionEvent(owner, + ActionEvent.ACTION_PERFORMED, + ((MenuItem)owner).getActionCommand()); + QtToolkit.eventQueue.postEvent(e); + } + + // ************ Public methods ********************* + + public void disable() + { + setEnabled(false); + } + + public void enable() + { + setEnabled(true); + } + + public native void setEnabled(boolean b); + + public native void setLabel(String label); + + public native void setState(boolean state); +} + diff --git a/gnu/java/awt/peer/qt/QtMenuPeer.java b/gnu/java/awt/peer/qt/QtMenuPeer.java new file mode 100644 index 000000000..2ad05ced5 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtMenuPeer.java @@ -0,0 +1,150 @@ +/* QtMenuPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.PopupMenu; +import java.awt.event.ActionEvent; +import java.awt.peer.MenuPeer; +import java.util.Vector; + +public class QtMenuPeer extends QtMenuComponentPeer implements MenuPeer +{ + Vector items; + boolean itemsAdded; + + public QtMenuPeer( QtToolkit kit, Menu owner ) + { + super( kit, owner ); + itemsAdded = false; + } + + protected native void init(); + + protected void setup() + { + items = new Vector(); + setLabel( ((Menu)owner).getLabel() ); + if( ((Menu)owner).isTearOff() ) + allowTearOff(); + } + + // Recurse the menu tree adding items, + // called from the MenuBar addMenus() method, called from the Frame peer. + void addItems() + { + if(!itemsAdded) + { + Menu o = (Menu)owner; + for( int i=0; i < o.getItemCount(); i++ ) + { + MenuItem ci = (MenuItem)o.getItem(i); + if (ci instanceof Menu && ci.getPeer() != null) + ((QtMenuPeer)ci.getPeer()).addItems(); + addItem( ci ); + } + itemsAdded = true; + } + } + + private void fireClick() + { + ActionEvent e = new ActionEvent(owner, + ActionEvent.ACTION_PERFORMED, + ((Menu)owner).getActionCommand()); + QtToolkit.eventQueue.postEvent(e); + } + + private native void allowTearOff(); + + private native long insertSeperator(); + + private native long insertItem(QtMenuItemPeer p); + + private native long insertMenu(QtMenuPeer menu); + + private native void delItem(long ptr); + + // ************ Public methods ********************* + + public void addItem( MenuItem item ) + { + long ptr; + if( item instanceof Menu || item instanceof PopupMenu) + ptr = insertMenu((QtMenuPeer)item.getPeer()); + else + { + QtMenuItemPeer p = (QtMenuItemPeer)item.getPeer(); + ptr = insertItem(p); + } + items.add(new Long(ptr)); + } + + public void addSeparator() + { + long ptr = insertSeperator(); + items.add(new Long(ptr)); + } + + public void delItem( int index ) + { + long ptr = ((Long)items.elementAt(index)).longValue(); + delItem(ptr); + items.removeElementAt(index); + } + + // Inherited methods.. + + public void disable() + { + setEnabled(false); + } + + public void enable() + { + setEnabled(true); + } + + public native void setEnabled(boolean enabled); + + public native void setLabel(String text); +} + + + diff --git a/gnu/java/awt/peer/qt/QtPanelPeer.java b/gnu/java/awt/peer/qt/QtPanelPeer.java new file mode 100644 index 000000000..8beb0eadb --- /dev/null +++ b/gnu/java/awt/peer/qt/QtPanelPeer.java @@ -0,0 +1,57 @@ +/* QtPanelPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Component; +import java.awt.peer.PanelPeer; +import java.awt.peer.LightweightPeer; + +public class QtPanelPeer extends QtContainerPeer implements PanelPeer, LightweightPeer +{ + public QtPanelPeer( QtToolkit kit, Component owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + } +} diff --git a/gnu/java/awt/peer/qt/QtPopupMenuPeer.java b/gnu/java/awt/peer/qt/QtPopupMenuPeer.java new file mode 100644 index 000000000..81577cc6c --- /dev/null +++ b/gnu/java/awt/peer/qt/QtPopupMenuPeer.java @@ -0,0 +1,82 @@ +/* QtPopupMenuPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Component; +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.Point; +import java.awt.PopupMenu; +import java.awt.Event; +import java.awt.event.ActionEvent; +import java.awt.peer.PopupMenuPeer; + +public class QtPopupMenuPeer extends QtMenuPeer implements PopupMenuPeer +{ + public QtPopupMenuPeer( QtToolkit kit, PopupMenu owner ) + { + super( kit, owner ); + } + + private native void showNative(int x, int y); + + // ************ Public methods ********************* + + /** + * Part of the older API, replaced by event version instead. + */ + public void show (Component origin, int x, int y) + { + if( origin == null ) + throw new NullPointerException("Null parent component."); + addItems(); + + Point p = origin.getLocationOnScreen(); + showNative( (int)p.getX() + x, (int)p.getY() + y ); + } + + public void show (Event e) + { + if (!(e.target instanceof Component)) + throw new IllegalArgumentException("Expecting a component Event target!"); + show((Component)e.target, e.x, e.y); + } +} + + + diff --git a/gnu/java/awt/peer/qt/QtScreenDevice.java b/gnu/java/awt/peer/qt/QtScreenDevice.java new file mode 100644 index 000000000..c2d73aed1 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtScreenDevice.java @@ -0,0 +1,116 @@ +/* QtScreenDevice.java -- Wrapper on a Qt screen Widget + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.DisplayMode; +import java.awt.GraphicsConfigTemplate; +import java.awt.Rectangle; +import java.awt.Window; + +public class QtScreenDevice extends GraphicsDevice +{ + private long nativeObject; + private int id; + private String IDstring; + QtScreenDeviceConfiguration config; + + public QtScreenDevice(int id) + { + this.id = id; + IDstring = "QtScreen" + id; + init( id ); + config = new QtScreenDeviceConfiguration(this); + } + + public native void init( int id ); + public native void dispose(); + + // Package-private methods used by QtScreenDeviceConfiguration + native Rectangle getBounds(); + native int getDpiX(); + native int getDpiY(); + native int depth(); + + // ****************** Public methods *********************** + + public GraphicsConfiguration getBestConfiguration(GraphicsConfigTemplate gct) + { + return config; + } + + public GraphicsConfiguration[] getConfigurations() + { + return new GraphicsConfiguration[]{ config }; + } + + public GraphicsConfiguration getDefaultConfiguration() + { + return config; + } + + public String getIDstring() + { + return IDstring; + } + + public int getType() + { + return TYPE_RASTER_SCREEN; + } + + public boolean isDisplayChangeSupported() + { + return false; + } + + public boolean isFullScreenSupported() + { + return false; + } + + public void setDisplayMode(DisplayMode dm) + { + } + + public void setFullScreenWindow(Window w) + { + } +} + diff --git a/gnu/java/awt/peer/qt/QtScreenDeviceConfiguration.java b/gnu/java/awt/peer/qt/QtScreenDeviceConfiguration.java new file mode 100644 index 000000000..a9241ee09 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtScreenDeviceConfiguration.java @@ -0,0 +1,141 @@ +/* QtScreenDeviceConfiguration.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.DisplayMode; +import java.awt.ImageCapabilities; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsConfigTemplate; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.VolatileImage; +import java.awt.geom.AffineTransform; + +public class QtScreenDeviceConfiguration extends GraphicsConfiguration { + + private QtScreenDevice owner; + private Rectangle bounds; + private double dpiX, dpiY; + private int depth; + + public QtScreenDeviceConfiguration(QtScreenDevice owner) + { + this.owner = owner; + bounds = owner.getBounds(); + dpiX = owner.getDpiX(); + dpiY = owner.getDpiY(); + depth = owner.depth(); + } + + public BufferedImage createCompatibleImage(int width, int height) + { + switch( depth ) + { + case 24: + return new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); + case 16: + return new BufferedImage(width, height, + BufferedImage.TYPE_USHORT_565_RGB); + case 8: + return new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED); + default: + case 32: + return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + } + } + + public BufferedImage createCompatibleImage(int width, int height, int transparency) + { + // FIXME: Take the transpareny flag into account? + // For now, ignore it and just use an alpha channel. + if(depth == 32) + return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + return createCompatibleImage(width, height); + } + + public VolatileImage createCompatibleVolatileImage(int width, int height) + { + return new QtVolatileImage( width, height ); + } + + public VolatileImage createCompatibleVolatileImage(int width, int height, + ImageCapabilities caps) + { + return createCompatibleVolatileImage( width, height ); + } + + public Rectangle getBounds() + { + return bounds; + } + + public ColorModel getColorModel() + { + // FIXME? + return QtToolkit.getDefaultToolkit().getColorModel(); + } + + public ColorModel getColorModel(int transparency) + { + // FIXME? + return QtToolkit.getDefaultToolkit().getColorModel(); + } + + public AffineTransform getDefaultTransform() + { + return new AffineTransform(); + } + + public GraphicsDevice getDevice() + { + return owner; + } + + /** + * Returns the transform which transforms from this display's resolution + * to a 72 DPI resolution. + */ + public AffineTransform getNormalizingTransform() + { + AffineTransform nTrans = new AffineTransform(); + nTrans.scale( 72.0 / dpiX, 72.0 / dpiY ); + return nTrans; + } +} diff --git a/gnu/java/awt/peer/qt/QtScrollPanePeer.java b/gnu/java/awt/peer/qt/QtScrollPanePeer.java new file mode 100644 index 000000000..02fa8fb22 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtScrollPanePeer.java @@ -0,0 +1,91 @@ +/* QtScrollPanePeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Adjustable; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.ScrollPane; +import java.awt.peer.ScrollPanePeer; + +public class QtScrollPanePeer extends QtContainerPeer implements ScrollPanePeer +{ + public QtScrollPanePeer( QtToolkit kit, ScrollPane owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setPolicy( ((ScrollPane)owner).getScrollbarDisplayPolicy() ); + } + + private native void setPolicy(int policy); + + // ************ Public methods ********************* + + public native void childResized(int width, int height); + + public native int getHScrollbarHeight(); + + public native int getVScrollbarWidth(); + + public native void setScrollPosition(int x, int y); + + public Insets getInsets() + { + // FIXME : more accurate? + return new Insets(5 + getHScrollbarHeight(), // Top + 5 + getVScrollbarWidth(), // Left + 5, // Bottom + 5); // Right + } + + public void setUnitIncrement(Adjustable item, int inc) + { + // FIXME + } + + public void setValue(Adjustable item, int value) + { + // FIXME + } +} diff --git a/gnu/java/awt/peer/qt/QtScrollbarPeer.java b/gnu/java/awt/peer/qt/QtScrollbarPeer.java new file mode 100644 index 000000000..838cca62d --- /dev/null +++ b/gnu/java/awt/peer/qt/QtScrollbarPeer.java @@ -0,0 +1,80 @@ +/* QtScrollbarPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Scrollbar; +import java.awt.event.AdjustmentEvent; +import java.awt.peer.ScrollbarPeer; + +public class QtScrollbarPeer extends QtComponentPeer implements ScrollbarPeer +{ + public QtScrollbarPeer( QtToolkit kit, Scrollbar owner ) + { + super( kit, owner ); + } + + public native void init(); + + protected void setup() + { + super.setup(); + Scrollbar o = (Scrollbar)owner; + setValues(o.getValue(), o.getVisible(), o.getMinimum(), o.getMaximum()); + setOrientation(o.getOrientation()); + setLineIncrement(o.getLineIncrement()); + setPageIncrement(o.getPageIncrement()); + } + + private native void setOrientation(int orientation); + + private void fireMoved(int type, int value) + { + AdjustmentEvent e = new AdjustmentEvent((Scrollbar)owner, + AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED, + type, value); + QtToolkit.eventQueue.postEvent(e); + } + + // ************ Public methods ********************* + + public native void setLineIncrement(int inc); + + public native void setPageIncrement(int inc); + + public native void setValues(int value, int visible, int min, int max); +} diff --git a/gnu/java/awt/peer/qt/QtTextAreaPeer.java b/gnu/java/awt/peer/qt/QtTextAreaPeer.java new file mode 100644 index 000000000..7f023f1e3 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtTextAreaPeer.java @@ -0,0 +1,155 @@ +/* QtTextAreaPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.TextArea; +import java.awt.peer.TextAreaPeer; + +public class QtTextAreaPeer extends QtComponentPeer implements TextAreaPeer +{ + public QtTextAreaPeer( QtToolkit kit, TextArea owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); +// setText(((TextArea)owner).getText()); +// setEditable(((TextArea)owner).isEditable()); + } + + /** + * Returns the start (start = true) or end (start = false) of the selection. + */ + private native int getSelection(boolean start); + + // ************ Public methods ********************* + + public long filterEvents(long filter) + { + return filter; + } + + public native int getCaretPosition(); + + public Rectangle getCharacterBounds(int pos) + { + // FIXME + return new Rectangle(0,0,0,0); + } + + public native int getIndexAtPoint(int x, int y); + +// public void reshape(int x, int y, +// int width, int height) +// { +// if(width != 0 || height != 0) +// super.reshape(x, y, width, height); +// else +// super.reshape(x, y, 10, 10); +// } + + public Dimension getMinimumSize(int rows, int cols) + { + // FIXME + return getMinimumSize(); + } + + public Dimension getPreferredSize(int rows, int cols) + { + // FIXME + return getPreferredSize(); + } + + public int getSelectionEnd() + { + return getSelection(false); + } + + public int getSelectionStart() + { + return getSelection(true); + } + + public native String getText(); + + public native void insert(String text, int pos); + + public void insertText(String text, int pos) + { + insert(text, pos); + } + + public Dimension minimumSize(int rows, int cols) + { + return getMinimumSize(rows, cols); + } + + public Dimension preferredSize(int rows, int cols) + { + return getPreferredSize(rows, cols); + } + + public void replaceRange(String insert, int start_pos, int end_pos) + { + // Not very efficient, no. + String text = getText(); + String right = text.substring(0, start_pos); + String left = text.substring(end_pos); + setText(right + insert + left); + } + + public void replaceText(String text, int start_pos, int end_pos) + { + replaceRange(text, start_pos, end_pos); + } + + public native void setText(String text); + + public native void select(int start_pos, int end_pos); + + public native void setEditable(boolean editable); + + public native void setCaretPosition(int pos); +} + diff --git a/gnu/java/awt/peer/qt/QtTextFieldPeer.java b/gnu/java/awt/peer/qt/QtTextFieldPeer.java new file mode 100644 index 000000000..151adb064 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtTextFieldPeer.java @@ -0,0 +1,143 @@ +/* QtTextFieldPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.TextField; +import java.awt.peer.TextFieldPeer; + +public class QtTextFieldPeer extends QtComponentPeer implements TextFieldPeer +{ + public QtTextFieldPeer( QtToolkit kit, TextField owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + setText(((TextField)owner).getText()); + setEditable(((TextField)owner).isEditable()); + } + + /** + * Returns the start (start = true) or end (start = false) of the selection. + */ + private native int getSelection(boolean start); + + private native Dimension getMinimumSizeNative(int columns); + + private native Dimension getPreferredSizeNative(int columns); + + // ************ Public methods ********************* + + public long filterEvents(long e) + { + return e; + } + + public native int getCaretPosition(); + + public Rectangle getCharacterBounds(int i) + { + return new Rectangle(0,0,0,0); + } + + public int getIndexAtPoint(int x, int y) + { + // FIXME + return 0; + } + + public Dimension getMinimumSize(int columns) + { + Dimension d = getMinimumSizeNative( columns ); + if ( d == null ) + return new Dimension(10, 10); + return d; + } + + public Dimension getPreferredSize(int columns) + { + Dimension d = getPreferredSizeNative( columns ); + if ( d == null ) + return owner.getSize(); + return d; + } + + public int getSelectionEnd() + { + return getSelection(false); + } + + public int getSelectionStart() + { + return getSelection(true); + } + + public native String getText(); + + public Dimension minimumSize(int cols) + { + return getMinimumSize(cols); + } + + public Dimension preferredSize(int cols) + { + return getPreferredSize(cols); + } + + public native void select(int selStart, int selEnd); + + public native void setCaretPosition(int pos); + + public void setEchoCharacter(char c) + { + setEchoChar(c); + } + + public native void setEchoChar(char echoChar); + + public native void setEditable(boolean editable); + + public native void setText(String l); +} + diff --git a/gnu/java/awt/peer/qt/QtToolkit.java b/gnu/java/awt/peer/qt/QtToolkit.java new file mode 100644 index 000000000..5a57b8551 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtToolkit.java @@ -0,0 +1,478 @@ +/* QtToolkit.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import gnu.java.awt.EmbeddedWindow; +import gnu.java.awt.peer.ClasspathFontPeer; +import gnu.java.awt.peer.EmbeddedWindowPeer; +import gnu.java.awt.peer.ClasspathTextLayoutPeer; +import java.awt.AWTEvent; +import java.awt.AWTException; +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.CheckboxMenuItem; +import java.awt.Choice; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.Image; +import java.awt.Label; +import java.awt.List; +import java.awt.MenuBar; +import java.awt.Menu; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.FileDialog; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.PopupMenu; +import java.awt.PrintJob; +import java.awt.Scrollbar; +import java.awt.ScrollPane; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.datatransfer.Clipboard; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragGestureListener; +import java.awt.dnd.DragGestureRecognizer; +import java.awt.dnd.DragSource; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.event.AWTEventListener; +import java.awt.image.ColorModel; +import java.awt.image.DirectColorModel; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.im.InputMethodHighlight; +import java.awt.peer.ButtonPeer; +import java.awt.peer.FontPeer; +import java.awt.peer.PanelPeer; +import java.awt.peer.CanvasPeer; +import java.awt.peer.FramePeer; +import java.awt.peer.PopupMenuPeer; +import java.awt.peer.CheckboxMenuItemPeer; +import java.awt.peer.LabelPeer; +import java.awt.peer.RobotPeer; +import java.awt.peer.CheckboxPeer; +import java.awt.peer.LightweightPeer; +import java.awt.peer.ScrollPanePeer; +import java.awt.peer.ChoicePeer; +import java.awt.peer.ListPeer; +import java.awt.peer.ScrollbarPeer; +import java.awt.peer.ComponentPeer; +import java.awt.peer.MenuBarPeer; +import java.awt.peer.TextAreaPeer; +import java.awt.peer.ContainerPeer; +import java.awt.peer.MenuComponentPeer; +import java.awt.peer.TextComponentPeer; +import java.awt.peer.DialogPeer; +import java.awt.peer.MenuItemPeer; +import java.awt.peer.TextFieldPeer; +import java.awt.peer.FileDialogPeer; +import java.awt.peer.MenuPeer; +import java.awt.peer.WindowPeer; +import java.awt.font.FontRenderContext; +import java.io.InputStream; +import java.net.URL; +import java.text.AttributedString; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import javax.imageio.spi.IIORegistry; + +import gnu.java.awt.ClasspathToolkit; + +public class QtToolkit extends ClasspathToolkit +{ + public static EventQueue eventQueue = null; // the native event queue + public static MainQtThread guiThread = null; + public static QtGraphicsEnvironment graphicsEnv = null; + + private static void initToolkit() + { + eventQueue = new EventQueue(); + + System.loadLibrary("qtpeer"); + + String theme = null; + try + { + String style = System.getProperty("qtoptions.style"); + if(style != null) + theme = style; + } + catch(SecurityException e) + { + } + catch(IllegalArgumentException e) + { + } + + guiThread = new MainQtThread( theme ); + guiThread.start(); + } + + /** + * Construct the toolkit! + */ + public QtToolkit() + { + if( guiThread == null ) + initToolkit(); + + while (!guiThread.isRunning()); // make sure the GUI thread has started. + + if( graphicsEnv == null ) + graphicsEnv = new QtGraphicsEnvironment( this ); + } + + native String[] nativeFontFamilies(); + + native int numScreens(); + + native int defaultScreen(); + + // ************ Public methods ********************* + + public synchronized native void beep(); + + public int checkImage(Image image, int w, int h, ImageObserver observer) + { + if(image instanceof QtImage) + return ((QtImage)image).checkImage(observer); + + return ImageObserver.ERROR; // FIXME + } + + protected ButtonPeer createButton( Button target ) + { + return new QtButtonPeer( this, target ); + } + + protected CanvasPeer createCanvas(Canvas target) + { + return new QtCanvasPeer( this, target ); + } + + protected LightweightPeer createComponent(Component target) + { + return new QtPanelPeer( this, target ); + } + + protected CheckboxPeer createCheckbox(Checkbox target) + { + return new QtCheckboxPeer( this, target ); + } + + protected ChoicePeer createChoice(Choice target) + { + return new QtChoicePeer( this, target ); + } + + protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) + { + return new QtMenuItemPeer( this, target ); + } + + public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) + { + throw new RuntimeException("Not implemented"); + } + + protected FramePeer createFrame(Frame target) + { + return new QtFramePeer( this, target ); + } + + protected FileDialogPeer createFileDialog(FileDialog target) + { + return new QtFileDialogPeer( this, target ); + } + + public Image createImage(ImageProducer producer) + { + return new QtImage( producer ); + } + + public Image createImage(byte[] imageData, + int imageOffset, + int imageLength) + { + byte[] dataCopy = new byte[imageLength]; + System.arraycopy(imageData, imageOffset, dataCopy, 0, imageLength); + return new QtImage( dataCopy ); + } + + public Image createImage(String filename) + { + return new QtImage( filename ); + } + + public Image createImage(URL url) + { + return new QtImage( url ); + } + + protected TextFieldPeer createTextField(TextField target) + { + return new QtTextFieldPeer(this,target); + } + + protected LabelPeer createLabel(Label target) + { + return new QtLabelPeer( this, target ); + } + + protected ListPeer createList(List target) + { + return new QtListPeer( this, target ); + } + + protected ScrollbarPeer createScrollbar(Scrollbar target) + { + return new QtScrollbarPeer( this, target ); + } + + protected ScrollPanePeer createScrollPane(ScrollPane target) + { + return new QtScrollPanePeer( this, target ); + } + + protected TextAreaPeer createTextArea(TextArea target) + { + return new QtTextAreaPeer( this, target ); + } + + protected PanelPeer createPanel(Panel target) + { + return new QtPanelPeer( this, target); + } + + protected WindowPeer createWindow(Window target) + { + return new QtWindowPeer( this, target ); + } + + protected DialogPeer createDialog(Dialog target) + { + return new QtDialogPeer( this, target ); + } + + protected MenuBarPeer createMenuBar(MenuBar target) + { + return new QtMenuBarPeer( this, target ); + } + + protected MenuPeer createMenu(Menu target) + { + return new QtMenuPeer( this, target ); + } + + protected PopupMenuPeer createPopupMenu(PopupMenu target) + { + return new QtPopupMenuPeer( this, target ); + } + + protected MenuItemPeer createMenuItem(MenuItem target) + { + return new QtMenuItemPeer( this, target ); + } + + /** + * @since 1.4 + */ + public AWTEventListener[] getAWTEventListeners() + { + return null; // FIXME + } + + /** + * @since 1.4 + */ + public AWTEventListener[] getAWTEventListeners(long mask) + { + return null; // FIXME + } + + public ColorModel getColorModel() + { + return new DirectColorModel(32, + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + } + + /** + * Just return the defaults. + */ + public String[] getFontList() + { + String[] builtIn = new String[] { "Dialog", + "DialogInput", + "Monospaced", + "Serif", + "SansSerif" }; + String[] nat = nativeFontFamilies(); + String[] allFonts = new String[ nat.length + 5 ]; + System.arraycopy(builtIn, 0, allFonts, 0, 5); + System.arraycopy(nat, 0, allFonts, 5, nat.length); + return allFonts; + } + + public FontMetrics getFontMetrics(Font font) + { + return new QtFontMetrics(font); + } + + protected FontPeer getFontPeer(String name, + int style) + { + Map attrs = new HashMap (); + ClasspathFontPeer.copyStyleToAttrs(style, attrs); + ClasspathFontPeer.copySizeToAttrs(12, attrs); // Default size is 12. + return getClasspathFontPeer (name, attrs); + } + + public Image getImage(String filename) + { + return new QtImage(filename); + } + + public Image getImage(URL url) + { + return createImage( url ); + } + + public PrintJob getPrintJob(Frame frame, + String jobtitle, + Properties props) + { + throw new RuntimeException("Not implemented"); + } + + public Clipboard getSystemClipboard() + { + throw new RuntimeException("Not implemented"); + } + + protected EventQueue getSystemEventQueueImpl() + { + return eventQueue; + } + + public native Dimension getScreenSize(); + + public native int getScreenResolution(); + + public Map mapInputMethodHighlight(InputMethodHighlight highlight) + { + return null; // FIXME + } + + public boolean prepareImage(Image image, int w, int h, ImageObserver observer) + { + if(image instanceof QtImage) + return true; + return false; // FIXME? + } + + public native void sync(); + + // ********************** ClasspathToolkit methods + + public GraphicsEnvironment getLocalGraphicsEnvironment() + { + return graphicsEnv; + } + + public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs) + { + return new QtFontPeer (name, attrs); + } + + public ClasspathTextLayoutPeer getClasspathTextLayoutPeer(AttributedString str, + FontRenderContext frc) + { + return null; + } + + // FIXME + public Font createFont(int format, InputStream stream) + { + throw new UnsupportedOperationException(); + } + + // FIXME + public RobotPeer createRobot (GraphicsDevice screen) throws AWTException + { + throw new UnsupportedOperationException(); + } + + // REMOVE. + public void registerImageIOSpis(IIORegistry reg) + { + } + + public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w) + { + return null; // FIXME + } + + // Yucky. + + public boolean nativeQueueEmpty() + { + return true; + } + + public void wakeNativeQueue() + { + } + + public void iterateNativeQueue(EventQueue locked, boolean block) + { + } +} diff --git a/gnu/java/awt/peer/qt/QtVolatileImage.java b/gnu/java/awt/peer/qt/QtVolatileImage.java new file mode 100644 index 000000000..2bb2260d1 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtVolatileImage.java @@ -0,0 +1,393 @@ +/* QtVolatileImage.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Color; +import java.awt.Image; +import java.awt.ImageCapabilities; +import java.awt.GraphicsConfiguration; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.DirectColorModel; +import java.awt.image.MemoryImageSource; +import java.awt.image.ImageConsumer; +import java.awt.image.ImageObserver; +import java.awt.image.ImageProducer; +import java.awt.image.VolatileImage; +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; +import java.util.Vector; + +/** + * QtVolatileImage - wraps a QImage + * + */ +public class QtVolatileImage extends VolatileImage +{ + int width = -1, height = -1; + + /** + * Properties. + */ + Hashtable props; + + /** + * Pointer to the QImage + */ + long nativeObject; + + /* + * The 32-bit AARRGGBB format the uses. + */ + static ColorModel nativeModel = new DirectColorModel(32, + 0x00FF0000, + 0x0000FF00, + 0x000000FF, + 0xFF000000); + + /** + * Clears the image to RGBA 0 + */ + public native void clear(); + + /** + * Returns a copy of the pixel data as a java array. + */ + private native int[] getPixels(); + + /** + * Allocates a QImage + */ + private native void createImage(); + + /** + * Frees the above. + */ + private native void freeImage(); + + /** + * Sets the image to scaled copy of src image. hints are rendering hints. + */ + private native void createScaledImage(QtVolatileImage src, int hints); + + /** + * Draws the image optionally composited. + */ + private native void drawPixels (QtGraphics gc, + int bg_red, int bg_green, int bg_blue, + int x, int y, + boolean composite); + /** + * Draws the image, optionally scaled and composited. + */ + private native void drawPixelsScaled (QtGraphics gc, + int bg_red, int bg_green, int bg_blue, + int x, int y, int width, int height, + boolean composite); + + /** + * Draws the image transformed. + */ + private native void drawPixelsTransformed (QtGraphics gc, QMatrix transform); + + /** + * Draws the image scaled flipped and optionally composited. + */ + private native void drawPixelsScaledFlipped (QtGraphics gc, + int bg_red, int bg_green, + int bg_blue, + boolean flipX, boolean flipY, + int srcX, int srcY, + int srcWidth, int srcHeight, + int dstX, int dstY, + int dstWidth, int dstHeight, + boolean composite); + + /** + * Constructs an empty QtVolatileImage. + */ + public QtVolatileImage (int width, int height) + { + this.width = width; + this.height = height; + props = new Hashtable(); + createImage(); + clear(); + } + + /** + * Constructs a scaled version of the src bitmap, using Qt + */ + private QtVolatileImage (QtVolatileImage src, int width, int height, + int hints) + { + this.width = width; + this.height = height; + props = new Hashtable(); + + createScaledImage(src, hints); + } + + // java.awt.Image methods //////////////////////////////////////////////// + + public int getWidth (ImageObserver observer) + { + return getWidth(); + } + + public int getHeight (ImageObserver observer) + { + return getHeight(); + } + + public Object getProperty (String name, ImageObserver observer) + { + Object value = props.get (name); + return (value == null) ? UndefinedProperty : value; + } + + /** + * Returns the source of this image. + */ + public ImageProducer getSource () + { + return new MemoryImageSource(width, height, nativeModel, getPixels(), + 0, width); + } + + /** + * Creates a Graphics context for this image. + */ + public Graphics getGraphics () + { + return new QtImageGraphics( this ); + } + + /** + * Returns a scaled instance of this image. + */ + public Image getScaledInstance(int width, + int height, + int hints) + { + if (width <= 0 || height <= 0) + throw new IllegalArgumentException("Width and height of scaled bitmap"+ + "must be >= 0"); + + return new QtVolatileImage(this, width, height, hints); + } + + /** + */ + public void flush () + { + // FIXME ? + } + + public void finalize() + { + freeImage(); + } + + /** + * Returns the image status, used by QtToolkit + */ + public int checkImage (ImageObserver observer) + { + return ImageObserver.ALLBITS | ImageObserver.WIDTH | ImageObserver.HEIGHT; + } + + // Drawing methods //////////////////////////////////////////////// + + /** + * Draws an image with eventual scaling/transforming. + */ + public boolean drawImage (QtGraphics g, QMatrix matrix, + ImageObserver observer) + { + drawPixelsTransformed (g, matrix); + return true; + } + + /** + * Draws an image to the QtGraphics context, at (x,y) with optional + * compositing with a background color. + */ + public boolean drawImage (QtGraphics g, int x, int y, + Color bgcolor, ImageObserver observer) + { + if(bgcolor != null) + drawPixels(g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), x, y, true); + else + drawPixels(g, 0, 0, 0, x, y, false); + + return true; + } + + /** + * Draws an image to the QtGraphics context, at (x,y) scaled to + * width and height, with optional compositing with a background color. + */ + public boolean drawImage (QtGraphics g, int x, int y, int width, int height, + Color bgcolor, ImageObserver observer) + { + if(bgcolor != null) + drawPixelsScaled(g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), x, y, width, height, true); + else + drawPixelsScaled(g, 0, 0, 0, x, y, width, height, false); + + return true; + } + + /** + * Draws an image with eventual scaling/transforming. + */ + public boolean drawImage (QtGraphics g, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + Color bgcolor, ImageObserver observer) + { + boolean flipX = (dx1 > dx2)^(sx1 > sx2); + boolean flipY = (dy1 > dy2)^(sy1 > sy2); + int dstWidth = Math.abs (dx2 - dx1); + int dstHeight = Math.abs (dy2 - dy1); + int srcWidth = Math.abs (sx2 - sx1); + int srcHeight = Math.abs (sy2 - sy1); + int srcX = (sx1 < sx2) ? sx1 : sx2; + int srcY = (sy1 < sy2) ? sy1 : sy2; + int dstX = (dx1 < dx2) ? dx1 : dx2; + int dstY = (dy1 < dy2) ? dy1 : dy2; + + // Clipping. This requires the dst to be scaled as well, + if (srcWidth > width) + { + dstWidth = (int)((double)dstWidth*((double)width/(double)srcWidth)); + srcWidth = width - srcX; + } + + if (srcHeight > height) + { + dstHeight = (int)((double)dstHeight*((double)height/(double)srcHeight)); + srcHeight = height - srcY; + } + + if (srcWidth + srcX > width) + { + dstWidth = (int)((double)dstWidth * (double)(width - srcX)/(double)srcWidth); + srcWidth = width - srcX; + } + + if (srcHeight + srcY > height) + { + dstHeight = (int)((double)dstHeight * (double)(width - srcY)/(double)srcHeight); + srcHeight = height - srcY; + } + + if ( srcWidth <= 0 || srcHeight <= 0 || dstWidth <= 0 || dstHeight <= 0) + return true; + + if(bgcolor != null) + drawPixelsScaledFlipped (g, bgcolor.getRed (), bgcolor.getGreen (), + bgcolor.getBlue (), + flipX, flipY, + srcX, srcY, + srcWidth, srcHeight, + dstX, dstY, + dstWidth, dstHeight, + true); + else + drawPixelsScaledFlipped (g, 0, 0, 0, flipX, flipY, + srcX, srcY, srcWidth, srcHeight, + dstX, dstY, dstWidth, dstHeight, + false); + return true; + } + + public native void copyArea(int x, int y, int width, int height, + int dx, int dy); + + //******************** VolatileImage stuff ******************** + + public boolean contentsLost() + { + return false; + } + + public Graphics2D createGraphics() + { + return new QtImageGraphics(this); + } + + public ImageCapabilities getCapabilities() + { + return new ImageCapabilities(false) + { + public boolean isTrueVolatile() + { + return false; + } + }; + } + + public int getHeight() + { + return height; + } + + public BufferedImage getSnapshot() + { + BufferedImage bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_ARGB_PRE); + bi.setRGB( 0, 0, width, height, getPixels(), 0, width); + return bi; + } + + public int getWidth() + { + return width; + } + + public int validate(GraphicsConfiguration gc) + { + return IMAGE_OK; + } +} diff --git a/gnu/java/awt/peer/qt/QtWindowPeer.java b/gnu/java/awt/peer/qt/QtWindowPeer.java new file mode 100644 index 000000000..e64ee65a1 --- /dev/null +++ b/gnu/java/awt/peer/qt/QtWindowPeer.java @@ -0,0 +1,68 @@ +/* QtWindowPeer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package gnu.java.awt.peer.qt; + +import java.awt.Window; +import java.awt.peer.WindowPeer; + +public class QtWindowPeer extends QtContainerPeer implements WindowPeer +{ + public QtWindowPeer( QtToolkit kit, Window owner ) + { + super( kit, owner ); + } + + protected native void init(); + + protected void setup() + { + super.setup(); + } + + // ************ Public methods ********************* + + public native void toBack(); + + public native void toFront(); + + /* + * Belongs to Frame and Dialog, but no sense in duplicating code. + */ + public native void setTitle(String title); + +} diff --git a/gnu/java/nio/charset/UTF_16Decoder.java b/gnu/java/nio/charset/UTF_16Decoder.java index 302c83e62..e3927d994 100644 --- a/gnu/java/nio/charset/UTF_16Decoder.java +++ b/gnu/java/nio/charset/UTF_16Decoder.java @@ -1,5 +1,5 @@ /* UTF_16Decoder.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -105,8 +105,9 @@ final class UTF_16Decoder extends CharsetDecoder } // FIXME: Change so you only do a single comparison here. - char c = byteOrder == BIG_ENDIAN ? (char) ((b1 << 8) | b2) - : (char) ((b2 << 8) | b1); + char c = (byteOrder == BIG_ENDIAN + ? (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF)) + : (char) (((b2 & 0xFF) << 8) | (b1 & 0xFF))); if (0xD800 <= c && c <= 0xDFFF) { @@ -119,8 +120,9 @@ final class UTF_16Decoder extends CharsetDecoder return CoderResult.UNDERFLOW; byte b3 = in.get (); byte b4 = in.get (); - char d = byteOrder == BIG_ENDIAN ? (char) ((b3 << 8) | b4) - : (char) ((b4 << 8) | b3); + char d = (byteOrder == BIG_ENDIAN + ? (char) (((b3 & 0xFF) << 8) | (b4 & 0xFF)) + : (char) (((b4 & 0xFF) << 8) | (b3 & 0xFF))); // make sure d is a low surrogate if (d < 0xDC00 || d > 0xDFFF) return CoderResult.malformedForLength (2); diff --git a/gnu/java/security/PolicyFile.java b/gnu/java/security/PolicyFile.java index dd3a4dec4..c6a3061ea 100644 --- a/gnu/java/security/PolicyFile.java +++ b/gnu/java/security/PolicyFile.java @@ -37,6 +37,10 @@ exception statement from your version. */ package gnu.java.security; +import gnu.classpath.SystemProperties; +import gnu.classpath.debug.Component; +import gnu.classpath.debug.SystemLogger; + import java.io.File; import java.io.IOException; import java.io.InputStreamReader; @@ -66,6 +70,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; +import java.util.logging.Logger; /** * An implementation of a {@link java.security.Policy} object whose @@ -143,24 +148,16 @@ public final class PolicyFile extends Policy // Constants and fields. // ------------------------------------------------------------------------- - private static final boolean DEBUG = true; - // Package-private to avoid a trampoline. - static void debug(String msg) - { - System.err.print(">> PolicyFile: "); - System.err.println(msg); - } - - private static void debug(Throwable t) - { - System.err.println(">> PolicyFile"); - t.printStackTrace(System.err); - } + private static final Logger logger = SystemLogger.SYSTEM; - private static final String DEFAULT_POLICY = System.getProperty("java.home") - + System.getProperty("file.separator") + "lib" - + System.getProperty("file.separator") + "security" - + System.getProperty("file.separator") + "java.policy"; + private static final String DEFAULT_POLICY = + SystemProperties.getProperty("java.home") + + SystemProperties.getProperty("file.separator") + "lib" + + SystemProperties.getProperty("file.separator") + "security" + + SystemProperties.getProperty("file.separator") + "java.policy"; + private static final String DEFAULT_USER_POLICY = + SystemProperties.getProperty ("user.home") + + SystemProperties.getProperty ("file.separator") + ".java.policy"; private final Map cs2pc; @@ -185,7 +182,8 @@ public final class PolicyFile extends Policy CodeSource cs = (CodeSource) e.getKey(); if (cs.implies(codeSource)) { - if (DEBUG) debug(cs+" -> "+codeSource); + logger.log (Component.POLICY, "{0} -> {1}", new Object[] + { cs, codeSource }); PermissionCollection pc = (PermissionCollection) e.getValue(); for (Enumeration ee = pc.elements(); ee.hasMoreElements(); ) { @@ -193,50 +191,69 @@ public final class PolicyFile extends Policy } } else - if (DEBUG) debug(cs+" !-> "+codeSource); + logger.log (Component.POLICY, "{0} !-> {1}", new Object[] + { cs, codeSource }); } - if (DEBUG) debug ("returning permissions " + perms + " for " + codeSource); + logger.log (Component.POLICY, "returning permissions {0} for {1}", + new Object[] { perms, codeSource }); return perms; } public void refresh() { cs2pc.clear(); - List policyFiles = new LinkedList(); + final List policyFiles = new LinkedList(); try { - policyFiles.add(new File(DEFAULT_POLICY).toURL()); - if (DEBUG) debug ("defualt policy is " + DEFAULT_POLICY); - policyFiles.addAll((List) AccessController.doPrivileged( + policyFiles.add (new File (DEFAULT_POLICY).toURL()); + policyFiles.add (new File (DEFAULT_USER_POLICY).toURL ()); + + AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws Exception { - LinkedList l = new LinkedList(); + String allow = Security.getProperty ("policy.allowSystemProperty"); + if (allow == null || Boolean.getBoolean (allow)) + { + String s = SystemProperties.getProperty ("java.security.policy"); + logger.log (Component.POLICY, "java.security.policy={0}", s); + if (s != null) + { + boolean only = s.startsWith ("="); + if (only) + s = s.substring (1); + policyFiles.clear (); + policyFiles.add (new URL (s)); + if (only) + return null; + } + } for (int i = 1; ; i++) { - String s = Security.getProperty("policy.file."+i); - if (DEBUG) debug("policy.file."+i+"="+s); + String pname = "policy.url." + i; + String s = Security.getProperty (pname); + logger.log (Component.POLICY, "{0}={1}", new Object [] + { pname, s }); if (s == null) break; - l.add(new URL(s)); + policyFiles.add (new URL (s)); } - String s = System.getProperty("java.security.policy"); - if (DEBUG) debug("java.security.policy="+s); - if (s != null) - l.add(new URL(s)); - return l; + return null; } - })); + }); } catch (PrivilegedActionException pae) { - if (DEBUG) debug(pae); + logger.log (Component.POLICY, "reading policy properties", pae); } catch (MalformedURLException mue) { - if (DEBUG) debug(mue); + logger.log (Component.POLICY, "setting default policies", mue); } + + logger.log (Component.POLICY, "building policy from URLs {0}", + policyFiles); for (Iterator it = policyFiles.iterator(); it.hasNext(); ) { try @@ -246,7 +263,7 @@ public final class PolicyFile extends Policy } catch (IOException ioe) { - if (DEBUG) debug(ioe); + logger.log (Component.POLICY, "reading policy", ioe); } } } @@ -273,7 +290,7 @@ public final class PolicyFile extends Policy */ private void parse(final URL url) throws IOException { - if (DEBUG) debug ("reading policy file from " + url); + logger.log (Component.POLICY, "reading policy file from {0}", url); final StreamTokenizer in = new StreamTokenizer(new InputStreamReader(url.openStream())); in.resetSyntax(); in.slashSlashComments(true); diff --git a/gnu/java/security/provider/DSAKeyPairGenerator.java b/gnu/java/security/provider/DSAKeyPairGenerator.java index 2c643d5c3..d326d2bfe 100644 --- a/gnu/java/security/provider/DSAKeyPairGenerator.java +++ b/gnu/java/security/provider/DSAKeyPairGenerator.java @@ -1,5 +1,5 @@ /* GnuDSAKeyPairGenerator.java --- Gnu DSA Key Pair Generator - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,10 +45,12 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidParameterException; import java.security.KeyPair; import java.security.KeyPairGeneratorSpi; +import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.interfaces.DSAParams; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.DSAParameterSpec; +import java.security.spec.InvalidParameterSpecException; import java.util.Random; public class DSAKeyPairGenerator extends KeyPairGeneratorSpi @@ -60,18 +62,15 @@ private BigInteger q = null; // the small prime private BigInteger p = null; // the big prime private BigInteger g = null; -DSAKeyPairGenerator() +public DSAKeyPairGenerator() { keysize = 1024; + getDefaults (); } public void initialize(int keysize, SecureRandom random) { - //if( ((keysize % 64) != 0) || (keysize < 512) || (keysize > 1024) ) - // throw new InvalidAlgorithmParameterException("Invalid key size"); - - this.keysize = keysize; - this.random = random; + initialize (keysize, false, random); } public void initialize(AlgorithmParameterSpec params, @@ -81,65 +80,87 @@ public void initialize(AlgorithmParameterSpec params, if( !( params instanceof DSAParameterSpec ) ) throw new InvalidAlgorithmParameterException("Must be DSAParameterSpec"); + try + { + initialize ((DSAParams) params, random); + } + catch (InvalidParameterException ipe) + { + InvalidAlgorithmParameterException iape = + new InvalidAlgorithmParameterException(); + iape.initCause (ipe); + throw iape; + } +} + +public void initialize (DSAParams params, SecureRandom random) +{ DSAParameterSpec dsaparameterspec = (DSAParameterSpec)params; + if (dsaparameterspec.getP() == null + || dsaparameterspec.getQ() == null + || dsaparameterspec.getG() == null) + { + throw new InvalidParameterException ("none of p, q, or g may be null"); + } p = dsaparameterspec.getP(); q = dsaparameterspec.getQ(); g = dsaparameterspec.getG(); this.random = random; } -public void initialize(DSAParams params, SecureRandom random) - throws InvalidParameterException -{ - if(params.getP() != null) - p = params.getP(); - else - throw new InvalidParameterException(); - - if(params.getQ() != null) - q = params.getQ(); - else - throw new InvalidParameterException(); - - if(params.getG() != null) - g = params.getG(); - else - throw new InvalidParameterException(); - - this.random = random; -} - public void initialize(int modlen, boolean genParams, SecureRandom random) throws InvalidParameterException { if( ((modlen % 64) != 0) || (modlen < 512) || (modlen > 1024) ) throw new InvalidParameterException(); - if( (genParams == false) && (modlen != 512) && (modlen != 768) && (modlen != 1024) ) - throw new InvalidParameterException(); - this.keysize = modlen; - this.random = random; - p = null; - q = null; - g = null; + this.keysize = keysize; + this.random = random; + if (this.random == null) + { + this.random = new SecureRandom (); + } + if (genParams) + { + try + { + AlgorithmParameterGenerator apgDSA = AlgorithmParameterGenerator.getInstance("DSA"); + apgDSA.init (modlen, random); + AlgorithmParameters apDSA = apgDSA.generateParameters(); + DSAParameterSpec dsaparameterspec = (DSAParameterSpec)apDSA.getParameterSpec( DSAParameterSpec.class ); + p = dsaparameterspec.getP(); + q = dsaparameterspec.getQ(); + g = dsaparameterspec.getG(); + } + catch (NoSuchAlgorithmException nsae) + { + InvalidParameterException ipe = + new InvalidParameterException ("can't generate DSA parameters"); + ipe.initCause (nsae); + throw ipe; + } + catch (InvalidParameterSpecException ipse) + { + InvalidParameterException ipe = + new InvalidParameterException ("can't generate DSA parameters"); + ipe.initCause (ipse); + throw ipe; + } + } + else if (!getDefaults ()) + { + throw new InvalidParameterException ("unsupported key size: " + modlen); + } } public KeyPair generateKeyPair() { - if( getDefaults() == false) { - try { - AlgorithmParameterGenerator apgDSA = AlgorithmParameterGenerator.getInstance("DSA"); - AlgorithmParameters apDSA = apgDSA.generateParameters(); - DSAParameterSpec dsaparameterspec = (DSAParameterSpec)apDSA.getParameterSpec( DSAParameterSpec.class ); - p = dsaparameterspec.getP(); - q = dsaparameterspec.getQ(); - g = dsaparameterspec.getG(); - } catch ( Exception e ) { - return null; - } - } + if (random == null) + { + random = new SecureRandom (); + } - BigInteger x = new BigInteger( 159, new Random() ); + BigInteger x = new BigInteger( 159, random ); BigInteger y = g.modPow( x, p ); @@ -160,7 +181,7 @@ private boolean getDefaults() p = new BigInteger("e9e642599d355f37c97ffd3567120b8e25c9cd43e927b3a9670fbec5d890141922d2c3b3ad2480093799869d1e846aab49fab0ad26d2ce6a22219d470bce7d777d4a21fbe9c270b57f607002f3cef8393694cf45ee3688c11a8c56ab127a3daf", 16); q = new BigInteger("9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511", 16); g = new BigInteger("30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5facbaecbe95f190aa7a31d23c4dbbcbe06174544401a5b2c020965d8c2bd2171d3668445771f74ba084d2029d83c1c158547f3a9f1a2715be23d51ae4d3e5a1f6a7064f316933a346d3f529252", 16); - } else if( keysize == 512) { + } else if( keysize == 1024) { p = new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", 16); q = new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5", 16); g = new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", 16); |