merged R-1_9 release tag against the root-B-1_9

This commit is contained in:
clay_shooter
2005-02-26 21:32:27 +00:00
parent ebb1eddb69
commit bcf7bb0f85
132 changed files with 7134 additions and 4068 deletions

View File

@@ -0,0 +1,2 @@
*.class

View File

@@ -0,0 +1,493 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.activeX;
import com.jacob.com.*;
/**
* This class provides a higher level, more object like, wrapper for
* top of the Dispatch object. The Dispatch class's method essentially
* directly map to Microsoft C API including the first parameter that is
* almost always the target of the message.
* ActiveXComponent assumes the target of every message is the MS
* COM object behind the ActiveXComponent. This removes the need
* to pass the Dispatch object into every method.
* <p>
* It is really up to the developer as to whether they want to
* use the Dispatch interface or the ActiveXComponent interface.
* <p>
* This class simulates com.ms.activeX.ActiveXComponent only in
* the senese that it is used for creating Dispatch objects
*/
public class ActiveXComponent extends Dispatch {
/**
* Normally used to create a new connection to a microsoft application.
* The passed in parameter is the name of the program as registred
* in the registry. It can also be the object name.
* <pre>new ActiveXComponent("ScriptControl");</pre>
* @param programId
*/
public ActiveXComponent(String programId) {
super(programId);
}
/**
* Creates an active X component that is built on top of the
* COM pointers held in the passed in dispatch.
* This widends the Dispatch object to pick up the ActiveXComponent API
*
* @param dispatchToBeWrapped
*/
public ActiveXComponent(Dispatch dispatchToBeWrapped) {
super(dispatchToBeWrapped);
}
/**
* Probably was a cover for something else in the past.
* Should be deprecated.
* @return Now it actually returns this exact same object.
*/
public Dispatch getObject() {
return this;
}
/**
* @see com.jacob.com.Dispatch#finalize()
*/
protected void finalize() {
super.finalize();
}
static {
System.loadLibrary("jacob");
}
/*============================================================
*
* start of instance based calls to the COM layer
* ===========================================================
*/
/**
* retrieves a property and returns it as a Variant
* @param propertyName
* @return variant value of property
*/
public Variant getProperty(String propertyName)
{
return Dispatch.get(this, propertyName);
}
/**
* retrieves a property and returns it as an ActiveX component
* @param propertyName
* @return Dispatch representing the object under the property name
*/
public ActiveXComponent getPropertyAsComponent(String propertyName){
return new ActiveXComponent(Dispatch.get(this,propertyName).toDispatch());
}
/**
* retrieves a property and returns it as a Boolean
* @param propertyName property we are looking up
* @return boolean value of property
*/
public boolean getPropertyAsBoolean(String propertyName){
return Dispatch.get(this, propertyName).toBoolean();
}
/**
* retrieves a property and returns it as a byte
* @param propertyName property we are looking up
* @return byte value of property
*/
public byte getPropertyAsByte(String propertyName){
return Dispatch.get(this, propertyName).toByte();
}
/**
* retrieves a property and returns it as a String
* @param propertyName
* @return String value of property
*/
public String getPropertyAsString(String propertyName){
return Dispatch.get(this, propertyName).toString();
}
/**
* retrieves a property and returns it as a int
* @param propertyName
* @return the property value as an int
*/
public int getPropertyAsInt(String propertyName){
return Dispatch.get(this,propertyName).toInt();
}
/**
* sets a property on this object
* @param propertyName property name
* @param arg variant value to be set
*/
public void setProperty(String propertyName, Variant arg)
{
Dispatch.put(this, propertyName, arg);
}
/**
* sets a property on this object
* @param propertyName property name
* @param arg variant value to be set
*/
public void setProperty(String propertyName, Dispatch arg)
{
Dispatch.put(this, propertyName, arg);
}
/**
* sets a property to be the value of the string
* @param propertyName
* @param propertyValue
*/
public void setProperty(String propertyName, String propertyValue){
this.setProperty(propertyName, new Variant(propertyValue));
}
/**
* sets a property as a boolean value
* @param propertyName
* @param propValue the boolean value we want the prop set to
*/
public void setProperty(String propertyName, boolean propValue){
this.setProperty(propertyName, new Variant(propValue));
}
/**
* sets a property as a boolean value
* @param propertyName
* @param propValue the boolean value we want the prop set to
*/
public void setProperty(String propertyName, byte propValue){
this.setProperty(propertyName, new Variant(propValue));
}
/**
* sets the property as an int value
* @param propertyName
* @param propValue the int value we want the prop to be set to.
*/
public void setProperty(String propertyName, int propValue){
this.setProperty(propertyName, new Variant(propValue));
}
/*-------------------------------------------------------
* Listener logging helpers
*-------------------------------------------------------
*/
/**
* This boolean determines if callback events should be logged
*/
public static boolean shouldLogEvents = false;
/**
* used by the doc and application listeners to get intelligent logging
* @param description event description
* @param args args passed in (variants)
*
*/
public void logCallbackEvent(String description, Variant[] args ) {
String argString = "";
if (args!=null && ActiveXComponent.shouldLogEvents){
if (args.length > 0){
argString+=" args: ";
}
for ( int i = 0; i < args.length; i++){
short argType = args[i].getvt();
argString+=",["+i+"]";
// break out the byref bits if they are on this
if ((argType & Variant.VariantByref) == Variant.VariantByref){
// show the type and the fact that its byref
argString += "("+(args[i].getvt() & ~Variant.VariantByref)+
"/"+Variant.VariantByref+")";
} else {
// show the type
argString += "("+argType+")";
}
argString += "=";
if (argType == Variant.VariantDispatch){
Dispatch foo = (Dispatch)args[i].getDispatch();
argString+=foo;
} else if ((argType & Variant.VariantBoolean) ==
Variant.VariantBoolean){
// do the boolean thing
if ((argType & Variant.VariantByref) ==
Variant.VariantByref){
// boolean by ref
argString += args[i].getBooleanRef();
} else {
// boolean by value
argString += args[i].getBoolean();
}
} else if ((argType & Variant.VariantString) ==
Variant.VariantString){
// do the string thing
if ((argType & Variant.VariantByref) ==
Variant.VariantByref){
// string by ref
argString += args[i].getStringRef();
} else {
// string by value
argString += args[i].getString();
}
} else {
argString+=args[i].toString();
}
}
System.out.println(description +argString);
}
}
/*==============================================================
*
* covers for dispatch call methods
*=============================================================*/
/**
* makes a dispatch call for the passed in action and no parameter
* @param callAction
* @return ActiveXComponent representing the results of the call
*/
public ActiveXComponent invokeGetComponent(String callAction){
return new ActiveXComponent(invoke(callAction).toDispatch());
}
/**
* makes a dispatch call for the passed in action and single parameter
* @param callAction
* @param parameter
* @return ActiveXComponent representing the results of the call
*/
public ActiveXComponent invokeGetComponent(String callAction,
Variant parameter){
return new ActiveXComponent(invoke(callAction, parameter).toDispatch());
}
/**
* makes a dispatch call for the passed in action and single parameter
* @param callAction
* @param parameter1
* @param parameter2
* @return ActiveXComponent representing the results of the call
*/
public ActiveXComponent invokeGetComponent(String callAction,
Variant parameter1, Variant parameter2){
return new ActiveXComponent(invoke(callAction,
parameter1, parameter2).toDispatch());
}
/**
* makes a dispatch call for the passed in action and single parameter
* @param callAction
* @param parameter1
* @param parameter2
* @param parameter3
* @return ActiveXComponent representing the results of the call
*/
public ActiveXComponent invokeGetComponent(String callAction,
Variant parameter1,
Variant parameter2,
Variant parameter3){
return new ActiveXComponent(invoke(callAction,
parameter1, parameter2, parameter3).toDispatch());
}
/**
* makes a dispatch call for the passed in action and single parameter
* @param callAction
* @param parameter1
* @param parameter2
* @param parameter3
* @param parameter4
* @return ActiveXComponent representing the results of the call
*/
public ActiveXComponent invokeGetComponent(String callAction,
Variant parameter1,
Variant parameter2,
Variant parameter3,
Variant parameter4){
return new ActiveXComponent(invoke(callAction,
parameter1, parameter2, parameter3, parameter4)
.toDispatch());
}
/**
* invokes a single parameter call on this dispatch
* that returns no value
* @param actionCommand
* @param parameter
* @return a Variant but that may be null for some calls
*/
public Variant invoke(String actionCommand, String parameter){
return Dispatch.call(this, actionCommand, parameter);
}
/**
* makes a dispatch call to the passed in action with a single boolean parameter
* @param actionCommand
* @param parameter
* @return Variant result
*/
public Variant invoke(String actionCommand, boolean parameter){
return Dispatch.call(this, actionCommand, new Variant(parameter));
}
/**
* makes a dispatch call to the passed in action with a single int parameter
* @param actionCommand
* @param parameter
* @return Variant result of the invoke (Dispatch.call)
*/
public Variant invoke(String actionCommand, int parameter){
return Dispatch.call(this, actionCommand, new Variant(parameter));
}
/**
* makes a dispatch call to the passed in action with a string and integer parameter
* (this was put in for some application)
* @param actionCommand
* @param parameter1
* @param parameter2
* @return Variant result
*/
public Variant invoke(String actionCommand, String parameter1, int parameter2){
return Dispatch.call(this, actionCommand, parameter1, new Variant(parameter2));
}
/**
* makes a dispatch call to the passed in action with two
* integer parameters
* (this was put in for some application)
* @param actionCommand
* @param parameter1
* @param parameter2
* @return a Variant but that may be null for some calls
*/
public Variant invoke(String actionCommand,
int parameter1, int parameter2){
return Dispatch.call(this, actionCommand,
new Variant(parameter1),new Variant(parameter2));
}
/**
* makes a dispatch call for the passed in action and single parameter
* @param callAction
* @param parameter
* @return a Variant but that may be null for some calls
*/
public Variant invoke(String callAction, Variant parameter){
return Dispatch.call(this,callAction, parameter);
}
/**
* makes a dispatch call for the passed in action and two parameter
* @param callAction
* @param parameter1
* @param parameter2
* @return a Variant but that may be null for some calls
*/
public Variant invoke(String callAction,
Variant parameter1,
Variant parameter2){
return Dispatch.call(this,callAction, parameter1,parameter2);
}
/**
* makes a dispatch call for the passed in action and two parameter
* @param callAction
* @param parameter1
* @param parameter2
* @param parameter3
* @return Variant result data
*/
public Variant invoke(String callAction,
Variant parameter1,
Variant parameter2,
Variant parameter3){
return Dispatch.call(this,callAction,
parameter1, parameter2, parameter3);
}
/**
* calls call() with 4 variant parameters
* @param callAction
* @param parameter1
* @param parameter2
* @param parameter3
* @param parameter4
* @return Variant result data
*/
public Variant invoke(String callAction,
Variant parameter1,
Variant parameter2,
Variant parameter3,
Variant parameter4){
return Dispatch.call(this,callAction,
parameter1, parameter2, parameter3, parameter4);
}
/**
* makes a dispatch call for the passed in action and no parameter
* @param callAction
* @return a Variant but that may be null for some calls
*/
public Variant invoke(String callAction){
return Dispatch.call(this,callAction);
}
/**
* This is really a cover for call(String,Variant[]) that should be eliminated
* call with a variable number of args mainly used for quit.
* @param name
* @param args
* @return Variant returned by the invoke (Dispatch.callN)
*/
public Variant invoke(String name, Variant[] args)
{
return Dispatch.callN(this, name, args);
}
}

