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
This commit is contained in:
clay_shooter
2005-01-08 17:02:55 +00:00
parent 7b81d761b7
commit 43dce6d42f
30 changed files with 3966 additions and 2402 deletions

283
EventCallbacks.htm Normal file
View File

@@ -0,0 +1,283 @@
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="EventsAndCallBacks_files/filelist.xml">
<title>Jacob can register Java classes for MS application events or callbacks</title>
<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:RemovePersonalInformation/>
</o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:DisplayBackgroundShape/>
<w:SpellingState>Clean</w:SpellingState>
<w:GrammarState>Clean</w:GrammarState>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SelectEntireFieldWithStartOrEnd/>
<w:UseWord2002TableStyleRules/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-font-family:"Times New Roman";}
span.SpellE
{mso-style-name:"";
mso-spl-e:yes;}
span.GramE
{mso-style-name:"";
mso-gram-e:yes;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 65.95pt 1.0in 65.95pt;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:369961789;
mso-list-type:hybrid;
mso-list-template-ids:-80199436 -1920937264 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-text:"%1\)";
mso-level-tab-stop:42.0pt;
mso-level-number-position:left;
margin-left:42.0pt;
text-indent:-24.0pt;}
@list l1
{mso-list-id:1316765558;
mso-list-type:hybrid;
mso-list-template-ids:860497186 -1920937264 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
{mso-level-text:"%1\)";
mso-level-tab-stop:42.0pt;
mso-level-number-position:left;
margin-left:42.0pt;
text-indent:-24.0pt;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>
<body lang=EN-US style='tab-interval:.5in'>
<div class=Section1>
<p class=MsoPlainText>Jacob can register Java classes for MS application events
or callbacks.<span style='mso-spacerun:yes'><EFBFBD> </span>The normal flow for this
is:</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>1)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>Application thread creates an instance of the
event handler and registers it with Jacob</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>2)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The application continues on doing other work.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>3)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>Some time later, the MS application takes some
action and initiates the event callback.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>4)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The Java VM receives the event and spins up a
new thread to handle it.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>5)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The Jacob <span class=SpellE>EventProxy</span>
in the <span class=SpellE>dll</span> is called by the VM.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>6)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The Jacob <span class=SpellE>EventProxy</span>
creates Variant objects to handle the parameters of the passed in event.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>7)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The Jacob <span class=SpellE>EventProxy</span>
uses reflection to map the event name to a method name with the exact same
name.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l1 level1 lfo1;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>8)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>The Jacob <span class=SpellE>EventProxy</span>
sends the message to the registered event handler.</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText>Swing developers should note that this message comes in
on a thread other than the event thread.<span style='mso-spacerun:yes'><EFBFBD>
</span>All objects receiving events that require user intervention or drawing
in the UI should use <span class=SpellE><span class=GramE>invokeLater</span></span><span
class=GramE>(</span>) to post requests for actions onto the event queue.<span
style='mso-spacerun:yes'><EFBFBD> </span>Failure to do so will insure random failures
in the GUI.</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText>Java Web Start (JWS) and other launchers can have
additional issues related to the class loader.<span style='mso-spacerun:yes'><EFBFBD>
</span>The Jacob C++ library uses <span class=SpellE><span class=GramE>FindClass</span></span><span
class=GramE>(</span>) to find the Variant class when building the parameter
list.<span style='mso-spacerun:yes'><EFBFBD> </span><span class=SpellE><span
class=GramE>FindClass</span></span><span class=GramE>(</span>) uses the system
class loader which includes only the classes specified at run time or in the
CLASSPATH.<span style='mso-spacerun:yes'><EFBFBD> </span>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.<span
style='mso-spacerun:yes'><EFBFBD> </span>This means that the search for Variant will
fail usually with the silent and immediate termination of the Java application.<span
style='mso-spacerun:yes'><EFBFBD> </span>The thread <span class=SpellE>classloader</span>
probably can<61>t be used to try and find the class because this new thread does
not have a <span class=SpellE>classloader</span> associated with it other than
the system class loader.<span style='mso-spacerun:yes'><EFBFBD> </span>The end result
is that the Variant class needs to be located via other means and that the
thread <span class=SpellE>classloader</span> should be set to be the context
class loader of the event handler class.</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText>The Jacob <span class=SpellE>EventProxy</span> class has
been modified (off of the 1.8 tree) so that it takes a two step approach to towards
fixing these problems.</p>
<p class=MsoPlainText><span style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span
style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span></p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l0 level1 lfo2;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>1)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]><span class=SpellE>EventProxy</span> first
attempts to locate the Variant class using <span class=SpellE>FindClass</span>()</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l0 level1 lfo2;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>2)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>Failing that, it looks to see if the event
callback object implements <span class=SpellE><span class=GramE>getVariantClass</span></span><span
class=GramE>(</span>) that returns the <span class=SpellE>Variant.class</span>
object.<span style='mso-spacerun:yes'><EFBFBD> </span>If so, it uses that class to
create variants for the callback parameters.</p>
<p class=MsoPlainText style='margin-left:42.0pt;text-indent:-24.0pt;mso-list:
l0 level1 lfo2;tab-stops:list 42.0pt'><![if !supportLists]><span
style='mso-fareast-font-family:"Courier New"'><span style='mso-list:Ignore'>3)<span
style='font:7.0pt "Times New Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><![endif]>If all that fails, it logs a message and then
fails in the spectacular fashion of the previous versions.</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText>This means developers can receive call back events in JWS
other Java launching programs by implementing <span class=SpellE><span
class=GramE>getVariantClass</span></span><span class=GramE>(</span>) on all of
their classes that receive Microsoft Events.<span style='mso-spacerun:yes'><EFBFBD>
</span>The <span class=SpellE><span class=GramE>getVariantClass</span></span><span
class=GramE>(</span>) method has the added benefit of providing a spot for the
thread <span class=SpellE>classloader</span> to be set:</p>
<p class=MsoPlainText><span style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span>Public Class <span
class=SpellE><span class=GramE>getVariantClass</span></span><span class=GramE>(</span>){</p>
<p class=MsoPlainText><span style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span
style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span class=SpellE><span class=GramE>Thread.currentThread</span></span><span
class=GramE>(</span>).<span class=SpellE>setContextClassLoader</span>(</p>
<p class=MsoPlainText><span style='mso-tab-count:3'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span
class=SpellE><span class=GramE>this.getClass</span></span><span class=GramE>(</span>).<span
class=SpellE>getClassLoader</span>());</p>
<p class=MsoPlainText><span style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span
style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span><span class=GramE>return</span> <span
class=SpellE>Variant.class</span></p>
<p class=MsoPlainText><span style='mso-tab-count:1'><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> </span>}</p>
<p class=MsoPlainText><o:p>&nbsp;</o:p></p>
<p class=MsoPlainText>There may still be a dual event queue issue in JWS
applications that needs to be looked at.</p>
</div>
</body>
</html>

View File

