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 0000000..6ad4068 Binary files /dev/null and b/samples/com/jacob/samples/office/TestDocument.doc differ 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 0000000..56c1004 Binary files /dev/null and b/samples/com/jacob/samples/office/~$stDocument.doc differ diff --git a/src/com/jacob/activeX/ActiveXComponent.java b/src/com/jacob/activeX/ActiveXComponent.java index a5dc44d..4d0096b 100644 --- a/src/com/jacob/activeX/ActiveXComponent.java +++ b/src/com/jacob/activeX/ActiveXComponent.java @@ -117,9 +117,9 @@ public class ActiveXComponent extends Dispatch { } /** - * 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. + * 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()); } } - }