From 43dce6d42fd2864e82374c358cac967e62a9c3dd Mon Sep 17 00:00:00 2001 From: clay_shooter Date: Sat, 8 Jan 2005 17:02:55 +0000 Subject: [PATCH] Generated basic javadoc for most methods. Still need some help here Reformatteda all source using eclipse eliminated parameters with same names as method variagles repackaged all tests so that their package names match the directories they are in merged in Jiffie and Variant EventProxy changes --- EventCallbacks.htm | 283 ++++++ com/jacob/activeX/ActiveXComponent.java | 161 ++-- com/jacob/com/ComException.java | 224 +++-- com/jacob/com/ComFailException.java | 153 +-- com/jacob/com/ComThread.java | 275 +++--- com/jacob/com/DispatchEvents.java | 70 +- com/jacob/com/DispatchProxy.java | 142 +-- com/jacob/com/EnumVariant.java | 253 ++--- com/jacob/com/JacobObject.java | 98 +- com/jacob/com/MainSTA.java | 85 +- com/jacob/com/ROT.java | 191 ++-- com/jacob/com/STA.java | 202 ++-- com/jacob/com/SafeArray.java | 906 +++++++++++++----- com/jacob/com/WrongThreadException.java | 85 +- jni/EventProxy.cpp | 668 ++++++++++++- jni/EventProxy.h | 2 + samples/ado/Command.java | 243 ++--- samples/ado/CommandTypeEnum.java | 26 +- samples/ado/Connection.java | 362 +++---- samples/ado/Field.java | 249 ++--- samples/ado/Fields.java | 101 +- samples/ado/Recordset.java | 823 ++++++++-------- samples/ado/ms/README | 3 - samples/ado/ms/README.txt | 9 + .../ado/ms/{testms.java => testms.java.txt} | 130 +-- samples/ado/test.java | 125 +-- samples/applet/AppTest.java | 86 +- samples/servlet/JacobScript.java | 148 +-- samples/test/Access.java | 199 ++-- .../{MultiFace.java => MultiFaceTest.java} | 66 +- 30 files changed, 3966 insertions(+), 2402 deletions(-) create mode 100644 EventCallbacks.htm delete mode 100644 samples/ado/ms/README create mode 100644 samples/ado/ms/README.txt rename samples/ado/ms/{testms.java => testms.java.txt} (96%) rename samples/test/atl/{MultiFace.java => MultiFaceTest.java} (95%) diff --git a/EventCallbacks.htm b/EventCallbacks.htm new file mode 100644 index 0000000..4859158 --- /dev/null +++ b/EventCallbacks.htm @@ -0,0 +1,283 @@ + + + + + + + + +Jacob can register Java classes for MS application events or callbacks + + + + + + + +
+ +

Jacob can register Java classes for MS application events +or callbacks.  The normal flow for this +is:

+ +

 

+ +

1)        +Application thread creates an instance of the +event handler and registers it with Jacob

+ +

2)        +The application continues on doing other work.

+ +

3)        +Some time later, the MS application takes some +action and initiates the event callback.

+ +

4)        +The Java VM receives the event and spins up a +new thread to handle it.

+ +

5)        +The Jacob EventProxy +in the dll is called by the VM.

+ +

6)        +The Jacob EventProxy +creates Variant objects to handle the parameters of the passed in event.

+ +

7)        +The Jacob EventProxy +uses reflection to map the event name to a method name with the exact same +name.

+ +

8)        +The Jacob EventProxy +sends the message to the registered event handler.

+ +

 

+ +

Swing developers should note that this message comes in +on a thread other than the event thread.  +All objects receiving events that require user intervention or drawing +in the UI should use invokeLater() to post requests for actions onto the event queue.  Failure to do so will insure random failures +in the GUI.

+ +

 

+ +

Java Web Start (JWS) and other launchers can have +additional issues related to the class loader.  +The Jacob C++ library uses FindClass() to find the Variant class when building the parameter +list.  FindClass() uses the system +class loader which includes only the classes specified at run time or in the +CLASSPATH.  Most of the application +classes in this situation live in an alternate set of class loaders that were +created when the launcher located and ran the application classes.  This means that the search for Variant will +fail usually with the silent and immediate termination of the Java application.  The thread classloader +probably can’t be used to try and find the class because this new thread does +not have a classloader associated with it other than +the system class loader.  The end result +is that the Variant class needs to be located via other means and that the +thread classloader should be set to be the context +class loader of the event handler class.

+ +

 

+ +

The Jacob EventProxy class has +been modified (off of the 1.8 tree) so that it takes a two step approach to towards +fixing these problems.

+ +

           

+ +

1)        +EventProxy first +attempts to locate the Variant class using FindClass()

+ +

2)        +Failing that, it looks to see if the event +callback object implements getVariantClass() that returns the Variant.class +object.  If so, it uses that class to +create variants for the callback parameters.

+ +

3)        +If all that fails, it logs a message and then +fails in the spectacular fashion of the previous versions.

+ +

 

+ +

This means developers can receive call back events in JWS +other Java launching programs by implementing getVariantClass() on all of +their classes that receive Microsoft Events.  +The getVariantClass() method has the added benefit of providing a spot for the +thread classloader to be set:

+ +

      Public Class getVariantClass(){

+ +

            Thread.currentThread().setContextClassLoader(

+ +

                  this.getClass().getClassLoader());

+ +

            return Variant.class

+ +

      }

+ +

 

+ +

There may still be a dual event queue issue in JWS +applications that needs to be looked at.