@@ -1,73 +1,88 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.activeX; package com.jacob.activeX;
import com.jacob.com.*; import com.jacob.com.*;
/** /**
* This class simulates com.ms.activeX.ActiveXComponent only as * This class simulates com.ms.activeX.ActiveXComponent only as it used for
* it used for creating Dispatch objects * creating Dispatch objects
*/ */
public class ActiveXComponent extends Dispatch public class ActiveXComponent extends Dispatch {
{ /**
public ActiveXComponent(String progid) * @param progid
{ */
super(progid); public ActiveXComponent(String progid) {
} super(progid);
}
public Object getObject()
{ /**
return this; * @return actually returns this bject
} */
public Object getObject() {
public Variant invoke(String name, Variant[] args) return this;
{ }
return Dispatch.callN(this, name, args);
} /**
* @param name
public Variant getProperty(String name) * @param args
{ * @return Variant result of the invoke
return Dispatch.get(this, name); */
} public Variant invoke(String name, Variant[] args) {
return Dispatch.callN(this, name, args);
public void setProperty(String name, Variant arg) }
{
Dispatch.put(this, name, arg); /**
} * @param name property name
* @return Variant value of property
protected void finalize() */
{ public Variant getProperty(String name) {
super.finalize(); return Dispatch.get(this, name);
} }
static { /**
System.loadLibrary("jacob"); * @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");
}
}

View File

@@ -1,88 +1,136 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in * materials provided with the distribution. 3. Redistributions in any form must
* the documentation and/or other materials provided with the * be accompanied by information on how to obtain complete source code for the
* distribution. * JACOB software.
* 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
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * POSSIBILITY OF SUCH DAMAGE.
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED package com.jacob.com;
* 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 public abstract class ComException extends RuntimeException {
{ // Fields
// Fields /** TODO: what is this field */
protected int hr; protected int hr;
protected int m_helpContext; /** TODO: what is this field */
protected String m_helpFile; protected int m_helpContext;
protected String m_source; /** TODO: what is this field */
protected String m_helpFile;
// Constructors /** TODO: what is this field */
public ComException() protected String m_source;
{
super(); /**
} * constructor
*
public ComException(int hr) */
{ public ComException() {
super(); super();
this.hr = hr; }
}
/**
public ComException(int hr, String description) * constructor with error code?
{ *
super(description); * @param newHr ??
this.hr = hr; */
} public ComException(int newHr) {
super();
public ComException(int hr, String source, String helpFile, this.hr = newHr;
int helpContext) }
{
super(); /**
this.hr = hr; * @param newHr
m_source = source; * @param description
m_helpFile = helpFile; */
m_helpContext = helpContext; public ComException(int newHr, String description) {
} super(description);
this.hr = newHr;
public ComException(int hr, String description, String source, }
String helpFile, int helpContext)
{ /**
super(description); * @param newHr
this.hr = hr; * @param source
m_source = source; * @param helpFile
m_helpFile = helpFile; * @param helpContext
m_helpContext = helpContext; */
} public ComException(int newHr, String source, String helpFile,
int helpContext) {
public ComException(String description) super();
{ this.hr = newHr;
super(description); m_source = source;
} m_helpFile = helpFile;
m_helpContext = helpContext;
// Methods }
public int getHelpContext() { return m_helpContext; }
public String getHelpFile() { return m_helpFile; } /**
public int getHResult() { return hr; } * @param newHr
public String getSource() { return m_source; } * @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;
}
}

View File

@@ -1,65 +1,88 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in * materials provided with the distribution. 3. Redistributions in any form must
* the documentation and/or other materials provided with the * be accompanied by information on how to obtain complete source code for the
* distribution. * JACOB software.
* 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
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * POSSIBILITY OF SUCH DAMAGE.
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED package com.jacob.com;
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ /**
package com.jacob.com; * @author joe
*
public class ComFailException extends ComException * TODO To change the template for this generated type comment go to
{ * Window - Preferences - Java - Code Style - Code Templates
// Constructors */
public ComFailException(int hr) public class ComFailException extends ComException {
{ /**
super(hr); * @param hrNew
} */
public ComFailException(int hr, String message) // Constructors
{ public ComFailException(int hrNew) {
super(hr, message); super(hrNew);
} }
public ComFailException(int hr, String source, String helpFile, /**
int helpContext) * @param hrNew
{ * @param message
super(hr, source, helpFile, helpContext); */
} public ComFailException(int hrNew, String message) {
super(hrNew, message);
public ComFailException(int hr, String description, }
String source, String helpFile, int helpContext)
{ /**
super(hr, description, source, helpFile, helpContext); * @param hrNew
} * @param source
* @param helpFile
public ComFailException() * @param helpContext
{ */
super(); public ComFailException(int hrNew, String source, String helpFile,
} int helpContext) {
super(hrNew, source, helpFile, helpContext);
public ComFailException(String message) }
{
super(message); /**
} * @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);
}
}

View File

@@ -1,130 +1,145 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in * materials provided with the distribution. 3. Redistributions in any form must
* the documentation and/or other materials provided with the * be accompanied by information on how to obtain complete source code for the
* distribution. * JACOB software.
* 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
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * POSSIBILITY OF SUCH DAMAGE.
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED package com.jacob.com;
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ /**
package com.jacob.com; * @author joe
import java.util.Hashtable; *
import java.util.Vector; * TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public abstract class ComThread */
{ public abstract class ComThread {
private static final int MTA = 0x0; private static final int MTA = 0x0;
private static final int STA = 0x2;
private static final int STA = 0x2;
public static boolean haveSTA = false;
public static MainSTA mainSTA = null; /**
* Comment for <code>haveSTA</code>
/** */
* Initialize the current java thread to be part of the public static boolean haveSTA = false;
* Multi-threaded COM Apartment
*/ /**
public static synchronized void InitMTA() * Comment for <code>mainSTA</code>
{ */
InitMTA(false); public static MainSTA mainSTA = null;
}
/**
/** * Initialize the current java thread to be part of the Multi-threaded COM
* Initialize the current java thread to be an STA * Apartment
*/ */
public static synchronized void InitSTA() public static synchronized void InitMTA() {
{ InitMTA(false);
InitSTA(false); }
}
/**
/** * Initialize the current java thread to be an STA
* Initialize the current java thread to be part of the */
* Multi-threaded COM Apartment, if createMainSTA is true, public static synchronized void InitSTA() {
* create a separate MainSTA InitSTA(false);
* thread that will house all Apartment Threaded components }
*/
public static synchronized void InitMTA(boolean createMainSTA) /**
{ * Initialize the current java thread to be part of the Multi-threaded COM
Init(createMainSTA, MTA); * Apartment, if createMainSTA is true, create a separate MainSTA thread
} * that will house all Apartment Threaded components
* @param createMainSTA
/** */
* Initialize the current java thread to be an STA public static synchronized void InitMTA(boolean createMainSTA) {
* COM Apartment, if createMainSTA is true, Init(createMainSTA, MTA);
* create a separate MainSTA }
* thread that will house all Apartment Threaded components
*/ /**
public static synchronized void InitSTA(boolean createMainSTA) * Initialize the current java thread to be an STA COM Apartment, if
{ * createMainSTA is true, create a separate MainSTA thread that will house
Init(createMainSTA, STA); * all Apartment Threaded components
} * @param createMainSTA
*/
public static synchronized void startMainSTA() public static synchronized void InitSTA(boolean createMainSTA) {
{ Init(createMainSTA, STA);
mainSTA = new MainSTA(); }
haveSTA = true;
} /**
*
public static synchronized void quitMainSTA() */
{ public static synchronized void startMainSTA() {
if (mainSTA != null) mainSTA.quit(); mainSTA = new MainSTA();
} haveSTA = true;
}
/**
* Initialize the current java thread to be part of the /**
* MTA/STA COM Apartment *
*/ */
public static synchronized void Init(boolean createMainSTA, int mode) public static synchronized void quitMainSTA() {
{ if (mainSTA != null)
if (createMainSTA && !haveSTA) mainSTA.quit();
{ }
// 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 * Initialize the current java thread to be part of the MTA/STA COM
startMainSTA(); * Apartment
} * @param createMainSTA
//System.out.println("before Init: "+mode); * @param mode
doCoInitialize(mode); */
//System.out.println("after Init"); public static synchronized void Init(boolean createMainSTA, int mode) {
ROT.addThread(); if (createMainSTA && !haveSTA) {
//System.out.println("after ROT.addThread"); // 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();
* Call CoUninitialize to release this java thread from COM }
*/ //System.out.println("before Init: "+mode);
public static synchronized void Release() doCoInitialize(mode);
{ //System.out.println("after Init");
//System.out.println("before clearObjects"); ROT.addThread();
ROT.clearObjects(); //System.out.println("after ROT.addThread");
//System.out.println("before UnInit"); }
doCoUninitialize();
//System.out.println("after UnInit"); /**
} * Call CoUninitialize to release this java thread from COM
*/
public static native void doCoInitialize(int threadModel); public static synchronized void Release() {
public static native void doCoUninitialize(); //System.out.println("before clearObjects");
ROT.clearObjects();
static { //System.out.println("before UnInit");
System.loadLibrary("jacob"); doCoUninitialize();
} //System.out.println("after UnInit");
} }
/**
* @param threadModel
*/
public static native void doCoInitialize(int threadModel);
/**
*
*/
public static native void doCoUninitialize();
static {
System.loadLibrary("jacob");
}
}

View File

@@ -29,36 +29,50 @@
*/ */
package com.jacob.com; package com.jacob.com;
public class DispatchEvents extends JacobObject /**
{ * @author joe
int m_pConnPtProxy = 0; *
* 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) /**
{ * @param src
init(src, sink); * @param sink
} */
public DispatchEvents(Dispatch src, Object sink, String progId) public DispatchEvents(Dispatch src, Object sink) {
{ init(src, sink);
init2(src, sink,progId); }
}
// hook up a connection point proxy object /**
// event methods on the sink object will be called * @param src
// by name with a signature of <name>(Variant[] args) * @param sink
protected native void init(Dispatch src, Object sink); * @param progId
protected native void init2(Dispatch src, Object sink, String progId); */
public DispatchEvents(Dispatch src, Object sink, String progId) {
init2(src, sink, progId);
}
// call this to explicitly release the com object before gc // hook up a connection point proxy object
public native void release(); // event methods on the sink object will be called
// by name with a signature of <name>(Variant[] args)
protected native void init(Dispatch src, Object sink);
protected void finalize() protected native void init2(Dispatch src, Object sink, String progId);
{
//System.out.println("DispatchEvents finalize start");
if (m_pConnPtProxy != 0) release();
//System.out.println("DispatchEvents finalize end");
}
static { // call this to explicitly release the com object before gc
System.loadLibrary("jacob"); 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");
}
}

View File

@@ -1,65 +1,77 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
/** /**
* If you need to pass a COM Dispatch object between STA threads, you * If you need to pass a COM Dispatch object between STA threads, you have to
* have to marshall the interface. * marshall the interface. This class is used as follows: the STA that creates
* This class is used as follows: the STA that creates the Dispatch * the Dispatch object must construct an instance of this class. Another thread
* object must construct an instance of this class. Another thread * can then call toDispatch() on that instance and get a Dispatch pointer which
* can then call toDispatch() on that instance and get a Dispatch * has been marshalled. WARNING: You can only call toDispatch() once! If you
* pointer which has been marshalled. * need to call it multiple times (or from multiple threads) you need to
* WARNING: You can only call toDispatch() once! If you need to call * construct a separate DispatchProxy instance for each such case!
* 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 class DispatchProxy extends JacobObject * Comment for <code>m_pStream</code>
{ */
public int m_pStream; public int m_pStream;
public DispatchProxy(Dispatch localDispatch) /**
{ * @param localDispatch
MarshalIntoStream(localDispatch); */
} public DispatchProxy(Dispatch localDispatch) {
MarshalIntoStream(localDispatch);
public Dispatch toDispatch() }
{
return MarshalFromStream(); /**
} * @return
*/
private native void MarshalIntoStream(Dispatch d); public Dispatch toDispatch() {
private native Dispatch MarshalFromStream(); return MarshalFromStream();
public native void release(); }
public void finalize() private native void MarshalIntoStream(Dispatch d);
{
if (m_pStream != 0) release(); 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();
}
}

View File

@@ -1,122 +1,131 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
/** /**
* An implementation of IEnumVariant based on code submitted by * An implementation of IEnumVariant based on code submitted by Thomas Hallgren
* Thomas Hallgren (mailto:Thomas.Hallgren@eoncompany.com) * (mailto:Thomas.Hallgren@eoncompany.com)
*/ */
public class EnumVariant extends JacobObject implements java.util.Enumeration public class EnumVariant extends JacobObject implements java.util.Enumeration {
{ private int m_pIEnumVARIANT;
private int m_pIEnumVARIANT;
private final Variant[] m_recBuf = new Variant[1]; private final Variant[] m_recBuf = new Variant[1];
// this only gets called from JNI // this only gets called from JNI
// //
protected EnumVariant(int pIEnumVARIANT) protected EnumVariant(int pIEnumVARIANT) {
{ m_pIEnumVARIANT = pIEnumVARIANT;
m_pIEnumVARIANT = pIEnumVARIANT; }
}
/**
public EnumVariant(Object disp) * @param disp
{ */
int[] hres = new int[1]; public EnumVariant(Object disp) {
Variant evv = Dispatch.invokev( int[] hres = new int[1];
disp, Variant evv = Dispatch.invokev(disp, Dispatch.DISPID_NEWENUM,
Dispatch.DISPID_NEWENUM, Dispatch.Get, new Variant[0], hres);
Dispatch.Get, if (evv.getvt() != Variant.VariantObject)
new Variant[0], //
hres); // The DISPID_NEWENUM did not result in a valid object
if(evv.getvt() != Variant.VariantObject) //
// throw new ComFailException("Can't obtain EnumVARIANT");
// The DISPID_NEWENUM did not result in a valid object
// EnumVariant tmp = evv.toEnumVariant();
throw new ComFailException("Can't obtain EnumVARIANT"); m_pIEnumVARIANT = tmp.m_pIEnumVARIANT;
tmp.m_pIEnumVARIANT = 0;
EnumVariant tmp = evv.toEnumVariant(); }
m_pIEnumVARIANT = tmp.m_pIEnumVARIANT;
tmp.m_pIEnumVARIANT = 0; /**
} * Implements java.util.Enumeration
* @return
/** */
* Implements java.util.Enumeration public boolean hasMoreElements() {
*/ {
public boolean hasMoreElements() if (m_recBuf[0] == null) {
{ if (this.Next(m_recBuf) <= 0)
{ return false;
if(m_recBuf[0] == null) }
{ return true;
if(this.Next(m_recBuf) <= 0) }
return false; }
}
return true; /**
} * Implements java.util.Enumeration
} * @return
*/
/** public Object nextElement() {
* Implements java.util.Enumeration Object last = m_recBuf[0];
*/ if (last == null) {
public Object nextElement() if (this.Next(m_recBuf) <= 0)
{ throw new java.util.NoSuchElementException();
Object last = m_recBuf[0]; last = m_recBuf[0];
if(last == null) }
{ m_recBuf[0] = null;
if(this.Next(m_recBuf) <= 0) return last;
throw new java.util.NoSuchElementException(); }
last = m_recBuf[0];
} /**
m_recBuf[0] = null; * Get next element in collection or null if at end
return last; * @return
} */
public Variant Next() {
/** if (hasMoreElements())
* Get next element in collection or null if at end return (Variant) nextElement();
*/ return null;
public Variant Next() }
{
if (hasMoreElements()) return (Variant)nextElement(); /**
return null; * @param receiverArray
} * @return
*/
public native int Next(Variant[] receiverArray); public native int Next(Variant[] receiverArray);
public native void Skip(int count); /**
* @param count
public native void Reset(); */
public native void Skip(int count);
public native void release();
/**
protected void finalize() *
{ */
//System.out.println("EnumVariant finalize start"); public native void Reset();
if (m_pIEnumVARIANT != 0) this.release();
//System.out.println("EnumVariant finalize end"); /* (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");
}
}

View File

@@ -1,46 +1,52 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
/** /**
* All COM object created by JACOB extend this class so that * All COM object created by JACOB extend this class so that we can
* we can automatically release them when the thread is detached from * automatically release them when the thread is detached from COM - if we leave
* COM - if we leave it to the finalizer it will call the release from * it to the finalizer it will call the release from another thread, which may
* another thread, which may result in a segmentation violation. * result in a segmentation violation.
*/ */
public class JacobObject public class JacobObject {
{ /**
public JacobObject() * Standard constructor
{ */
ROT.addObject(this); public JacobObject() {
} ROT.addObject(this);
}
public void release() {}
} /**
*
*/
public void release() {
// currently does nothing
}
}

View File

@@ -1,43 +1,42 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
/** /**
* We provide our own main sta thread to avoid COM tagging a random * 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 * thread as the main STA - this is the thread in which all Apartment
* threaded components will be created if the client chooses an MTA * threaded components will be created if the client chooses an MTA
* threading model for the java side of the app. * threading model for the java side of the app.
*/ */
public class MainSTA extends STA public class MainSTA extends STA {
{ static {
static { System.loadLibrary("jacob");
System.loadLibrary("jacob"); }
} }
}

View File

@@ -1,99 +1,92 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
import java.util.Hashtable;
import java.util.Vector; 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 * The Running Object Table (ROT) maps each thread to a vector of all the
* operates on the current thread so all the methods are static and * JacobObjects that were created in that thread. It always operates on the
* they implicitly get the current thread. * current thread so all the methods are static and they implicitly get the
* Conceptually, this is similar to the ThreadLocal class of Java 1.2 * current thread. Conceptually, this is similar to the ThreadLocal class of
* but we are also supporting Java 1.6 * Java 1.2 but we are also supporting Java 1.6 The clearObjects method is used
* The clearObjects method is used to release all the COM objects * to release all the COM objects created by Jacob in the current thread prior
* created by Jacob in the current thread prior to uninitializing COM * to uninitializing COM for that thread. If we leave this job to the garbage
* for that thread. If we leave this job to the garbage collector, * collector, then finalize might get called from a separate thread which is not
* then finalize might get called from a separate thread which is not * initialized for COM, and also the component itself may have been freed.
* initialized for COM, and also the component itself may have been */
* freed. public abstract class ROT {
*/ private static Hashtable rot = new Hashtable();
public abstract class ROT
{ protected static void addThread() {
private static Hashtable rot = new Hashtable(); String t_name = Thread.currentThread().getName();
if (rot.contains(t_name))
protected static void addThread() return;
{ Vector v = new Vector();
String t_name = Thread.currentThread().getName(); rot.put(t_name, v);
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);
protected static void clearObjects() if (v != null) {
{ while (!v.isEmpty()) {
String t_name = Thread.currentThread().getName(); JacobObject o = (JacobObject) v.elementAt(0);
Vector v = (Vector)rot.get(t_name); //System.out.println(t_name + "
if (v != null) // release:"+o+"->"+o.getClass().getName());
{ if (o != null)
while (!v.isEmpty()) o.release();
{ v.removeElementAt(0);
JacobObject o = (JacobObject)v.elementAt(0); }
//System.out.println(t_name + " release:"+o+"->"+o.getClass().getName()); rot.remove(t_name);
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);
protected static void addObject(JacobObject o) if (v == null) {
{ // this thread has not been initialized as a COM thread
String t_name = Thread.currentThread().getName(); // so make it part of MTA for backwards compatibility
//System.out.println(t_name + " add:"+o+"->"+o.getClass().getName()); ComThread.InitMTA(false);
Vector v = (Vector)rot.get(t_name); addThread();
if (v == null) v = (Vector) rot.get(t_name);
{ }
// this thread has not been initialized as a COM thread if (v != null) {
// so make it part of MTA for backwards compatibility v.addElement(o);
ComThread.InitMTA(false); }
addThread(); }
v = (Vector)rot.get(t_name);
} static {
if (v != null) System.loadLibrary("jacob");
{ }
v.addElement(o); }
}
}
static {
System.loadLibrary("jacob");
}
}

View File

@@ -1,98 +1,104 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * All rights reserved. Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the * the documentation and/or other materials provided with the
* distribution. * distribution.
* 3. Redistributions in any form must be accompanied by information on * 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software. * how to obtain complete source code for the JACOB software.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jacob.com; package com.jacob.com;
/** /**
* A class that implements a Single Threaded Apartment. * A class that implements a Single Threaded Apartment. Users will subclass this
* Users will subclass this and override OnInit() and OnQuit() * and override OnInit() and OnQuit() where they will create and destroy a COM
* where they will create and destroy a COM component that wants to * component that wants to run in an STA other than the main STA.
* run in an STA other than the main STA. */
*/ public class STA extends Thread {
public class STA extends Thread /**
{ * TODO: no references exist to this. should it be dropped
public int threadID; */
public int threadID;
public STA()
{ /**
start(); // start the thread * constructor for STA
} */
public STA() {
public void run() start(); // start the thread
{ }
// init COM
ComThread.InitSTA(); /* (non-Javadoc)
if (OnInit()) * @see java.lang.Thread#run()
{ */
// this call blocks in the win32 message loop public void run() {
// until quitMessagePump is called // init COM
doMessagePump(); ComThread.InitSTA();
} if (OnInit()) {
OnQuit(); // this call blocks in the win32 message loop
// uninit COM // until quitMessagePump is called
ComThread.Release(); doMessagePump();
} }
OnQuit();
/** // uninit COM
* Override this method to create and initialize any COM ComThread.Release();
* component that you want to run in this thread. If anything }
* fails, return false to terminate the thread.
*/ /**
public boolean OnInit() * 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
return true; * the thread.
} * @return always returns true
*/
/** public boolean OnInit() {
* Override this method to destroy any resource return true;
* before the thread exits and COM in uninitialized }
*/
public void OnQuit() /**
{ * Override this method to destroy any resource before the thread exits and
} * COM in uninitialized
*/
public void quit() public void OnQuit() {
{ // there is nothing to see here
quitMessagePump(); }
}
/**
/** * calls quitMessagePump
* run a message pump for the main STA */
*/ public void quit() {
public native void doMessagePump(); quitMessagePump();
}
/**
* quit message pump for the main STA /**
*/ * run a message pump for the main STA
public native void quitMessagePump(); */
public native void doMessagePump();
static {
System.loadLibrary("jacob"); /**
} * quit message pump for the main STA
} */
public native void quitMessagePump();
static {
System.loadLibrary("jacob");
}
}

View File

@@ -1,247 +1,659 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in * materials provided with the distribution. 3. Redistributions in any form must
* the documentation and/or other materials provided with the * be accompanied by information on how to obtain complete source code for the
* distribution. * JACOB software.
* 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
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * POSSIBILITY OF SUCH DAMAGE.
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED package com.jacob.com;
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ /**
package com.jacob.com; * @author joe
*
public class SafeArray extends JacobObject * TODO To change the template for this generated type comment go to
{ * Window - Preferences - Java - Code Style - Code Templates
int m_pV = 0; */
public class SafeArray extends JacobObject {
public SafeArray() {} int m_pV = 0;
public SafeArray(int vt) /**
{ * constructor
init(vt, new int[] {0}, new int[] {-1}); *
} */
public SafeArray() {
public SafeArray(int vt,int celems) }
{
init(vt, new int[] {0}, new int[] {celems}); /**
} * constructor
* @param vt
public SafeArray(int vt,int celems1,int celems2) */
{ public SafeArray(int vt) {
init(vt, new int[] {0,0}, new int[] {celems1, celems2}); init(vt, new int[] { 0 }, new int[] { -1 });
} }
public SafeArray(int vt,int lbounds[],int celems[]) /**
{ * constructor
init(vt, lbounds, celems); * @param vt
} * @param celems
*/
// convert a string to a VT_UI1 array public SafeArray(int vt, int celems) {
public SafeArray(String s) init(vt, new int[] { 0 }, new int[] { celems });
{ }
char[] ca = s.toCharArray();
init(Variant.VariantByte, new int[] {0}, new int[] {ca.length}); /**
fromCharArray(ca); * @param vt
} * @param celems1
* @param celems2
protected native void init(int vt, int lbounds[], int celems[]); */
public SafeArray(int vt, int celems1, int celems2) {
// not impl init(vt, new int[] { 0, 0 }, new int[] { celems1, celems2 });
public int getNumLocks() { return 0; } }
// convert a VT_UI1 array to string /**
public String asString() * constructor
{ * @param vt
if (getvt() != Variant.VariantByte) return null; * @param lbounds
char ja[] = toCharArray(); * @param celems
return new String(ja); */
} public SafeArray(int vt, int lbounds[], int celems[]) {
init(vt, lbounds, celems);
}
public native Object clone();
// call this to explicitly release the com object before gc /**
* convert a string to a VT_UI1 array
public void release() * @param s source string
{ */
destroy(); public SafeArray(String s) {
} char[] ca = s.toCharArray();
init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length });
public native void destroy(); fromCharArray(ca);
public native int getvt(); }
protected void finalize()
{ protected native void init(int vt, int lbounds[], int celems[]);
//System.out.println("SafeArray finalize start");
if (m_pV != 0) release(); /**
//System.out.println("SafeArray finalize end"); * not impl
} * @return 0
public native void reinit(SafeArray sa); */
public native void reinterpretType(int vt); public int getNumLocks() {
return 0;
public native int getLBound(); }
public native int getLBound(int dim);
public native int getUBound(); /**
public native int getUBound(int dim); * convert a VT_UI1 array to string
* @return variant byte as a string
public native int getNumDim(); */
public native int getFeatures(); public String asString() {
public native int getElemSize(); if (getvt() != Variant.VariantByte)
return null;
public native void fromCharArray(char ja[]); char ja[] = toCharArray();
public native void fromIntArray(int ja[]); return new String(ja);
public native void fromShortArray(short ja[]); }
public native void fromDoubleArray(double ja[]);
public native void fromStringArray(String ja[]); public native Object clone();
public native void fromByteArray(byte ja[]);
public native void fromFloatArray(float ja[]);
public native void fromBooleanArray(boolean ja[]); /**
public native void fromVariantArray(Variant ja[]); * call this to explicitly release the com object before gc
*/
public native char[] toCharArray(); public void release() {
public native int[] toIntArray(); destroy();
public native short[] toShortArray(); }
public native double[] toDoubleArray();
public native String[] toStringArray(); public native void destroy();
public native byte[] toByteArray();
public native float[] toFloatArray(); public native int getvt();
public native boolean[] toBooleanArray();
public native Variant[] toVariantArray(); protected void finalize() {
//System.out.println("SafeArray finalize start");
// char access if (m_pV != 0)
public native char getChar(int sa_idx); release();
public native char getChar(int sa_idx1, int sa_idx2); //System.out.println("SafeArray finalize end");
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 reinit(SafeArray sa);
public native void setChars(int sa_idx, int nelems, char ja[], int ja_start);
public native void reinterpretType(int vt);
// int access
public native int getInt(int sa_idx); public native int getLBound();
public native int getInt(int sa_idx1, int sa_idx2);
public native void setInt(int sa_idx, int c); public native int getLBound(int dim);
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 int getUBound();
public native void setInts(int sa_idx, int nelems, int ja[], int ja_start);
public native int getUBound(int dim);
// short access
public native short getShort(int sa_idx); public native int getNumDim();
public native short getShort(int sa_idx1, int sa_idx2);
public native void setShort(int sa_idx, short c); public native int getFeatures();
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 int getElemSize();
public native void setShorts(int sa_idx, int nelems, short ja[], int ja_start);
public native void fromCharArray(char ja[]);
// double access
public native double getDouble(int sa_idx); public native void fromIntArray(int ja[]);
public native double getDouble(int sa_idx1, int sa_idx2);
public native void setDouble(int sa_idx, double c); public native void fromShortArray(short ja[]);
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 fromDoubleArray(double ja[]);
public native void setDoubles(int sa_idx, int nelems, double ja[], int ja_start);
public native void fromStringArray(String ja[]);
// string access
public native String getString(int sa_idx); public native void fromByteArray(byte ja[]);
public native String getString(int sa_idx1, int sa_idx2);
public native void setString(int sa_idx, String c); public native void fromFloatArray(float ja[]);
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 fromBooleanArray(boolean ja[]);
public native void setStrings(int sa_idx, int nelems, String ja[], int ja_start);
public native void fromVariantArray(Variant ja[]);
// byte access
public native byte getByte(int sa_idx); public native char[] toCharArray();
public native byte getByte(int sa_idx1, int sa_idx2);
public native void setByte(int sa_idx, byte c); public native int[] toIntArray();
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 short[] toShortArray();
public native void setBytes(int sa_idx, int nelems, byte ja[], int ja_start);
public native double[] toDoubleArray();
// float access
public native float getFloat(int sa_idx); public native String[] toStringArray();
public native float getFloat(int sa_idx1, int sa_idx2);
public native void setFloat(int sa_idx, float c); public native byte[] toByteArray();
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 float[] toFloatArray();
public native void setFloats(int sa_idx, int nelems, float ja[], int ja_start);
public native boolean[] toBooleanArray();
// boolean access
public native boolean getBoolean(int sa_idx); public native Variant[] toVariantArray();
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); * char access
public native void getBooleans(int sa_idx, int nelems, boolean ja[], int ja_start); * @param sa_idx
public native void setBooleans(int sa_idx, int nelems, boolean ja[], int ja_start); * @return
*/
// variant access public native char getChar(int sa_idx);
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); * char access
public native void setVariant(int sa_idx1, int sa_idx2, Variant c); * @param sa_idx1
public native void getVariants(int sa_idx, int nelems, Variant ja[], int ja_start); * @param sa_idx2
public native void setVariants(int sa_idx, int nelems, Variant ja[], int ja_start); * @return
*/
public String toString() public native char getChar(int sa_idx1, int sa_idx2);
{
String s = ""; /**
int ndim = getNumDim(); * char access
if (ndim == 1) * @param sa_idx
{ * @param c
int ldim = getLBound(); */
int udim = getUBound(); public native void setChar(int sa_idx, char c);
for (int i = ldim; i <= udim; i++)
{ /**
Variant v = getVariant(i); * char access
* @param sa_idx1
if (((v.getvt() & Variant.VariantTypeMask) | Variant.VariantArray) == v.getvt()) * @param sa_idx2
{ * @param c
return s + "[" + v.toSafeArray().toString() + "]"; */
} public native void setChar(int sa_idx1, int sa_idx2, char c);
else
{ /**
s += " " + v.toString(); * char access
} * @param sa_idx
} * @param nelems
} * @param ja
else if (ndim == 2) * @param ja_start
{ */
int ldim1 = getLBound(1); public native void getChars(int sa_idx, int nelems, char ja[], int ja_start);
int udim1 = getUBound(1);
/**
int ldim2 = getLBound(2); * char access
int udim2 = getUBound(2); * @param sa_idx
* @param nelems
for (int i = ldim1; i <= udim1; i++) * @param ja
{ * @param ja_start
for (int j = ldim2; j <= udim2; j++) */
{ public native void setChars(int sa_idx, int nelems, char ja[], int ja_start);
Variant v = getVariant(i, j);
s += " " + v.toString(); /**
} * int access
s += "\n"; * @param sa_idx
} * @return
} */
return s; public native int getInt(int sa_idx);
}
/**
static { * int access
System.loadLibrary("jacob"); * @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");
}
}

View File

@@ -1,37 +1,48 @@
/* /*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. * Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* All rights reserved. Originator: Dan Adler (http://danadler.com). * Originator: Dan Adler (http://danadler.com).
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are met:
* are met: * 1. Redistributions of source code must retain the above copyright notice,
* 1. Redistributions of source code must retain the above copyright * this list of conditions and the following disclaimer. 2. Redistributions in
* notice, this list of conditions and the following disclaimer. * binary form must reproduce the above copyright notice, this list of
* 2. Redistributions in binary form must reproduce the above copyright * conditions and the following disclaimer in the documentation and/or other
* notice, this list of conditions and the following disclaimer in * materials provided with the distribution. 3. Redistributions in any form must
* the documentation and/or other materials provided with the * be accompanied by information on how to obtain complete source code for the
* distribution. * JACOB software.
* 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
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * POSSIBILITY OF SUCH DAMAGE.
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED package com.jacob.com;
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/ /**
package com.jacob.com; * TODO: Exception thrown when? No references found
*/
public class WrongThreadException extends RuntimeException public class WrongThreadException extends RuntimeException {
{ /**
// Constructors * standard 0 arg constructor with no message
public WrongThreadException() { super(); } *
public WrongThreadException(String s) { super(s); } */
} public WrongThreadException() {
super();
}
/**
* standard constructor with a string message
* @param s
*/
public WrongThreadException(String s) {
super(s);
}
}

View File

@@ -35,18 +35,28 @@ EventProxy::EventProxy(JNIEnv *env, jobject aSinkObj,
IID eid, CComBSTR mName[], DISPID mID[], int mNum) : IID eid, CComBSTR mName[], DISPID mID[], int mNum) :
m_cRef(0), pCP(pConn), m_cRef(0), pCP(pConn),
eventIID(eid), MethNum(mNum), MethName(mName), eventIID(eid), MethNum(mNum), MethName(mName),
MethID(mID), JMethID(NULL), javaSinkClass(NULL) MethID(mID), JMethID(NULL), javaSinkClass(NULL),
variantClassMethod(NULL)
{ {
javaSinkObj = env->NewGlobalRef(aSinkObj); javaSinkObj = env->NewGlobalRef(aSinkObj);
if (env->ExceptionOccurred()) { env->ExceptionDescribe();}
// we need this to attach to the event invocation thread // we need this to attach to the event invocation thread
env->GetJavaVM(&jvm); env->GetJavaVM(&jvm);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
AddRef(); AddRef();
HRESULT hr = pCP->Advise(this, &dwEventCookie); HRESULT hr = pCP->Advise(this, &dwEventCookie);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
// create a mapping from the DISPID's to jmethodID's by using // create a mapping from the DISPID's to jmethodID's by using
// the method names I extracted from the classinfo // the method names I extracted from the classinfo
JMethID = new jmethodID[MethNum]; JMethID = new jmethodID[MethNum];
javaSinkClass = env->GetObjectClass(javaSinkObj); 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; const char *method;
for(int i=0;i<MethNum;i++) for(int i=0;i<MethNum;i++)
{ {
@@ -73,6 +83,7 @@ EventProxy::~EventProxy()
jvm->AttachCurrentThread((void **)&env, jvm); jvm->AttachCurrentThread((void **)&env, jvm);
env->DeleteGlobalRef(javaSinkObj); env->DeleteGlobalRef(javaSinkObj);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
if (MethNum) { if (MethNum) {
delete [] MethName; delete [] MethName;
delete [] MethID; delete [] MethID;
@@ -131,19 +142,41 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
// attach to the current running thread // attach to the current running thread
jvm->AttachCurrentThread((void**)&env, jvm); 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 // how many params
int num = pDispParams->cArgs; int num = pDispParams->cArgs;
// get variant class
jclass vClass = env->FindClass("com/jacob/com/Variant");
// and the constructor // and the constructor
jmethodID vCons = env->GetMethodID(vClass, "<init>", "()V"); jmethodID vCons = env->GetMethodID(vClass, "<init>", "()V");
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
// make an array of them // make an array of them
jobjectArray varr = env->NewObjectArray(num, vClass, 0); jobjectArray varr = env->NewObjectArray(num, vClass, 0);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
int i,j; int i,j;
for(i=num-1,j=0;i>=0;i--,j++) for(i=num-1,j=0;i>=0;i--,j++)
{ {
// construct a java variant holder // construct a java variant holder
jobject arg = env->NewObject(vClass, vCons); jobject arg = env->NewObject(vClass, vCons);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
// get the empty variant from it // get the empty variant from it
VARIANT *va = extractVariant(env, arg); VARIANT *va = extractVariant(env, arg);
// copy the value // copy the value
@@ -151,11 +184,638 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
// put it in the array // put it in the array
env->SetObjectArrayElement(varr, j, arg); env->SetObjectArrayElement(varr, j, arg);
env->DeleteLocalRef(arg); env->DeleteLocalRef(arg);
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); }
} }
// call the method // call the method
env->CallVoidMethod(javaSinkObj, meth, varr); 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(); jvm->DetachCurrentThread();
return S_OK; return S_OK;
} }

View File

@@ -59,6 +59,8 @@ private:
DWORD dwEventCookie; // connection point cookie DWORD dwEventCookie; // connection point cookie
jobject javaSinkObj; // the java object to delegate calls jobject javaSinkObj; // the java object to delegate calls
jclass javaSinkClass; // the java class of the object 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 IID eventIID; // the interface iid passed in
int MethNum; int MethNum;
CComBSTR *MethName; // Array of method names CComBSTR *MethName; // Array of method names

View File

@@ -1,120 +1,123 @@
import com.jacob.com.*; package samples.ado;
public class Command extends Dispatch import com.jacob.com.*;
{
public Command() public class Command extends Dispatch
{ {
super("ADODB.Command"); 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 * This constructor is used instead of a case operation to
* method calls wrapped in VT_DISPATCH Variants. * turn a Dispatch object into a wider object - it must exist
*/ * in every wrapper class whose instances may be returned from
public Command(Dispatch d) * method calls wrapped in VT_DISPATCH Variants.
{ * @param dispatchTarget
// take over the IDispatch pointer */
m_pDispatch = d.m_pDispatch; public Command(Dispatch dispatchTarget)
// null out the input's pointer {
d.m_pDispatch = 0; // take over the IDispatch pointer
} m_pDispatch = dispatchTarget.m_pDispatch;
// null out the input's pointer
public Variant getProperties() dispatchTarget.m_pDispatch = 0;
{ }
return Dispatch.get(this, "Properties");
} public Variant getProperties()
{
public Connection getActiveConnection() return Dispatch.get(this, "Properties");
{ }
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
} public Connection getActiveConnection()
{
public void setActiveConnection(Connection ppvObject) return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
{ }
Dispatch.put(this, "ActiveConnection", ppvObject);
} public void setActiveConnection(Connection ppvObject)
{
public String getCommandText() Dispatch.put(this, "ActiveConnection", ppvObject);
{ }
return Dispatch.get(this, "CommandText").toString();
} public String getCommandText()
{
public void setCommandText(String pbstr) return Dispatch.get(this, "CommandText").toString();
{ }
Dispatch.put(this, "CommandText", pbstr);
} public void setCommandText(String pbstr)
{
public int getCommandTimeout() Dispatch.put(this, "CommandText", pbstr);
{ }
return Dispatch.get(this, "CommandTimeout").toInt();
} public int getCommandTimeout()
{
public void setCommandTimeout(int plTimeout) return Dispatch.get(this, "CommandTimeout").toInt();
{ }
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
} public void setCommandTimeout(int plTimeout)
{
public boolean getPrepared() Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
{ }
return Dispatch.get(this, "Prepared").toBoolean();
} public boolean getPrepared()
{
public void setPrepared(boolean pfPrepared) return Dispatch.get(this, "Prepared").toBoolean();
{ }
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
} public void setPrepared(boolean pfPrepared)
{
public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options) Dispatch.put(this, "Prepared", new Variant(pfPrepared));
{ }
return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch();
} public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options)
{
public Recordset Execute() return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch();
{ }
Variant dummy = new Variant();
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch()); public Recordset Execute()
} {
Variant dummy = new Variant();
public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value) return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
{ }
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value);
} public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value)
{
// need to wrap Parameters return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value);
public Variant getParameters() }
{
return Dispatch.get(this, "Parameters"); // need to wrap Parameters
} public Variant getParameters()
{
public void setCommandType(int plCmdType) return Dispatch.get(this, "Parameters");
{ }
Dispatch.put(this, "CommandType", new Variant(plCmdType));
} public void setCommandType(int plCmdType)
{
public int getCommandType() Dispatch.put(this, "CommandType", new Variant(plCmdType));
{ }
return Dispatch.get(this, "CommandType").toInt();
} public int getCommandType()
{
public String getName() return Dispatch.get(this, "CommandType").toInt();
{ }
return Dispatch.get(this, "Name").toString();
} public String getName()
{
public void setName(String pbstrName) return Dispatch.get(this, "Name").toString();
{ }
Dispatch.put(this, "Name", pbstrName);
} public void setName(String pbstrName)
{
public int getState() Dispatch.put(this, "Name", pbstrName);
{ }
return Dispatch.get(this, "State").toInt();
} public int getState()
{
public void Cancel() return Dispatch.get(this, "State").toInt();
{ }
Dispatch.call(this, "Cancel");
} public void Cancel()
} {
Dispatch.call(this, "Cancel");
}
}

View File

@@ -1,12 +1,14 @@
// Enum: CommandTypeEnum package samples.ado;
public interface CommandTypeEnum // Enum: CommandTypeEnum
{
public static final int adCmdUnspecified = -1; public interface CommandTypeEnum
public static final int adCmdUnknown = 8; {
public static final int adCmdText = 1; public static final int adCmdUnspecified = -1;
public static final int adCmdTable = 2; public static final int adCmdUnknown = 8;
public static final int adCmdStoredProc = 4; public static final int adCmdText = 1;
public static final int adCmdFile = 256; public static final int adCmdTable = 2;
public static final int adCmdTableDirect = 512; public static final int adCmdStoredProc = 4;
} public static final int adCmdFile = 256;
public static final int adCmdTableDirect = 512;
}

View File

@@ -1,180 +1,182 @@
import com.jacob.com.*; package samples.ado;
public class Connection extends Dispatch import com.jacob.com.*;
{
public Connection() public class Connection extends Dispatch
{ {
super("ADODB.Connection"); 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 * This constructor is used instead of a case operation to
* method calls wrapped in VT_DISPATCH Variants. * turn a Dispatch object into a wider object - it must exist
*/ * in every wrapper class whose instances may be returned from
public Connection(Dispatch d) * method calls wrapped in VT_DISPATCH Variants.
{ */
// take over the IDispatch pointer public Connection(Dispatch d)
m_pDispatch = d.m_pDispatch; {
// null out the input's pointer // take over the IDispatch pointer
d.m_pDispatch = 0; m_pDispatch = d.m_pDispatch;
} // null out the input's pointer
d.m_pDispatch = 0;
// need to wrap Properties }
public Variant getProperties()
{ // need to wrap Properties
return Dispatch.get(this, "Properties"); public Variant getProperties()
} {
return Dispatch.get(this, "Properties");
public String getConnectionString() }
{
return Dispatch.get(this, "ConnectionString").toString(); public String getConnectionString()
} {
return Dispatch.get(this, "ConnectionString").toString();
public void setConnectionString(String pbstr) }
{
Dispatch.put(this, "ConnectionString", pbstr); public void setConnectionString(String pbstr)
} {
Dispatch.put(this, "ConnectionString", pbstr);
public int getCommandTimeout() }
{
return Dispatch.get(this, "CommandTimeout").toInt(); public int getCommandTimeout()
} {
return Dispatch.get(this, "CommandTimeout").toInt();
public void setCommandTimeout(int plTimeout) }
{
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout)); public void setCommandTimeout(int plTimeout)
} {
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
public int getConnectionTimeout() }
{
return Dispatch.get(this, "ConnectionTimeout").toInt(); public int getConnectionTimeout()
} {
return Dispatch.get(this, "ConnectionTimeout").toInt();
public void setConnectionTimeout(int plTimeout) }
{
Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout)); public void setConnectionTimeout(int plTimeout)
} {
Dispatch.put(this, "ConnectionTimeout", new Variant(plTimeout));
public String getVersion() }
{
return Dispatch.get(this, "Version").toString(); public String getVersion()
} {
return Dispatch.get(this, "Version").toString();
public void Close() }
{
Dispatch.call(this, "Close"); public void Close()
} {
Dispatch.call(this, "Close");
// how to deal with RecordsAffected being output? }
public Variant Execute(String CommandText, Variant RecordsAffected, int Options)
{ // how to deal with RecordsAffected being output?
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(Options)); 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 int BeginTrans()
} {
return Dispatch.call(this, "BeginTrans").toInt();
public void CommitTrans() }
{
Dispatch.call(this, "CommitTrans"); public void CommitTrans()
} {
Dispatch.call(this, "CommitTrans");
public void RollbackTrans() }
{
Dispatch.call(this, "RollbackTrans"); 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(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 void Open()
} {
Dispatch.call(this, "Open");
public Variant getErrors() }
{
return Dispatch.get(this, "Errors"); public Variant getErrors()
} {
return Dispatch.get(this, "Errors");
public String getDefaultDatabase() }
{
return Dispatch.get(this, "DefaultDatabase").toString(); public String getDefaultDatabase()
} {
return Dispatch.get(this, "DefaultDatabase").toString();
public void setDefaultDatabase(String pbstr) }
{
Dispatch.put(this, "DefaultDatabase", pbstr); public void setDefaultDatabase(String pbstr)
} {
Dispatch.put(this, "DefaultDatabase", pbstr);
public int getIsolationLevel() }
{
return Dispatch.get(this, "IsolationLevel").toInt(); public int getIsolationLevel()
} {
return Dispatch.get(this, "IsolationLevel").toInt();
public void setIsolationLevel(int Level) }
{
Dispatch.put(this, "IsolationLevel", new Variant(Level)); public void setIsolationLevel(int Level)
} {
Dispatch.put(this, "IsolationLevel", new Variant(Level));
public int getAttributes() }
{
return Dispatch.get(this, "Attributes").toInt(); public int getAttributes()
} {
return Dispatch.get(this, "Attributes").toInt();
public void setAttributes(int plAttr) }
{
Dispatch.put(this, "Attributes", new Variant(plAttr)); public void setAttributes(int plAttr)
} {
Dispatch.put(this, "Attributes", new Variant(plAttr));
public int getCursorLocation() }
{
return Dispatch.get(this, "CursorLocation").toInt(); public int getCursorLocation()
} {
return Dispatch.get(this, "CursorLocation").toInt();
public void setCursorLocation(int plCursorLoc) }
{
Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc)); public void setCursorLocation(int plCursorLoc)
} {
Dispatch.put(this, "CursorLocation", new Variant(plCursorLoc));
public int getMode() }
{
return Dispatch.get(this, "Mode").toInt(); public int getMode()
} {
return Dispatch.get(this, "Mode").toInt();
public void setMode(int plMode) }
{
Dispatch.put(this, "Mode", new Variant(plMode)); public void setMode(int plMode)
} {
Dispatch.put(this, "Mode", new Variant(plMode));
public String getProvider() }
{
return Dispatch.get(this, "Provider").toString(); public String getProvider()
} {
return Dispatch.get(this, "Provider").toString();
public void setProvider(String pbstr) }
{
Dispatch.put(this, "Provider", pbstr); public void setProvider(String pbstr)
} {
Dispatch.put(this, "Provider", pbstr);
public int getState() }
{
return Dispatch.get(this, "State").toInt(); 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 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"); public void Cancel()
} {
} Dispatch.call(this, "Cancel");
}
}

View File

@@ -1,124 +1,125 @@
import com.jacob.com.*; package samples.ado;
import com.jacob.com.*;
public class Field extends Dispatch
{ 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 * This constructor is used instead of a case operation to
* in every wrapper class whose instances may be returned from * turn a Dispatch object into a wider object - it must exist
* method calls wrapped in VT_DISPATCH Variants. * in every wrapper class whose instances may be returned from
*/ * method calls wrapped in VT_DISPATCH Variants.
public Field(Dispatch d) */
{ public Field(Dispatch d)
// take over the IDispatch pointer {
m_pDispatch = d.m_pDispatch; // take over the IDispatch pointer
// null out the input's pointer m_pDispatch = d.m_pDispatch;
d.m_pDispatch = 0; // null out the input's pointer
} d.m_pDispatch = 0;
}
public Variant getProperties()
{ public Variant getProperties()
return Dispatch.get(this, "Properties"); {
} return Dispatch.get(this, "Properties");
}
public int getActualSize()
{ public int getActualSize()
return Dispatch.get(this, "ActualSize").toInt(); {
} return Dispatch.get(this, "ActualSize").toInt();
}
public int getAttributes()
{ public int getAttributes()
return Dispatch.get(this, "Attributes").toInt(); {
} return Dispatch.get(this, "Attributes").toInt();
}
public int getDefinedSize()
{ public int getDefinedSize()
return Dispatch.get(this, "DefinedSize").toInt(); {
} return Dispatch.get(this, "DefinedSize").toInt();
}
public String getName()
{ public String getName()
return Dispatch.get(this, "Name").toString(); {
} return Dispatch.get(this, "Name").toString();
}
public int getType()
{ public int getType()
return Dispatch.get(this, "Type").toInt(); {
} return Dispatch.get(this, "Type").toInt();
}
public Variant getValue()
{ public Variant getValue()
return Dispatch.get(this, "Value"); {
} return Dispatch.get(this, "Value");
}
public void setValue(Variant pvar)
{ public void setValue(Variant pvar)
Dispatch.put(this, "Value", pvar); {
} Dispatch.put(this, "Value", pvar);
}
public byte getPrecision()
{ public byte getPrecision()
return Dispatch.get(this, "Precision").toByte(); {
} return Dispatch.get(this, "Precision").toByte();
}
public byte getNumericScale()
{ public byte getNumericScale()
return Dispatch.get(this, "NumericScale").toByte(); {
} return Dispatch.get(this, "NumericScale").toByte();
}
public void AppendChunk(Variant Data)
{ public void AppendChunk(Variant Data)
Dispatch.call(this, "AppendChunk", Data); {
} Dispatch.call(this, "AppendChunk", Data);
}
public Variant GetChunk(int Length)
{ public Variant GetChunk(int Length)
return Dispatch.call(this, "GetChunk", new Variant(Length)); {
} return Dispatch.call(this, "GetChunk", new Variant(Length));
}
public Variant getOriginalValue()
{ public Variant getOriginalValue()
return Dispatch.get(this, "OriginalValue"); {
} return Dispatch.get(this, "OriginalValue");
}
public Variant getUnderlyingValue()
{ public Variant getUnderlyingValue()
return Dispatch.get(this, "UnderlyingValue"); {
} return Dispatch.get(this, "UnderlyingValue");
}
public Variant getDataFormat()
{ public Variant getDataFormat()
return Dispatch.get(this, "DataFormat"); {
} return Dispatch.get(this, "DataFormat");
}
public void setDataFormat(Variant ppiDF)
{ public void setDataFormat(Variant ppiDF)
Dispatch.put(this, "DataFormat", ppiDF); {
} Dispatch.put(this, "DataFormat", ppiDF);
}
public void setPrecision(byte pb)
{ public void setPrecision(byte pb)
Dispatch.put(this, "Precision", new Variant(pb)); {
} Dispatch.put(this, "Precision", new Variant(pb));
}
public void setNumericScale(byte pb)
{ public void setNumericScale(byte pb)
Dispatch.put(this, "NumericScale", new Variant(pb)); {
} Dispatch.put(this, "NumericScale", new Variant(pb));
}
public void setType(int pDataType)
{ public void setType(int pDataType)
Dispatch.put(this, "Type", new Variant(pDataType)); {
} Dispatch.put(this, "Type", new Variant(pDataType));
}
public void setDefinedSize(int pl)
{ public void setDefinedSize(int pl)
Dispatch.put(this, "DefinedSize", new Variant(pl)); {
} Dispatch.put(this, "DefinedSize", new Variant(pl));
}
public void setAttributes(int pl)
{ public void setAttributes(int pl)
Dispatch.put(this, "Attributes", new Variant(pl)); {
} Dispatch.put(this, "Attributes", new Variant(pl));
}
}
}

View File

@@ -1,50 +1,51 @@
import com.jacob.com.*; package samples.ado;
import com.jacob.com.*;
public class Fields extends Dispatch
{ 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 * This constructor is used instead of a case operation to
* in every wrapper class whose instances may be returned from * turn a Dispatch object into a wider object - it must exist
* method calls wrapped in VT_DISPATCH Variants. * in every wrapper class whose instances may be returned from
*/ * method calls wrapped in VT_DISPATCH Variants.
public Fields(Dispatch d) */
{ public Fields(Dispatch d)
// take over the IDispatch pointer {
m_pDispatch = d.m_pDispatch; // take over the IDispatch pointer
// null out the input's pointer m_pDispatch = d.m_pDispatch;
d.m_pDispatch = 0; // null out the input's pointer
} d.m_pDispatch = 0;
}
public int getCount()
{ public int getCount()
return Dispatch.get(this, "Count").toInt(); {
} return Dispatch.get(this, "Count").toInt();
}
public Variant _NewEnum()
{ public Variant _NewEnum()
return Dispatch.call(this, "_NewEnum"); {
} return Dispatch.call(this, "_NewEnum");
}
public void Refresh()
{ public void Refresh()
Dispatch.call(this, "Refresh"); {
} Dispatch.call(this, "Refresh");
}
public Field getItem(int Index)
{ public Field getItem(int Index)
return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch()); {
} return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch());
}
public void Append(String Name, int Type, int DefinedSize, int Attrib)
{ 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)); Dispatch.call(this, "Append", Name, new Variant(Type),
} new Variant(DefinedSize), new Variant(Attrib));
}
public void Delete(Variant Index)
{ public void Delete(Variant Index)
Dispatch.call(this, "Delete", Index); {
} Dispatch.call(this, "Delete", Index);
}
}
}

