diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html index 2ee23e2..ff65995 100644 --- a/docs/ReleaseNotes.html +++ b/docs/ReleaseNotes.html @@ -9,6 +9,18 @@
+ * This does not convert the data + * @deprecated callers should use getDate() + * @return java.util.Date version of this variant if it is a date, otherwise null + * */ public Date toJavaDate(){ - double windowsDate = toDate(); - if (windowsDate == 0){ - return null; - } else { - return DateUtilities.convertWindowsTimeToDate(getDate()); - } + changeType(Variant.VariantDate); + return getJavaDate(); } /** + * @deprecated should be replaced by changeType() followed by getBoolean() * @return the value of this variant as boolean (after possible conversion) */ - public native boolean toBoolean(); + public boolean toBoolean(){ + changeType(Variant.VariantBoolean); + return getBoolean(); + } /** @return the value of this variant as an enumeration (java style) */ public native EnumVariant toEnumVariant(); @@ -173,22 +184,42 @@ public class Variant extends JacobObject { /** * Set this Variant's type to VT_NULL (the VB equivalent of NULL) * */ - public native void putNull(); + private native void putVariantNull(); + /** + * Set this Variant's type to VT_NULL (the VB equivalent of NULL) + * */ + public void putNull(){ + // verify we aren't released yet + getvt(); + putVariantNull(); + } + /** * @deprecated No longer used * @return null ! */ public native Variant cloneIndirect(); - /** @return the content of this variant as a double */ - public native double toDouble(); + /** + * @deprecated should call changeType() then getDouble() + * @return the content of this variant as a double + * (after possible conversion) + **/ + public double toDouble(){ + changeType(Variant.VariantDouble); + return getDouble(); + } /** + * @deprecated should be replaced by changeType() followed by getCurrency * @return the content of this variant as a long reprensenting a monetary * amount */ - public native long toCurrency(); + public long toCurrency(){ + changeType(Variant.VariantCurrency); + return getCurrency(); + } /** * @deprecated superceded by SafeArray @@ -211,6 +242,7 @@ public class Variant extends JacobObject { /** * Exists to support jacobgen. * This would be deprecated if it weren't for jacobgen + * @deprecated superceded by "this" * @return this same object */ public Variant toVariant() { return this; } @@ -228,25 +260,65 @@ public class Variant extends JacobObject { * set the content of this variant to a short (VT_I2|VT_BYREF) * @param in */ - public native void putShortRef(short in); + private native void putVariantShortRef(short in); + + /** + * set the content of this variant to a short (VT_I2|VT_BYREF) + * @param in + */ + public void putShortRef(short in){ + // verify we aren't released + getvt(); + putVariantShortRef(in); + } /** * set the content of this variant to an int (VT_I4|VT_BYREF) * @param in */ - public native void putIntRef(int in); + private native void putVariantIntRef(int in); + + /** + * set the content of this variant to an int (VT_I4|VT_BYREF) + * @param in + */ + public void putIntRef(int in){ + // verify we aren't released + getvt(); + putVariantIntRef(in); + } /** * set the content of this variant to a double (VT_R8|VT_BYREF) * @param in */ - public native void putDoubleRef(double in); + private native void putVariantDoubleRef(double in); + + /** + * set the content of this variant to a double (VT_R8|VT_BYREF) + * @param in + */ + public void putDoubleRef(double in){ + // verify we aren't released + getvt(); + putVariantDoubleRef(in); + } /** * set the content of this variant to a date (VT_DATE|VT_BYREF) * @param in */ - public native void putDateRef(double in); + private native void putVariantDateRef(double in); + + /** + * set the content of this variant to a date (VT_DATE|VT_BYREF) + * @param in + */ + public void putDateRef(double in){ + // verify we aren't released + getvt(); + putVariantDateRef(in); + } /** * converts a java date to a windows time and calls putDateRef(double) @@ -267,43 +339,132 @@ public class Variant extends JacobObject { * set the content of this variant to a string (VT_BSTR|VT_BYREF) * @param in */ - public native void putStringRef(String in); + private native void putVariantStringRef(String in); + /** + * set the content of this variant to a string (VT_BSTR|VT_BYREF) + * @param in + */ + public void putStringRef(String in){ + // verify we aren't released + getvt(); + putVariantStringRef(in); + } /** * get the content of this variant as a short * @return short */ - public native short getShortRef(); + private native short getVariantShortRef(); /** * get the content of this variant as an int * @return int */ - public native int getIntRef(); + public short getShortRef(){ + if ((this.getvt() & VariantShort) == VariantShort && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantShortRef(); + } else { + throw new IllegalStateException( + "getShortRef() only legal on byRef Variants of type VariantShort, not "+this.getvt()); + } + } + + /** + * get the content of this variant as an int + * @return int + */ + private native int getVariantIntRef(); + + /** + * get the content of this variant as an int + * @return int + */ + public int getIntRef(){ + if ((this.getvt() & VariantInt) == VariantInt && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantIntRef(); + } else { + throw new IllegalStateException( + "getIntRef() only legal on byRef Variants of type VariantInt, not "+this.getvt()); + } + } /** * set the content of this variant to a short (VT_I2) * @param in */ - public native void putShort(short in); + private native void putVariantShort(short in); + /** + * set the content of this variant to a short (VT_I2) + * @param in + */ + public void putShort(short in){ + // verify we aren't released + getvt(); + putVariantShort(in); + } /** * get the content of this variant as a short * @return short */ - public native short getShort(); + private native short getVariantShort(); + /** + * return the int value held in this variant (fails on other types?) + * @return int + */ + public short getShort(){ + if (this.getvt() == VariantShort){ + return getVariantShort(); + } else { + throw new IllegalStateException( + "getShort() only legal on Variants of type VariantShort, not "+this.getvt()); + } + } + + /** * get the content of this variant as a double * @return double */ - public native double getDoubleRef(); + private native double getVariantDoubleRef(); + /** + * + * @return returns the double value, throws exception if not a currency type + */ + public double getDobuleRef(){ + if ((this.getvt() & VariantDouble) == VariantDouble && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantDoubleRef(); + } else { + throw new IllegalStateException( + "getDoubleRef() only legal on byRef Variants of type VariantDouble, not "+this.getvt()); + } + } + + /** * get the content of this variant as a double representing a date * @return double */ - public native double getDateRef(); + private native double getVariantDateRef(); + + /** + * + * @return returns the date value as a double, throws exception if not a currency type + */ + public double getDateRef(){ + if ((this.getvt() & VariantDate) == VariantDate && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantDateRef(); + } else { + throw new IllegalStateException( + "getDateRef() only legal on byRef Variants of type VariantDate, not "+this.getvt()); + } + } /** * returns the windows time contained in this Variant to a Java Date @@ -324,7 +485,22 @@ public class Variant extends JacobObject { * get the content of this variant as a string * @return String */ - public native String getStringRef(); + private native String getVariantStringRef(); + + /** + * gets the content of the veriant as a string ref + * @return + */ + public String getStringRef(){ + if ((this.getvt() & VariantString) == VariantString && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantStringRef(); + } else { + throw new IllegalStateException( + "getStringRef() only legal on byRef Variants of type VariantString, not "+this.getvt()); + } + } + /** * @deprecated superceded by SafeArray @@ -341,15 +517,15 @@ public class Variant extends JacobObject { public native void VariantClear(); /** - * @return the content of this variant as a Dispatch object + * @return the content of this variant as a Dispatch object (after possible conversion) */ - public Dispatch toDispatch(){ return toDispatchObject(); } + public Dispatch toDispatch(){ return toVariantDispatch(); } /** * native method used by toDispatch() * @return */ - private native Dispatch toDispatchObject(); + private native Dispatch toVariantDispatch(); /** * this returns null @@ -358,52 +534,133 @@ public class Variant extends JacobObject { public native Object clone(); /** + * This method now correctly implements java toString() semantics * Attempts to return the content of this variant as a string - * Will convert the underlying data type to a string(!) - * @return String + *
+ * calls toSafeArray(true) */ public SafeArray toSafeArray() { + // verify we haven't been released yet + getvt(); return toSafeArray(true); } + + /** + * This lets folk turn into a safe array without a deep copy. + * Shoudl this API be public? + * @param deepCopy + * @return + */ + public SafeArray toSafeArray(boolean deepCopy){ + // verify we haven't been released yet + getvt(); + return toVariantSafeArray(deepCopy); + } - public native SafeArray toSafeArray(boolean deepCopy); + private native void putVariantSafeArrayRef(SafeArray in); - public native void putSafeArrayRef(SafeArray in); + /** + * have no idea... + * @param in + */ + public void putSafeArrayRef(SafeArray in){ + // verify we haven't been released yet + getvt(); + putVariantSafeArrayRef(in); + } + + private native void putVariantSafeArray(SafeArray in); - public native void putSafeArray(SafeArray in); + /** + * have no idea... + * @param in + */ + public void putSafeArray(SafeArray in){ + // verify we haven't been released yet + getvt(); + putVariantSafeArray(in); + } + /** * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND * */ - public native void noParam(); + private native void putVariantNoParam(); + + /** + * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND + * */ + public void putNoParam(){ + // verify we aren't released yet + getvt(); + putVariantNoParam(); + } + /** + * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND + * @deprecated replaced by putNoParam() + * */ + public void noParam(){ + putNoParam(); + } /** * @deprecated superceded by SafeArray * @throws com.jacob.com.NotImplementedException @@ -605,32 +1219,61 @@ public class Variant extends JacobObject { * * @return returns the value as a float if the type is of type float */ - public native float getFloat(); + private native float getVariantFloat(); + + /** + * @return returns the value as a float if the type is of type float + */ + public float getFloat(){ + if (this.getvt() == VariantFloat){ + return getVariantFloat(); + } else { + throw new IllegalStateException( + "getFloat() only legal on Variants of type VariantFloat, not "+this.getvt()); + } + } + + + /** + * fills the Variant with a float and sets the type to float + * @param in + */ + private native void putVariantFloat(float in); /** * fills the Variant with a float and sets the type to float * @param in */ - public native void putFloat(float in); - + public void putFloat(float in){ + // verify we haven't been released yet + getvt(); + putVariantFloat(in); + } + /** * Dispatch and dispatchRef are treated the same - * This is a cover for putDispatch(). + * This is a cover for putVariantDispatch(). * Dispatch and dispatchRef are treated the same * @param in */ public void putDispatchRef(Dispatch in) { - putDispatchObject(in); + putVariantDispatch(in); } /** * Dispatch and dispatchRef are treated the same - * This is just a cover for getDispatch() + * This is just a cover for getDispatch() with a flag check * @return the results of getDispatch() */ public Dispatch getDispatchRef() { - return getDispatch(); - } + if ((this.getvt() & VariantDispatch) == VariantDispatch && + (this.getvt() & VariantByref) == VariantByref) { + return getDispatch(); + } else { + throw new IllegalStateException( + "getDispatchRef() only legal on byRef Variants of type VariantDispatch, not "+this.getvt()); + } + } /** * @deprecated superceded by SafeArray @@ -649,18 +1292,21 @@ public class Variant extends JacobObject { } /** - * Convertes variant to the passed in type by converting the underlying - * windows variant structure + * Converts variant to the passed in type by converting the underlying + * windows variant structure. private so folks use public java method * @param in the desired resulting type */ - public native void changeType(short in); + private native void changeVariantType(short in); /** - * cover for changeType(short) + * cover for native method so we can cover it. * @param in type to convert this variant too + * @return Variant returns this same object so folks can change when replacing calls + * toXXX() with changeType().getXXX() */ - public void changeType(int in) { - changeType((short) in); + public Variant changeType(short in) { + changeVariantType((short) in); + return this; } /** @@ -673,7 +1319,7 @@ public class Variant extends JacobObject { } /** - * public constructor + * public constructor, initializes and sets type to VariantEmpty */ public Variant() { init(); @@ -790,15 +1436,35 @@ public class Variant extends JacobObject { } } + /** + * Returns the variant type via a native method call + * @return short one of the VT_xx types + */ + private native short getVariantType(); - public native short getvt(); - + /** + * Reports the type of the underlying Variant object + * @return returns the variant type as a short, one of the Variantxxx + * values defined as statics in this class. returns VariantNull if not initialized + */ + public short getvt(){ + if (m_pVariant != 0){ + return getVariantType(); + } else { + throw new IllegalStateException("uninitialized Variant"); + } + } + /** * attempts to return the contents of this Variant as a short * (after possible conversion) + * @deprecated callers should use changeType() followed by getShort() * @return short */ - public native short toShort(); + public short toShort() { + this.changeType(Variant.VariantShort); + return getShort(); + } /** * now private so only this object can asccess was: call this to explicitly @@ -943,30 +1609,44 @@ public class Variant extends JacobObject { * is the variant null or empty or error or null dispatch * @return true if it is null or false if not */ - public native boolean isNull(); + private native boolean isVariantConsideredNull(); + + /** + * + * @return returns true if the variant is considered null + * @throws IllegalStateException if there is no underlying windows memory + */ + public boolean isNull(){ + getvt(); + return isVariantConsideredNull(); + } /** * this is supposed to create a byte array that represents the underlying * variant object struct */ - public native byte[] SerializationWriteToBytes(); + protected native byte[] SerializationWriteToBytes(); /** * this is supposed to cause the underlying variant object struct to * be rebuilt from a previously serialized byte array. * @param ba */ - public native void SerializationReadFromBytes(byte[] ba); + protected native void SerializationReadFromBytes(byte[] ba); /*===================================================================== * * *=====================================================================*/ /** - * Convert a JACOB Variant value to a Java object (type conversions). - * provided in Sourceforge feature request 959381 + * Convert a JACOB Variant value to a Java object + * (type conversions). + * provided in Sourceforge feature request 959381. + * + * Unlike other toXXX() methods, it does not do a type conversion + * except for special data types (it shouldn't do any!) * - * @return Corresponding Java type object. + * @return Corresponding Java object of the type matching the Variant type. * @throws Exception if conversion failed. */ protected Object toJavaObject() throws JacobException { @@ -1010,32 +1690,32 @@ public class Variant extends JacobObject { result = this.getDispatchRef(); break; case Variant.VariantError : //10 - result = new NotImplementedException("Not implemented: VariantError"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantError"); break; case Variant.VariantBoolean : //11 result = new Boolean(this.getBoolean()); break; case Variant.VariantVariant : //12 - result = new NotImplementedException("Not implemented: VariantVariant"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantVariant"); break; case Variant.VariantObject : //13 - result = new NotImplementedException("Not implemented: VariantObject"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantObject"); break; case Variant.VariantByte : //17 result = new Byte(this.getByte()); - //result = new NotImplementedException("Not implemented: VariantByte"); + //result = new IllegalStateException("toJavaObject() Not implemented for VariantByte"); break; case Variant.VariantTypeMask : //4095 - result = new NotImplementedException("Not implemented: VariantTypeMask"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantTypeMask"); break; case Variant.VariantArray : //8192 - result = new NotImplementedException("Not implemented: VariantArray"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantArray"); break; case Variant.VariantByref : //16384 - result = new NotImplementedException("Not implemented: VariantByref"); + result = new IllegalStateException("toJavaObject() Not implemented for VariantByref"); break; default : - result = new NotImplementedException("Unknown return type: " + type); + result = new IllegalStateException("Unknown return type: " + type); result = this; break; }//switch (type) diff --git a/unittest/com/jacob/com/VariantTest.java b/unittest/com/jacob/com/VariantTest.java index 879cb8a..b0e7c83 100644 --- a/unittest/com/jacob/com/VariantTest.java +++ b/unittest/com/jacob/com/VariantTest.java @@ -1,5 +1,7 @@ package com.jacob.com; +import java.util.Date; + /** * runs through some of the get and set methods on Variant * @@ -9,6 +11,8 @@ class VariantTest { public static void main(String[] args) { System.out.println("Testing Started"); VariantTest testJig = new VariantTest(); + testJig.testUninitializedVariant(); + testJig.testToStringDoesNotConvert(); testJig.testPutsAndGets(); testJig.testSafeReleaseBoolean(); testJig.testSafeReleaseConstant(); @@ -26,40 +30,103 @@ class VariantTest { } - private void testSafeReleaseBoolean(){ - Variant v = new Variant(true); - System.out.println("Newly created Variant ("+ v.getBoolean()+") "+ - "trying to create access violation but it doesn't seem to be easy"); - v.safeRelease(); - if (v.getBoolean() != true){ - System.out.println("Variant value ("+v.getBoolean()+") " - +"has been broken by SafeRelease()"); - } else { - System.out.println("Variant value ("+v.getBoolean()+") " - +"has survived SafeRelease()"); + /** + * make sure variant with no backing store works. + * + */ + private void testUninitializedVariant(){ + Variant v; + // Variants created without parameters are auto set to VariantEmpty + v = new Variant(); + try { + if (v.getvt() == Variant.VariantEmpty){ + // successful + // System.out.println("Variant initialized without parameters correctly set to empty"); + } else { + throw new RuntimeException("getvt() on uninitialized variant shoud have returned VariantEmpty, instead returned "+v.getvt()); + } + } catch (IllegalStateException ise){ + throw new RuntimeException("getvt() on uninitialized variant shoud have succeeded, but instead threw exception"); } + try { + v.toString(); + } catch (IllegalStateException ise){ + System.out.println("toString() should never throw a runtime exception"); + throw new RuntimeException("toString() should not blow up even with uninitialized Variant"); + } + + } + + + /** + * + * verify the toString() method does not do type conversion + */ + private void testToStringDoesNotConvert(){ + Variant v; + v = new Variant(true); + v.toString(); + if (v.getvt() != Variant.VariantBoolean){ + throw new RuntimeException("toString() converted boolean to something else"); + } else { + //System.out.println("toString() correctly does not convert type"); + } + if (v.getBoolean() != true){ + System.out.println("toString() converted boolean true to "+ v.getBoolean()); + } + v = new Variant(false); + v.toString(); + if (v.getvt() != Variant.VariantBoolean){ + throw new RuntimeException("toString() converted boolean to something else"); + } else { + //System.out.println("toString() correctly does not convert type"); + } + if (v.getBoolean() != false){ + System.out.println("toString() converted boolean false to "+ v.getBoolean()); + } + } + + private void testSafeReleaseBoolean(){ + Variant v; + v = new Variant(true); + //System.out.println("Newly created Variant ("+ v.getBoolean()+") "+ + // "trying to create access violation but it doesn't seem to be easy"); + v.safeRelease(); + try { + v.getBoolean(); + System.out.println("IllegalStateException should have been thrown when querying safeReleased object"); + throw new RuntimeException("test failed"); + } catch (IllegalStateException ise){ + //System.out.println("IllegalStateException correctly thrown after safeRelease"); + } + v = new Variant(true); for ( int i = 0 ; i < 10; i ++){ new Variant ("xxx"+i); new Variant(i); new Variant ("yyy"+i); } ComThread.Release(); - if (v.getBoolean() != true){ - System.out.println("Variant value ("+v.getBoolean()+") " - +"has been broken by ComThread.Release()"); - } else { - System.out.println("Variant value ("+v.getBoolean()+") " - +"has been survived by ComThread.Release()"); + try { + v.getBoolean(); + System.out.println("IllegalStateException should have been thrown when querying ComThread.Release"); + throw new RuntimeException("test failed"); + } catch (IllegalStateException ise){ + //System.out.println("IllegalStateException correctly thrown after ComThread.Release"); } } + /** + * verify the constant values aren't released with safeRelease + * + */ private void testSafeReleaseConstant(){ System.out.println("Using Static constant Variant - should never throw access violation"); Variant.VT_TRUE.safeRelease(); if (Variant.VT_TRUE.getBoolean() != true){ System.out.println("VT_TRUE has been broken by SafeRelease()"); + throw new RuntimeException("test failed"); } else { - System.out.println("VT_TRUE survived SafeRelease()"); + //System.out.println("VT_TRUE survived SafeRelease()"); } for ( int i = 0 ; i < 10; i ++){ @@ -71,24 +138,31 @@ class VariantTest { if (Variant.VT_TRUE.getBoolean() != true){ System.out.println("VT_TRUE has been broken by ComThread.Release()"); + throw new RuntimeException("test failed"); } else { - System.out.println("VT_TRUE survived ComThread.Release()"); + //System.out.println("VT_TRUE survived ComThread.Release()"); } } + /** + * this used to try and and create an access violation but that + * didn't work and now the methods on the Variant are smarter about + * working after a release + * + */ private void testSafeReleaseString(){ String mTestString = "Guitar Hero"; Variant v = new Variant(mTestString); - System.out.println("Newly created Variant ("+ v.getString()+") "+ - "trying to create access violation but it doesn't seem to be easy"); + //System.out.println("Newly created Variant ("+ v.getString()+") "+ + // "about to safe release and then access"); v.safeRelease(); - if (v.getString() == null || !v.getString().equals(mTestString)){ - System.out.println("Variant value ("+v.getString()+") " - +"has been broken by SafeRelease()"); - } else { - System.out.println("Variant value ("+v.getString()+") " - +"has survived SafeRelease()"); + try { + v.getString(); + System.out.println("IllegalStateException should have been thrown when querying safeReleased object"); + throw new RuntimeException("test failed"); + } catch (IllegalStateException ise){ + //System.out.println("IllegalStateException correctly thrown after safeRelease"); } } @@ -127,28 +201,47 @@ class VariantTest { private void testPutsAndGets(){ Variant v = new Variant(); v.putInt(10); - if (v.toInt() != 10){ + if (v.getInt() != 10){ System.out.println("int test failed"); } - v.putInt(10); - if (v.toDouble() != 10.0){ + v.putShort((short)10); + if (v.getShort() != 10){ + System.out.println("short test failed"); + } + v.putByte((byte)10); + if (v.getByte() != 10){ + System.out.println("int test failed"); + } + v.putFloat(10); + if (v.getFloat() != 10.0){ + System.out.println("float test failed"); + } + v.putDouble(10); + if (v.getDouble() != 10.0){ System.out.println("double test failed"); } v.putString("1234.567"); - if (!"1234.567".equals(v.toString())){ + if (!"1234.567".equals(v.getString())){ System.out.println("string test failed"); } v.putBoolean(true); - if (v.toBoolean() != true){ + if (v.getBoolean() != true){ System.out.println("failed boolean test(true)"); } v.putBoolean(false); - if (v.toBoolean() != false){ + if (v.getBoolean() != false){ System.out.println("failed boolean test(false)"); } v.putCurrency(123456789123456789L); - if (v.toCurrency()!=123456789123456789L){ - System.out.println("failed long test"); + if (v.getCurrency()!=123456789123456789L){ + System.out.println("failed currency test"); + } + + Date ourDate = new Date(); + v.putDate(ourDate); + Date retrievedDate = v.getJavaDate(); + if (!retrievedDate.equals(ourDate)){ + System.out.println("failed java date load and unload"); } v.putNull(); diff --git a/unittest/com/jacob/test/events/IETest.java b/unittest/com/jacob/test/events/IETest.java index 056fd74..46cd0bd 100644 --- a/unittest/com/jacob/test/events/IETest.java +++ b/unittest/com/jacob/test/events/IETest.java @@ -34,10 +34,12 @@ class IETest //e.printStackTrace(); } } - System.out.println("Thread quit, about to quit main sta"); + System.out.println("Main: Thread quit, about to quit main sta in thread " + +Thread.currentThread().getName()); // this line only does someting if startMainSTA() was called ComThread.quitMainSTA(); - System.out.println("did quit main sta"); + System.out.println("Main: did quit main sta in thread " + +Thread.currentThread().getName()); } } @@ -59,22 +61,33 @@ class IETestThread extends Thread try { Dispatch.put(ie, "Visible", new Variant(true)); Dispatch.put(ie, "AddressBar", new Variant(true)); - System.out.println(Dispatch.get(ie, "Path")); + System.out.println("IETestThread: " + Dispatch.get(ie, "Path")); Dispatch.put(ie, "StatusText", new Variant("My Status Text")); + System.out.println("IETestThread: About to hookup event listener"); IEEvents ieE = new IEEvents(); new DispatchEvents((Dispatch) ie, ieE,"InternetExplorer.Application.1"); + System.out.println("IETestThread: Did hookup event listener"); + /// why is this here? Was there some other code here in the past? Variant optional = new Variant(); - optional.noParam(); + optional.putNoParam(); + System.out.println("IETestThread: About to call navigate to sourceforge"); Dispatch.call(ie, "Navigate", new Variant("http://sourceforge.net/projects/jacob-project")); + System.out.println("IETestThread: Did call navigate to sourceforge"); try { Thread.sleep(delay); } catch (Exception e) {} + System.out.println("IETestThread: About to call navigate to yahoo"); Dispatch.call(ie, "Navigate", new Variant("http://groups.yahoo.com/group/jacob-project")); + System.out.println("IETestThread: Did call navigate to yahoo"); try { Thread.sleep(delay); } catch (Exception e) {} } catch (Exception e) { e.printStackTrace(); + } catch (Throwable re){ + re.printStackTrace(); } finally { - ie.invoke("Quit", new Variant[] {}); + System.out.println("IETestThread: About to send Quit"); + ie.invoke("Quit", new Variant[] {}); + System.out.println("IETestThread: Did send Quit"); } // this blows up when it tries to release a DispatchEvents object // I think this is because there is still one event we should get back @@ -83,13 +96,14 @@ class IETestThread extends Thread // freed before the callback // commenting out ie.invoke(quit...) causes this to work without error // this code tries to wait until the quit has been handled but that doesn't work - System.out.println("IETest: Waiting until we've received the quit callback"); + System.out.println("IETestThread: Waiting until we've received the quit callback"); while (!quitHandled){ try { Thread.sleep(delay/5);} catch (InterruptedException e) {} } + System.out.println("IETestThread: Received the quit callback"); // wait a little while for it to end - try {Thread.sleep(delay); } catch (InterruptedException e) {} - System.out.println("IETest: about to call release in thread " + + //try {Thread.sleep(delay); } catch (InterruptedException e) {} + System.out.println("IETestThread: about to call ComThread.Release in thread " + Thread.currentThread().getName()); ComThread.Release(); @@ -101,76 +115,76 @@ class IETestThread extends Thread public class IEEvents { public void BeforeNavigate2(Variant[] args) { - System.out.println("IEEvents: BeforeNavigate2"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): BeforeNavigate2 "+args.length); } public void CommandStateChange(Variant[] args) { - System.out.println("IEEvents: CommandStateChange"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): CommandStateChange "+args.length); } public void DocumentComplete(Variant[] args) { - System.out.println("IEEvents: DocumentComplete"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DocumentComplete "+args.length); } public void DownloadBegin(Variant[] args) { - System.out.println("IEEvents: DownloadBegin"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DownloadBegin "+args.length); } public void DownloadComplete(Variant[] args) { - System.out.println("IEEvents: DownloadComplete"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DownloadComplete "+args.length); } public void NavigateComplete2(Variant[] args) { - System.out.println("IEEvents: NavigateComplete2"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NavigateComplete "+args.length); } public void NewWindow2(Variant[] args) { - System.out.println("IEEvents: NewWindow2"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NewWindow2 "+args.length); } public void OnFullScreen(Variant[] args) { - System.out.println("IEEvents: OnFullScreen"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnFullScreen "+args.length); } public void OnMenuBar(Variant[] args) { - System.out.println("IEEvents: OnMenuBar"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnMenuBar "+args.length); } public void OnQuit(Variant[] args) { - System.out.println("IEEvents: OnQuit"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnQuit "+args.length); IETestThread.quitHandled = true; } public void OnStatusBar(Variant[] args) { - System.out.println("IEEvents: OnStatusBar"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnStatusBar "+args.length); } public void OnTheaterMode(Variant[] args) { - System.out.println("IEEvents: OnTheaterMode"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnTheaterMode "+args.length); } public void OnToolBar(Variant[] args) { - System.out.println("IEEvents: OnToolBar"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnToolBar "+args.length); } public void OnVisible(Variant[] args) { - System.out.println("IEEvents: OnVisible"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnVisible "+args.length); } public void ProgressChange(Variant[] args) { - System.out.println("IEEvents: ProgressChange"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): ProgressChange "+args.length); } public void PropertyChange(Variant[] args) { - System.out.println("IEEvents: PropertyChange"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): PropertyChange "+args.length); } public void StatusTextChange(Variant[] args) { - System.out.println("IEEvents: StatusTextChange"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): StatusTextChange "+args.length); } public void TitleChange(Variant[] args) { - System.out.println("IEEvents: TitleChange"); + System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): TitleChange "+args.length); } }