From 623c6e9b6b53d24215d0c1c9121a91751aeddb78 Mon Sep 17 00:00:00 2001 From: clay_shooter Date: Sun, 7 Nov 2010 15:36:32 +0000 Subject: [PATCH] SF2963102 use varargs in Dispatch instead of a million overloaded methods --- .cvsignore | 1 + README.txt | 2 +- build.xml | 2 +- docs/BuildingJacobFromSource.html | 4 + docs/ReleaseNotes.html | 7 +- .../com/jacob/samples/office/TestDocument.doc | Bin 0 -> 23040 bytes .../office/WordDocumentProperties.java | 8 +- .../com/jacob/samples/office/~$stDocument.doc | Bin 0 -> 162 bytes src/com/jacob/activeX/ActiveXComponent.java | 116 +--- src/com/jacob/com/Dispatch.java | 568 ++---------------- src/com/jacob/com/JacobObject.java | 1 - src/com/jacob/com/VariantUtilities.java | 13 +- unittest/com/jacob/com/LibraryLoaderTest.java | 21 +- .../com/jacob/com/VariantUtilitiesTest.java | 29 + unittest/com/jacob/test/events/IETest.java | 4 +- .../com/jacob/test/windowsmedia/WMPlayer.java | 47 +- 16 files changed, 174 insertions(+), 649 deletions(-) create mode 100644 samples/com/jacob/samples/office/TestDocument.doc create mode 100644 samples/com/jacob/samples/office/~$stDocument.doc diff --git a/.cvsignore b/.cvsignore index 51e41b6..8f16a71 100644 --- a/.cvsignore +++ b/.cvsignore @@ -15,3 +15,4 @@ foo.foo foo.ser JacobVersion.properties .settings +setenv.sh diff --git a/README.txt b/README.txt index 0039ff6..883ac81 100644 --- a/README.txt +++ b/README.txt @@ -2,7 +2,7 @@ JACOB (Java-COM bridge) is hosted on Sourceforge http://sourceforge.net/project/ Information about what's new in this release can be found in docs/ReleaseNotes.html -Instructions on building this project can be found in docs/HowToBuild.html +Instructions on building this project can be found in docs/BuildingJacobFromSource.html Detailed instructions on creating a build configuration file are in build.xml Put the appropriate DLL for your platform into your runtime library path. diff --git a/build.xml b/build.xml index e920840..36a5396 100644 --- a/build.xml +++ b/build.xml @@ -57,7 +57,7 @@ - + diff --git a/docs/BuildingJacobFromSource.html b/docs/BuildingJacobFromSource.html index 03cfbf2..7cd5f75 100644 --- a/docs/BuildingJacobFromSource.html +++ b/docs/BuildingJacobFromSource.html @@ -120,6 +120,10 @@ Sympton: Can't find jni.h or can't find C++ compiler

Problem: compilation_tools.properties configured incorrectly. Either paths are wrong or the separator is wrong. It requires two backslashes for a separator.