View File

@@ -1,411 +1,412 @@
import com.jacob.com.*; package samples.ado;
import com.jacob.com.*;
public class Recordset extends Dispatch
{ public class Recordset extends Dispatch
public Recordset() {
{ public Recordset()
super("ADODB.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 * This constructor is used instead of a case operation to
* in every wrapper class whose instances may be returned from * turn a Dispatch object into a wider object - it must exist
* method calls wrapped in VT_DISPATCH Variants. * in every wrapper class whose instances may be returned from
*/ * method calls wrapped in VT_DISPATCH Variants.
public Recordset(Dispatch d) */
{ public Recordset(Dispatch d)
// take over the IDispatch pointer {
m_pDispatch = d.m_pDispatch; // take over the IDispatch pointer
// null out the input's pointer m_pDispatch = d.m_pDispatch;
d.m_pDispatch = 0; // null out the input's pointer
} d.m_pDispatch = 0;
}
public Variant getProperties()
{ public Variant getProperties()
return Dispatch.get(this, "Properties"); {
} return Dispatch.get(this, "Properties");
}
public int getAbsolutePosition()
{ public int getAbsolutePosition()
return Dispatch.get(this, "AbsolutePosition").toInt(); {
} return Dispatch.get(this, "AbsolutePosition").toInt();
}
public void setAbsolutePosition(int pl)
{ public void setAbsolutePosition(int pl)
Dispatch.put(this, "AbsolutePosition", new Variant(pl)); {
} Dispatch.put(this, "AbsolutePosition", new Variant(pl));
}
public Connection getActiveConnection()
{ public Connection getActiveConnection()
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch()); {
} return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
}
public void setActiveConnection(Connection ppvObject)
{ public void setActiveConnection(Connection ppvObject)
Dispatch.put(this, "ActiveConnection", ppvObject); {
} Dispatch.put(this, "ActiveConnection", ppvObject);
}
public void setActiveConnection(Variant ppvObject)
{ public void setActiveConnection(Variant ppvObject)
Dispatch.put(this, "ActiveConnection", ppvObject); {
} Dispatch.put(this, "ActiveConnection", ppvObject);
}
public boolean getBOF()
{ public boolean getBOF()
return Dispatch.get(this, "BOF").toBoolean(); {
} return Dispatch.get(this, "BOF").toBoolean();
}
public Variant getBookmark()
{ public Variant getBookmark()
return Dispatch.get(this, "Bookmark"); {
} return Dispatch.get(this, "Bookmark");
}
public void setBookmark(Variant pvBookmark)
{ public void setBookmark(Variant pvBookmark)
Dispatch.put(this, "Bookmark", pvBookmark); {
} Dispatch.put(this, "Bookmark", pvBookmark);
}
public int getCacheSize()
{ public int getCacheSize()
return Dispatch.get(this, "CacheSize").toInt(); {
} return Dispatch.get(this, "CacheSize").toInt();
}
public void setCacheSize(int pl)
{ public void setCacheSize(int pl)
Dispatch.put(this, "CacheSize", new Variant(pl)); {
} Dispatch.put(this, "CacheSize", new Variant(pl));
}
public int getCursorType()
{ public int getCursorType()
return Dispatch.get(this, "CursorType").toInt(); {
} return Dispatch.get(this, "CursorType").toInt();
}
public void setCursorType(int pl)
{ public void setCursorType(int pl)
Dispatch.put(this, "CursorType", new Variant(pl)); {
} Dispatch.put(this, "CursorType", new Variant(pl));
}
public boolean getEOF()
{ public boolean getEOF()
return Dispatch.get(this, "EOF").toBoolean(); {
} return Dispatch.get(this, "EOF").toBoolean();
}
public Fields getFields()
{ public Fields getFields()
return new Fields(Dispatch.get(this, "Fields").toDispatch()); {
} return new Fields(Dispatch.get(this, "Fields").toDispatch());
}
public int getLockType()
{ public int getLockType()
return Dispatch.get(this, "LockType").toInt(); {
} return Dispatch.get(this, "LockType").toInt();
}
public void setLockType(int plLockType)
{ public void setLockType(int plLockType)
Dispatch.put(this, "LockType", new Variant(plLockType)); {
} Dispatch.put(this, "LockType", new Variant(plLockType));
}
public int getMaxRecords()
{ public int getMaxRecords()
return Dispatch.get(this, "MaxRecords").toInt(); {
} return Dispatch.get(this, "MaxRecords").toInt();
}
public void setMaxRecords(int pl)
{ public void setMaxRecords(int pl)
Dispatch.put(this, "MaxRecords", new Variant(pl)); {
} Dispatch.put(this, "MaxRecords", new Variant(pl));
}
public int getRecordCount()
{ public int getRecordCount()
return Dispatch.get(this, "RecordCount").toInt(); {
} return Dispatch.get(this, "RecordCount").toInt();
}
public void setSource(Object pvSource)
{ public void setSource(Object pvSource)
Dispatch.put(this, "Source", pvSource); {
} Dispatch.put(this, "Source", pvSource);
}
public void setSource(String pvSource)
{ public void setSource(String pvSource)
Dispatch.put(this, "Source", pvSource); {
} Dispatch.put(this, "Source", pvSource);
}
public Variant getSource()
{ public Variant getSource()
return Dispatch.get(this, "Source"); {
} return Dispatch.get(this, "Source");
}
public void AddNew(Variant FieldList, Variant Values)
{ public void AddNew(Variant FieldList, Variant Values)
Dispatch.call(this, "AddNew", FieldList, Values); {
} Dispatch.call(this, "AddNew", FieldList, Values);
}
public void CancelUpdate()
{ public void CancelUpdate()
Dispatch.call(this, "CancelUpdate"); {
} Dispatch.call(this, "CancelUpdate");
}
public void Close()
{ public void Close()
Dispatch.call(this, "Close"); {
} Dispatch.call(this, "Close");
}
public void Delete(int AffectRecords)
{ public void Delete(int AffectRecords)
Dispatch.call(this, "Delete", new Variant(AffectRecords)); {
} Dispatch.call(this, "Delete", new Variant(AffectRecords));
}
public Variant GetRows(int Rows, Variant Start, Variant Fields)
{ public Variant GetRows(int Rows, Variant Start, Variant Fields)
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields); {
} return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
}
// get all rows
public Variant GetRows() // get all rows
{ public Variant GetRows()
return Dispatch.call(this, "GetRows"); {
} return Dispatch.call(this, "GetRows");
}
public void Move(int NumRecords, Variant Start)
{ public void Move(int NumRecords, Variant Start)
Dispatch.call(this, "Move", new Variant(NumRecords), Start); {
} Dispatch.call(this, "Move", new Variant(NumRecords), Start);
}
public void MoveNext()
{ public void MoveNext()
Dispatch.call(this, "MoveNext"); {
} Dispatch.call(this, "MoveNext");
}
public void MovePrevious()
{ public void MovePrevious()
Dispatch.call(this, "MovePrevious"); {
} Dispatch.call(this, "MovePrevious");
}
public void MoveFirst()
{ public void MoveFirst()
Dispatch.call(this, "MoveFirst"); {
} Dispatch.call(this, "MoveFirst");
}
public void MoveLast()
{ public void MoveLast()
Dispatch.call(this, "MoveLast"); {
} Dispatch.call(this, "MoveLast");
}
public void Open(Variant Source, Variant ActiveConnection, int CursorType, int LockType, int Options)
{ 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)); {
} Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(CursorType), new Variant(LockType), new Variant(Options));
}
public void Open(Variant Source, Variant ActiveConnection)
{ public void Open(Variant Source, Variant ActiveConnection)
Dispatch.call(this, "Open", Source, ActiveConnection); {
} Dispatch.call(this, "Open", Source, ActiveConnection);
}
public void Requery(int Options)
{ public void Requery(int Options)
Dispatch.call(this, "Requery", new Variant(Options)); {
} Dispatch.call(this, "Requery", new Variant(Options));
}
public void Update(Variant Fields, Variant Values)
{ public void Update(Variant Fields, Variant Values)
Dispatch.call(this, "Update", Fields, Values); {
} Dispatch.call(this, "Update", Fields, Values);
}
public int getAbsolutePage()
{ public int getAbsolutePage()
return Dispatch.get(this, "AbsolutePage").toInt(); {
} return Dispatch.get(this, "AbsolutePage").toInt();
}
public void setAbsolutePage(int pl)
{ public void setAbsolutePage(int pl)
Dispatch.put(this, "AbsolutePage", new Variant(pl)); {
} Dispatch.put(this, "AbsolutePage", new Variant(pl));
}
public int getEditMode()
{ public int getEditMode()
return Dispatch.get(this, "EditMode").toInt(); {
} return Dispatch.get(this, "EditMode").toInt();
}
public Variant getFilter()
{ public Variant getFilter()
return Dispatch.get(this, "Filter"); {
} return Dispatch.get(this, "Filter");
}
public void setFilter(Variant Criteria)
{ public void setFilter(Variant Criteria)
Dispatch.put(this, "Filter", Criteria); {
} Dispatch.put(this, "Filter", Criteria);
}
public int getPageCount()
{ public int getPageCount()
return Dispatch.get(this, "PageCount").toInt(); {
} return Dispatch.get(this, "PageCount").toInt();
}
public int getPageSize()
{ public int getPageSize()
return Dispatch.get(this, "PageSize").toInt(); {
} return Dispatch.get(this, "PageSize").toInt();
}
public void setPageSize(int pl)
{ public void setPageSize(int pl)
Dispatch.put(this, "PageSize", new Variant(pl)); {
} Dispatch.put(this, "PageSize", new Variant(pl));
}
public String getSort()
{ public String getSort()
return Dispatch.get(this, "Sort").toString(); {
} return Dispatch.get(this, "Sort").toString();
}
public void setSort(String Criteria)
{ public void setSort(String Criteria)
Dispatch.put(this, "Sort", Criteria); {
} Dispatch.put(this, "Sort", Criteria);
}
public int getStatus()
{ public int getStatus()
return Dispatch.get(this, "Status").toInt(); {
} return Dispatch.get(this, "Status").toInt();
}
public int getState()
{ public int getState()
return Dispatch.get(this, "State").toInt(); {
} return Dispatch.get(this, "State").toInt();
}
public void UpdateBatch(int AffectRecords)
{ public void UpdateBatch(int AffectRecords)
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords)); {
} Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
}
public void CancelBatch(int AffectRecords)
{ public void CancelBatch(int AffectRecords)
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords)); {
} Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
}
public int getCursorLocation()
{ public int getCursorLocation()
return Dispatch.get(this, "CursorLocation").toInt(); {
} return Dispatch.get(this, "CursorLocation").toInt();
}
public void setCursorLocation(int pl)
{ public void setCursorLocation(int pl)
Dispatch.put(this, "CursorLocation", new Variant(pl)); {
} Dispatch.put(this, "CursorLocation", new Variant(pl));
}
public Recordset NextRecordset(Variant RecordsAffected)
{ public Recordset NextRecordset(Variant RecordsAffected)
return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch()); {
} return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch());
}
public boolean Supports(int CursorOptions)
{ public boolean Supports(int CursorOptions)
return Dispatch.call(this, "Supports", new Variant(CursorOptions)).toBoolean(); {
} return Dispatch.call(this, "Supports", new Variant(CursorOptions)).toBoolean();
}
public Variant getCollect(Variant Index)
{ public Variant getCollect(Variant Index)
return Dispatch.get(this, "Collect"); {
} return Dispatch.get(this, "Collect");
}
public void setCollect(Variant Index, Variant pvar)
{ public void setCollect(Variant Index, Variant pvar)
Dispatch.call(this, "Collect", Index, pvar); {
} Dispatch.call(this, "Collect", Index, pvar);
}
public int getMarshalOptions()
{ public int getMarshalOptions()
return Dispatch.get(this, "MarshalOptions").toInt(); {
} return Dispatch.get(this, "MarshalOptions").toInt();
}
public void setMarshalOptions(int pl)
{ public void setMarshalOptions(int pl)
Dispatch.put(this, "MarshalOptions", new Variant(pl)); {
} Dispatch.put(this, "MarshalOptions", new Variant(pl));
}
public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start)
{ public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start)
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start); {
} Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start);
}
public void Cancel()
{ public void Cancel()
Dispatch.call(this, "Cancel"); {
} Dispatch.call(this, "Cancel");
}
public Variant getDataSource()
{ public Variant getDataSource()
return Dispatch.get(this, "DataSource"); {
} return Dispatch.get(this, "DataSource");
}
public void setDataSource(Variant ppunkDataSource)
{ public void setDataSource(Variant ppunkDataSource)
Dispatch.put(this, "DataSource", ppunkDataSource); {
} Dispatch.put(this, "DataSource", ppunkDataSource);
}
public void Save(String FileName, int PersistFormat)
{ public void Save(String FileName, int PersistFormat)
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat)); {
} Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
}
public Variant getActiveCommand()
{ public Variant getActiveCommand()
return Dispatch.get(this, "ActiveCommand"); {
} return Dispatch.get(this, "ActiveCommand");
}
public void setStayInSync(boolean pb)
{ public void setStayInSync(boolean pb)
Dispatch.put(this, "StayInSync", new Variant(pb)); {
} Dispatch.put(this, "StayInSync", new Variant(pb));
}
public boolean getStayInSync()
{ public boolean getStayInSync()
return Dispatch.get(this, "StayInSync").toBoolean(); {
} return Dispatch.get(this, "StayInSync").toBoolean();
}
public String GetString(int StringFormat, int NumRows, String ColumnDelimeter, String RowDelimeter, String NullExpr)
{ 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(); return Dispatch.call(this, "GetString", new Variant(StringFormat),
} new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr).toString();
}
public String getDataMember()
{ public String getDataMember()
return Dispatch.get(this, "DataMember").toString(); {
} return Dispatch.get(this, "DataMember").toString();
}
public void setDataMember(String pl)
{ public void setDataMember(String pl)
Dispatch.put(this, "DataMember", new Variant(pl)); {
} Dispatch.put(this, "DataMember", new Variant(pl));
}
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2)
{ public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2)
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).toInt(); {
} return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).toInt();
}
public Recordset Clone(int LockType)
{ public Recordset Clone(int LockType)
return new Recordset(Dispatch.call(this, "Clone", {
new Variant(LockType)).toDispatch()); return new Recordset(Dispatch.call(this, "Clone",
} new Variant(LockType)).toDispatch());
}
public void Resync(int AffectRecords, int ResyncValues)
{ public void Resync(int AffectRecords, int ResyncValues)
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues)); {
} Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues));
}
public void Seek(Variant KeyValues, int SeekOption)
{ public void Seek(Variant KeyValues, int SeekOption)
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption)); {
} Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
}
public void setIndex(String pl)
{ public void setIndex(String pl)
Dispatch.put(this, "Index", new Variant(pl)); {
} Dispatch.put(this, "Index", new Variant(pl));
}
public String getIndex()
{ public String getIndex()
return Dispatch.get(this, "Index)").toString(); {
} return Dispatch.get(this, "Index)").toString();
} }
}