+ +
+ + + + diff --git a/com/jacob/activeX/ActiveXComponent.java b/com/jacob/activeX/ActiveXComponent.java index 6835076..8195c5a 100644 --- a/com/jacob/activeX/ActiveXComponent.java +++ b/com/jacob/activeX/ActiveXComponent.java @@ -1,73 +1,88 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.activeX; - -import com.jacob.com.*; - -/** - * This class simulates com.ms.activeX.ActiveXComponent only as - * it used for creating Dispatch objects - */ -public class ActiveXComponent extends Dispatch -{ - public ActiveXComponent(String progid) - { - super(progid); - } - - public Object getObject() - { - return this; - } - - public Variant invoke(String name, Variant[] args) - { - return Dispatch.callN(this, name, args); - } - - public Variant getProperty(String name) - { - return Dispatch.get(this, name); - } - - public void setProperty(String name, Variant arg) - { - Dispatch.put(this, name, arg); - } - - protected void finalize() - { - super.finalize(); - } - - static { - System.loadLibrary("jacob"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.activeX; + +import com.jacob.com.*; + +/** + * This class simulates com.ms.activeX.ActiveXComponent only as it used for + * creating Dispatch objects + */ +public class ActiveXComponent extends Dispatch { + /** + * @param progid + */ + public ActiveXComponent(String progid) { + super(progid); + } + + /** + * @return actually returns this bject + */ + public Object getObject() { + return this; + } + + /** + * @param name + * @param args + * @return Variant result of the invoke + */ + public Variant invoke(String name, Variant[] args) { + return Dispatch.callN(this, name, args); + } + + /** + * @param name property name + * @return Variant value of property + */ + public Variant getProperty(String name) { + return Dispatch.get(this, name); + } + + /** + * @param name + * @param arg + */ + public void setProperty(String name, Variant arg) { + Dispatch.put(this, name, arg); + } + + /** + * @see com.jacob.com.Dispatch#finalize() + */ + protected void finalize() { + super.finalize(); + } + + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/ComException.java b/com/jacob/com/ComException.java index 742d703..a7874cb 100644 --- a/com/jacob/com/ComException.java +++ b/com/jacob/com/ComException.java @@ -1,88 +1,136 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -public abstract class ComException extends RuntimeException -{ - // Fields - protected int hr; - protected int m_helpContext; - protected String m_helpFile; - protected String m_source; - - // Constructors - public ComException() - { - super(); - } - - public ComException(int hr) - { - super(); - this.hr = hr; - } - - public ComException(int hr, String description) - { - super(description); - this.hr = hr; - } - - public ComException(int hr, String source, String helpFile, - int helpContext) - { - super(); - this.hr = hr; - m_source = source; - m_helpFile = helpFile; - m_helpContext = helpContext; - } - - public ComException(int hr, String description, String source, - String helpFile, int helpContext) - { - super(description); - this.hr = hr; - m_source = source; - m_helpFile = helpFile; - m_helpContext = helpContext; - } - - public ComException(String description) - { - super(description); - } - - // Methods - public int getHelpContext() { return m_helpContext; } - public String getHelpFile() { return m_helpFile; } - public int getHResult() { return hr; } - public String getSource() { return m_source; } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. + * Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Redistributions in any form must + * be accompanied by information on how to obtain complete source code for the + * JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * Standard exception thrown by com jni code when there is a problem + */ +public abstract class ComException extends RuntimeException { + // Fields + /** TODO: what is this field */ + protected int hr; + /** TODO: what is this field */ + protected int m_helpContext; + /** TODO: what is this field */ + protected String m_helpFile; + /** TODO: what is this field */ + protected String m_source; + + /** + * constructor + * + */ + public ComException() { + super(); + } + + /** + * constructor with error code? + * + * @param newHr ?? + */ + public ComException(int newHr) { + super(); + this.hr = newHr; + } + + /** + * @param newHr + * @param description + */ + public ComException(int newHr, String description) { + super(description); + this.hr = newHr; + } + + /** + * @param newHr + * @param source + * @param helpFile + * @param helpContext + */ + public ComException(int newHr, String source, String helpFile, + int helpContext) { + super(); + this.hr = newHr; + m_source = source; + m_helpFile = helpFile; + m_helpContext = helpContext; + } + + /** + * @param newHr + * @param description + * @param source + * @param helpFile + * @param helpContext + */ + public ComException(int newHr, String description, String source, + String helpFile, int helpContext) { + super(description); + this.hr = newHr; + m_source = source; + m_helpFile = helpFile; + m_helpContext = helpContext; + } + + /** + * @param description + */ + public ComException(String description) { + super(description); + } + + /** + * @return int representation of the help context + */ + // Methods + public int getHelpContext() { + return m_helpContext; + } + + /** + * @return String ??? help file + */ + public String getHelpFile() { + return m_helpFile; + } + + /** + * @return int hr result ?? + */ + public int getHResult() { + return hr; + } + + /** + * @return String source ?? + */ + public String getSource() { + return m_source; + } +} \ No newline at end of file diff --git a/com/jacob/com/ComFailException.java b/com/jacob/com/ComFailException.java index 6f72140..bb3a415 100644 --- a/com/jacob/com/ComFailException.java +++ b/com/jacob/com/ComFailException.java @@ -1,65 +1,88 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -public class ComFailException extends ComException -{ - // Constructors - public ComFailException(int hr) - { - super(hr); - } - public ComFailException(int hr, String message) - { - super(hr, message); - } - - public ComFailException(int hr, String source, String helpFile, - int helpContext) - { - super(hr, source, helpFile, helpContext); - } - - public ComFailException(int hr, String description, - String source, String helpFile, int helpContext) - { - super(hr, description, source, helpFile, helpContext); - } - - public ComFailException() - { - super(); - } - - public ComFailException(String message) - { - super(message); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. + * Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Redistributions in any form must + * be accompanied by information on how to obtain complete source code for the + * JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * @author joe + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class ComFailException extends ComException { + /** + * @param hrNew + */ + // Constructors + public ComFailException(int hrNew) { + super(hrNew); + } + + /** + * @param hrNew + * @param message + */ + public ComFailException(int hrNew, String message) { + super(hrNew, message); + } + + /** + * @param hrNew + * @param source + * @param helpFile + * @param helpContext + */ + public ComFailException(int hrNew, String source, String helpFile, + int helpContext) { + super(hrNew, source, helpFile, helpContext); + } + + /** + * @param hrNew + * @param description + * @param source + * @param helpFile + * @param helpContext + */ + public ComFailException(int hrNew, String description, String source, + String helpFile, int helpContext) { + super(hrNew, description, source, helpFile, helpContext); + } + + /** + * + */ + public ComFailException() { + super(); + } + + /** + * @param message + */ + public ComFailException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/com/jacob/com/ComThread.java b/com/jacob/com/ComThread.java index f375060..976f40a 100644 --- a/com/jacob/com/ComThread.java +++ b/com/jacob/com/ComThread.java @@ -1,130 +1,145 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; -import java.util.Hashtable; -import java.util.Vector; - -public abstract class ComThread -{ - private static final int MTA = 0x0; - private static final int STA = 0x2; - - public static boolean haveSTA = false; - public static MainSTA mainSTA = null; - - /** - * Initialize the current java thread to be part of the - * Multi-threaded COM Apartment - */ - public static synchronized void InitMTA() - { - InitMTA(false); - } - - /** - * Initialize the current java thread to be an STA - */ - public static synchronized void InitSTA() - { - InitSTA(false); - } - - /** - * Initialize the current java thread to be part of the - * Multi-threaded COM Apartment, if createMainSTA is true, - * create a separate MainSTA - * thread that will house all Apartment Threaded components - */ - public static synchronized void InitMTA(boolean createMainSTA) - { - Init(createMainSTA, MTA); - } - - /** - * Initialize the current java thread to be an STA - * COM Apartment, if createMainSTA is true, - * create a separate MainSTA - * thread that will house all Apartment Threaded components - */ - public static synchronized void InitSTA(boolean createMainSTA) - { - Init(createMainSTA, STA); - } - - public static synchronized void startMainSTA() - { - mainSTA = new MainSTA(); - haveSTA = true; - } - - public static synchronized void quitMainSTA() - { - if (mainSTA != null) mainSTA.quit(); - } - - /** - * Initialize the current java thread to be part of the - * MTA/STA COM Apartment - */ - public static synchronized void Init(boolean createMainSTA, int mode) - { - if (createMainSTA && !haveSTA) - { - // if the current thread is going to be in the MTA and there - // is no STA thread yet, then create a main STA thread - // to avoid COM creating its own - startMainSTA(); - } - //System.out.println("before Init: "+mode); - doCoInitialize(mode); - //System.out.println("after Init"); - ROT.addThread(); - //System.out.println("after ROT.addThread"); - } - - /** - * Call CoUninitialize to release this java thread from COM - */ - public static synchronized void Release() - { - //System.out.println("before clearObjects"); - ROT.clearObjects(); - //System.out.println("before UnInit"); - doCoUninitialize(); - //System.out.println("after UnInit"); - } - - public static native void doCoInitialize(int threadModel); - public static native void doCoUninitialize(); - - static { - System.loadLibrary("jacob"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. + * Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Redistributions in any form must + * be accompanied by information on how to obtain complete source code for the + * JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * @author joe + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public abstract class ComThread { + private static final int MTA = 0x0; + + private static final int STA = 0x2; + + /** + * Comment for haveSTA + */ + public static boolean haveSTA = false; + + /** + * Comment for mainSTA + */ + public static MainSTA mainSTA = null; + + /** + * Initialize the current java thread to be part of the Multi-threaded COM + * Apartment + */ + public static synchronized void InitMTA() { + InitMTA(false); + } + + /** + * Initialize the current java thread to be an STA + */ + public static synchronized void InitSTA() { + InitSTA(false); + } + + /** + * Initialize the current java thread to be part of the Multi-threaded COM + * Apartment, if createMainSTA is true, create a separate MainSTA thread + * that will house all Apartment Threaded components + * @param createMainSTA + */ + public static synchronized void InitMTA(boolean createMainSTA) { + Init(createMainSTA, MTA); + } + + /** + * Initialize the current java thread to be an STA COM Apartment, if + * createMainSTA is true, create a separate MainSTA thread that will house + * all Apartment Threaded components + * @param createMainSTA + */ + public static synchronized void InitSTA(boolean createMainSTA) { + Init(createMainSTA, STA); + } + + /** + * + */ + public static synchronized void startMainSTA() { + mainSTA = new MainSTA(); + haveSTA = true; + } + + /** + * + */ + public static synchronized void quitMainSTA() { + if (mainSTA != null) + mainSTA.quit(); + } + + /** + * Initialize the current java thread to be part of the MTA/STA COM + * Apartment + * @param createMainSTA + * @param mode + */ + public static synchronized void Init(boolean createMainSTA, int mode) { + if (createMainSTA && !haveSTA) { + // if the current thread is going to be in the MTA and there + // is no STA thread yet, then create a main STA thread + // to avoid COM creating its own + startMainSTA(); + } + //System.out.println("before Init: "+mode); + doCoInitialize(mode); + //System.out.println("after Init"); + ROT.addThread(); + //System.out.println("after ROT.addThread"); + } + + /** + * Call CoUninitialize to release this java thread from COM + */ + public static synchronized void Release() { + //System.out.println("before clearObjects"); + ROT.clearObjects(); + //System.out.println("before UnInit"); + doCoUninitialize(); + //System.out.println("after UnInit"); + } + + /** + * @param threadModel + */ + public static native void doCoInitialize(int threadModel); + + /** + * + */ + public static native void doCoUninitialize(); + + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/DispatchEvents.java b/com/jacob/com/DispatchEvents.java index 1ef9761..a35c624 100644 --- a/com/jacob/com/DispatchEvents.java +++ b/com/jacob/com/DispatchEvents.java @@ -29,36 +29,50 @@ */ package com.jacob.com; -public class DispatchEvents extends JacobObject -{ - int m_pConnPtProxy = 0; +/** + * @author joe + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Style - Code Templates + */ +public class DispatchEvents extends JacobObject { + int m_pConnPtProxy = 0; - public DispatchEvents(Dispatch src, Object sink) - { - init(src, sink); - } - public DispatchEvents(Dispatch src, Object sink, String progId) - { - init2(src, sink,progId); - } + /** + * @param src + * @param sink + */ + public DispatchEvents(Dispatch src, Object sink) { + init(src, sink); + } - // hook up a connection point proxy object - // event methods on the sink object will be called - // by name with a signature of (Variant[] args) - protected native void init(Dispatch src, Object sink); - protected native void init2(Dispatch src, Object sink, String progId); + /** + * @param src + * @param sink + * @param progId + */ + public DispatchEvents(Dispatch src, Object sink, String progId) { + init2(src, sink, progId); + } - // call this to explicitly release the com object before gc - public native void release(); + // hook up a connection point proxy object + // event methods on the sink object will be called + // by name with a signature of (Variant[] args) + protected native void init(Dispatch src, Object sink); - protected void finalize() - { - //System.out.println("DispatchEvents finalize start"); - if (m_pConnPtProxy != 0) release(); - //System.out.println("DispatchEvents finalize end"); - } + protected native void init2(Dispatch src, Object sink, String progId); - static { - System.loadLibrary("jacob"); - } -} + // call this to explicitly release the com object before gc + public native void release(); + + protected void finalize() { + //System.out.println("DispatchEvents finalize start"); + if (m_pConnPtProxy != 0) + release(); + //System.out.println("DispatchEvents finalize end"); + } + + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/DispatchProxy.java b/com/jacob/com/DispatchProxy.java index b384f39..4892efe 100644 --- a/com/jacob/com/DispatchProxy.java +++ b/com/jacob/com/DispatchProxy.java @@ -1,65 +1,77 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -/** - * If you need to pass a COM Dispatch object between STA threads, you - * have to marshall the interface. - * This class is used as follows: the STA that creates the Dispatch - * object must construct an instance of this class. Another thread - * can then call toDispatch() on that instance and get a Dispatch - * pointer which has been marshalled. - * WARNING: You can only call toDispatch() once! If you need to call - * it multiple times (or from multiple threads) you need to construct - * a separate DispatchProxy instance for each such case! - */ -public class DispatchProxy extends JacobObject -{ - public int m_pStream; - - public DispatchProxy(Dispatch localDispatch) - { - MarshalIntoStream(localDispatch); - } - - public Dispatch toDispatch() - { - return MarshalFromStream(); - } - - private native void MarshalIntoStream(Dispatch d); - private native Dispatch MarshalFromStream(); - public native void release(); - - public void finalize() - { - if (m_pStream != 0) release(); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * If you need to pass a COM Dispatch object between STA threads, you have to + * marshall the interface. This class is used as follows: the STA that creates + * the Dispatch object must construct an instance of this class. Another thread + * can then call toDispatch() on that instance and get a Dispatch pointer which + * has been marshalled. WARNING: You can only call toDispatch() once! If you + * need to call it multiple times (or from multiple threads) you need to + * construct a separate DispatchProxy instance for each such case! + */ +public class DispatchProxy extends JacobObject { + /** + * Comment for m_pStream + */ + public int m_pStream; + + /** + * @param localDispatch + */ + public DispatchProxy(Dispatch localDispatch) { + MarshalIntoStream(localDispatch); + } + + /** + * @return + */ + public Dispatch toDispatch() { + return MarshalFromStream(); + } + + private native void MarshalIntoStream(Dispatch d); + + private native Dispatch MarshalFromStream(); + + /* (non-Javadoc) + * @see com.jacob.com.JacobObject#release() + */ + public native void release(); + + /* (non-Javadoc) + * @see java.lang.Object#finalize() + */ + public void finalize() { + if (m_pStream != 0) + release(); + } +} \ No newline at end of file diff --git a/com/jacob/com/EnumVariant.java b/com/jacob/com/EnumVariant.java index 07519e7..aed37ee 100644 --- a/com/jacob/com/EnumVariant.java +++ b/com/jacob/com/EnumVariant.java @@ -1,122 +1,131 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -/** - * An implementation of IEnumVariant based on code submitted by - * Thomas Hallgren (mailto:Thomas.Hallgren@eoncompany.com) - */ -public class EnumVariant extends JacobObject implements java.util.Enumeration -{ - private int m_pIEnumVARIANT; - private final Variant[] m_recBuf = new Variant[1]; - - // this only gets called from JNI - // - protected EnumVariant(int pIEnumVARIANT) - { - m_pIEnumVARIANT = pIEnumVARIANT; - } - - public EnumVariant(Object disp) - { - int[] hres = new int[1]; - Variant evv = Dispatch.invokev( - disp, - Dispatch.DISPID_NEWENUM, - Dispatch.Get, - new Variant[0], - hres); - if(evv.getvt() != Variant.VariantObject) - // - // The DISPID_NEWENUM did not result in a valid object - // - throw new ComFailException("Can't obtain EnumVARIANT"); - - EnumVariant tmp = evv.toEnumVariant(); - m_pIEnumVARIANT = tmp.m_pIEnumVARIANT; - tmp.m_pIEnumVARIANT = 0; - } - - /** - * Implements java.util.Enumeration - */ - public boolean hasMoreElements() - { - { - if(m_recBuf[0] == null) - { - if(this.Next(m_recBuf) <= 0) - return false; - } - return true; - } - } - - /** - * Implements java.util.Enumeration - */ - public Object nextElement() - { - Object last = m_recBuf[0]; - if(last == null) - { - if(this.Next(m_recBuf) <= 0) - throw new java.util.NoSuchElementException(); - last = m_recBuf[0]; - } - m_recBuf[0] = null; - return last; - } - - /** - * Get next element in collection or null if at end - */ - public Variant Next() - { - if (hasMoreElements()) return (Variant)nextElement(); - return null; - } - - public native int Next(Variant[] receiverArray); - - public native void Skip(int count); - - public native void Reset(); - - public native void release(); - - protected void finalize() - { - //System.out.println("EnumVariant finalize start"); - if (m_pIEnumVARIANT != 0) this.release(); - //System.out.println("EnumVariant finalize end"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * An implementation of IEnumVariant based on code submitted by Thomas Hallgren + * (mailto:Thomas.Hallgren@eoncompany.com) + */ +public class EnumVariant extends JacobObject implements java.util.Enumeration { + private int m_pIEnumVARIANT; + + private final Variant[] m_recBuf = new Variant[1]; + + // this only gets called from JNI + // + protected EnumVariant(int pIEnumVARIANT) { + m_pIEnumVARIANT = pIEnumVARIANT; + } + + /** + * @param disp + */ + public EnumVariant(Object disp) { + int[] hres = new int[1]; + Variant evv = Dispatch.invokev(disp, Dispatch.DISPID_NEWENUM, + Dispatch.Get, new Variant[0], hres); + if (evv.getvt() != Variant.VariantObject) + // + // The DISPID_NEWENUM did not result in a valid object + // + throw new ComFailException("Can't obtain EnumVARIANT"); + + EnumVariant tmp = evv.toEnumVariant(); + m_pIEnumVARIANT = tmp.m_pIEnumVARIANT; + tmp.m_pIEnumVARIANT = 0; + } + + /** + * Implements java.util.Enumeration + * @return + */ + public boolean hasMoreElements() { + { + if (m_recBuf[0] == null) { + if (this.Next(m_recBuf) <= 0) + return false; + } + return true; + } + } + + /** + * Implements java.util.Enumeration + * @return + */ + public Object nextElement() { + Object last = m_recBuf[0]; + if (last == null) { + if (this.Next(m_recBuf) <= 0) + throw new java.util.NoSuchElementException(); + last = m_recBuf[0]; + } + m_recBuf[0] = null; + return last; + } + + /** + * Get next element in collection or null if at end + * @return + */ + public Variant Next() { + if (hasMoreElements()) + return (Variant) nextElement(); + return null; + } + + /** + * @param receiverArray + * @return + */ + public native int Next(Variant[] receiverArray); + + /** + * @param count + */ + public native void Skip(int count); + + /** + * + */ + public native void Reset(); + + /* (non-Javadoc) + * @see com.jacob.com.JacobObject#release() + */ + public native void release(); + + protected void finalize() { + //System.out.println("EnumVariant finalize start"); + if (m_pIEnumVARIANT != 0) + this.release(); + //System.out.println("EnumVariant finalize end"); + } +} \ No newline at end of file diff --git a/com/jacob/com/JacobObject.java b/com/jacob/com/JacobObject.java index 4685eb4..51dffe9 100644 --- a/com/jacob/com/JacobObject.java +++ b/com/jacob/com/JacobObject.java @@ -1,46 +1,52 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -/** - * All COM object created by JACOB extend this class so that - * we can automatically release them when the thread is detached from - * COM - if we leave it to the finalizer it will call the release from - * another thread, which may result in a segmentation violation. - */ -public class JacobObject -{ - public JacobObject() - { - ROT.addObject(this); - } - - public void release() {} -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * All COM object created by JACOB extend this class so that we can + * automatically release them when the thread is detached from COM - if we leave + * it to the finalizer it will call the release from another thread, which may + * result in a segmentation violation. + */ +public class JacobObject { + /** + * Standard constructor + */ + public JacobObject() { + ROT.addObject(this); + } + + /** + * + */ + public void release() { + // currently does nothing + } +} \ No newline at end of file diff --git a/com/jacob/com/MainSTA.java b/com/jacob/com/MainSTA.java index b1e4c79..8cac13a 100644 --- a/com/jacob/com/MainSTA.java +++ b/com/jacob/com/MainSTA.java @@ -1,43 +1,42 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -/** - * We provide our own main sta thread to avoid COM tagging a random - * thread as the main STA - this is the thread in which all Apartment - * threaded components will be created if the client chooses an MTA - * threading model for the java side of the app. - */ -public class MainSTA extends STA -{ - static { - System.loadLibrary("jacob"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * We provide our own main sta thread to avoid COM tagging a random + * thread as the main STA - this is the thread in which all Apartment + * threaded components will be created if the client chooses an MTA + * threading model for the java side of the app. + */ +public class MainSTA extends STA { + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/ROT.java b/com/jacob/com/ROT.java index ac7704d..e706219 100644 --- a/com/jacob/com/ROT.java +++ b/com/jacob/com/ROT.java @@ -1,99 +1,92 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; -import java.util.Hashtable; -import java.util.Vector; - -/** - * The Running Object Table (ROT) maps each thread to a vector of - * all the JacobObjects that were created in that thread. It always - * operates on the current thread so all the methods are static and - * they implicitly get the current thread. - * Conceptually, this is similar to the ThreadLocal class of Java 1.2 - * but we are also supporting Java 1.6 - * The clearObjects method is used to release all the COM objects - * created by Jacob in the current thread prior to uninitializing COM - * for that thread. If we leave this job to the garbage collector, - * then finalize might get called from a separate thread which is not - * initialized for COM, and also the component itself may have been - * freed. - */ -public abstract class ROT -{ - private static Hashtable rot = new Hashtable(); - - protected static void addThread() - { - String t_name = Thread.currentThread().getName(); - if (rot.contains(t_name)) return; - Vector v = new Vector(); - rot.put(t_name, v); - } - - protected static void clearObjects() - { - String t_name = Thread.currentThread().getName(); - Vector v = (Vector)rot.get(t_name); - if (v != null) - { - while (!v.isEmpty()) - { - JacobObject o = (JacobObject)v.elementAt(0); - //System.out.println(t_name + " release:"+o+"->"+o.getClass().getName()); - if (o != null) o.release(); - v.removeElementAt(0); - } - rot.remove(t_name); - } - } - - protected static void addObject(JacobObject o) - { - String t_name = Thread.currentThread().getName(); - //System.out.println(t_name + " add:"+o+"->"+o.getClass().getName()); - Vector v = (Vector)rot.get(t_name); - if (v == null) - { - // this thread has not been initialized as a COM thread - // so make it part of MTA for backwards compatibility - ComThread.InitMTA(false); - addThread(); - v = (Vector)rot.get(t_name); - } - if (v != null) - { - v.addElement(o); - } - } - - static { - System.loadLibrary("jacob"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +import java.util.Hashtable; +import java.util.Vector; + +/** + * The Running Object Table (ROT) maps each thread to a vector of all the + * JacobObjects that were created in that thread. It always operates on the + * current thread so all the methods are static and they implicitly get the + * current thread. Conceptually, this is similar to the ThreadLocal class of + * Java 1.2 but we are also supporting Java 1.6 The clearObjects method is used + * to release all the COM objects created by Jacob in the current thread prior + * to uninitializing COM for that thread. If we leave this job to the garbage + * collector, then finalize might get called from a separate thread which is not + * initialized for COM, and also the component itself may have been freed. + */ +public abstract class ROT { + private static Hashtable rot = new Hashtable(); + + protected static void addThread() { + String t_name = Thread.currentThread().getName(); + if (rot.contains(t_name)) + return; + Vector v = new Vector(); + rot.put(t_name, v); + } + + protected static void clearObjects() { + String t_name = Thread.currentThread().getName(); + Vector v = (Vector) rot.get(t_name); + if (v != null) { + while (!v.isEmpty()) { + JacobObject o = (JacobObject) v.elementAt(0); + //System.out.println(t_name + " + // release:"+o+"->"+o.getClass().getName()); + if (o != null) + o.release(); + v.removeElementAt(0); + } + rot.remove(t_name); + } + } + + protected static void addObject(JacobObject o) { + String t_name = Thread.currentThread().getName(); + //System.out.println(t_name + " add:"+o+"->"+o.getClass().getName()); + Vector v = (Vector) rot.get(t_name); + if (v == null) { + // this thread has not been initialized as a COM thread + // so make it part of MTA for backwards compatibility + ComThread.InitMTA(false); + addThread(); + v = (Vector) rot.get(t_name); + } + if (v != null) { + v.addElement(o); + } + } + + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/STA.java b/com/jacob/com/STA.java index 08fb89d..1407ba0 100644 --- a/com/jacob/com/STA.java +++ b/com/jacob/com/STA.java @@ -1,98 +1,104 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -/** - * A class that implements a Single Threaded Apartment. - * Users will subclass this and override OnInit() and OnQuit() - * where they will create and destroy a COM component that wants to - * run in an STA other than the main STA. - */ -public class STA extends Thread -{ - public int threadID; - - public STA() - { - start(); // start the thread - } - - public void run() - { - // init COM - ComThread.InitSTA(); - if (OnInit()) - { - // this call blocks in the win32 message loop - // until quitMessagePump is called - doMessagePump(); - } - OnQuit(); - // uninit COM - ComThread.Release(); - } - - /** - * Override this method to create and initialize any COM - * component that you want to run in this thread. If anything - * fails, return false to terminate the thread. - */ - public boolean OnInit() - { - return true; - } - - /** - * Override this method to destroy any resource - * before the thread exits and COM in uninitialized - */ - public void OnQuit() - { - } - - public void quit() - { - quitMessagePump(); - } - - /** - * run a message pump for the main STA - */ - public native void doMessagePump(); - - /** - * quit message pump for the main STA - */ - public native void quitMessagePump(); - - static { - System.loadLibrary("jacob"); - } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. + * All rights reserved. Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Redistributions in any form must be accompanied by information on + * how to obtain complete source code for the JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * A class that implements a Single Threaded Apartment. Users will subclass this + * and override OnInit() and OnQuit() where they will create and destroy a COM + * component that wants to run in an STA other than the main STA. + */ +public class STA extends Thread { + /** + * TODO: no references exist to this. should it be dropped + */ + public int threadID; + + /** + * constructor for STA + */ + public STA() { + start(); // start the thread + } + + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ + public void run() { + // init COM + ComThread.InitSTA(); + if (OnInit()) { + // this call blocks in the win32 message loop + // until quitMessagePump is called + doMessagePump(); + } + OnQuit(); + // uninit COM + ComThread.Release(); + } + + /** + * Override this method to create and initialize any COM component that you + * want to run in this thread. If anything fails, return false to terminate + * the thread. + * @return always returns true + */ + public boolean OnInit() { + return true; + } + + /** + * Override this method to destroy any resource before the thread exits and + * COM in uninitialized + */ + public void OnQuit() { + // there is nothing to see here + } + + /** + * calls quitMessagePump + */ + public void quit() { + quitMessagePump(); + } + + /** + * run a message pump for the main STA + */ + public native void doMessagePump(); + + /** + * quit message pump for the main STA + */ + public native void quitMessagePump(); + + static { + System.loadLibrary("jacob"); + } +} \ No newline at end of file diff --git a/com/jacob/com/SafeArray.java b/com/jacob/com/SafeArray.java index dc561aa..4c5e2a9 100644 --- a/com/jacob/com/SafeArray.java +++ b/com/jacob/com/SafeArray.java @@ -1,247 +1,659 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -public class SafeArray extends JacobObject -{ - int m_pV = 0; - - public SafeArray() {} - - public SafeArray(int vt) - { - init(vt, new int[] {0}, new int[] {-1}); - } - - public SafeArray(int vt,int celems) - { - init(vt, new int[] {0}, new int[] {celems}); - } - - public SafeArray(int vt,int celems1,int celems2) - { - init(vt, new int[] {0,0}, new int[] {celems1, celems2}); - } - - public SafeArray(int vt,int lbounds[],int celems[]) - { - init(vt, lbounds, celems); - } - - // convert a string to a VT_UI1 array - public SafeArray(String s) - { - char[] ca = s.toCharArray(); - init(Variant.VariantByte, new int[] {0}, new int[] {ca.length}); - fromCharArray(ca); - } - - protected native void init(int vt, int lbounds[], int celems[]); - - // not impl - public int getNumLocks() { return 0; } - - // convert a VT_UI1 array to string - public String asString() - { - if (getvt() != Variant.VariantByte) return null; - char ja[] = toCharArray(); - return new String(ja); - } - - - public native Object clone(); - // call this to explicitly release the com object before gc - - public void release() - { - destroy(); - } - - public native void destroy(); - public native int getvt(); - protected void finalize() - { - //System.out.println("SafeArray finalize start"); - if (m_pV != 0) release(); - //System.out.println("SafeArray finalize end"); - } - public native void reinit(SafeArray sa); - public native void reinterpretType(int vt); - - public native int getLBound(); - public native int getLBound(int dim); - public native int getUBound(); - public native int getUBound(int dim); - - public native int getNumDim(); - public native int getFeatures(); - public native int getElemSize(); - - public native void fromCharArray(char ja[]); - public native void fromIntArray(int ja[]); - public native void fromShortArray(short ja[]); - public native void fromDoubleArray(double ja[]); - public native void fromStringArray(String ja[]); - public native void fromByteArray(byte ja[]); - public native void fromFloatArray(float ja[]); - public native void fromBooleanArray(boolean ja[]); - public native void fromVariantArray(Variant ja[]); - - public native char[] toCharArray(); - public native int[] toIntArray(); - public native short[] toShortArray(); - public native double[] toDoubleArray(); - public native String[] toStringArray(); - public native byte[] toByteArray(); - public native float[] toFloatArray(); - public native boolean[] toBooleanArray(); - public native Variant[] toVariantArray(); - - // char access - public native char getChar(int sa_idx); - public native char getChar(int sa_idx1, int sa_idx2); - public native void setChar(int sa_idx, char c); - public native void setChar(int sa_idx1, int sa_idx2, char c); - public native void getChars(int sa_idx, int nelems, char ja[], int ja_start); - public native void setChars(int sa_idx, int nelems, char ja[], int ja_start); - - // int access - public native int getInt(int sa_idx); - public native int getInt(int sa_idx1, int sa_idx2); - public native void setInt(int sa_idx, int c); - public native void setInt(int sa_idx1, int sa_idx2, int c); - public native void getInts(int sa_idx, int nelems, int ja[], int ja_start); - public native void setInts(int sa_idx, int nelems, int ja[], int ja_start); - - // short access - public native short getShort(int sa_idx); - public native short getShort(int sa_idx1, int sa_idx2); - public native void setShort(int sa_idx, short c); - public native void setShort(int sa_idx1, int sa_idx2, short c); - public native void getShorts(int sa_idx, int nelems, short ja[], int ja_start); - public native void setShorts(int sa_idx, int nelems, short ja[], int ja_start); - - // double access - public native double getDouble(int sa_idx); - public native double getDouble(int sa_idx1, int sa_idx2); - public native void setDouble(int sa_idx, double c); - public native void setDouble(int sa_idx1, int sa_idx2, double c); - public native void getDoubles(int sa_idx, int nelems, double ja[], int ja_start); - public native void setDoubles(int sa_idx, int nelems, double ja[], int ja_start); - - // string access - public native String getString(int sa_idx); - public native String getString(int sa_idx1, int sa_idx2); - public native void setString(int sa_idx, String c); - public native void setString(int sa_idx1, int sa_idx2, String c); - public native void getStrings(int sa_idx, int nelems, String ja[], int ja_start); - public native void setStrings(int sa_idx, int nelems, String ja[], int ja_start); - - // byte access - public native byte getByte(int sa_idx); - public native byte getByte(int sa_idx1, int sa_idx2); - public native void setByte(int sa_idx, byte c); - public native void setByte(int sa_idx1, int sa_idx2, byte c); - public native void getBytes(int sa_idx, int nelems, byte ja[], int ja_start); - public native void setBytes(int sa_idx, int nelems, byte ja[], int ja_start); - - // float access - public native float getFloat(int sa_idx); - public native float getFloat(int sa_idx1, int sa_idx2); - public native void setFloat(int sa_idx, float c); - public native void setFloat(int sa_idx1, int sa_idx2, float c); - public native void getFloats(int sa_idx, int nelems, float ja[], int ja_start); - public native void setFloats(int sa_idx, int nelems, float ja[], int ja_start); - - // boolean access - public native boolean getBoolean(int sa_idx); - public native boolean getBoolean(int sa_idx1, int sa_idx2); - public native void setBoolean(int sa_idx, boolean c); - public native void setBoolean(int sa_idx1, int sa_idx2, boolean c); - public native void getBooleans(int sa_idx, int nelems, boolean ja[], int ja_start); - public native void setBooleans(int sa_idx, int nelems, boolean ja[], int ja_start); - - // variant access - public native Variant getVariant(int sa_idx); - public native Variant getVariant(int sa_idx1, int sa_idx2); - public native void setVariant(int sa_idx, Variant c); - public native void setVariant(int sa_idx1, int sa_idx2, Variant c); - public native void getVariants(int sa_idx, int nelems, Variant ja[], int ja_start); - public native void setVariants(int sa_idx, int nelems, Variant ja[], int ja_start); - - public String toString() - { - String s = ""; - int ndim = getNumDim(); - if (ndim == 1) - { - int ldim = getLBound(); - int udim = getUBound(); - for (int i = ldim; i <= udim; i++) - { - Variant v = getVariant(i); - - if (((v.getvt() & Variant.VariantTypeMask) | Variant.VariantArray) == v.getvt()) - { - return s + "[" + v.toSafeArray().toString() + "]"; - } - else - { - s += " " + v.toString(); - } - } - } - else if (ndim == 2) - { - int ldim1 = getLBound(1); - int udim1 = getUBound(1); - - int ldim2 = getLBound(2); - int udim2 = getUBound(2); - - for (int i = ldim1; i <= udim1; i++) - { - for (int j = ldim2; j <= udim2; j++) - { - Variant v = getVariant(i, j); - s += " " + v.toString(); - } - s += "\n"; - } - } - return s; - } - - static { - System.loadLibrary("jacob"); - } - -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. + * Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Redistributions in any form must + * be accompanied by information on how to obtain complete source code for the + * JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * @author joe + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class SafeArray extends JacobObject { + int m_pV = 0; + + /** + * constructor + * + */ + public SafeArray() { + } + + /** + * constructor + * @param vt + */ + public SafeArray(int vt) { + init(vt, new int[] { 0 }, new int[] { -1 }); + } + + /** + * constructor + * @param vt + * @param celems + */ + public SafeArray(int vt, int celems) { + init(vt, new int[] { 0 }, new int[] { celems }); + } + + /** + * @param vt + * @param celems1 + * @param celems2 + */ + public SafeArray(int vt, int celems1, int celems2) { + init(vt, new int[] { 0, 0 }, new int[] { celems1, celems2 }); + } + + /** + * constructor + * @param vt + * @param lbounds + * @param celems + */ + public SafeArray(int vt, int lbounds[], int celems[]) { + init(vt, lbounds, celems); + } + + /** + * convert a string to a VT_UI1 array + * @param s source string + */ + public SafeArray(String s) { + char[] ca = s.toCharArray(); + init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length }); + fromCharArray(ca); + } + + protected native void init(int vt, int lbounds[], int celems[]); + + /** + * not impl + * @return 0 + */ + public int getNumLocks() { + return 0; + } + + /** + * convert a VT_UI1 array to string + * @return variant byte as a string + */ + public String asString() { + if (getvt() != Variant.VariantByte) + return null; + char ja[] = toCharArray(); + return new String(ja); + } + + public native Object clone(); + + + /** + * call this to explicitly release the com object before gc + */ + public void release() { + destroy(); + } + + public native void destroy(); + + public native int getvt(); + + protected void finalize() { + //System.out.println("SafeArray finalize start"); + if (m_pV != 0) + release(); + //System.out.println("SafeArray finalize end"); + } + + public native void reinit(SafeArray sa); + + public native void reinterpretType(int vt); + + public native int getLBound(); + + public native int getLBound(int dim); + + public native int getUBound(); + + public native int getUBound(int dim); + + public native int getNumDim(); + + public native int getFeatures(); + + public native int getElemSize(); + + public native void fromCharArray(char ja[]); + + public native void fromIntArray(int ja[]); + + public native void fromShortArray(short ja[]); + + public native void fromDoubleArray(double ja[]); + + public native void fromStringArray(String ja[]); + + public native void fromByteArray(byte ja[]); + + public native void fromFloatArray(float ja[]); + + public native void fromBooleanArray(boolean ja[]); + + public native void fromVariantArray(Variant ja[]); + + public native char[] toCharArray(); + + public native int[] toIntArray(); + + public native short[] toShortArray(); + + public native double[] toDoubleArray(); + + public native String[] toStringArray(); + + public native byte[] toByteArray(); + + public native float[] toFloatArray(); + + public native boolean[] toBooleanArray(); + + public native Variant[] toVariantArray(); + + /** + * char access + * @param sa_idx + * @return + */ + public native char getChar(int sa_idx); + + /** + * char access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native char getChar(int sa_idx1, int sa_idx2); + + /** + * char access + * @param sa_idx + * @param c + */ + public native void setChar(int sa_idx, char c); + + /** + * char access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setChar(int sa_idx1, int sa_idx2, char c); + + /** + * char access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getChars(int sa_idx, int nelems, char ja[], int ja_start); + + /** + * char access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setChars(int sa_idx, int nelems, char ja[], int ja_start); + + /** + * int access + * @param sa_idx + * @return + */ + public native int getInt(int sa_idx); + + /** + * int access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native int getInt(int sa_idx1, int sa_idx2); + + /** + * int access + * @param sa_idx + * @param c + */ + public native void setInt(int sa_idx, int c); + + /** + * int access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setInt(int sa_idx1, int sa_idx2, int c); + + /** + * int access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getInts(int sa_idx, int nelems, int ja[], int ja_start); + + /** + * int access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setInts(int sa_idx, int nelems, int ja[], int ja_start); + + /** + * short access + * @param sa_idx + * @return + */ + public native short getShort(int sa_idx); + + /** + * short access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native short getShort(int sa_idx1, int sa_idx2); + + /** + * short access + * @param sa_idx + * @param c + */ + public native void setShort(int sa_idx, short c); + + /** + * short access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setShort(int sa_idx1, int sa_idx2, short c); + + /** + * short access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getShorts(int sa_idx, int nelems, short ja[], + int ja_start); + + /** + * short access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setShorts(int sa_idx, int nelems, short ja[], + int ja_start); + + /** + * double access + * @param sa_idx + * @return + */ + public native double getDouble(int sa_idx); + + /** + * double access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native double getDouble(int sa_idx1, int sa_idx2); + + /** + * double access + * @param sa_idx + * @param c + */ + public native void setDouble(int sa_idx, double c); + + /** + * double access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setDouble(int sa_idx1, int sa_idx2, double c); + + /** + * double access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getDoubles(int sa_idx, int nelems, double ja[], + int ja_start); + + /** + * double access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setDoubles(int sa_idx, int nelems, double ja[], + int ja_start); + + /** + * string access + * @param sa_idx + * @return + */ + public native String getString(int sa_idx); + + /** + * string access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native String getString(int sa_idx1, int sa_idx2); + + /** + * string access + * @param sa_idx + * @param c + */ + public native void setString(int sa_idx, String c); + + /** + * string access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setString(int sa_idx1, int sa_idx2, String c); + + /** + * string access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getStrings(int sa_idx, int nelems, String ja[], + int ja_start); + + /** + * string access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setStrings(int sa_idx, int nelems, String ja[], + int ja_start); + + /** + * byte access + * @param sa_idx + * @return + */ + public native byte getByte(int sa_idx); + + /** + * byte access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native byte getByte(int sa_idx1, int sa_idx2); + + /** + * byte access + * @param sa_idx + * @param c + */ + public native void setByte(int sa_idx, byte c); + + /** + * byte access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setByte(int sa_idx1, int sa_idx2, byte c); + + public native void getBytes(int sa_idx, int nelems, byte ja[], int ja_start); + + public native void setBytes(int sa_idx, int nelems, byte ja[], int ja_start); + + /** + * float access + * @param sa_idx + * @return + */ + public native float getFloat(int sa_idx); + + /** + * float access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native float getFloat(int sa_idx1, int sa_idx2); + + /** + * float access + * @param sa_idx + * @param c + */ + public native void setFloat(int sa_idx, float c); + + /** + * float access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setFloat(int sa_idx1, int sa_idx2, float c); + + /** + * float access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getFloats(int sa_idx, int nelems, float ja[], + int ja_start); + + /** + * float access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setFloats(int sa_idx, int nelems, float ja[], + int ja_start); + + /** + * boolean access + * @param sa_idx + * @return + */ + public native boolean getBoolean(int sa_idx); + + /** + * boolean access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native boolean getBoolean(int sa_idx1, int sa_idx2); + + /** + * boolean access + * @param sa_idx + * @param c + */ + public native void setBoolean(int sa_idx, boolean c); + + /** + * boolean access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setBoolean(int sa_idx1, int sa_idx2, boolean c); + + /** + * boolean access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getBooleans(int sa_idx, int nelems, boolean ja[], + int ja_start); + + /** + * boolean access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setBooleans(int sa_idx, int nelems, boolean ja[], + int ja_start); + + /** + * variant access + * @param sa_idx + * @return + */ + public native Variant getVariant(int sa_idx); + + /** + * variant access + * @param sa_idx1 + * @param sa_idx2 + * @return + */ + public native Variant getVariant(int sa_idx1, int sa_idx2); + + /** + * variant access + * @param sa_idx + * @param c + */ + public native void setVariant(int sa_idx, Variant c); + + /** + * variant access + * @param sa_idx1 + * @param sa_idx2 + * @param c + */ + public native void setVariant(int sa_idx1, int sa_idx2, Variant c); + + /** + * variant access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void getVariants(int sa_idx, int nelems, Variant ja[], + int ja_start); + + /** + * variant access + * @param sa_idx + * @param nelems + * @param ja + * @param ja_start + */ + public native void setVariants(int sa_idx, int nelems, Variant ja[], + int ja_start); + + /** + * standard toString + * @return + */ + public String toString() { + String s = ""; + int ndim = getNumDim(); + if (ndim == 1) { + int ldim = getLBound(); + int udim = getUBound(); + for (int i = ldim; i <= udim; i++) { + Variant v = getVariant(i); + + if (((v.getvt() & Variant.VariantTypeMask) | Variant.VariantArray) == v + .getvt()) { + return s + "[" + v.toSafeArray().toString() + "]"; + } else { + s += " " + v.toString(); + } + } + } else if (ndim == 2) { + int ldim1 = getLBound(1); + int udim1 = getUBound(1); + + int ldim2 = getLBound(2); + int udim2 = getUBound(2); + + for (int i = ldim1; i <= udim1; i++) { + for (int j = ldim2; j <= udim2; j++) { + Variant v = getVariant(i, j); + s += " " + v.toString(); + } + s += "\n"; + } + } + return s; + } + + static { + System.loadLibrary("jacob"); + } + +} \ No newline at end of file diff --git a/com/jacob/com/WrongThreadException.java b/com/jacob/com/WrongThreadException.java index 4b79b7f..863af7e 100644 --- a/com/jacob/com/WrongThreadException.java +++ b/com/jacob/com/WrongThreadException.java @@ -1,37 +1,48 @@ -/* - * Copyright (c) 1999-2004 Sourceforge JACOB Project. - * All rights reserved. Originator: Dan Adler (http://danadler.com). - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Redistributions in any form must be accompanied by information on - * how to obtain complete source code for the JACOB software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jacob.com; - -public class WrongThreadException extends RuntimeException -{ - // Constructors - public WrongThreadException() { super(); } - public WrongThreadException(String s) { super(s); } -} +/* + * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved. + * Originator: Dan Adler (http://danadler.com). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. 2. Redistributions in + * binary form must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. 3. Redistributions in any form must + * be accompanied by information on how to obtain complete source code for the + * JACOB software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.jacob.com; + +/** + * TODO: Exception thrown when? No references found + */ +public class WrongThreadException extends RuntimeException { + /** + * standard 0 arg constructor with no message + * + */ + public WrongThreadException() { + super(); + } + + /** + * standard constructor with a string message + * @param s + */ + public WrongThreadException(String s) { + super(s); + } +} \ No newline at end of file diff --git a/jni/EventProxy.cpp b/jni/EventProxy.cpp index 7bcbb92..bc75b7b 100644 --- a/jni/EventProxy.cpp +++ b/jni/EventProxy.cpp @@ -35,18 +35,28 @@ EventProxy::EventProxy(JNIEnv *env, jobject aSinkObj, IID eid, CComBSTR mName[], DISPID mID[], int mNum) : m_cRef(0), pCP(pConn), eventIID(eid), MethNum(mNum), MethName(mName), - MethID(mID), JMethID(NULL), javaSinkClass(NULL) + MethID(mID), JMethID(NULL), javaSinkClass(NULL), + variantClassMethod(NULL) { javaSinkObj = env->NewGlobalRef(aSinkObj); + if (env->ExceptionOccurred()) { env->ExceptionDescribe();} // we need this to attach to the event invocation thread env->GetJavaVM(&jvm); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } AddRef(); HRESULT hr = pCP->Advise(this, &dwEventCookie); if (SUCCEEDED(hr)) { // create a mapping from the DISPID's to jmethodID's by using // the method names I extracted from the classinfo JMethID = new jmethodID[MethNum]; + javaSinkClass = env->GetObjectClass(javaSinkObj); + if (javaSinkClass == NULL){ printf("can't figure out java sink class"); } + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } + variantClassMethod = env->GetMethodID(javaSinkClass, "getVariantClass", "()Ljava/lang/Class;"); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } + if (variantClassMethod == NULL) { printf("variantClassMethod == null\n"); } + const char *method; for(int i=0;iAttachCurrentThread((void **)&env, jvm); env->DeleteGlobalRef(javaSinkObj); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } if (MethNum) { delete [] MethName; delete [] MethID; @@ -131,19 +142,41 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, // attach to the current running thread jvm->AttachCurrentThread((void**)&env, jvm); + + // get variant class + jclass vClass; + // do this in a JACOB 1.8 backwards compatable way + // this succeeds if the class was loaded from the bootstrap class loader + vClass = env->FindClass("com/jacob/com/Variant"); + if (vClass == NULL){ + // see if our call back class implements our "special" method + if (variantClassMethod != NULL){ + jobject variantFound = env->CallObjectMethod(javaSinkObj, variantClassMethod); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } + if (variantFound == NULL) { printf("variantFound == null\n"); } + vClass = (jclass)variantFound; + } else { + // dang they didn't. lets tell the user they are having a bad day + printf("We're going to fail now in a way that is probably pretty ugly"); + printf("This application is probably running from a launcher where system class loader knows not Jacob\n"); + printf("The call back class does not implement 'Class getVariantClass()' that we can use to work around this\n"); + } + } + // how many params int num = pDispParams->cArgs; - // get variant class - jclass vClass = env->FindClass("com/jacob/com/Variant"); // and the constructor jmethodID vCons = env->GetMethodID(vClass, "", "()V"); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } // make an array of them jobjectArray varr = env->NewObjectArray(num, vClass, 0); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } int i,j; for(i=num-1,j=0;i>=0;i--,j++) { // construct a java variant holder jobject arg = env->NewObject(vClass, vCons); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } // get the empty variant from it VARIANT *va = extractVariant(env, arg); // copy the value @@ -151,11 +184,638 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, // put it in the array env->SetObjectArrayElement(varr, j, arg); env->DeleteLocalRef(arg); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } } // call the method env->CallVoidMethod(javaSinkObj, meth, varr); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); } - // detach from thread + + // Begin code from Jiffie team that copies parameters back from java to COM + for(i=num-1,j=0;i>=0;i--,j++) + { + jobject arg = env->GetObjectArrayElement(varr, j); + VARIANT *java = extractVariant(env, arg); + VARIANT *com = &pDispParams->rgvarg[i]; + + switch (com->vt) + { + case VT_DISPATCH: + { + switch (java->vt) + { + case VT_DISPATCH: + { + V_DISPATCH(com) = V_DISPATCH(java); + break; + } + + case VT_DISPATCH | VT_BYREF: + { + V_DISPATCH(com) = *V_DISPATCHREF(java); + break; + } + } + break; + } + + case VT_DISPATCH | VT_BYREF: + { + switch (java->vt) + { + case VT_DISPATCH: + { + *V_DISPATCHREF(com) = V_DISPATCH(java); + break; + } + + case VT_DISPATCH | VT_BYREF: + { + *V_DISPATCHREF(com) = *V_DISPATCHREF(java); + break; + } + } + break; + } + + case VT_BOOL: + { + switch (java->vt) + { + case VT_BOOL: + { + V_BOOL(com) = V_BOOL(java); + break; + } + + case VT_BOOL | VT_BYREF: + { + V_BOOL(com) = *V_BOOLREF(java); + break; + } + } + break; + } + + case VT_BOOL | VT_BYREF: + { + switch (java->vt) + { + case VT_BOOL: + { + *V_BOOLREF(com) = V_BOOL(java); + break; + } + + case VT_BOOL | VT_BYREF: + { + *V_BOOLREF(com) = *V_BOOLREF(java); + break; + } + } + break; + } + + case VT_UI1: + { + switch (java->vt) + { + case VT_UI1: + { + V_UI1(com) = V_UI1(java); + break; + } + + case VT_UI1 | VT_BYREF: + { + V_UI1(com) = *V_UI1REF(java); + break; + } + } + break; + } + + case VT_UI1 | VT_BYREF: + { + switch (java->vt) + { + case VT_UI1: + { + *V_UI1REF(com) = V_UI1(java); + break; + } + + case VT_UI1 | VT_BYREF: + { + *V_UI1REF(com) = *V_UI1REF(java); + break; + } + } + break; + } + + + case VT_I2: + { + switch (java->vt) + { + case VT_I2: + { + V_I2(com) = V_I2(java); + break; + } + + case VT_I2 | VT_BYREF: + { + V_I2(com) = *V_I2REF(java); + break; + } + } + break; + } + + case VT_I2 | VT_BYREF: + { + switch (java->vt) + { + case VT_I2: + { + *V_I2REF(com) = V_I2(java); + break; + } + + case VT_I2 | VT_BYREF: + { + *V_I2REF(com) = *V_I2REF(java); + break; + } + } + break; + } + + case VT_I4: + { + switch (java->vt) + { + case VT_I4: + { + V_I4(com) = V_I4(java); + break; + } + + case VT_I4 | VT_BYREF: + { + V_I4(com) = *V_I4REF(java); + break; + } + } + break; + } + + case VT_I4 | VT_BYREF: + { + switch (java->vt) + { + case VT_I4: + { + *V_I4REF(com) = V_I4(java); + break; + } + + case VT_I4 | VT_BYREF: + { + *V_I4REF(com) = *V_I4REF(java); + break; + } + } + break; + } + + case VT_R4: + { + switch (java->vt) + { + case VT_R4: + { + V_R4(com) = V_R4(java); + break; + } + + case VT_R4 | VT_BYREF: + { + V_R4(com) = *V_R4REF(java); + break; + } + } + break; + } + + case VT_R4 | VT_BYREF: + { + switch (java->vt) + { + case VT_R4: + { + *V_R4REF(com) = V_R4(java); + break; + } + + case VT_R4 | VT_BYREF: + { + *V_R4REF(com) = *V_R4REF(java); + break; + } + } + break; + } + + case VT_R8: + { + switch (java->vt) + { + case VT_R8: + { + V_R8(com) = V_R8(java); + break; + } + + case VT_R8 | VT_BYREF: + { + V_R8(com) = *V_R8REF(java); + break; + } + } + break; + } + + case VT_R8 | VT_BYREF: + { + switch (java->vt) + { + case VT_R8: + { + *V_R8REF(com) = V_R8(java); + break; + } + + case VT_R8 | VT_BYREF: + { + *V_R8REF(com) = *V_R8REF(java); + break; + } + } + break; + } + + case VT_I1: + { + switch (java->vt) + { + case VT_I1: + { + V_I1(com) = V_I1(java); + break; + } + + case VT_I1 | VT_BYREF: + { + V_I1(com) = *V_I1REF(java); + break; + } + } + break; + } + + case VT_I1 | VT_BYREF: + { + switch (java->vt) + { + case VT_I1: + { + *V_I1REF(com) = V_I1(java); + break; + } + + case VT_I1 | VT_BYREF: + { + *V_I1REF(com) = *V_I1REF(java); + break; + } + } + break; + } + + case VT_UI2: + { + switch (java->vt) + { + case VT_UI2: + { + V_UI2(com) = V_UI2(java); + break; + } + + case VT_UI2 | VT_BYREF: + { + V_UI2(com) = *V_UI2REF(java); + break; + } + } + break; + } + + case VT_UI2 | VT_BYREF: + { + switch (java->vt) + { + case VT_UI2: + { + *V_UI2REF(com) = V_UI2(java); + break; + } + + case VT_UI2 | VT_BYREF: + { + *V_UI2REF(com) = *V_UI2REF(java); + break; + } + } + break; + } + + case VT_UI4: + { + switch (java->vt) + { + case VT_UI4: + { + V_UI4(com) = V_UI4(java); + break; + } + + case VT_UI4 | VT_BYREF: + { + V_UI4(com) = *V_UI4REF(java); + break; + } + } + break; + } + + case VT_UI4 | VT_BYREF: + { + switch (java->vt) + { + case VT_UI4: + { + *V_UI4REF(com) = V_UI4(java); + break; + } + + case VT_UI4 | VT_BYREF: + { + *V_UI4REF(com) = *V_UI4REF(java); + break; + } + } + break; + } + + case VT_INT: + { + switch (java->vt) + { + case VT_INT: + { + V_INT(com) = V_INT(java); + break; + } + + case VT_INT | VT_BYREF: + { + V_INT(com) = *V_INTREF(java); + break; + } + } + break; + } + + case VT_INT | VT_BYREF: + { + switch (java->vt) + { + case VT_INT: + { + *V_INTREF(com) = V_INT(java); + break; + } + + case VT_INT | VT_BYREF: + { + *V_INTREF(com) = *V_INTREF(java); + break; + } + } + break; + } + + case VT_UINT: + { + switch (java->vt) + { + case VT_UINT: + { + V_UINT(com) = V_UINT(java); + break; + } + + case VT_UINT | VT_BYREF: + { + V_UINT(com) = *V_UINTREF(java); + break; + } + } + break; + } + + case VT_UINT | VT_BYREF: + { + switch (java->vt) + { + case VT_UINT: + { + *V_UINTREF(com) = V_UINT(java); + break; + } + + case VT_UINT | VT_BYREF: + { + *V_UINTREF(com) = *V_UINTREF(java); + break; + } + } + break; + } + + case VT_CY: + { + switch (java->vt) + { + case VT_CY: + { + V_CY(com) = V_CY(java); + break; + } + + case VT_CY | VT_BYREF: + { + V_CY(com) = *V_CYREF(java); + break; + } + } + break; + } + + case VT_CY | VT_BYREF: + { + switch (java->vt) + { + case VT_CY: + { + *V_CYREF(com) = V_CY(java); + break; + } + + case VT_CY | VT_BYREF: + { + *V_CYREF(com) = *V_CYREF(java); + break; + } + } + break; + } + + case VT_DATE: + { + switch (java->vt) + { + case VT_DATE: + { + V_DATE(com) = V_DATE(java); + break; + } + + case VT_DATE | VT_BYREF: + { + V_DATE(com) = *V_DATEREF(java); + break; + } + } + break; + } + + case VT_DATE | VT_BYREF: + { + switch (java->vt) + { + case VT_DATE: + { + *V_DATEREF(com) = V_DATE(java); + break; + } + + case VT_DATE | VT_BYREF: + { + *V_DATEREF(com) = *V_DATEREF(java); + break; + } + } + break; + } + + case VT_BSTR: + { + switch (java->vt) + { + case VT_BSTR: + { + V_BSTR(com) = V_BSTR(java); + break; + } + + case VT_BSTR | VT_BYREF: + { + V_BSTR(com) = *V_BSTRREF(java); + break; + } + } + break; + } + + case VT_BSTR | VT_BYREF: + { + switch (java->vt) + { + case VT_BSTR: + { + *V_BSTRREF(com) = V_BSTR(java); + break; + } + + case VT_BSTR | VT_BYREF: + { + *V_BSTRREF(com) = *V_BSTRREF(java); + break; + } + } + break; + } + + case VT_DECIMAL: + { + switch (java->vt) + { + case VT_DECIMAL: + { + V_DECIMAL(com) = V_DECIMAL(java); + break; + } + + case VT_DECIMAL | VT_BYREF: + { + V_DECIMAL(com) = *V_DECIMALREF(java); + break; + } + } + break; + } + + case VT_DECIMAL | VT_BYREF: + { + switch (java->vt) + { + case VT_DECIMAL: + { + *V_DECIMALREF(com) = V_DECIMAL(java); + break; + } + + case VT_DECIMAL | VT_BYREF: + { + *V_DECIMALREF(com) = *V_DECIMALREF(java); + break; + } + } + break; + } + + + } + env->DeleteLocalRef(arg); + } + // End code from Jiffie team that copies parameters back from java to COM + + // detach from thread jvm->DetachCurrentThread(); return S_OK; } diff --git a/jni/EventProxy.h b/jni/EventProxy.h index ee419e6..9e6add4 100644 --- a/jni/EventProxy.h +++ b/jni/EventProxy.h @@ -59,6 +59,8 @@ private: DWORD dwEventCookie; // connection point cookie jobject javaSinkObj; // the java object to delegate calls jclass javaSinkClass; // the java class of the object + jmethodID variantClassMethod; // the method on the javaSinkObj that will return the Variant class + IID eventIID; // the interface iid passed in int MethNum; CComBSTR *MethName; // Array of method names diff --git a/samples/ado/Command.java b/samples/ado/Command.java index b7618a8..bb62125 100644 --- a/samples/ado/Command.java +++ b/samples/ado/Command.java @@ -1,120 +1,123 @@ -import com.jacob.com.*; - -public class Command extends Dispatch -{ - public Command() - { - super("ADODB.Command"); - } - - /** - * This constructor is used instead of a case operation to - * turn a Dispatch object into a wider object - it must exist - * in every wrapper class whose instances may be returned from - * method calls wrapped in VT_DISPATCH Variants. - */ - public Command(Dispatch d) - { - // take over the IDispatch pointer - m_pDispatch = d.m_pDispatch; - // null out the input's pointer - d.m_pDispatch = 0; - } - - public Variant getProperties() - { - return Dispatch.get(this, "Properties"); - } - - public Connection getActiveConnection() - { - return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch()); - } - - public void setActiveConnection(Connection ppvObject) - { - Dispatch.put(this, "ActiveConnection", ppvObject); - } - - public String getCommandText() - { - return Dispatch.get(this, "CommandText").toString(); - } - - public void setCommandText(String pbstr) - { - Dispatch.put(this, "CommandText", pbstr); - } - - public int getCommandTimeout() - { - return Dispatch.get(this, "CommandTimeout").toInt(); - } - - public void setCommandTimeout(int plTimeout) - { - Dispatch.put(this, "CommandTimeout", new Variant(plTimeout)); - } - - public boolean getPrepared() - { - return Dispatch.get(this, "Prepared").toBoolean(); - } - - public void setPrepared(boolean pfPrepared) - { - Dispatch.put(this, "Prepared", new Variant(pfPrepared)); - } - - public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options) - { - return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch(); - } - - public Recordset Execute() - { - Variant dummy = new Variant(); - return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch()); - } - - public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value) - { - return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value); - } - - // need to wrap Parameters - public Variant getParameters() - { - return Dispatch.get(this, "Parameters"); - } - - public void setCommandType(int plCmdType) - { - Dispatch.put(this, "CommandType", new Variant(plCmdType)); - } - - public int getCommandType() - { - return Dispatch.get(this, "CommandType").toInt(); - } - - public String getName() - { - return Dispatch.get(this, "Name").toString(); - } - - public void setName(String pbstrName) - { - Dispatch.put(this, "Name", pbstrName); - } - - public int getState() - { - return Dispatch.get(this, "State").toInt(); - } - - public void Cancel() - { - Dispatch.call(this, "Cancel"); - } -} +package samples.ado; + +import com.jacob.com.*; + +public class Command extends Dispatch +{ + public Command() + { + super("ADODB.Command"); + } + + /** + * This constructor is used instead of a case operation to + * turn a Dispatch object into a wider object - it must exist + * in every wrapper class whose instances may be returned from + * method calls wrapped in VT_DISPATCH Variants. + * @param dispatchTarget + */ + public Command(Dispatch dispatchTarget) + { + // take over the IDispatch pointer + m_pDispatch = dispatchTarget.m_pDispatch; + // null out the input's pointer + dispatchTarget.m_pDispatch = 0; + } + + public Variant getProperties() + { + return Dispatch.get(this, "Properties"); + } + + public Connection getActiveConnection() + { + return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch()); + } + + public void setActiveConnection(Connection ppvObject) + { + Dispatch.put(this, "ActiveConnection", ppvObject); + } + + public String getCommandText() + { + return Dispatch.get(this, "CommandText").toString(); + } + + public void setCommandText(String pbstr) + { + Dispatch.put(this, "CommandText", pbstr); + } + + public int getCommandTimeout() + { + return Dispatch.get(this, "CommandTimeout").toInt(); + } + + public void setCommandTimeout(int plTimeout) + { + Dispatch.put(this, "CommandTimeout", new Variant(plTimeout)); + } + + public boolean getPrepared() + { + return Dispatch.get(this, "Prepared").toBoolean(); + } + + public void setPrepared(boolean pfPrepared) + { + Dispatch.put(this, "Prepared", new Variant(pfPrepared)); + } + + public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options) + { + return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch(); + } + + public Recordset Execute() + { + Variant dummy = new Variant(); + return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch()); + } + + public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value) + { + return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value); + } + + // need to wrap Parameters + public Variant getParameters() + { + return Dispatch.get(this, "Parameters"); + } + + public void setCommandType(int plCmdType) + { + Dispatch.put(this, "CommandType", new Variant(plCmdType)); + } + + public int getCommandType() + { + return Dispatch.get(this, "CommandType").toInt(); + } + + public String getName() + { + return Dispatch.get(this, "Name").toString(); + } + + public void setName(String pbstrName) + { + Dispatch.put(this, "Name", pbstrName); + } + + public int getState() + { + return Dispatch.get(this, "State").toInt(); + } + + public void Cancel() + { + Dispatch.call(this, "Cancel"); + } +} diff --git a/samples/ado/CommandTypeEnum.java b/samples/ado/CommandTypeEnum.java index 69720ce..4b1f137 100644 --- a/samples/ado/CommandTypeEnum.java +++ b/samples/ado/CommandTypeEnum.java @@ -1,12 +1,14 @@ -// Enum: CommandTypeEnum - -public interface CommandTypeEnum -{ - public static final int adCmdUnspecified = -1; - public static final int adCmdUnknown = 8; - public static final int adCmdText = 1; - public static final int adCmdTable = 2; - public static final int adCmdStoredProc = 4; - public static final int adCmdFile = 256; - public static final int adCmdTableDirect = 512; -} +package samples.ado; + +// Enum: CommandTypeEnum + +public interface CommandTypeEnum +{ + public static final int adCmdUnspecified = -1; + public static final int adCmdUnknown = 8; + public static final int adCmdText = 1; + public static final int adCmdTable = 2; + public static final int adCmdStoredProc = 4; + public static final int adCmdFile = 256; + public static final int adCmdTableDirect = 512; +} diff --git a/samples/ado/Connection.java b/samples/ado/Connection.java index 2e42ff9..e21a620 100644 --- a/samples/ado/Connection.java +++ b/samples/ado/Connection.java @@ -1,180 +1,182 @@ -import com.jacob.com.*; - -public class Connection extends Dispatch -{ - public Connection() - { - super("ADODB.Connection"); - } - - /** - * This constructor is used instead of a case operation to - * turn a Dispatch object into a wider object - it must exist - * in every wrapper class whose instances may be returned from - * method calls wrapped in VT_DISPATCH Variants. - */ - public Connection(Dispatch d) - { - // take over the IDispatch pointer - m_pDispatch = d.m_pDispatch; - // null out the input's pointer - d.m_pDispatch = 0; - } - - // need to wrap Properties - public Variant getProperties() - { - return Dispatch.get(this, "Properties"); - } - - public String getConnectionString() - { - return Dispatch.get(this, "ConnectionString").toString(); - } - - public void setConnectionString(String pbstr) - { - Dispatch.put(this, "ConnectionString", pbstr); - } - - public int getCommandTimeout() - { - return Dispatch.get(this, "CommandTimeout").toInt(); - } - - public void setCommandTimeout(int plTimeout) - { - Dispatch.put(this, "CommandTimeout", new Variant(plTimeout)); - } - - public int getConnectionTimeout() - { - return Dispatch.get(this, "ConnectionTimeout").toInt(); - } - - public void setConnectionTimeout(int plTimeout) - { - Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout)); - } - - public String getVersion() - { - return Dispatch.get(this, "Version").toString(); - } - - public void Close() - { - Dispatch.call(this, "Close"); - } - - // how to deal with RecordsAffected being output? - public Variant Execute(String CommandText, Variant RecordsAffected, int Options) - { - return Dispatch.call(this, CommandText, RecordsAffected, new Variant(Options)); - } - - public int BeginTrans() - { - return Dispatch.call(this, "BeginTrans").toInt(); - } - - public void CommitTrans() - { - Dispatch.call(this, "CommitTrans"); - } - - public void RollbackTrans() - { - Dispatch.call(this, "RollbackTrans"); - } - - public void Open(String ConnectionString, String UserID, String Password, int Options) - { - Dispatch.call(this, "Open", ConnectionString, UserID, Password, new Variant(Options)); - } - - public void Open() - { - Dispatch.call(this, "Open"); - } - - public Variant getErrors() - { - return Dispatch.get(this, "Errors"); - } - - public String getDefaultDatabase() - { - return Dispatch.get(this, "DefaultDatabase").toString(); - } - - public void setDefaultDatabase(String pbstr) - { - Dispatch.put(this, "DefaultDatabase", pbstr); - } - - public int getIsolationLevel() - { - return Dispatch.get(this, "IsolationLevel").toInt(); - } - - public void setIsolationLevel(int Level) - { - Dispatch.put(this, "IsolationLevel", new Variant(Level)); - } - - public int getAttributes() - { - return Dispatch.get(this, "Attributes").toInt(); - } - - public void setAttributes(int plAttr) - { - Dispatch.put(this, "Attributes", new Variant(plAttr)); - } - - public int getCursorLocation() - { - return Dispatch.get(this, "CursorLocation").toInt(); - } - - public void setCursorLocation(int plCursorLoc) - { - Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc)); - } - - public int getMode() - { - return Dispatch.get(this, "Mode").toInt(); - } - - public void setMode(int plMode) - { - Dispatch.put(this, "Mode", new Variant(plMode)); - } - - public String getProvider() - { - return Dispatch.get(this, "Provider").toString(); - } - - public void setProvider(String pbstr) - { - Dispatch.put(this, "Provider", pbstr); - } - - public int getState() - { - return Dispatch.get(this, "State").toInt(); - } - - public Variant OpenSchema(int Schema, Variant Restrictions, Variant SchemaID) - { - return Dispatch.call(this, "OpenSchema", new Variant(Schema), Restrictions, SchemaID); - } - - public void Cancel() - { - Dispatch.call(this, "Cancel"); - } -} +package samples.ado; + +import com.jacob.com.*; + +public class Connection extends Dispatch +{ + public Connection() + { + super("ADODB.Connection"); + } + + /** + * This constructor is used instead of a case operation to + * turn a Dispatch object into a wider object - it must exist + * in every wrapper class whose instances may be returned from + * method calls wrapped in VT_DISPATCH Variants. + */ + public Connection(Dispatch d) + { + // take over the IDispatch pointer + m_pDispatch = d.m_pDispatch; + // null out the input's pointer + d.m_pDispatch = 0; + } + + // need to wrap Properties + public Variant getProperties() + { + return Dispatch.get(this, "Properties"); + } + + public String getConnectionString() + { + return Dispatch.get(this, "ConnectionString").toString(); + } + + public void setConnectionString(String pbstr) + { + Dispatch.put(this, "ConnectionString", pbstr); + } + + public int getCommandTimeout() + { + return Dispatch.get(this, "CommandTimeout").toInt(); + } + + public void setCommandTimeout(int plTimeout) + { + Dispatch.put(this, "CommandTimeout", new Variant(plTimeout)); + } + + public int getConnectionTimeout() + { + return Dispatch.get(this, "ConnectionTimeout").toInt(); + } + + public void setConnectionTimeout(int plTimeout) + { + Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout)); + } + + public String getVersion() + { + return Dispatch.get(this, "Version").toString(); + } + + public void Close() + { + Dispatch.call(this, "Close"); + } + + // how to deal with RecordsAffected being output? + public Variant Execute(String CommandText, Variant RecordsAffected, int Options) + { + return Dispatch.call(this, CommandText, RecordsAffected, new Variant(Options)); + } + + public int BeginTrans() + { + return Dispatch.call(this, "BeginTrans").toInt(); + } + + public void CommitTrans() + { + Dispatch.call(this, "CommitTrans"); + } + + public void RollbackTrans() + { + Dispatch.call(this, "RollbackTrans"); + } + + public void Open(String ConnectionString, String UserID, String Password, int Options) + { + Dispatch.call(this, "Open", ConnectionString, UserID, Password, new Variant(Options)); + } + + public void Open() + { + Dispatch.call(this, "Open"); + } + + public Variant getErrors() + { + return Dispatch.get(this, "Errors"); + } + + public String getDefaultDatabase() + { + return Dispatch.get(this, "DefaultDatabase").toString(); + } + + public void setDefaultDatabase(String pbstr) + { + Dispatch.put(this, "DefaultDatabase", pbstr); + } + + public int getIsolationLevel() + { + return Dispatch.get(this, "IsolationLevel").toInt(); + } + + public void setIsolationLevel(int Level) + { + Dispatch.put(this, "IsolationLevel", new Variant(Level)); + } + + public int getAttributes() + { + return Dispatch.get(this, "Attributes").toInt(); + } + + public void setAttributes(int plAttr) + { + Dispatch.put(this, "Attributes", new Variant(plAttr)); + } + + public int getCursorLocation() + { + return Dispatch.get(this, "CursorLocation").toInt(); + } + + public void setCursorLocation(int plCursorLoc) + { + Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc)); + } + + public int getMode() + { + return Dispatch.get(this, "Mode").toInt(); + } + + public void setMode(int plMode) + { + Dispatch.put(this, "Mode", new Variant(plMode)); + } + + public String getProvider() + { + return Dispatch.get(this, "Provider").toString(); + } + + public void setProvider(String pbstr) + { + Dispatch.put(this, "Provider", pbstr); + } + + public int getState() + { + return Dispatch.get(this, "State").toInt(); + } + + public Variant OpenSchema(int Schema, Variant Restrictions, Variant SchemaID) + { + return Dispatch.call(this, "OpenSchema", new Variant(Schema), Restrictions, SchemaID); + } + + public void Cancel() + { + Dispatch.call(this, "Cancel"); + } +} diff --git a/samples/ado/Field.java b/samples/ado/Field.java index 345d137..1867ecb 100644 --- a/samples/ado/Field.java +++ b/samples/ado/Field.java @@ -1,124 +1,125 @@ -import com.jacob.com.*; - -public class Field extends Dispatch -{ - /** - * This constructor is used instead of a case operation to - * turn a Dispatch object into a wider object - it must exist - * in every wrapper class whose instances may be returned from - * method calls wrapped in VT_DISPATCH Variants. - */ - public Field(Dispatch d) - { - // take over the IDispatch pointer - m_pDispatch = d.m_pDispatch; - // null out the input's pointer - d.m_pDispatch = 0; - } - - public Variant getProperties() - { - return Dispatch.get(this, "Properties"); - } - - public int getActualSize() - { - return Dispatch.get(this, "ActualSize").toInt(); - } - - public int getAttributes() - { - return Dispatch.get(this, "Attributes").toInt(); - } - - public int getDefinedSize() - { - return Dispatch.get(this, "DefinedSize").toInt(); - } - - public String getName() - { - return Dispatch.get(this, "Name").toString(); - } - - public int getType() - { - return Dispatch.get(this, "Type").toInt(); - } - - public Variant getValue() - { - return Dispatch.get(this, "Value"); - } - - public void setValue(Variant pvar) - { - Dispatch.put(this, "Value", pvar); - } - - public byte getPrecision() - { - return Dispatch.get(this, "Precision").toByte(); - } - - public byte getNumericScale() - { - return Dispatch.get(this, "NumericScale").toByte(); - } - - public void AppendChunk(Variant Data) - { - Dispatch.call(this, "AppendChunk", Data); - } - - public Variant GetChunk(int Length) - { - return Dispatch.call(this, "GetChunk", new Variant(Length)); - } - - public Variant getOriginalValue() - { - return Dispatch.get(this, "OriginalValue"); - } - - public Variant getUnderlyingValue() - { - return Dispatch.get(this, "UnderlyingValue"); - } - - public Variant getDataFormat() - { - return Dispatch.get(this, "DataFormat"); - } - - public void setDataFormat(Variant ppiDF) - { - Dispatch.put(this, "DataFormat", ppiDF); - } - - public void setPrecision(byte pb) - { - Dispatch.put(this, "Precision", new Variant(pb)); - } - - public void setNumericScale(byte pb) - { - Dispatch.put(this, "NumericScale", new Variant(pb)); - } - - public void setType(int pDataType) - { - Dispatch.put(this, "Type", new Variant(pDataType)); - } - - public void setDefinedSize(int pl) - { - Dispatch.put(this, "DefinedSize", new Variant(pl)); - } - - public void setAttributes(int pl) - { - Dispatch.put(this, "Attributes", new Variant(pl)); - } - -} +package samples.ado; +import com.jacob.com.*; + +public class Field extends Dispatch +{ + /** + * This constructor is used instead of a case operation to + * turn a Dispatch object into a wider object - it must exist + * in every wrapper class whose instances may be returned from + * method calls wrapped in VT_DISPATCH Variants. + */ + public Field(Dispatch d) + { + // take over the IDispatch pointer + m_pDispatch = d.m_pDispatch; + // null out the input's pointer + d.m_pDispatch = 0; + } + + public Variant getProperties() + { + return Dispatch.get(this, "Properties"); + } + + public int getActualSize() + { + return Dispatch.get(this, "ActualSize").toInt(); + } + + public int getAttributes() + { + return Dispatch.get(this, "Attributes").toInt(); + } + + public int getDefinedSize() + { + return Dispatch.get(this, "DefinedSize").toInt(); + } + + public String getName() + { + return Dispatch.get(this, "Name").toString(); + } + + public int getType() + { + return Dispatch.get(this, "Type").toInt(); + } + + public Variant getValue() + { + return Dispatch.get(this, "Value"); + } + + public void setValue(Variant pvar) + { + Dispatch.put(this, "Value", pvar); + } + + public byte getPrecision() + { + return Dispatch.get(this, "Precision").toByte(); + } + + public byte getNumericScale() + { + return Dispatch.get(this, "NumericScale").toByte(); + } + + public void AppendChunk(Variant Data) + { + Dispatch.call(this, "AppendChunk", Data); + } + + public Variant GetChunk(int Length) + { + return Dispatch.call(this, "GetChunk", new Variant(Length)); + } + + public Variant getOriginalValue() + { + return Dispatch.get(this, "OriginalValue"); + } + + public Variant getUnderlyingValue() + { + return Dispatch.get(this, "UnderlyingValue"); + } + + public Variant getDataFormat() + { + return Dispatch.get(this, "DataFormat"); + } + + public void setDataFormat(Variant ppiDF) + { + Dispatch.put(this, "DataFormat", ppiDF); + } + + public void setPrecision(byte pb) + { + Dispatch.put(this, "Precision", new Variant(pb)); + } + + public void setNumericScale(byte pb) + { + Dispatch.put(this, "NumericScale", new Variant(pb)); + } + + public void setType(int pDataType) + { + Dispatch.put(this, "Type", new Variant(pDataType)); + } + + public void setDefinedSize(int pl) + { + Dispatch.put(this, "DefinedSize", new Variant(pl)); + } + + public void setAttributes(int pl) + { + Dispatch.put(this, "Attributes", new Variant(pl)); + } + +} diff --git a/samples/ado/Fields.java b/samples/ado/Fields.java index c8fd6cb..dc6ae33 100644 --- a/samples/ado/Fields.java +++ b/samples/ado/Fields.java @@ -1,50 +1,51 @@ -import com.jacob.com.*; - -public class Fields extends Dispatch -{ - /** - * This constructor is used instead of a case operation to - * turn a Dispatch object into a wider object - it must exist - * in every wrapper class whose instances may be returned from - * method calls wrapped in VT_DISPATCH Variants. - */ - public Fields(Dispatch d) - { - // take over the IDispatch pointer - m_pDispatch = d.m_pDispatch; - // null out the input's pointer - d.m_pDispatch = 0; - } - - public int getCount() - { - return Dispatch.get(this, "Count").toInt(); - } - - public Variant _NewEnum() - { - return Dispatch.call(this, "_NewEnum"); - } - - public void Refresh() - { - Dispatch.call(this, "Refresh"); - } - - public Field getItem(int Index) - { - return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch()); - } - - public void Append(String Name, int Type, int DefinedSize, int Attrib) - { - Dispatch.call(this, "Append", Name, new Variant(Type), - new Variant(DefinedSize), new Variant(Attrib)); - } - - public void Delete(Variant Index) - { - Dispatch.call(this, "Delete", Index); - } - -} +package samples.ado; +import com.jacob.com.*; + +public class Fields extends Dispatch +{ + /** + * This constructor is used instead of a case operation to + * turn a Dispatch object into a wider object - it must exist + * in every wrapper class whose instances may be returned from + * method calls wrapped in VT_DISPATCH Variants. + */ + public Fields(Dispatch d) + { + // take over the IDispatch pointer + m_pDispatch = d.m_pDispatch; + // null out the input's pointer + d.m_pDispatch = 0; + } + + public int getCount() + { + return Dispatch.get(this, "Count").toInt(); + } + + public Variant _NewEnum() + { + return Dispatch.call(this, "_NewEnum"); + } + + public void Refresh() + { + Dispatch.call(this, "Refresh"); + } + + public Field getItem(int Index) + { + return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch()); + } + + public void Append(String Name, int Type, int DefinedSize, int Attrib) + { + Dispatch.call(this, "Append", Name, new Variant(Type), + new Variant(DefinedSize), new Variant(Attrib)); + } + + public void Delete(Variant Index) + { + Dispatch.call(this, "Delete", Index); + } + +} diff --git a/samples/ado/Recordset.java b/samples/ado/Recordset.java index fbedc51..b56334c 100644 --- a/samples/ado/Recordset.java +++ b/samples/ado/Recordset.java @@ -1,411 +1,412 @@ -import com.jacob.com.*; - -public class Recordset extends Dispatch -{ - public Recordset() - { - super("ADODB.Recordset"); - } - - /** - * This constructor is used instead of a case operation to - * turn a Dispatch object into a wider object - it must exist - * in every wrapper class whose instances may be returned from - * method calls wrapped in VT_DISPATCH Variants. - */ - public Recordset(Dispatch d) - { - // take over the IDispatch pointer - m_pDispatch = d.m_pDispatch; - // null out the input's pointer - d.m_pDispatch = 0; - } - - public Variant getProperties() - { - return Dispatch.get(this, "Properties"); - } - - public int getAbsolutePosition() - { - return Dispatch.get(this, "AbsolutePosition").toInt(); - } - - public void setAbsolutePosition(int pl) - { - Dispatch.put(this, "AbsolutePosition", new Variant(pl)); - } - - public Connection getActiveConnection() - { - return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch()); - } - - public void setActiveConnection(Connection ppvObject) - { - Dispatch.put(this, "ActiveConnection", ppvObject); - } - - public void setActiveConnection(Variant ppvObject) - { - Dispatch.put(this, "ActiveConnection", ppvObject); - } - - public boolean getBOF() - { - return Dispatch.get(this, "BOF").toBoolean(); - } - - public Variant getBookmark() - { - return Dispatch.get(this, "Bookmark"); - } - - public void setBookmark(Variant pvBookmark) - { - Dispatch.put(this, "Bookmark", pvBookmark); - } - - public int getCacheSize() - { - return Dispatch.get(this, "CacheSize").toInt(); - } - - public void setCacheSize(int pl) - { - Dispatch.put(this, "CacheSize", new Variant(pl)); - } - - public int getCursorType() - { - return Dispatch.get(this, "CursorType").toInt(); - } - - public void setCursorType(int pl) - { - Dispatch.put(this, "CursorType", new Variant(pl)); - } - - public boolean getEOF() - { - return Dispatch.get(this, "EOF").toBoolean(); - } - - public Fields getFields() - { - return new Fields(Dispatch.get(this, "Fields").toDispatch()); - } - - public int getLockType() - { - return Dispatch.get(this, "LockType").toInt(); - } - - public void setLockType(int plLockType) - { - Dispatch.put(this, "LockType", new Variant(plLockType)); - } - - public int getMaxRecords() - { - return Dispatch.get(this, "MaxRecords").toInt(); - } - - public void setMaxRecords(int pl) - { - Dispatch.put(this, "MaxRecords", new Variant(pl)); - } - - public int getRecordCount() - { - return Dispatch.get(this, "RecordCount").toInt(); - } - - public void setSource(Object pvSource) - { - Dispatch.put(this, "Source", pvSource); - } - - public void setSource(String pvSource) - { - Dispatch.put(this, "Source", pvSource); - } - - public Variant getSource() - { - return Dispatch.get(this, "Source"); - } - - public void AddNew(Variant FieldList, Variant Values) - { - Dispatch.call(this, "AddNew", FieldList, Values); - } - - public void CancelUpdate() - { - Dispatch.call(this, "CancelUpdate"); - } - - public void Close() - { - Dispatch.call(this, "Close"); - } - - public void Delete(int AffectRecords) - { - Dispatch.call(this, "Delete", new Variant(AffectRecords)); - } - - public Variant GetRows(int Rows, Variant Start, Variant Fields) - { - return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields); - } - - // get all rows - public Variant GetRows() - { - return Dispatch.call(this, "GetRows"); - } - - public void Move(int NumRecords, Variant Start) - { - Dispatch.call(this, "Move", new Variant(NumRecords), Start); - } - - public void MoveNext() - { - Dispatch.call(this, "MoveNext"); - } - - public void MovePrevious() - { - Dispatch.call(this, "MovePrevious"); - } - - public void MoveFirst() - { - Dispatch.call(this, "MoveFirst"); - } - - public void MoveLast() - { - Dispatch.call(this, "MoveLast"); - } - - public void Open(Variant Source, Variant ActiveConnection, int CursorType, int LockType, int Options) - { - Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(CursorType), new Variant(LockType), new Variant(Options)); - } - - public void Open(Variant Source, Variant ActiveConnection) - { - Dispatch.call(this, "Open", Source, ActiveConnection); - } - - public void Requery(int Options) - { - Dispatch.call(this, "Requery", new Variant(Options)); - } - - public void Update(Variant Fields, Variant Values) - { - Dispatch.call(this, "Update", Fields, Values); - } - - public int getAbsolutePage() - { - return Dispatch.get(this, "AbsolutePage").toInt(); - } - - public void setAbsolutePage(int pl) - { - Dispatch.put(this, "AbsolutePage", new Variant(pl)); - } - - public int getEditMode() - { - return Dispatch.get(this, "EditMode").toInt(); - } - - public Variant getFilter() - { - return Dispatch.get(this, "Filter"); - } - - public void setFilter(Variant Criteria) - { - Dispatch.put(this, "Filter", Criteria); - } - - public int getPageCount() - { - return Dispatch.get(this, "PageCount").toInt(); - } - - public int getPageSize() - { - return Dispatch.get(this, "PageSize").toInt(); - } - - public void setPageSize(int pl) - { - Dispatch.put(this, "PageSize", new Variant(pl)); - } - - public String getSort() - { - return Dispatch.get(this, "Sort").toString(); - } - - public void setSort(String Criteria) - { - Dispatch.put(this, "Sort", Criteria); - } - - public int getStatus() - { - return Dispatch.get(this, "Status").toInt(); - } - - public int getState() - { - return Dispatch.get(this, "State").toInt(); - } - - public void UpdateBatch(int AffectRecords) - { - Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords)); - } - - public void CancelBatch(int AffectRecords) - { - Dispatch.call(this, "CancelBatch", new Variant(AffectRecords)); - } - - public int getCursorLocation() - { - return Dispatch.get(this, "CursorLocation").toInt(); - } - - public void setCursorLocation(int pl) - { - Dispatch.put(this, "CursorLocation", new Variant(pl)); - } - - public Recordset NextRecordset(Variant RecordsAffected) - { - return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch()); - } - - public boolean Supports(int CursorOptions) - { - return Dispatch.call(this, "Supports", new Variant(CursorOptions)).toBoolean(); - } - - public Variant getCollect(Variant Index) - { - return Dispatch.get(this, "Collect"); - } - - public void setCollect(Variant Index, Variant pvar) - { - Dispatch.call(this, "Collect", Index, pvar); - } - - public int getMarshalOptions() - { - return Dispatch.get(this, "MarshalOptions").toInt(); - } - - public void setMarshalOptions(int pl) - { - Dispatch.put(this, "MarshalOptions", new Variant(pl)); - } - - public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start) - { - Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start); - } - - public void Cancel() - { - Dispatch.call(this, "Cancel"); - } - - public Variant getDataSource() - { - return Dispatch.get(this, "DataSource"); - } - - public void setDataSource(Variant ppunkDataSource) - { - Dispatch.put(this, "DataSource", ppunkDataSource); - } - - public void Save(String FileName, int PersistFormat) - { - Dispatch.call(this, "Save", FileName, new Variant(PersistFormat)); - } - - public Variant getActiveCommand() - { - return Dispatch.get(this, "ActiveCommand"); - } - - public void setStayInSync(boolean pb) - { - Dispatch.put(this, "StayInSync", new Variant(pb)); - } - - public boolean getStayInSync() - { - return Dispatch.get(this, "StayInSync").toBoolean(); - } - - public String GetString(int StringFormat, int NumRows, String ColumnDelimeter, String RowDelimeter, String NullExpr) - { - return Dispatch.call(this, "GetString", new Variant(StringFormat), - new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr).toString(); - } - - public String getDataMember() - { - return Dispatch.get(this, "DataMember").toString(); - } - - public void setDataMember(String pl) - { - Dispatch.put(this, "DataMember", new Variant(pl)); - } - - public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2) - { - return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).toInt(); - } - - public Recordset Clone(int LockType) - { - return new Recordset(Dispatch.call(this, "Clone", - new Variant(LockType)).toDispatch()); - } - - public void Resync(int AffectRecords, int ResyncValues) - { - Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues)); - } - - public void Seek(Variant KeyValues, int SeekOption) - { - Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption)); - } - - public void setIndex(String pl) - { - Dispatch.put(this, "Index", new Variant(pl)); - } - - public String getIndex() - { - return Dispatch.get(this, "Index)").toString(); - } -} +package samples.ado; +import com.jacob.com.*; + +public class Recordset extends Dispatch +{ + public Recordset() + { + super("ADODB.Recordset"); + } + + /** + * This constructor is used instead of a case operation to + * turn a Dispatch object into a wider object - it must exist + * in every wrapper class whose instances may be returned from + * method calls wrapped in VT_DISPATCH Variants. + */ + public Recordset(Dispatch d) + { + // take over the IDispatch pointer + m_pDispatch = d.m_pDispatch; + // null out the input's pointer + d.m_pDispatch = 0; + } + + public Variant getProperties() + { + return Dispatch.get(this, "Properties"); + } + + public int getAbsolutePosition() + { + return Dispatch.get(this, "AbsolutePosition").toInt(); + } + + public void setAbsolutePosition(int pl) + { + Dispatch.put(this, "AbsolutePosition", new Variant(pl)); + } + + public Connection getActiveConnection() + { + return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch()); + } + + public void setActiveConnection(Connection ppvObject) + { + Dispatch.put(this, "ActiveConnection", ppvObject); + } + + public void setActiveConnection(Variant ppvObject) + { + Dispatch.put(this, "ActiveConnection", ppvObject); + } + + public boolean getBOF() + { + return Dispatch.get(this, "BOF").toBoolean(); + } + + public Variant getBookmark() + { + return Dispatch.get(this, "Bookmark"); + } + + public void setBookmark(Variant pvBookmark) + { + Dispatch.put(this, "Bookmark", pvBookmark); + } + + public int getCacheSize() + { + return Dispatch.get(this, "CacheSize").toInt(); + } + + public void setCacheSize(int pl) + { + Dispatch.put(this, "CacheSize", new Variant(pl)); + } + + public int getCursorType() + { + return Dispatch.get(this, "CursorType").toInt(); + } + + public void setCursorType(int pl) + { + Dispatch.put(this, "CursorType", new Variant(pl)); + } + + public boolean getEOF() + { + return Dispatch.get(this, "EOF").toBoolean(); + } + + public Fields getFields() + { + return new Fields(Dispatch.get(this, "Fields").toDispatch()); + } + + public int getLockType() + { + return Dispatch.get(this, "LockType").toInt(); + } + + public void setLockType(int plLockType) + { + Dispatch.put(this, "LockType", new Variant(plLockType)); + } + + public int getMaxRecords() + { + return Dispatch.get(this, "MaxRecords").toInt(); + } + + public void setMaxRecords(int pl) + { + Dispatch.put(this, "MaxRecords", new Variant(pl)); + } + + public int getRecordCount() + { + return Dispatch.get(this, "RecordCount").toInt(); + } + + public void setSource(Object pvSource) + { + Dispatch.put(this, "Source", pvSource); + } + + public void setSource(String pvSource) + { + Dispatch.put(this, "Source", pvSource); + } + + public Variant getSource() + { + return Dispatch.get(this, "Source"); + } + + public void AddNew(Variant FieldList, Variant Values) + { + Dispatch.call(this, "AddNew", FieldList, Values); + } + + public void CancelUpdate() + { + Dispatch.call(this, "CancelUpdate"); + } + + public void Close() + { + Dispatch.call(this, "Close"); + } + + public void Delete(int AffectRecords) + { + Dispatch.call(this, "Delete", new Variant(AffectRecords)); + } + + public Variant GetRows(int Rows, Variant Start, Variant Fields) + { + return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields); + } + + // get all rows + public Variant GetRows() + { + return Dispatch.call(this, "GetRows"); + } + + public void Move(int NumRecords, Variant Start) + { + Dispatch.call(this, "Move", new Variant(NumRecords), Start); + } + + public void MoveNext() + { + Dispatch.call(this, "MoveNext"); + } + + public void MovePrevious() + { + Dispatch.call(this, "MovePrevious"); + } + + public void MoveFirst() + { + Dispatch.call(this, "MoveFirst"); + } + + public void MoveLast() + { + Dispatch.call(this, "MoveLast"); + } + + public void Open(Variant Source, Variant ActiveConnection, int CursorType, int LockType, int Options) + { + Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(CursorType), new Variant(LockType), new Variant(Options)); + } + + public void Open(Variant Source, Variant ActiveConnection) + { + Dispatch.call(this, "Open", Source, ActiveConnection); + } + + public void Requery(int Options) + { + Dispatch.call(this, "Requery", new Variant(Options)); + } + + public void Update(Variant Fields, Variant Values) + { + Dispatch.call(this, "Update", Fields, Values); + } + + public int getAbsolutePage() + { + return Dispatch.get(this, "AbsolutePage").toInt(); + } + + public void setAbsolutePage(int pl) + { + Dispatch.put(this, "AbsolutePage", new Variant(pl)); + } + + public int getEditMode() + { + return Dispatch.get(this, "EditMode").toInt(); + } + + public Variant getFilter() + { + return Dispatch.get(this, "Filter"); + } + + public void setFilter(Variant Criteria) + { + Dispatch.put(this, "Filter", Criteria); + } + + public int getPageCount() + { + return Dispatch.get(this, "PageCount").toInt(); + } + + public int getPageSize() + { + return Dispatch.get(this, "PageSize").toInt(); + } + + public void setPageSize(int pl) + { + Dispatch.put(this, "PageSize", new Variant(pl)); + } + + public String getSort() + { + return Dispatch.get(this, "Sort").toString(); + } + + public void setSort(String Criteria) + { + Dispatch.put(this, "Sort", Criteria); + } + + public int getStatus() + { + return Dispatch.get(this, "Status").toInt(); + } + + public int getState() + { + return Dispatch.get(this, "State").toInt(); + } + + public void UpdateBatch(int AffectRecords) + { + Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords)); + } + + public void CancelBatch(int AffectRecords) + { + Dispatch.call(this, "CancelBatch", new Variant(AffectRecords)); + } + + public int getCursorLocation() + { + return Dispatch.get(this, "CursorLocation").toInt(); + } + + public void setCursorLocation(int pl) + { + Dispatch.put(this, "CursorLocation", new Variant(pl)); + } + + public Recordset NextRecordset(Variant RecordsAffected) + { + return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch()); + } + + public boolean Supports(int CursorOptions) + { + return Dispatch.call(this, "Supports", new Variant(CursorOptions)).toBoolean(); + } + + public Variant getCollect(Variant Index) + { + return Dispatch.get(this, "Collect"); + } + + public void setCollect(Variant Index, Variant pvar) + { + Dispatch.call(this, "Collect", Index, pvar); + } + + public int getMarshalOptions() + { + return Dispatch.get(this, "MarshalOptions").toInt(); + } + + public void setMarshalOptions(int pl) + { + Dispatch.put(this, "MarshalOptions", new Variant(pl)); + } + + public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start) + { + Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start); + } + + public void Cancel() + { + Dispatch.call(this, "Cancel"); + } + + public Variant getDataSource() + { + return Dispatch.get(this, "DataSource"); + } + + public void setDataSource(Variant ppunkDataSource) + { + Dispatch.put(this, "DataSource", ppunkDataSource); + } + + public void Save(String FileName, int PersistFormat) + { + Dispatch.call(this, "Save", FileName, new Variant(PersistFormat)); + } + + public Variant getActiveCommand() + { + return Dispatch.get(this, "ActiveCommand"); + } + + public void setStayInSync(boolean pb) + { + Dispatch.put(this, "StayInSync", new Variant(pb)); + } + + public boolean getStayInSync() + { + return Dispatch.get(this, "StayInSync").toBoolean(); + } + + public String GetString(int StringFormat, int NumRows, String ColumnDelimeter, String RowDelimeter, String NullExpr) + { + return Dispatch.call(this, "GetString", new Variant(StringFormat), + new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr).toString(); + } + + public String getDataMember() + { + return Dispatch.get(this, "DataMember").toString(); + } + + public void setDataMember(String pl) + { + Dispatch.put(this, "DataMember", new Variant(pl)); + } + + public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2) + { + return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).toInt(); + } + + public Recordset Clone(int LockType) + { + return new Recordset(Dispatch.call(this, "Clone", + new Variant(LockType)).toDispatch()); + } + + public void Resync(int AffectRecords, int ResyncValues) + { + Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues)); + } + + public void Seek(Variant KeyValues, int SeekOption) + { + Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption)); + } + + public void setIndex(String pl) + { + Dispatch.put(this, "Index", new Variant(pl)); + } + + public String getIndex() + { + return Dispatch.get(this, "Index)").toString(); + } +} diff --git a/samples/ado/ms/README b/samples/ado/ms/README deleted file mode 100644 index ba754f0..0000000 --- a/samples/ado/ms/README +++ /dev/null @@ -1,3 +0,0 @@ -This is the WFC equivalent of the JACOB ADO example. - -This code must be compiled with JVC and run with JVIEW. diff --git a/samples/ado/ms/README.txt b/samples/ado/ms/README.txt new file mode 100644 index 0000000..cc76d1c --- /dev/null +++ b/samples/ado/ms/README.txt @@ -0,0 +1,9 @@ +This is the WFC equivalent of the JACOB ADO example. + +This code must be compiled with JVC and run with JVIEW. + +The file testms.java has been renamed to tesetms.java.txt +because most folks building this application will +not have the MS JVM installed and will get compiler +warnings. The MS JVM is going away eventually +so this whole test will eventually go away. \ No newline at end of file diff --git a/samples/ado/ms/testms.java b/samples/ado/ms/testms.java.txt similarity index 96% rename from samples/ado/ms/testms.java rename to samples/ado/ms/testms.java.txt index 49ee06e..1d6bd52 100644 --- a/samples/ado/ms/testms.java +++ b/samples/ado/ms/testms.java.txt @@ -1,64 +1,66 @@ -import com.ms.com.*; -import com.ms.wfc.data.*; - -// an ms-only version of test.java -public class testms -{ - public static void printRS(Recordset rs) - { - Fields fs = rs.getFields(); - - for (int i=0;i Recordset"); - Connection c = new Connection(); - c.setConnectionString(con); - c.open(); - Command comm = new Command(); - comm.setActiveConnection(c); - comm.setCommandType(AdoEnums.CommandType.TEXT); - comm.setCommandText(query); - Recordset rs = comm.execute(); - printRS(rs); - c.close(); - } - - public static void main(String[] args) - { - String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs"; - String queryStr = "select * from authors"; - getCommand(connectStr, queryStr); - getRS(connectStr, queryStr); - } -} +package samples.ado.ms; + +import com.ms.com.*; +import com.ms.wfc.data.*; + +// an ms-only version of test.java +public class testms +{ + public static void printRS(Recordset rs) + { + Fields fs = rs.getFields(); + + for (int i=0;i Recordset"); + Connection c = new Connection(); + c.setConnectionString(con); + c.open(); + Command comm = new Command(); + comm.setActiveConnection(c); + comm.setCommandType(AdoEnums.CommandType.TEXT); + comm.setCommandText(query); + Recordset rs = comm.execute(); + printRS(rs); + c.close(); + } + + public static void main(String[] args) + { + String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs"; + String queryStr = "select * from authors"; + getCommand(connectStr, queryStr); + getRS(connectStr, queryStr); + } +} diff --git a/samples/ado/test.java b/samples/ado/test.java index decdac4..5d0ab77 100644 --- a/samples/ado/test.java +++ b/samples/ado/test.java @@ -1,62 +1,63 @@ -import com.jacob.com.*; - -public class test -{ - public static void printRS(Recordset rs) - { - Fields fs = rs.getFields(); - - for (int i=0;i Recordset"); - Connection c = new Connection(); - c.setConnectionString(con); - c.Open(); - Command comm = new Command(); - comm.setActiveConnection(c); - comm.setCommandType(CommandTypeEnum.adCmdText); - comm.setCommandText(query); - Recordset rs = comm.Execute(); - printRS(rs); - c.Close(); - } - - public static void main(String[] args) - { - String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs"; - String queryStr = "select * from authors"; - getCommand(connectStr, queryStr); - getRS(connectStr, queryStr); - } -} +package samples.ado; +import com.jacob.com.*; + +public class test +{ + public static void printRS(Recordset rs) + { + Fields fs = rs.getFields(); + + for (int i=0;i Recordset"); + Connection c = new Connection(); + c.setConnectionString(con); + c.Open(); + Command comm = new Command(); + comm.setActiveConnection(c); + comm.setCommandType(CommandTypeEnum.adCmdText); + comm.setCommandText(query); + Recordset rs = comm.Execute(); + printRS(rs); + c.Close(); + } + + public static void main(String[] args) + { + String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs"; + String queryStr = "select * from authors"; + getCommand(connectStr, queryStr); + getRS(connectStr, queryStr); + } +} diff --git a/samples/applet/AppTest.java b/samples/applet/AppTest.java index ec0febf..8c099e5 100644 --- a/samples/applet/AppTest.java +++ b/samples/applet/AppTest.java @@ -1,37 +1,49 @@ -import java.awt.*; -import java.awt.event.*; -import java.applet.*; - -import com.jacob.com.*; -import com.jacob.activeX.*; - -public class AppTest extends Applet implements ActionListener -{ - TextField in; - TextField out; - Button calc; - ActiveXComponent sC = null; - Object sControl = null; - - public void init() - { - setLayout(new FlowLayout()); - add(in = new TextField("1+1", 16)); - add(out = new TextField("?", 16)); - add(calc = new Button("Calculate")); - calc.addActionListener(this); - - } - - public void actionPerformed(ActionEvent ev) - { - if (sC == null) { - String lang = "VBScript"; - sC = new ActiveXComponent("ScriptControl"); - sControl = sC.getObject(); - Dispatch.put(sControl, "Language", lang); - } - Variant v = Dispatch.call(sControl, "Eval", in.getText()); - out.setText(v.toString()); - } -} +package samples.applet; + +import java.awt.*; +import java.awt.event.*; +import java.applet.*; + +import com.jacob.com.*; +import com.jacob.activeX.*; + +/** + * Applet test case + */ +public class AppTest extends Applet implements ActionListener +{ + TextField in; + TextField out; + Button calc; + ActiveXComponent sC = null; + Object sControl = null; + + /** + * startup method + */ + public void init() + { + setLayout(new FlowLayout()); + add(in = new TextField("1+1", 16)); + add(out = new TextField("?", 16)); + add(calc = new Button("Calculate")); + calc.addActionListener(this); + + } + + /** + * action method that receives button actions + * @param ev the event + */ + public void actionPerformed(ActionEvent ev) + { + if (sC == null) { + String lang = "VBScript"; + sC = new ActiveXComponent("ScriptControl"); + sControl = sC.getObject(); + Dispatch.put(sControl, "Language", lang); + } + Variant v = Dispatch.call(sControl, "Eval", in.getText()); + out.setText(v.toString()); + } +} diff --git a/samples/servlet/JacobScript.java b/samples/servlet/JacobScript.java index 452f456..6324d75 100644 --- a/samples/servlet/JacobScript.java +++ b/samples/servlet/JacobScript.java @@ -1,73 +1,75 @@ -import javax.servlet.*; -import javax.servlet.http.*; -import java.io.*; - -import com.jacob.com.*; -import com.jacob.activeX.*; - -public class JacobScript extends javax.servlet.http.HttpServlet -{ - public void doGet(HttpServletRequest req, - HttpServletResponse res) - throws ServletException - { - PrintWriter out = null; - try - { - res.setContentType("text/html"); - out = res.getWriter(); - // display a form - out.println("

Enter a VBScript Expression

"); - out.println("
"); - out.println(""); - out.println(""); - out.println("
"); - } catch (Exception e) { - e.printStackTrace(); - out.println("

Error:"+e+"

"); - } - } - - public void doPost(HttpServletRequest req, - HttpServletResponse res) - throws ServletException - { - PrintWriter out = null; - - try - { - res.setContentType("text/html"); - out = res.getWriter(); - // get what they typed in - String expr = (String)req.getParameter("expr"); - // make sure we have a session - HttpSession session = req.getSession(true); - Object sControl = null; - if (session.isNew()) - { - // initialize the control and store it on the session - String lang = "VBScript"; - ActiveXComponent sC = new ActiveXComponent("ScriptControl"); - sControl = sC.getObject(); - Dispatch.put(sControl, "Language", lang); - session.putValue("control", sControl); - } - else - { - sControl = session.getValue("control"); - } - Variant result = Dispatch.call(sControl, "Eval", expr); - // display a form - out.println("

Enter a VBScript Expression

"); - out.println("
"); - out.println(""); - out.println(""); - out.println("
"); - out.println("

Jacob Response:

"); - out.println("

"+result+"

"); - } catch (Exception e) { - e.printStackTrace(); - out.println("

Error:"+e+"

"); - } - } -} +package samples.servlet; + +import javax.servlet.*; +import javax.servlet.http.*; +import java.io.*; + +import com.jacob.com.*; +import com.jacob.activeX.*; + +public class JacobScript extends javax.servlet.http.HttpServlet +{ + public void doGet(HttpServletRequest req, + HttpServletResponse res) + throws ServletException + { + PrintWriter out = null; + try + { + res.setContentType("text/html"); + out = res.getWriter(); + // display a form + out.println("

Enter a VBScript Expression

"); + out.println("
"); + out.println(""); + out.println(""); + out.println("
"); + } catch (Exception e) { + e.printStackTrace(); + out.println("

Error:"+e+"

"); + } + } + + public void doPost(HttpServletRequest req, + HttpServletResponse res) + throws ServletException + { + PrintWriter out = null; + + try + { + res.setContentType("text/html"); + out = res.getWriter(); + // get what they typed in + String expr = (String)req.getParameter("expr"); + // make sure we have a session + HttpSession session = req.getSession(true); + Object sControl = null; + if (session.isNew()) + { + // initialize the control and store it on the session + String lang = "VBScript"; + ActiveXComponent sC = new ActiveXComponent("ScriptControl"); + sControl = sC.getObject(); + Dispatch.put(sControl, "Language", lang); + session.putValue("control", sControl); + } + else + { + sControl = session.getValue("control"); + } + Variant result = Dispatch.call(sControl, "Eval", expr); + // display a form + out.println("

Enter a VBScript Expression

"); + out.println("
"); + out.println(""); + out.println(""); + out.println("
"); + out.println("

Jacob Response:

"); + out.println("

"+result+"

"); + } catch (Exception e) { + e.printStackTrace(); + out.println("

Error:"+e+"

"); + } + } +} diff --git a/samples/test/Access.java b/samples/test/Access.java index 88d1206..07c57c2 100644 --- a/samples/test/Access.java +++ b/samples/test/Access.java @@ -1,89 +1,110 @@ -package samples.test; - -import com.jacob.com.*; -import com.jacob.activeX.*; - -class Access -{ - public static void main(String[] args) throws Exception - { - ComThread.InitSTA(); - ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine"); - // this only works for access files pre-access-2000 - Dispatch db = open(ax, ".\\sample2.mdb"); - String sql = "select * from MainTable"; - // make a temporary querydef - Dispatch qd = Dispatch.call(db, "CreateQueryDef","").toDispatch(); - // set the SQL string on it - Dispatch.put(qd, "SQL", sql); - Variant result = getByQueryDef(qd); - // the 2-d safearray is transposed from what you might expect - System.out.println(result.toSafeArray()); - close(db); - ComThread.Release(); - } - - /** - * Open a database - */ - public static Dispatch open(ActiveXComponent ax, String fileName) - { - Variant f = new Variant(false); - // open the file in read-only mode - Variant[] args = new Variant[] {new Variant(fileName), f, f}; - Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch(); - return openDB; - } - - /** - * Close a database - */ - public static void close(Dispatch openDB) - { - Dispatch.call(openDB, "Close"); - } - - /** - * Extract the values from the recordset - */ - public static Variant getValues(Dispatch recset) - { - Dispatch.callSub(recset,"moveFirst"); - Variant vi = new Variant(4096); - Variant v = Dispatch.call(recset,"GetRows", vi); - return v; - } - - public static Variant getByQueryDef(Dispatch qd) - { - // get a reference to the recordset - Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch(); - // get the values as a safe array - String[] cols = getColumns(recset); - for(int i=0;i