+

  • +Symptom: Ant fails with the message Could not create task or type of type: junit..

    +Problem: junit.jar must be copied from this project to the $ANT_HOME/lib directory.

    +

  • Running Samples and Tests

    diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html index e77f3df..080746b 100644 --- a/docs/ReleaseNotes.html +++ b/docs/ReleaseNotes.html @@ -1,7 +1,7 @@ -

    JACOB 1.15 M2

    +

    JACOB 1.15 M4

    What's New

    • @@ -54,6 +54,11 @@ Feature Requests + + 2963102 + Convert API to use var args and remove the many overloaded Dispatch + methods that each added one more parameter.(M4) +     diff --git a/samples/com/jacob/samples/office/TestDocument.doc b/samples/com/jacob/samples/office/TestDocument.doc new file mode 100644 index 0000000000000000000000000000000000000000..6ad406882231fa43f90ca75a3a34f3be1627a314 GIT binary patch literal 23040 zcmeG^2V7H0^GhJ~CITX$MnuIzM?g+MG@O7U2#CD|2oOvNgn(F3ELiaT#CjG^5qm+n zQ*77}1#E~F)KdYwf`?}TPBGt1lBW>mM8Et0e)qr2@SDu;?9S}&ynXw2_RXX8Vw;MM zKO0vP8E_+t=YtBoZOJDtP z@gfoeR~A5(5FJ2m5)u^>wJ&&Iu$bHIM@`9)IA{}cy`O>@b()oanh}XU)@UhBNgWU; zmeD17q}TK$=|7|TlsHhl2$+2$mHQmkg!0!=j+83j2uf^VS}U|g=`Yh?rS)Vf6ZFtP z{(EVsT1zh(5RwUkaYlsfmdXR`6QJxswJTeJ;J1Jch`W zj!Twed+Jaut4B7E_Gt#P`DTSJXQ=UgQQtS}Z?R>mKFUtie5+9H#al4r94?Gvpyt&> zsa-zUOImINdQep?{MZ1+`6mV`?bKe9tp$0!HL1L;9!afl|NWp>s)D*+*berKvNJ`g z_NhEYzt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}*0l5X_7LZ#&ZUMOk57|2mIXG z0!FZ5KhW35aY;@bP&-P&*##iwt1}>tTz5c}86?eP8prA#EqM_GuXz}O{CGhqyV(#w z9ASK>9!SeUZUMOk_cxTR?6Bxdr4FkXt}*fiGJC{ZjNp(N{%(9es85 zXYsu~{$DSAUytwT(MLyL8+~!~qtVAle;s{!e3y@YEc(hQgMK^u_UO3cKd&(cgs(ls z->P6a`plgG8GxMu%>cUqnge2aBVcz(TS)WB>m^M?QVxHi1u#60FAlfy6o=giAoT5P zz>v@tsP5n#QdYy+M92y8FML|p1Wxp_6#r+Wp2(9Pj@UwI5A|(bld7#wYQyZM+DFB}1C{9zY=}Wm`28c=-W#q$xVTTq z5kgQPew)}bSU~$|alCh1JAUzh6T_Pqfd0wIzpg*d&^|Tx*0wMHuu|H-F9d7yp$|A# z7T7{49((J9v5etljcOm)t&tkqg9wxWb<-*b#*fvIo(?OV_W6Y z2K`~yVOSg+D9$zvp8Xmy{D%7v=jw2L@Bk=42rLHZ#t=Vo5TAtG`d>X5KdQp#R%^$P z&$F*v<^H@s)ck90`+u(O>r4Na_R)6K^B@QK}*3bIGVBBE3whF%bBb#Wxq6`@p_pQSZ zjfduWBY9jiw|>yPlznq4nzu(C{3m~Uo^RvRC#kOHhKim)K# zT_wABL?7V8yS=6{w2Zz^mhhF5{fB>CCw5VM12Mi9=9+kKg=s5l;#oP9SABnpZPkqU HcUAf?kzmYA literal 0 HcmV?d00001 diff --git a/samples/com/jacob/samples/office/WordDocumentProperties.java b/samples/com/jacob/samples/office/WordDocumentProperties.java index 8bb090d..223ea82 100644 --- a/samples/com/jacob/samples/office/WordDocumentProperties.java +++ b/samples/com/jacob/samples/office/WordDocumentProperties.java @@ -1,5 +1,7 @@ package com.jacob.samples.office; +import java.io.File; + import com.jacob.activeX.ActiveXComponent; import com.jacob.com.ComException; import com.jacob.com.Dispatch; @@ -7,6 +9,8 @@ import com.jacob.com.Variant; /** * Submitted to the Jacob SourceForge web site as a sample 3/2005 + *

      + * This sample is BROKEN because it doesn't call quit! * * @author Date Created Description Jason Twist 04 Mar 2005 Code opens a locally * stored Word document and extracts the Built In properties and Custom @@ -137,7 +141,9 @@ public class WordDocumentProperties { WordDocumentProperties jacTest = new WordDocumentProperties(); // Open the word doc - jacTest.open("\\\\Saturn\\documentstorage\\s.doc"); + File doc = new File( + "samples/com/jacob/samples/office/TestDocument.doc"); + jacTest.open(doc.getAbsolutePath()); // Set Custom Properties jacTest.selectCustomDocumentProperitiesMode(); diff --git a/samples/com/jacob/samples/office/~$stDocument.doc b/samples/com/jacob/samples/office/~$stDocument.doc new file mode 100644 index 0000000000000000000000000000000000000000..56c1004d91f90aac6a1eefd51dc34fcaff59e659 GIT binary patch literal 162 zcmZS1%1>n=889Experimental in release 1.9.2. + * Most code should use the standard ActiveXComponent(String) constructor + * and not this factory method. This method exists for applications that + * need special behavior. Experimental in release 1.9.2. *

      * Factory that returns a Dispatch wrapped around the result of a * getActiveObject() call. This differs from the standard constructor in @@ -150,6 +150,7 @@ public class ActiveXComponent extends Dispatch { /** * @see com.jacob.com.Dispatch#finalize() */ + @Override protected void finalize() { super.finalize(); } @@ -382,58 +383,12 @@ public class ActiveXComponent extends Dispatch { * makes a dispatch call for the passed in action and single parameter * * @param callAction - * @param parameter + * @param parameters * @return ActiveXComponent representing the results of the call */ public ActiveXComponent invokeGetComponent(String callAction, - Variant parameter) { - return new ActiveXComponent(invoke(callAction, parameter).toDispatch()); - } - - /** - * makes a dispatch call for the passed in action and single parameter - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @return ActiveXComponent representing the results of the call - */ - public ActiveXComponent invokeGetComponent(String callAction, - Variant parameter1, Variant parameter2) { - return new ActiveXComponent(invoke(callAction, parameter1, parameter2) - .toDispatch()); - } - - /** - * makes a dispatch call for the passed in action and single parameter - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @param parameter3 - * @return ActiveXComponent representing the results of the call - */ - public ActiveXComponent invokeGetComponent(String callAction, - Variant parameter1, Variant parameter2, Variant parameter3) { - return new ActiveXComponent(invoke(callAction, parameter1, parameter2, - parameter3).toDispatch()); - } - - /** - * makes a dispatch call for the passed in action and single parameter - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @param parameter3 - * @param parameter4 - * @return ActiveXComponent representing the results of the call - */ - public ActiveXComponent invokeGetComponent(String callAction, - Variant parameter1, Variant parameter2, Variant parameter3, - Variant parameter4) { - return new ActiveXComponent(invoke(callAction, parameter1, parameter2, - parameter3, parameter4).toDispatch()); + Variant... parameters) { + return new ActiveXComponent(invoke(callAction, parameters).toDispatch()); } /** @@ -499,61 +454,6 @@ public class ActiveXComponent extends Dispatch { new Variant(parameter2)); } - /** - * makes a dispatch call for the passed in action and single parameter - * - * @param callAction - * @param parameter - * @return a Variant but that may be null for some calls - */ - public Variant invoke(String callAction, Variant parameter) { - return Dispatch.call(this, callAction, parameter); - } - - /** - * makes a dispatch call for the passed in action and two parameter - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @return a Variant but that may be null for some calls - */ - public Variant invoke(String callAction, Variant parameter1, - Variant parameter2) { - return Dispatch.call(this, callAction, parameter1, parameter2); - } - - /** - * makes a dispatch call for the passed in action and two parameter - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @param parameter3 - * @return Variant result data - */ - public Variant invoke(String callAction, Variant parameter1, - Variant parameter2, Variant parameter3) { - return Dispatch.call(this, callAction, parameter1, parameter2, - parameter3); - } - - /** - * calls call() with 4 variant parameters - * - * @param callAction - * @param parameter1 - * @param parameter2 - * @param parameter3 - * @param parameter4 - * @return Variant result data - */ - public Variant invoke(String callAction, Variant parameter1, - Variant parameter2, Variant parameter3, Variant parameter4) { - return Dispatch.call(this, callAction, parameter1, parameter2, - parameter3, parameter4); - } - /** * makes a dispatch call for the passed in action and no parameter * @@ -572,7 +472,7 @@ public class ActiveXComponent extends Dispatch { * @param args * @return Variant returned by the invoke (Dispatch.callN) */ - public Variant invoke(String name, Variant[] args) { + public Variant invoke(String name, Variant... args) { return Dispatch.callN(this, name, args); } diff --git a/src/com/jacob/com/Dispatch.java b/src/com/jacob/com/Dispatch.java index 0af2959..a214afc 100644 --- a/src/com/jacob/com/Dispatch.java +++ b/src/com/jacob/com/Dispatch.java @@ -1,21 +1,19 @@ /* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * Get more information about JACOB at http://sourceforge.net/projects/jacob-project - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. Originator: Dan Adler + * (http://danadler.com). Get more information about JACOB at + * http://sourceforge.net/projects/jacob-project + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * You should have received a copy of the GNU Lesser General Public License along with this library; + * if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA */ package com.jacob.com; @@ -235,6 +233,7 @@ public class Dispatch extends JacobObject { * * @see java.lang.Object#finalize() */ + @Override protected void finalize() { safeRelease(); } @@ -244,6 +243,7 @@ public class Dispatch extends JacobObject { * * @see com.jacob.com.JacobObject#safeRelease() */ + @Override public void safeRelease() { super.safeRelease(); if (isAttached()) { @@ -380,11 +380,10 @@ public class Dispatch extends JacobObject { * an array of argument objects */ public static void callSubN(Dispatch dispatchTarget, String name, - Object[] args) { + Object... args) { throwIfUnattachedDispatch(dispatchTarget); invokeSubv(dispatchTarget, name, Dispatch.Method | Dispatch.Get, - VariantUtilities.objectsToVariants(args), - new int[args.length]); + VariantUtilities.objectsToVariants(args), new int[args.length]); } /** @@ -394,11 +393,10 @@ public class Dispatch extends JacobObject { * an array of argument objects */ public static void callSubN(Dispatch dispatchTarget, int dispID, - Object[] args) { + Object... args) { throwIfUnattachedDispatch(dispatchTarget); invokeSubv(dispatchTarget, dispID, Dispatch.Method | Dispatch.Get, - VariantUtilities.objectsToVariants(args), - new int[args.length]); + VariantUtilities.objectsToVariants(args), new int[args.length]); } /* @@ -450,11 +448,10 @@ public class Dispatch extends JacobObject { * @return Variant returned by call */ public static Variant callN(Dispatch dispatchTarget, String name, - Object[] args) { + Object... args) { throwIfUnattachedDispatch(dispatchTarget); return invokev(dispatchTarget, name, Dispatch.Method | Dispatch.Get, - VariantUtilities.objectsToVariants(args), - new int[args.length]); + VariantUtilities.objectsToVariants(args), new int[args.length]); } /** @@ -464,11 +461,10 @@ public class Dispatch extends JacobObject { * @return Variant returned by call */ public static Variant callN(Dispatch dispatchTarget, int dispID, - Object[] args) { + Object... args) { throwIfUnattachedDispatch(dispatchTarget); return invokev(dispatchTarget, dispID, Dispatch.Method | Dispatch.Get, - VariantUtilities.objectsToVariants(args), - new int[args.length]); + VariantUtilities.objectsToVariants(args), new int[args.length]); } /** @@ -536,128 +532,13 @@ public class Dispatch extends JacobObject { /** * @param dispatchTarget * @param name - * @param a1 + * @param attributes * @return Variant returned by underlying callN */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1) { + public static Variant call(Dispatch dispatchTarget, String name, + Object... attributes) { throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @return Variant retuned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3, a4 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @return Variant retuned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, - a6 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, - a6, a7 }); - } - - /** - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @param a8 - * @return Variant retuned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, - Object a8) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, - a6, a7, a8 }); + return callN(dispatchTarget, name, attributes); } /** @@ -673,129 +554,15 @@ public class Dispatch extends JacobObject { /** * @param dispatchTarget * @param dispid - * @param a1 + * @param attributes + * var arg list of attributes that will be passed to the + * underlying function * @return Variant returned by underlying callN */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1) { + public static Variant call(Dispatch dispatchTarget, int dispid, + Object... attributes) { throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2, a3 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, - new Object[] { a1, a2, a3, a4, a5 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5, - a6 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5, - a6, a7 }); - } - - /** - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @param a8 - * @return Variant returned by underlying callN - */ - public static Variant call(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, - Object a8) { - throwIfUnattachedDispatch(dispatchTarget); - return callN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5, - a6, a7, a8 }); + return callN(dispatchTarget, dispid, attributes); } /* @@ -910,8 +677,8 @@ public class Dispatch extends JacobObject { public static void invokeSub(Dispatch dispatchTarget, String name, int dispid, int lcid, int wFlags, Object[] oArg, int[] uArgErr) { throwIfUnattachedDispatch(dispatchTarget); - invokeSubv(dispatchTarget, name, dispid, lcid, wFlags, - VariantUtilities.objectsToVariants(oArg), uArgErr); + invokeSubv(dispatchTarget, name, dispid, lcid, wFlags, VariantUtilities + .objectsToVariants(oArg), uArgErr); } /* @@ -968,133 +735,14 @@ public class Dispatch extends JacobObject { * * @param dispatchTarget * @param name - * @param a1 + * @param attributes + * var args list of attributes to be passed to underlying + * functions */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1) { + public static void callSub(Dispatch dispatchTarget, String name, + Object... attributes) { throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3, a4 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, a6 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, a6, - a7 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param name - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @param a8 - */ - public static void callSub(Dispatch dispatchTarget, String name, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, - Object a8) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, name, new Object[] { a1, a2, a3, a4, a5, a6, - a7, a8 }); + callSubN(dispatchTarget, name, attributes); } /** @@ -1113,132 +761,14 @@ public class Dispatch extends JacobObject { * * @param dispatchTarget * @param dispid - * @param a1 + * @param attributes + * var args list of attributes to be passed to underlying + * function */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1) { + public static void callSub(Dispatch dispatchTarget, int dispid, + Object... attributes) { throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, new Object[] { a1 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, new Object[] { a1, a2 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3) { - callSubN(dispatchTarget, dispid, new Object[] { a1, a2, a3 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, - new Object[] { a1, a2, a3, a4, a5, a6 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7) { - throwIfUnattachedDispatch(dispatchTarget); - callSubN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5, a6, - a7 }); - } - - /** - * makes call to native callSubN - * - * @param dispatchTarget - * @param dispid - * @param a1 - * @param a2 - * @param a3 - * @param a4 - * @param a5 - * @param a6 - * @param a7 - * @param a8 - */ - public static void callSub(Dispatch dispatchTarget, int dispid, Object a1, - Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, - Object a8) { - callSubN(dispatchTarget, dispid, new Object[] { a1, a2, a3, a4, a5, a6, - a7, a8 }); + callSubN(dispatchTarget, dispid, attributes); } /* @@ -1315,4 +845,4 @@ public class Dispatch extends JacobObject { throw new NotImplementedException("not implemented yet"); } -} \ No newline at end of file +} diff --git a/src/com/jacob/com/JacobObject.java b/src/com/jacob/com/JacobObject.java index 3b96363..acd346c 100644 --- a/src/com/jacob/com/JacobObject.java +++ b/src/com/jacob/com/JacobObject.java @@ -63,7 +63,6 @@ public class JacobObject { "true".equalsIgnoreCase(System.getProperty("com.jacob.debug")); protected static boolean isDebugEnabled() { - // return true; return DEBUG; } diff --git a/src/com/jacob/com/VariantUtilities.java b/src/com/jacob/com/VariantUtilities.java index 9d03e66..afaa8bb 100644 --- a/src/com/jacob/com/VariantUtilities.java +++ b/src/com/jacob/com/VariantUtilities.java @@ -213,11 +213,16 @@ public final class VariantUtilities { */ protected static Variant[] objectsToVariants( Object[] arrayOfObjectsToBeConverted) { - Variant vArg[] = new Variant[arrayOfObjectsToBeConverted.length]; - for (int i = 0; i < arrayOfObjectsToBeConverted.length; i++) { - vArg[i] = objectToVariant(arrayOfObjectsToBeConverted[i]); + if (arrayOfObjectsToBeConverted instanceof Variant[]) { + // just return the passed in array if it is a Variant array + return (Variant[]) arrayOfObjectsToBeConverted; + } else { + Variant vArg[] = new Variant[arrayOfObjectsToBeConverted.length]; + for (int i = 0; i < arrayOfObjectsToBeConverted.length; i++) { + vArg[i] = objectToVariant(arrayOfObjectsToBeConverted[i]); + } + return vArg; } - return vArg; } /** diff --git a/unittest/com/jacob/com/LibraryLoaderTest.java b/unittest/com/jacob/com/LibraryLoaderTest.java index 70ddd48..7705f27 100644 --- a/unittest/com/jacob/com/LibraryLoaderTest.java +++ b/unittest/com/jacob/com/LibraryLoaderTest.java @@ -32,14 +32,9 @@ public class LibraryLoaderTest extends TestCase { * verify LibraryLoader.JACOB_DLL_NAME is read by LibraryLoader */ public void testJacobDllNameSystemProperty() { - // fill with bad dll name - System.setProperty(LibraryLoader.JACOB_DLL_NAME, "xxx"); - try { - LibraryLoader.loadJacobLibrary(); - fail("Should have been unable to load dll with name xxx"); - } catch (UnsatisfiedLinkError ule) { - // yes, this is what we want to see when using a bad name - } + // this test used to run in the reverse order but that caused + // ClassDefNotFound on DEBUG + // no way to clear a system property once set so lets try setting to // default System.setProperty(LibraryLoader.JACOB_DLL_NAME, LibraryLoader @@ -52,6 +47,16 @@ public class LibraryLoaderTest extends TestCase { + LibraryLoader.getPreferredDLLName() + " " + ule.getMessage()); } + + // fill with bad dll name and try again + System.setProperty(LibraryLoader.JACOB_DLL_NAME, "xxx"); + try { + LibraryLoader.loadJacobLibrary(); + fail("Should have been unable to load dll with name xxx"); + } catch (UnsatisfiedLinkError ule) { + System.out.println("correctly caught UnsatisfiedLinkError"); + // yes, this is what we want to see when using a bad name + } } /** diff --git a/unittest/com/jacob/com/VariantUtilitiesTest.java b/unittest/com/jacob/com/VariantUtilitiesTest.java index 736884c..423ca25 100644 --- a/unittest/com/jacob/com/VariantUtilitiesTest.java +++ b/unittest/com/jacob/com/VariantUtilitiesTest.java @@ -11,6 +11,35 @@ import com.jacob.test.BaseTestCase; */ public class VariantUtilitiesTest extends BaseTestCase { + /** + * verifies our unpacking stuff + */ + public void testObjectsToVariants() { + Object testArray[] = new Object[] { Integer.valueOf(1), + Integer.valueOf(2) }; + Variant resultArray[] = VariantUtilities.objectsToVariants(testArray); + assertEquals(2, resultArray.length); + + Variant resultArray2[] = VariantUtilities + .objectsToVariants(resultArray); + assertEquals(2, resultArray2.length); + assertSame(resultArray[0], resultArray2[0]); + assertSame(resultArray[1], resultArray2[1]); + } + + /** + * test nested arrays + */ + public void testObjectsToVariantNestedArray() { + Object testArray[] = new Object[] { Integer.valueOf(1), + Integer.valueOf(2) }; + Object testArrayOuter[] = new Object[] { testArray }; + Variant resultArray[] = VariantUtilities + .objectsToVariants(testArrayOuter); + // should be a SafeArray + assertEquals(1, resultArray.length); + } + /** * verify that dispatch can convert from object to variant and that the * variant holds the right value diff --git a/unittest/com/jacob/test/events/IETest.java b/unittest/com/jacob/test/events/IETest.java index e4560a9..40d529f 100644 --- a/unittest/com/jacob/test/events/IETest.java +++ b/unittest/com/jacob/test/events/IETest.java @@ -25,7 +25,7 @@ public class IETest extends BaseTestCase { /** * well known address we can navigate to */ - private String testUrls[] = { + private final String testUrls[] = { "http://sourceforge.net/projects/jacob-project", "http://www.google.com" }; @@ -70,6 +70,7 @@ public class IETest extends BaseTestCase { + Thread.currentThread().getName()); if (aThread.threadFailedWithException != null) { + aThread.threadFailedWithException.printStackTrace(); fail("caught an unexpected exception " + aThread.threadFailedWithException); } @@ -113,6 +114,7 @@ class IETestThread extends Thread { /** * Run through the addresses passed in via the constructor */ + @Override public void run() { // pick a time that lets sourceforge respond (in msec) int delay = 3000; diff --git a/unittest/com/jacob/test/windowsmedia/WMPlayer.java b/unittest/com/jacob/test/windowsmedia/WMPlayer.java index 734d391..0cd6237 100644 --- a/unittest/com/jacob/test/windowsmedia/WMPlayer.java +++ b/unittest/com/jacob/test/windowsmedia/WMPlayer.java @@ -5,26 +5,65 @@ package com.jacob.test.windowsmedia; * that says you get a random "can't map name to dispid" when * getting the URL from the player *

      + * this doesn't actually play for some reason. It always says the length is 0. + *

      * May need to run with some command line options (including from inside Eclipse). * Look in the docs area at the Jacob usage document for command line options. + *

      */ +import java.io.File; + import com.jacob.activeX.ActiveXComponent; +import com.jacob.com.Dispatch; +import com.jacob.com.Variant; import com.jacob.test.BaseTestCase; public class WMPlayer extends BaseTestCase { + /** + * This should demo the media player but it doesn't + */ public void testOpenWMPlayer() { + // this file exists in windows 7 installations + File file = new File( + "C:/Windows/winsxs/x86_microsoft-windows-videosamples_31bf3856ad364e35_6.1.7600.16385_none_f583837f77a63ec7"); + String filePath = file.getAbsolutePath(); + String microsoftTestURL = filePath; + // use these instead if not on windows 7 + // "http://support.microsoft.com/support/mediaplayer/wmptest/samples/new/mediaexample.wma"; + // "http://support.microsoft.com/support/mediaplayer/wmptest/samples/new/mediaexample.wmv"; ActiveXComponent wmp = null; - wmp = new ActiveXComponent("WMPlayer.OCX"); + // could use WMPlayer.OCX alias also + wmp = new ActiveXComponent( + "CLSID:{6BF52A52-394A-11D3-B153-00C04F79FAA6}");// ("WMPlayer.OCX"); + wmp.setProperty("URL", microsoftTestURL); + assertEquals(wmp.getProperty("URL").toString(), microsoftTestURL); + + // alternative way to get the controls + Dispatch controls = Dispatch.get(wmp, "controls").toDispatch(); + Dispatch.call(controls, "Play"); // the sourceforge posting didn't post all the code so this is all we // have we need some other information on how to set the document // so that we have a url to open + + // pause to let it play a second or two + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + System.out.println("Thread interrupted"); + } for (int i = 0; i < 1000; i++) { - System.out.println("the wmp url is " - + wmp.getProperty("URL").toString()); + // Get media object + Dispatch vMedObj = wmp.getProperty("currentMedia").toDispatch(); + // Get duration of media object + Variant vdur = Dispatch.call(vMedObj, "duration"); + // why is this always 0? + // System.out.println(microsoftTestURL + " length is " + // + vdur.getDouble()); + // System.out.println("the wmp url is " + // + wmp.getProperty("URL").toString()); } } - }