View File

@@ -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.

View File

@@ -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.

View File

@@ -1,64 +1,66 @@
import com.ms.com.*; package samples.ado.ms;
import com.ms.wfc.data.*;
import com.ms.com.*;
// an ms-only version of test.java import com.ms.wfc.data.*;
public class testms
{ // an ms-only version of test.java
public static void printRS(Recordset rs) public class testms
{ {
Fields fs = rs.getFields(); public static void printRS(Recordset rs)
{
for (int i=0;i<fs.getCount();i++) Fields fs = rs.getFields();
{
System.out.print(fs.getItem(i).getName() + " "); for (int i=0;i<fs.getCount();i++)
} {
System.out.println(""); System.out.print(fs.getItem(i).getName() + " ");
}
rs.moveFirst(); System.out.println("");
while (!rs.getEOF())
{ rs.moveFirst();
for(int i=0;i<fs.getCount();i++) while (!rs.getEOF())
{ {
Field f = fs.getItem(i); for(int i=0;i<fs.getCount();i++)
Variant v = f.getValue(); {
System.out.print(v + " "); Field f = fs.getItem(i);
} Variant v = f.getValue();
System.out.println(""); System.out.print(v + " ");
rs.moveNext(); }
} System.out.println("");
} rs.moveNext();
}
// open a recordset directly }
public static void getRS(String con, String query)
{ // open a recordset directly
System.out.println("Recordset Open"); public static void getRS(String con, String query)
Recordset rs = new Recordset(); {
rs.open(new Variant(query), new Variant(con)); System.out.println("Recordset Open");
printRS(rs); Recordset rs = new Recordset();
} rs.open(new Variant(query), new Variant(con));
printRS(rs);
// create connection and command objects and use them }
// to get a recordset
public static void getCommand(String con, String query) // create connection and command objects and use them
{ // to get a recordset
System.out.println("Command+Connection -> Recordset"); public static void getCommand(String con, String query)
Connection c = new Connection(); {
c.setConnectionString(con); System.out.println("Command+Connection -> Recordset");
c.open(); Connection c = new Connection();
Command comm = new Command(); c.setConnectionString(con);
comm.setActiveConnection(c); c.open();
comm.setCommandType(AdoEnums.CommandType.TEXT); Command comm = new Command();
comm.setCommandText(query); comm.setActiveConnection(c);
Recordset rs = comm.execute(); comm.setCommandType(AdoEnums.CommandType.TEXT);
printRS(rs); comm.setCommandText(query);
c.close(); 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"; public static void main(String[] args)
String queryStr = "select * from authors"; {
getCommand(connectStr, queryStr); String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
getRS(connectStr, queryStr); String queryStr = "select * from authors";
} getCommand(connectStr, queryStr);
} getRS(connectStr, queryStr);
}
}

View File

@@ -1,62 +1,63 @@
import com.jacob.com.*; package samples.ado;
import com.jacob.com.*;
public class test
{ public class test
public static void printRS(Recordset rs) {
{ public static void printRS(Recordset rs)
Fields fs = rs.getFields(); {
Fields fs = rs.getFields();
for (int i=0;i<fs.getCount();i++)
{ for (int i=0;i<fs.getCount();i++)
System.out.print(fs.getItem(i).getName() + " "); {
} System.out.print(fs.getItem(i).getName() + " ");
System.out.println(""); }
System.out.println("");
rs.MoveFirst();
while (!rs.getEOF()) rs.MoveFirst();
{ while (!rs.getEOF())
for(int i=0;i<fs.getCount();i++) {
{ for(int i=0;i<fs.getCount();i++)
Field f = fs.getItem(i); {
Variant v = f.getValue(); Field f = fs.getItem(i);
System.out.print(v + " "); Variant v = f.getValue();
} System.out.print(v + " ");
System.out.println(""); }
rs.MoveNext(); System.out.println("");
} rs.MoveNext();
} }
}
// open a recordset directly
public static void getRS(String con, String query) // open a recordset directly
{ public static void getRS(String con, String query)
System.out.println("Recordset Open"); {
Recordset rs = new Recordset(); System.out.println("Recordset Open");
rs.Open(new Variant(query), new Variant(con)); Recordset rs = new Recordset();
printRS(rs); rs.Open(new Variant(query), new Variant(con));
} printRS(rs);
}
// create connection and command objects and use them
// to get a recordset // create connection and command objects and use them
public static void getCommand(String con, String query) // to get a recordset
{ public static void getCommand(String con, String query)
System.out.println("Command+Connection -> Recordset"); {
Connection c = new Connection(); System.out.println("Command+Connection -> Recordset");
c.setConnectionString(con); Connection c = new Connection();
c.Open(); c.setConnectionString(con);
Command comm = new Command(); c.Open();
comm.setActiveConnection(c); Command comm = new Command();
comm.setCommandType(CommandTypeEnum.adCmdText); comm.setActiveConnection(c);
comm.setCommandText(query); comm.setCommandType(CommandTypeEnum.adCmdText);
Recordset rs = comm.Execute(); comm.setCommandText(query);
printRS(rs); Recordset rs = comm.Execute();
c.Close(); printRS(rs);
} c.Close();
}
public static void main(String[] args)
{ 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"; String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
getCommand(connectStr, queryStr); String queryStr = "select * from authors";
getRS(connectStr, queryStr); getCommand(connectStr, queryStr);
} getRS(connectStr, queryStr);
} }
}

View File

@@ -1,37 +1,49 @@
import java.awt.*; package samples.applet;
import java.awt.event.*;
import java.applet.*; import java.awt.*;
import java.awt.event.*;
import com.jacob.com.*; import java.applet.*;
import com.jacob.activeX.*;
import com.jacob.com.*;
public class AppTest extends Applet implements ActionListener import com.jacob.activeX.*;
{
TextField in; /**
TextField out; * Applet test case
Button calc; */
ActiveXComponent sC = null; public class AppTest extends Applet implements ActionListener
Object sControl = null; {
TextField in;
public void init() TextField out;
{ Button calc;
setLayout(new FlowLayout()); ActiveXComponent sC = null;
add(in = new TextField("1+1", 16)); Object sControl = null;
add(out = new TextField("?", 16));
add(calc = new Button("Calculate")); /**
calc.addActionListener(this); * startup method
*/
} public void init()
{
public void actionPerformed(ActionEvent ev) setLayout(new FlowLayout());
{ add(in = new TextField("1+1", 16));
if (sC == null) { add(out = new TextField("?", 16));
String lang = "VBScript"; add(calc = new Button("Calculate"));
sC = new ActiveXComponent("ScriptControl"); calc.addActionListener(this);
sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang); }
}
Variant v = Dispatch.call(sControl, "Eval", in.getText()); /**
out.setText(v.toString()); * 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());
}
}

View File

@@ -1,73 +1,75 @@
import javax.servlet.*; package samples.servlet;
import javax.servlet.http.*;
import java.io.*; import javax.servlet.*;
import javax.servlet.http.*;
import com.jacob.com.*; import java.io.*;
import com.jacob.activeX.*;
import com.jacob.com.*;
public class JacobScript extends javax.servlet.http.HttpServlet import com.jacob.activeX.*;
{
public void doGet(HttpServletRequest req, public class JacobScript extends javax.servlet.http.HttpServlet
HttpServletResponse res) {
throws ServletException public void doGet(HttpServletRequest req,
{ HttpServletResponse res)
PrintWriter out = null; throws ServletException
try {
{ PrintWriter out = null;
res.setContentType("text/html"); try
out = res.getWriter(); {
// display a form res.setContentType("text/html");
out.println("<h1>Enter a VBScript Expression</h1>"); out = res.getWriter();
out.println("<form method=\"POST\" action=\"/JacobScript\">"); // display a form
out.println("<input name=\"expr\" type=\"text\" width=64>"); out.println("<h1>Enter a VBScript Expression</h1>");
out.println("<input type=\"submit\">"); out.println("<form method=\"POST\" action=\"/JacobScript\">");
out.println("</form>"); out.println("<input name=\"expr\" type=\"text\" width=64>");
} catch (Exception e) { out.println("<input type=\"submit\">");
e.printStackTrace(); out.println("</form>");
out.println("<H2>Error:"+e+"</H2>"); } catch (Exception e) {
} e.printStackTrace();
} out.println("<H2>Error:"+e+"</H2>");
}
public void doPost(HttpServletRequest req, }
HttpServletResponse res)
throws ServletException public void doPost(HttpServletRequest req,
{ HttpServletResponse res)
PrintWriter out = null; throws ServletException
{
try PrintWriter out = null;
{
res.setContentType("text/html"); try
out = res.getWriter(); {
// get what they typed in res.setContentType("text/html");
String expr = (String)req.getParameter("expr"); out = res.getWriter();
// make sure we have a session // get what they typed in
HttpSession session = req.getSession(true); String expr = (String)req.getParameter("expr");
Object sControl = null; // make sure we have a session
if (session.isNew()) HttpSession session = req.getSession(true);
{ Object sControl = null;
// initialize the control and store it on the session if (session.isNew())
String lang = "VBScript"; {
ActiveXComponent sC = new ActiveXComponent("ScriptControl"); // initialize the control and store it on the session
sControl = sC.getObject(); String lang = "VBScript";
Dispatch.put(sControl, "Language", lang); ActiveXComponent sC = new ActiveXComponent("ScriptControl");
session.putValue("control", sControl); sControl = sC.getObject();
} Dispatch.put(sControl, "Language", lang);
else session.putValue("control", sControl);
{ }
sControl = session.getValue("control"); else
} {
Variant result = Dispatch.call(sControl, "Eval", expr); sControl = session.getValue("control");
// display a form }
out.println("<h1>Enter a VBScript Expression</h1>"); Variant result = Dispatch.call(sControl, "Eval", expr);
out.println("<form method=\"POST\" action=\"/JacobScript\">"); // display a form
out.println("<input name=\"expr\" type=\"text\" value=\""+expr+"\" width=64>"); out.println("<h1>Enter a VBScript Expression</h1>");
out.println("<input type=\"submit\">"); out.println("<form method=\"POST\" action=\"/JacobScript\">");
out.println("</form>"); out.println("<input name=\"expr\" type=\"text\" value=\""+expr+"\" width=64>");
out.println("<H1>Jacob Response:</H1>"); out.println("<input type=\"submit\">");
out.println("<H2>"+result+"</H2>"); out.println("</form>");
} catch (Exception e) { out.println("<H1>Jacob Response:</H1>");
e.printStackTrace(); out.println("<H2>"+result+"</H2>");
out.println("<H2>Error:"+e+"</H2>"); } catch (Exception e) {
} e.printStackTrace();
} out.println("<H2>Error:"+e+"</H2>");
} }
}
}

View File

@@ -1,89 +1,110 @@
package samples.test; package samples.test;
import com.jacob.com.*; import com.jacob.com.*;
import com.jacob.activeX.*; import com.jacob.activeX.*;
class Access class Access
{ {
public static void main(String[] args) throws Exception /**
{ * the main loop for the test
ComThread.InitSTA(); * @param args
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine"); * @throws Exception
// this only works for access files pre-access-2000 */
Dispatch db = open(ax, ".\\sample2.mdb"); public static void main(String[] args) throws Exception
String sql = "select * from MainTable"; {
// make a temporary querydef ComThread.InitSTA();
Dispatch qd = Dispatch.call(db, "CreateQueryDef","").toDispatch(); ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
// set the SQL string on it // this only works for access files pre-access-2000
Dispatch.put(qd, "SQL", sql); Dispatch db = open(ax, ".\\sample2.mdb");
Variant result = getByQueryDef(qd); String sql = "select * from MainTable";
// the 2-d safearray is transposed from what you might expect // make a temporary querydef
System.out.println(result.toSafeArray()); Dispatch qd = Dispatch.call(db, "CreateQueryDef","").toDispatch();
close(db); // set the SQL string on it
ComThread.Release(); 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());
* Open a database close(db);
*/ ComThread.Release();
public static Dispatch open(ActiveXComponent ax, String fileName) }
{
Variant f = new Variant(false); /**
// open the file in read-only mode * Open a database
Variant[] args = new Variant[] {new Variant(fileName), f, f}; * @param ax
Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch(); * @param fileName
return openDB; * @return dispatch object that was opened
} */
public static Dispatch open(ActiveXComponent ax, String fileName)
/** {
* Close a database Variant f = new Variant(false);
*/ // open the file in read-only mode
public static void close(Dispatch openDB) Variant[] args = new Variant[] {new Variant(fileName), f, f};
{ Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
Dispatch.call(openDB, "Close"); return openDB;
} }
/** /**
* Extract the values from the recordset * Close a database
*/ * @param openDB db to be closed
public static Variant getValues(Dispatch recset) */
{ public static void close(Dispatch openDB)
Dispatch.callSub(recset,"moveFirst"); {
Variant vi = new Variant(4096); Dispatch.call(openDB, "Close");
Variant v = Dispatch.call(recset,"GetRows", vi); }
return v;
} /**
* Extract the values from the recordset
public static Variant getByQueryDef(Dispatch qd) * @param recset
{ * @return Variant that is the returned values
// get a reference to the recordset */
Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch(); public static Variant getValues(Dispatch recset)
// get the values as a safe array {
String[] cols = getColumns(recset); Dispatch.callSub(recset,"moveFirst");
for(int i=0;i<cols.length;i++) Variant vi = new Variant(4096);
{ Variant v = Dispatch.call(recset,"GetRows", vi);
System.out.print(cols[i]+" "); return v;
} }
System.out.println("");
Variant vals = getValues(recset); /**
return vals; * should return ?? for the passed in ??
} * @param qd
* @return Variant results of query?
public static String[] getColumns(Dispatch recset) */
{ public static Variant getByQueryDef(Dispatch qd)
Dispatch flds = Dispatch.get(recset, "Fields").toDispatch(); {
int n_flds = Dispatch.get(flds, "Count").toInt(); // get a reference to the recordset
String[] s = new String[n_flds]; Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
Variant vi = new Variant(); // get the values as a safe array
for (int i=0;i<n_flds;i++) { String[] cols = getColumns(recset);
vi.putInt(i); for(int i=0;i<cols.length;i++)
// must use the invoke method because this is a method call {
// that wants to have a Dispatch.Get flag... System.out.print(cols[i]+" ");
Dispatch fld = Dispatch.invoke(recset, "Fields", }
Dispatch.Get, new Object[] {vi}, new int[1]).toDispatch(); System.out.println("");
Variant name = Dispatch.get(fld, "Name"); Variant vals = getValues(recset);
s[i] = name.toString(); return vals;
} }
return s;
} /**
} * gets the columns form the rec set
* @param recset
* @return list of column names
*/
public static String[] getColumns(Dispatch recset)
{
Dispatch flds = Dispatch.get(recset, "Fields").toDispatch();
int n_flds = Dispatch.get(flds, "Count").toInt();
String[] s = new String[n_flds];
Variant vi = new Variant();
for (int i=0;i<n_flds;i++) {
vi.putInt(i);
// must use the invoke method because this is a method call
// that wants to have a Dispatch.Get flag...
Dispatch fld = Dispatch.invoke(recset, "Fields",
Dispatch.Get, new Object[] {vi}, new int[1]).toDispatch();
Variant name = Dispatch.get(fld, "Name");
s[i] = name.toString();
}
return s;
}
}