View File

@@ -0,0 +1,2 @@
*.class

View File

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

View File

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

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Redistributions in any form must
* be accompanied by information on how to obtain complete source code for the
* JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
/**
* represents a COM level thread
*/
public abstract class ComThread {
private static final int MTA = 0x0;
private static final int STA = 0x2;
/**
* Comment for <code>haveSTA</code>
*/
public static boolean haveSTA = false;
/**
* Comment for <code>mainSTA</code>
*/
public static MainSTA mainSTA = null;
/**
* Initialize the current java thread to be part of the Multi-threaded COM
* Apartment
*/
public static synchronized void InitMTA() {
InitMTA(false);
}
/**
* Initialize the current java thread to be an STA
*/
public static synchronized void InitSTA() {
InitSTA(false);
}
/**
* Initialize the current java thread to be part of the Multi-threaded COM
* Apartment, if createMainSTA is true, create a separate MainSTA thread
* that will house all Apartment Threaded components
* @param createMainSTA
*/
public static synchronized void InitMTA(boolean createMainSTA) {
Init(createMainSTA, MTA);
}
/**
* Initialize the current java thread to be an STA COM Apartment, if
* createMainSTA is true, create a separate MainSTA thread that will house
* all Apartment Threaded components
* @param createMainSTA
*/
public static synchronized void InitSTA(boolean createMainSTA) {
Init(createMainSTA, STA);
}
/**
*
*/
public static synchronized void startMainSTA() {
mainSTA = new MainSTA();
haveSTA = true;
}
/**
*
*/
public static synchronized void quitMainSTA() {
if (mainSTA != null)
mainSTA.quit();
}
/**
* Initialize the current java thread to be part of the MTA/STA COM
* Apartment
* @param createMainSTA
* @param mode
*/
public static synchronized void Init(boolean createMainSTA, int mode) {
if (createMainSTA && !haveSTA) {
// if the current thread is going to be in the MTA and there
// is no STA thread yet, then create a main STA thread
// to avoid COM creating its own
startMainSTA();
}
//System.out.println("before Init: "+mode);
doCoInitialize(mode);
//System.out.println("after Init");
ROT.addThread();
//System.out.println("after ROT.addThread");
}
/**
* Call CoUninitialize to release this java thread from COM
*/
public static synchronized void Release() {
//System.out.println("before clearObjects");
ROT.clearObjects();
//System.out.println("before UnInit");
doCoUninitialize();
//System.out.println("after UnInit");
}
/**
* @deprecated the java model leave the responsibility of clearing up objects
* to the Garbage Collector. Our programming model should not require that the
* user specifically remove object from the thread.
*
* This will remove an object from the ROT
* @param o
*/
public static synchronized void RemoveObject(JacobObject o)
{
ROT.removeObject(o);
}
/**
* @param threadModel
*/
public static native void doCoInitialize(int threadModel);
/**
*
*/
public static native void doCoUninitialize();
static {
System.loadLibrary("jacob");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
/**
* This class creates the scaffolding for event callbacks.
* Every instance of tis acts as a wrapper around some java object
* that wants callbacks from the microsoft side. It represents
* the connection between Java and COM for callbacks.
* <p>
* The callback mechanism will take any event that it receives and
* try and find a java method with the same name that accepts the
* Variant... as a parameter. It will then wrap the call back data
* in the Variant array and call the java method of the object
* that this DispatchEvents object was initialized with.
*
*/
public class DispatchEvents extends JacobObject {
/**
* ponter to an MS data struct.
*/
int m_pConnPtProxy = 0;
/**
* create a permanent reference to this Variant so that
* it never gets garbage collected. The
* Dispatch proxies will keep a handle on this so
* we don't really want it released
*/
private static Variant prototypicalVariant = new VariantViaEvent();
/**
* Creates the event callback linkage between the the
* MS program represented by the Dispatch object and the
* Java object that will receive the callback.
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
*/
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink) {
init(sourceOfEvent, eventSink, prototypicalVariant);
}
/**
* Creates the event callback linkage between the the
* MS program represented by the Dispatch object and the
* Java object that will receive the callback.
* @param sourceOfEvent Dispatch object who's MS app will generate callbacks
* @param eventSink Java object that wants to receive the events
* @param progId
*/
public DispatchEvents(Dispatch sourceOfEvent, Object eventSink, String progId) {
init2(sourceOfEvent, eventSink, prototypicalVariant, progId);
}
/**
* hooks up a connection point proxy by progId
* event methods on the sink object will be called
* by name with a signature of <name>(Variant[] args)
* protoVariant is a sacrificial variant object so we don't have to do findClass in callbacks
* @param src
* @param sink
* @param protoVariant
*/
protected native void init(Dispatch src, Object sink, Object protoVariant);
/**
* hooks up a connection point proxy by progId
* event methods on the sink object will be called
* by name with a signature of <name>(Variant[] args)
* protoVariant is a sacrificial variant object so we don't have to do findClass in callbacks
* @param src
* @param sink
* @param protoVariant
* @param progId
*/
protected native void init2(Dispatch src, Object sink, Object protoVariant, String progId);
/**
* now private so only this object can asccess
* was: call this to explicitly release the com object before gc
*
*/
private native void release();
/*
* (non-Javadoc)
* @see java.lang.Object#finalize()
*/
protected void finalize() {
safeRelease();
}
/*
* (non-Javadoc)
* @see com.jacob.com.JacobObject#safeRelease()
*/
public void safeRelease(){
super.safeRelease();
if (m_pConnPtProxy != 0){
release();
m_pConnPtProxy = 0;
} else {
// looks like a double release
if (isDebugEnabled()){debug(this.getClass().getName()+":"+this.hashCode()+" double release");}
}
}
static {
System.loadLibrary("jacob");
}
}

View File

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

View File

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

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
/**
* The superclass of all Jacob objects. It is used to
* create a standard API framework and to facillitate memory management
* for Java and COM memory elements.
* <p>
* All COM object created by JACOB extend this class so that we can
* automatically release them when the thread is detached from COM - if we leave
* it to the finalizer it will call the release from another thread, which may
* result in a segmentation violation.
*/
public class JacobObject {
private static String buildVersion = "";
private static String buildDate = "";
/**
* Standard constructor that adds this JacobObject
* to the memory management pool.
*/
public JacobObject() {
ROT.addObject(this);
}
/**
* Loads version information from version.properties that was
* built as part of this release.
*
*/
private static void loadVersionProperties(){
Properties versionProps = new Properties();
// can't use system class loader cause won't work in jws
InputStream stream =
JacobObject.class.getClassLoader().getResourceAsStream("version.properties");
try {
versionProps.load(stream);
stream.close();
buildVersion = (String)versionProps.get("version");
buildDate = (String)versionProps.get("build.date");
} catch (IOException ioe){
System.out.println("blah, couldn't load props");
}
}
/**
* loads version.properties and returns the value of versin in it
* @return String value of version in version.properties or "" if none
*/
public static String getBuildDate(){
if (buildDate.equals("")){
loadVersionProperties();
}
return buildDate;
}
/**
* loads version.properties and returns the value of versin in it
* @return String value of version in version.properties or "" if none
*/
public static String getBuildVersion(){
if (buildVersion.equals("")){
loadVersionProperties();
}
return buildVersion;
}
/**
* Finalizers call this method.
* This method should release any COM data structures in a way
* that it can be called multiple times.
* This can happen if someone manually calls this and then
* a finalizer calls it.
*/
public void safeRelease() {
// currently does nothing - subclasses may do something
if (isDebugEnabled()){
debug(this.getClass().getName()+":"+this.hashCode()+" release");
}
}
/**
* When things go wrong, it is usefull to be able to debug the ROT.
*/
private static final boolean DEBUG =
//true;
"true".equalsIgnoreCase(System.getProperty("com.jacob.debug"));
protected static boolean isDebugEnabled(){
//return true;
return DEBUG;
}
/**
* Very basic debugging fucntion.
* @param istrMessage
*/
protected static void debug(String istrMessage)
{
if(isDebugEnabled())
{
System.out.println(istrMessage);
}
}
}

View File

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

214
src/com/jacob/com/ROT.java Normal file
View File

@@ -0,0 +1,214 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
/**
* The Running Object Table (ROT) maps each thread to a collection of all the
* JacobObjects that were created in that thread. It always operates on the
* current thread so all the methods are static and they implicitly get the
* current thread.
* <p>
* The clearObjects method is used to release all the COM objects created by Jacob
* in the current thread prior to uninitializing COM for that thread.
* <p>
* Prior to 1.9, manual garbage collection was the only option in Jacob, but
* from 1.9 onward, setting the com.jacob.autogc system property
* allows the objects referenced by the ROT to be automatically GCed.
* <p>
* TODO : explain when automatic GC is preferable, and when it isn't.
* Is [ 1116101 ] jacob-msg 0284 relevant???
*/
public abstract class ROT {
/**
* Manual garbage collection was the only option pre 1.9
*/
protected static final boolean USE_AUTOMATIC_GARBAGE_COLLECTION =
"true".equalsIgnoreCase(System.getProperty("com.jacob.autogc"));
/**
* A hash table where each element is another
* HashMap that represents a thread.
* Each thread HashMap contains the com objects created
* in that thread
*/
private static HashMap rot = new HashMap();
/**
* adds a new thread storage area to rot
* @return Map corresponding to the thread that this call was made in
*/
protected static Map addThread() {
String t_name = Thread.currentThread().getName();
if (rot.containsKey(t_name)){
// nothing to do
} else {
Map tab = null;
if (JacobObject.isDebugEnabled()){ JacobObject.debug("Automatic GC flag == "+USE_AUTOMATIC_GARBAGE_COLLECTION);}
if (!USE_AUTOMATIC_GARBAGE_COLLECTION){
tab = new HashMap();
} else {
tab = new WeakHashMap();
}
rot.put(t_name,tab);
}
return getThreadObjects(false);
}
/**
* returns the pool for this thread if it exists. can create a new
* one if you wish by passing in TRUE
* @param createIfDoesNotExist
* @return Map the collection that holds the objects created in the current thread
*/
protected static Map getThreadObjects(boolean createIfDoesNotExist) {
String t_name = Thread.currentThread().getName();
if (!rot.containsKey(t_name) && createIfDoesNotExist){
addThread();
}
return (Map)rot.get(t_name);
}
/**
* Iterates across all of the entries in the Hashmap in the rot
* that corresponds to this thread.
* This calls safeRelease() on each entry and then
* clears the map when done and removes it from the rot.
* All traces of this thread's objects will disapear.
* This is called by COMThread in the tear down and provides a
* synchronous way of releasing memory
*/
protected static void clearObjects() {
Map tab = getThreadObjects(false);
if (JacobObject.isDebugEnabled()){ JacobObject.debug("starting clear objects");}
if (tab != null){
// walk the values
Iterator it;
if (USE_AUTOMATIC_GARBAGE_COLLECTION){
it = tab.keySet().iterator();
} else {
it = tab.values().iterator();
}
while (it.hasNext()) {
JacobObject o = (JacobObject) it.next();
if (o != null
// can't use this cause creates a Variant if calling SafeAray
// and we get an exceptin modifying the collection while iterating
// && o.toString() != null
){
if (JacobObject.isDebugEnabled()){ JacobObject.debug(" removing "+o.getClass().getName());}
o.safeRelease();
}
// used to be an iterator.remove() but why bother when we're nuking them all anyway?
}
// empty the collection
tab.clear();
// remove the collection from rot
rot.remove(Thread.currentThread().getName());
} else {
if (JacobObject.isDebugEnabled()){ JacobObject.debug("nothing to clear!");}
}
}
/**
* generates the key used to insert object into the thread's list of objects.
* @param targetMap the map we need the key for. Used to make sure we create a compatabile key
* @param o JacobObject we need key for
* @return some key compatabile with hashmaps
*/
protected static Object getMapKey(Map targetMap, JacobObject o){
if (targetMap instanceof WeakHashMap){
return o;
} else {
return new Integer(o.hashCode());
}
}
/**
* generates the object used to insert object into the thread's list of objects.
* @param targetMap the map we need the key for. Used to make sure we create a compatabile key
* @param o JacobObject we need key for
* @return some compatabile with hashmaps (null for weak has map)
*/
protected static Object getMapValue(Map targetMap, JacobObject o){
if (targetMap instanceof WeakHashMap){
return null;
} else {
return o;
}
}
/**
* @deprecated the java model leave the responsibility of clearing up objects
* to the Garbage Collector. Our programming model should not require that the
* user specifically remove object from the thread.
*
* This will remove an object from the ROT
* @param o
*/
protected static void removeObject(JacobObject o) {
String t_name = Thread.currentThread().getName();
Map tab = (Map) rot.get(t_name);
if (tab != null) {
tab.remove(getMapKey(tab,o));
}
o.safeRelease();
}
/**
* adds an object to the HashMap for the current thread
* @param o
*/
protected static void addObject(JacobObject o) {
String t_name = Thread.currentThread().getName();
if (JacobObject.isDebugEnabled()){ JacobObject.debug(" add:"+o+"->"+o.getClass().getName());}
Map tab = getThreadObjects(false);
if (tab == null) {
// this thread has not been initialized as a COM thread
// so make it part of MTA for backwards compatibility
ComThread.InitMTA(false);
tab = getThreadObjects(true);
}
if (tab != null) {
tab.put(getMapKey(tab,o),getMapValue(tab,o));
if (JacobObject.isDebugEnabled()){ JacobObject.debug(" ROT thread table size after addition is :"+tab.size());}
}
}
static {
System.loadLibrary("jacob");
}
}

104
src/com/jacob/com/STA.java Normal file
View File

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

View File

@@ -0,0 +1,760 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project. All rights reserved.
* Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Redistributions in any form must
* be accompanied by information on how to obtain complete source code for the
* JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
/**
* This creates an array wrapper around Variant objects(?).
* Lookslike it supports 1 and two dimensional arrays
*/
public class SafeArray extends JacobObject {
int m_pV = 0;
/**
* constructor
*
*/
public SafeArray() {
}
/**
* constructor
* @param vt
*/
public SafeArray(int vt) {
init(vt, new int[] { 0 }, new int[] { -1 });
}
/**
* constructor
* @param vt
* @param celems
*/
public SafeArray(int vt, int celems) {
init(vt, new int[] { 0 }, new int[] { celems });
}
/**
* @param vt
* @param celems1
* @param celems2
*/
public SafeArray(int vt, int celems1, int celems2) {
init(vt, new int[] { 0, 0 }, new int[] { celems1, celems2 });
}
/**
* constructor
* @param vt
* @param lbounds
* @param celems
*/
public SafeArray(int vt, int lbounds[], int celems[]) {
init(vt, lbounds, celems);
}
/**
* convert a string to a VT_UI1 array
* @param s source string
*/
public SafeArray(String s) {
char[] ca = s.toCharArray();
init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length });
fromCharArray(ca);
}
protected native void init(int vt, int lbounds[], int celems[]);
/**
* not impl
* @return 0
*/
public int getNumLocks() {
return 0;
}
/**
* convert a VT_UI1 array to string
* @return variant byte as a string
*/
public String asString() {
if (getvt() != Variant.VariantByte)
return null;
char ja[] = toCharArray();
return new String(ja);
}
public native Object clone();
/**
* now private so only this object can asccess
* was: call this to explicitly release the com object before gc
*
*/
private native void destroy();
public native int getvt();
/*
* (non-Javadoc)
* @see java.lang.Object#finalize()
*/
protected void finalize() {
safeRelease();
}
/*
* (non-Javadoc)
* @see com.jacob.com.JacobObject#safeRelease()
*/
public void safeRelease()
{
super.safeRelease();
if (m_pV != 0){
destroy();
m_pV = 0;
} else {
// looks like a double release
if (isDebugEnabled()){debug(this.getClass().getName()+":"+this.hashCode()+" double release");}
}
}
public native void reinit(SafeArray sa);
public native void reinterpretType(int vt);
public native int getLBound();
public native int getLBound(int dim);
public native int getUBound();
public native int getUBound(int dim);
public native int getNumDim();
public native int getFeatures();
public native int getElemSize();
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromCharArray(char ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromIntArray(int ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromShortArray(short ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromDoubleArray(double ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromStringArray(String ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromByteArray(byte ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromFloatArray(float ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromBooleanArray(boolean ja[]);
/**
* populate the safe array from the passed in array of data
* @param ja
*/
public native void fromVariantArray(Variant ja[]);
/**
* Retrieves the data from the array cast to a Java data type
* @return char[] character array contained in this collection
*/
public native char[] toCharArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return int[] int array contained in this collection
*/
public native int[] toIntArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return short[] short array contained in this collection
*/
public native short[] toShortArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return double[] double array contained in this colleciton
*/
public native double[] toDoubleArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return String[] String array contained in this collecition
*/
public native String[] toStringArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return byte[] byte array contained in this collecition
*/
public native byte[] toByteArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return float[] array of float contained in this collection
*/
public native float[] toFloatArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return boolean[] array of booleans contained in this collection
*/
public native boolean[] toBooleanArray();
/**
* Retrieves the data from the array cast to a Java data type
* @return Variant[] array of variants contained in this collection
*/
public native Variant[] toVariantArray();
/**
* char access
* @param sa_idx
* @return single character rpeesentation
*/
public native char getChar(int sa_idx);
/**
* char access
* @param sa_idx1
* @param sa_idx2
* @return single character repesentation
*/
public native char getChar(int sa_idx1, int sa_idx2);
/**
* char access
* @param sa_idx
* @param c
*/
public native void setChar(int sa_idx, char c);
/**
* char access
* @param sa_idx1
* @param sa_idx2
* @param c
*/
public native void setChar(int sa_idx1, int sa_idx2, char c);
/**
* char access
* @param sa_idx
* @param nelems
* @param ja
* @param ja_start
*/
public native void getChars(int sa_idx, int nelems, char ja[], int ja_start);
/**
* char access
* @param sa_idx
* @param nelems
* @param ja
* @param ja_start
*/
public native void setChars(int sa_idx, int nelems, char ja[], int ja_start);
/**
* int access
* @param sa_idx
* @return int stored in array
*/
public native int getInt(int sa_idx);
/**
* int access
* @param sa_idx1
* @param sa_idx2
* @return int stored in array
*/
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 short stored in array
*/
public native short getShort(int sa_idx);
/**
* short access
* @param sa_idx1
* @param sa_idx2
* @return short stored in array
*/
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 double stored in array
*/
public native double getDouble(int sa_idx);
/**
* double access
* @param sa_idx1
* @param sa_idx2
* @return double storedin array
*/
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 String stored in array
*
*/
public native String getString(int sa_idx);
/**
* string access
* @param sa_idx1
* @param sa_idx2
* @return String stored in array
*/
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 byte representaton
*/
public native byte getByte(int sa_idx);
/**
* byte access
* @param sa_idx1
* @param sa_idx2
* @return byte representation
*/
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);
/**
* Fills byte array(?) from contents of this array
* @param sa_idx
* @param nelems
* @param ja
* @param ja_start
*/
public native void getBytes(int sa_idx, int nelems, byte ja[], int ja_start);
/**
* fills array with passed in bytes
* @param sa_idx
* @param nelems
* @param ja
* @param ja_start
*/
public native void setBytes(int sa_idx, int nelems, byte ja[], int ja_start);
/**
* float access
* @param sa_idx
* @return float held in array at location
*/
public native float getFloat(int sa_idx);
/**
* float access
* @param sa_idx1
* @param sa_idx2
* @return float held in array at location
*/
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 boolean representation
*/
public native boolean getBoolean(int sa_idx);
/**
* boolean access
* @param sa_idx1
* @param sa_idx2
* @return boolean representation
*/
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 Variant held in locatioon in the array?
*/
public native Variant getVariant(int sa_idx);
/**
* variant access
* @param sa_idx1
* @param sa_idx2
* @return Variant held in a location in the array?
*/
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()
* Warning, this creates new Variant objects!
* @return String contents of varaint
*/
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

@@ -0,0 +1,721 @@
/*
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
* All rights reserved. Originator: Dan Adler (http://danadler.com).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Redistributions in any form must be accompanied by information on
* how to obtain complete source code for the JACOB software.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jacob.com;
/**
* The multi-format data type used for all call backs and most communications
* between Java and COM. It provides a single class that can handle all data
* types
*/
public class Variant extends JacobObject implements java.io.Serializable {
/**
* Use this constant for optional parameters
*/
public final static com.jacob.com.Variant DEFAULT;
/**
* Same than {@link #DEFAULT}
*/
public final static com.jacob.com.Variant VT_MISSING;
static {
com.jacob.com.Variant vtMissing = new com.jacob.com.Variant();
vtMissing.noParam();
DEFAULT = vtMissing;
VT_MISSING = vtMissing;
}
/**
* Use for true/false variant parameters
*/
public final static com.jacob.com.Variant VT_TRUE = new com.jacob.com.Variant(
true);
/**
* Use for true/false variant parameters
*/
public final static com.jacob.com.Variant VT_FALSE = new com.jacob.com.Variant(
false);
/**
* Pointer to MS struct.
*/
int m_pVariant = 0;
/** variant's type is empty : equivalent to VB Nothing */
public static final short VariantEmpty = 0;
/** variant's type is null : equivalent to VB Null */
public static final short VariantNull = 1;
/** variant's type is short */
public static final short VariantShort = 2;
/** variant's type is int */
public static final short VariantInt = 3;
/** variant's type is float */
public static final short VariantFloat = 4;
/** variant's type is double */
public static final short VariantDouble = 5;
/** variant's type is currency */
public static final short VariantCurrency = 6;
/** variant's type is date */
public static final short VariantDate = 7;
/** variant's type is string */
public static final short VariantString = 8;
/** variant's type is dispatch */
public static final short VariantDispatch = 9;
/** variant's type is error */
public static final short VariantError = 10;
/** variant's type is boolean */
public static final short VariantBoolean = 11;
/** variant's type is variant it encapsulate another variant */
public static final short VariantVariant = 12;
/** variant's type is object */
public static final short VariantObject = 13;
/** variant's type is byte */
public static final short VariantByte = 17;
/** @todo */
public static final short VariantTypeMask = 4095;
/** variant's type is array */
public static final short VariantArray = 8192;
/** variant's type is a reference (to IDispatch?) */
public static final short VariantByref = 16384;
/** @return the value of this variant as an int */
public native int toInt();
/** @return the value of this variant as a date */
public native double toDate();
/** @return the value of this variant as boolean */
public native boolean toBoolean();
/** @return the value of this variant as an enumeration (java style) */
public native EnumVariant toEnumVariant();
/** As far as I can tell : this does absolutely nothing */
public native void getNull();
/** Set this Variant's type to VT_NULL (the VB equivalent of NULL) */
public native void putNull();
/**
* @deprecated No longer used
* @return null !
*/
public native Variant cloneIndirect();
/** @return the content of this variant as a double */
public native double toDouble();
/**
* @return the content of this variant as a long reprensenting a monetary
* amount
*/
public native long toCurrency();
/**
* @deprecated superceded by SafeArray
* @param in
* doesn't matter because this method does nothing
* @throws com.jacob.com.ComFailException
*/
public void putVariantArray(Variant[] in) {
throw new ComFailException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @return never returns
* @throws com.jacob.com.ComFailException
*/
public Variant[] getVariantArray() {
throw new ComFailException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @param in
* doesn't matter because this method does nothing
* @throws com.jacob.com.ComFailException
*/
public void putByteArray(Object in) {
throw new ComFailException("Not implemented");
}
/**
* set the content of this variant to a short (VT_I2|VT_BYREF)
* @param in
*/
public native void putShortRef(short in);
/**
* set the content of this variant to an int (VT_I4|VT_BYREF)
* @param in
*/
public native void putIntRef(int in);
/**
* set the content of this variant to a double (VT_R8|VT_BYREF)
* @param in
*/
public native void putDoubleRef(double in);
/**
* set the content of this variant to a date (VT_DATE|VT_BYREF)
* @param in
*/
public native void putDateRef(double in);
/**
* set the content of this variant to a string (VT_BSTR|VT_BYREF)
* @param in
*/
public native void putStringRef(String in);
/**
* get the content of this variant as a short
* @return short
*/
public native short getShortRef();
/**
* get the content of this variant as an int
* @return int
*/
public native int getIntRef();
/**
* set the content of this variant to a short (VT_I2)
* @param in
*/
public native void putShort(short in);
/**
* get the content of this variant as a short
* @return short
*/
public native short getShort();
/**
* get the content of this variant as a double
* @return double
*/
public native double getDoubleRef();
/**
* get the content of this variant as a double representing a date
* @return double
*/
public native double getDateRef();
/**
* get the content of this variant as a string
* @return String
*/
public native String getStringRef();
/**
* @return never returns anything
* @throws com.jacob.com.ComFailException
* @deprecated superceded by SafeArray
*/
public Object toCharArray() {
throw new ComFailException("Not implemented");
}
/**
* Clear the content of this variant
*/
public native void VariantClear();
/**
* @return the content of this variant as a Dispatch object
*/
public native Dispatch toDispatch();
/**
* this returns null
* @return ?? comment says null?
*/
public native Object clone();
/**
* attempts to return the content of this variant as a string
* @return String
*/
public native String toString();
/**
* return the int value held in this variant (fails on other types?)
* @return int
*/
public native int getInt();
/**
* return the date (as a double) value held in this variant (fails on other
* types?)
* @return double
*/
public native double getDate();
/**
* set the value of this variant
* @param in
*/
public native void putInt(int in);
/**
* set the value of this variant
* @param in
*/
public native void putDate(double in);
/**
* attempts to return the content of this variant as a double
* @return byte
*/
public native byte toByte();
/**
* same as {@link #toDispatch()}
* @return this object as a dispatch
*/
public Object getDispatch() {
return toDispatch();
}
/**
* same as {@link #putObject(Object)}
* @param in
*/
public void putDispatch(Object in) {
putObject(in);
}
public native boolean getBoolean();
public native byte getByte();
public native void putBoolean(boolean in);
public native void putByte(byte in);
public native int toError();
public Object toObject() {
return toDispatch();
}
public native void getEmpty();
public native void putEmpty();
public native int getError();
public native void putError(int in);
public native double getDouble();
public Object getObject() {
return toDispatch();
}
public native void putCurrency(long in);
/** puts an object into the */
public native void putObject(Object in);
public native void putDouble(double in);
public native long getCurrency();
public native void putFloatRef(float in);
public native void putCurrencyRef(long in);
public native void putErrorRef(int in);
public native void putBooleanRef(boolean in);
public void putObjectRef(Object in) {
putObject(in);
}
public native void putByteRef(byte in);
public native String getString();
public native void putString(String in);
public native float getFloatRef();
public native long getCurrencyRef();
public native int getErrorRef();
public native boolean getBooleanRef();
public native Object getObjectRef();
public native byte getByteRef();
public native float toFloat();
/**
* By default toSafeArray makes a deep copy due to the fact that this
* Variant owns the embedded SafeArray and will destroy it when it gc's
*/
public SafeArray toSafeArray() {
return toSafeArray(true);
}
public native SafeArray toSafeArray(boolean deepCopy);
public native void putSafeArrayRef(SafeArray in);
public native void putSafeArray(SafeArray in);
public native void noParam();
/**
* superceded by SafeArray
* @throws com.jacob.com.ComFailException
*/
public void putCharArray(Object in) {
throw new ComFailException("Not implemented");
}
public native float getFloat();
public native void putFloat(float in);
public void putDispatchRef(Object in) {
putDispatch(in);
}
public Object getDispatchRef() {
return getDispatch();
}
/**
* superceded by SafeArray
* @throws com.jacob.com.ComFailException
*/
public void putVariantArrayRef(Variant[] in) {
throw new ClassCastException("Not implemented");
}
/**
* superceded by SafeArray
* @throws com.jacob.com.ComFailException
*/
public Variant[] getVariantArrayRef() {
throw new ClassCastException("Not implemented");
}
public native void changeType(short in);
public void changeType(int in) {
changeType((short) in);
}
public Object toScriptObject() {
return toDispatch();
}
/**
* public constructor
*/
public Variant() {
init();
putEmpty();
if (isDebugEnabled()) {
debug("create " + getClass().getName() + " in thread "
+ Thread.currentThread().getName());
}
}
/**
* constructor that calls init() and then putXXX()
* @param in
*/
public Variant(int in) {
init();
putInt(in);
}
/**
* constructor that calls init() and then putXXX()
* @param in
*/
public Variant(double in) {
init();
putDouble(in);
}
/**
* constructor that calls init() and then putXXX()
* @param in
*/
public Variant(boolean in) {
init();
putBoolean(in);
}
/**
* constructor that calls init() and then putXXX()
* @param in
*/
public Variant(String in) {
init();
putString(in);
}
/**
* constructor that calls init() and then putSafeArrayXXX()
* @param in
* @param fByRef is this data by reference or not?
*/
public Variant(SafeArray in, boolean fByRef) {
init();
if (fByRef) {
putSafeArrayRef(in);
} else {
putSafeArray(in);
}
}
/**
* constructor that calls two parameter constructor
* with 1st parameter as object and 2nd parameter as false
* @param in
*/
public Variant(Object in) {
this(in, false);
}
/**
* constructor that accepts the data object and informaton about
* whether this is by reference or not
* @param o
* @param fByRef
*/
public Variant(Object o, boolean fByRef) {
init();
if (o == null) {
putEmpty();
} else if (o instanceof Integer) {
if (fByRef)
putIntRef(((Integer) o).intValue());
else
putInt(((Integer) o).intValue());
} else if (o instanceof String) {
if (fByRef)
putStringRef((String) o);
else
putString((String) o);
} else if (o instanceof Boolean) {
if (fByRef)
putBooleanRef(((Boolean) o).booleanValue());
else
putBoolean(((Boolean) o).booleanValue());
} else if (o instanceof Double) {
if (fByRef)
putDoubleRef(((Double) o).doubleValue());
else
putDouble(((Double) o).doubleValue());
} else if (o instanceof Float) {
if (fByRef)
putFloatRef(((Float) o).floatValue());
else
putFloat(((Float) o).floatValue());
} else if (o instanceof SafeArray) {
if (fByRef)
putSafeArrayRef((SafeArray) o);
else
putSafeArray((SafeArray) o);
} else {
if (fByRef)
putObjectRef(o);
else
putObject(o);
}
}
/**
* wierd constructor that is no longer supported
* @param in
* @param in1
* @throws com.jacob.com.ComFailException
*/
public Variant(int in, int in1) {
throw new ComFailException("Not implemented");
}
/**
* wierd constructor that is no longer supported
* @param in
* @param in1
* @throws com.jacob.com.ComFailException
*/
public Variant(int in, boolean in1) {
throw new ComFailException("Not implemented");
}
/**
* wierd constructor that is no longer supported
* @param in
* @param in1
* @throws com.jacob.com.ComFailException
*/
public Variant(int in, double in1) {
throw new ComFailException("Not implemented");
}
/**
* wierd constructor that is no longer supported
* @param in
* @param in1
* @throws com.jacob.com.ComFailException
*/
public Variant(int in, Object in1) {
throw new ComFailException("Not implemented");
}
public native short getvt();
public native short toShort();
/**
* now private so only this object can asccess was: call this to explicitly
* release the com object before gc
*
*/
private native void release();
protected native void init();
/*
* (non-Javadoc)
*
* @see java.lang.Object#finalize()
*/
protected void finalize() {
super.safeRelease();
safeRelease();
}
/*
* (non-Javadoc)
*
* @see com.jacob.com.JacobObject#safeRelease()
*/
public void safeRelease() {
super.safeRelease();
if (m_pVariant != 0) {
release();
m_pVariant = 0;
} else {
// looks like a double release
// this should almost always happen due to gc
// after someone has called ComThread.Release
if (isDebugEnabled()) {
debug(this.getClass().getName() + ":" + this.hashCode()
+ " double release");
//Throwable x = new Throwable();
//x.printStackTrace();
}
}
}
// superceded by SafeArray
public Variant[] toVariantArray() {
throw new ClassCastException("Not implemented");
}
// superceded by SafeArray
public Object toByteArray() {
throw new ClassCastException("Not implemented");
}
static {
System.loadLibrary("jacob");
}
/**
* custom serialization support
* @param oos
*/
private void writeObject(java.io.ObjectOutputStream oos) {
try {
Save(oos);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* custom serialization support
* @param ois
*/
private void readObject(java.io.ObjectInputStream ois) {
try {
Load(ois);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* is the variant null or empty or error or null disp
* @return true if it is null or false if not
*/
public native boolean isNull();
public native void Save(java.io.OutputStream os) throws java.io.IOException;
public native void Load(java.io.InputStream is) throws java.io.IOException;
}

View File

@@ -0,0 +1,14 @@
package com.jacob.com;
/**
* a public class to variant that is used
* to track which variant objects are created by event callbacks
* This is soley used for that purpose.
*/
public class VariantViaEvent extends Variant {
public VariantViaEvent(){
super();
}
}

View File

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