View File

@@ -1,32 +1,34 @@
import com.jacob.com.*; package samples.test.atl;
import com.jacob.activeX.*;
import com.jacob.com.*;
class MultiFace import com.jacob.activeX.*;
{
public static void main(String[] args) class MultiFaceTest
{ {
System.runFinalizersOnExit(true); public static void main(String[] args)
{
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face"); System.runFinalizersOnExit(true);
try {
// I am now dealing with the default interface (IFace1) ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1")); try {
System.out.println(Dispatch.get(mf, "Face1Name")); // I am now dealing with the default interface (IFace1)
Dispatch.put(mf, "Face1Name", new Variant("Hello Face1"));
// get to IFace2 through the IID System.out.println(Dispatch.get(mf, "Face1Name"));
Dispatch f2 = mf.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
// I am now dealing with IFace2 // get to IFace2 through the IID
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2")); Dispatch f2 = mf.QueryInterface("{9BF24410-B2E0-11D4-A695-00104BFF3241}");
System.out.println(Dispatch.get(f2, "Face2Nam")); // I am now dealing with IFace2
Dispatch.put(f2, "Face2Nam", new Variant("Hello Face2"));
// get to IFace3 through the IID System.out.println(Dispatch.get(f2, "Face2Nam"));
Dispatch f3 = mf.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
// I am now dealing with IFace3 // get to IFace3 through the IID
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3")); Dispatch f3 = mf.QueryInterface("{9BF24411-B2E0-11D4-A695-00104BFF3241}");
System.out.println(Dispatch.get(f3, "Face3Name")); // I am now dealing with IFace3
Dispatch.put(f3, "Face3Name", new Variant("Hello Face3"));
} catch (Exception e) { System.out.println(Dispatch.get(f3, "Face3Name"));
e.printStackTrace();
} } catch (Exception e) {
} e.printStackTrace();
} }
}
}