B-1_14-DEV merge back to main
This commit is contained in:
@@ -4,62 +4,71 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.jacob.com.LibraryLoader;
|
||||
|
||||
/**
|
||||
* It is sometimes necessary to run Jacob without being able to install the dll
|
||||
* on the client machine. This is true in JavaWebStart (JWS) and possibly
|
||||
* Applet (assuming security allows access to the file system).
|
||||
* The obvious thing to do here is to jar up
|
||||
* the Jacob.dll so that it can be downloaded the client along with the rest
|
||||
* of the resources. This is simple except that the System.Load() function
|
||||
* does not search jar files for DLLs. It searches the classpath.
|
||||
* The work around to this problem is to write the DLL to a temporary file and then
|
||||
* on the client machine. This is true in JavaWebStart (JWS) and possibly Applet
|
||||
* (assuming security allows access to the file system). The obvious thing to do
|
||||
* here is to jar up the Jacob.dll so that it can be downloaded the client along
|
||||
* with the rest of the resources. This is simple except that the System.Load()
|
||||
* function does not search jar files for DLLs. It searches the classpath. The
|
||||
* work around to this problem is to write the DLL to a temporary file and then
|
||||
* explicitly load the DLL calling passing the full path to the temporary file.
|
||||
*
|
||||
* The following code demonstrates this idea.
|
||||
*
|
||||
* @author joe
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DLLFromJARClassLoader {
|
||||
|
||||
/**
|
||||
* Load the DLL from the classpath rather than from the java path.
|
||||
* This code uses this class's class loader to find the dell in one
|
||||
* of the jar files in this class's class path. It then
|
||||
* writes the file as a temp file and calls Load() on the temp file.
|
||||
* The temporary file is marked to be deleted on exit so the dll
|
||||
* is deleted from the system when the application exits.
|
||||
* <p>
|
||||
* Derived from ample code found in Sun's java forums
|
||||
* <p.
|
||||
* @return true if the native library has loaded, false if there was a problem.
|
||||
*/
|
||||
public boolean loadLibrary()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Finds a stream to the dll. Change path/class if necessary
|
||||
InputStream inputStream = getClass().getResource("/jacob.dll").openStream();
|
||||
//Change name if necessary
|
||||
File temporaryDll = File.createTempFile("jacob", ".dll");
|
||||
FileOutputStream outputStream = new FileOutputStream(temporaryDll);
|
||||
byte[] array = new byte[8192];
|
||||
for (int i = inputStream.read(array);
|
||||
i != -1;
|
||||
i = inputStream.read(array)) {
|
||||
outputStream.write(array, 0, i);
|
||||
}
|
||||
outputStream.close();
|
||||
temporaryDll.deleteOnExit();
|
||||
System.load(temporaryDll.getPath());
|
||||
return true;
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the DLL from the classpath rather than from the java path. This code
|
||||
* uses this class's class loader to find the dell in one of the jar files
|
||||
* in this class's class path. It then writes the file as a temp file and
|
||||
* calls Load() on the temp file. The temporary file is marked to be deleted
|
||||
* on exit so the dll is deleted from the system when the application exits.
|
||||
* <p>
|
||||
* Derived from ample code found in Sun's java forums <p.
|
||||
*
|
||||
* @return true if the native library has loaded, false if there was a
|
||||
* problem.
|
||||
*/
|
||||
public boolean loadLibrary() {
|
||||
try {
|
||||
// this assumes that the dll is in the root dir of the signed
|
||||
// jws jar file for this application.
|
||||
//
|
||||
// Starting in 1.14M6, the dll is named by platform and architecture
|
||||
// so the best thing to do is to ask the LibraryLoader what name we
|
||||
// expect.
|
||||
// this code might be different if you customize the name of
|
||||
// the jacob dll to match some custom naming convention
|
||||
InputStream inputStream = getClass().getResource(
|
||||
"/" + LibraryLoader.getPreferredDLLName() + ".dll")
|
||||
.openStream();
|
||||
// Put the DLL somewhere we can find it with a name Jacob expects
|
||||
File temporaryDll = File.createTempFile(LibraryLoader
|
||||
.getPreferredDLLName(), ".dll");
|
||||
FileOutputStream outputStream = new FileOutputStream(temporaryDll);
|
||||
byte[] array = new byte[8192];
|
||||
for (int i = inputStream.read(array); i != -1; i = inputStream
|
||||
.read(array)) {
|
||||
outputStream.write(array, 0, i);
|
||||
}
|
||||
outputStream.close();
|
||||
temporaryDll.deleteOnExit();
|
||||
// Ask LibraryLoader to load the dll for us based on the path we
|
||||
// set
|
||||
System.setProperty(LibraryLoader.JACOB_DLL_PATH, temporaryDll
|
||||
.getPath());
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,38 @@
|
||||
package com.jacob.samples.MathProj;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.DispatchEvents;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* This example uses the MathTest sample VB COM DLL under
|
||||
* the MathProj directory
|
||||
* This example uses the MathTest sample VB COM DLL under the MathProj directory
|
||||
* <p>
|
||||
* May need to run with some command line options (including from inside Eclipse).
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
* May need to run with some command line options (including from inside
|
||||
* Eclipse). Look in the docs area at the Jacob usage document for command line
|
||||
* options.
|
||||
*/
|
||||
class MathTest {
|
||||
/**
|
||||
* standard main program to run the sample
|
||||
*
|
||||
* @param args
|
||||
* command line parameters
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
MathTest me = new MathTest();
|
||||
me.runTest();
|
||||
}
|
||||
|
||||
public MathTest(){
|
||||
|
||||
/** default constructor */
|
||||
public MathTest() {
|
||||
}
|
||||
|
||||
public void runTest(){
|
||||
|
||||
/**
|
||||
* not clear why we need a class and run method but that's the way it was
|
||||
* written
|
||||
*/
|
||||
public void runTest() {
|
||||
// deprecated
|
||||
// System.runFinalizersOnExit(true);
|
||||
Dispatch test = new ActiveXComponent("MathTest.Math");
|
||||
@@ -42,14 +55,29 @@ class MathTest {
|
||||
System.out.println("v.toDispatch=" + v.toDispatch());
|
||||
}
|
||||
|
||||
public class TestEvents {
|
||||
public void DoneAdd(Variant[] args) {
|
||||
System.out.println("DoneAdd called in java");
|
||||
/**
|
||||
*
|
||||
* sample class to catch the events
|
||||
*
|
||||
*/
|
||||
public class TestEvents {
|
||||
/**
|
||||
* catches the DoneAdd event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneAdd(Variant[] args) {
|
||||
System.out.println("DoneAdd called in java");
|
||||
}
|
||||
|
||||
/**
|
||||
* catches the DoneMult event
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public void DoneMult(Variant[] args) {
|
||||
System.out.println("DoneMult called in java");
|
||||
}
|
||||
}
|
||||
|
||||
public void DoneMult(Variant[] args) {
|
||||
System.out.println("DoneMult called in java");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,123 +19,126 @@
|
||||
*/
|
||||
package com.jacob.samples.access;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* May need to run with some command line options (including from inside Eclipse).
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
*
|
||||
* May need to run with some command line options (including from inside
|
||||
* Eclipse). Look in the docs area at the Jacob usage document for command line
|
||||
* options.
|
||||
*
|
||||
*/
|
||||
class Access
|
||||
{
|
||||
/**
|
||||
* the main loop for the test
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
ComThread.InitSTA();
|
||||
// original test used this
|
||||
// ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// my xp box with a later release of access needed this
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
|
||||
// this only works for access files pre-access-2000
|
||||
// this line doesn't work on my xp box in Eclipse
|
||||
//Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// this works when running in eclipse because the test cases run pwd project root
|
||||
Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
|
||||
String sql = "select * from MainTable";
|
||||
// make a temporary querydef
|
||||
Dispatch qd = Dispatch.call(db, "CreateQueryDef","").toDispatch();
|
||||
// set the SQL string on it
|
||||
Dispatch.put(qd, "SQL", sql);
|
||||
Variant result = getByQueryDef(qd);
|
||||
class Access {
|
||||
/**
|
||||
* the main loop for the test
|
||||
*
|
||||
* @param args
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
ComThread.InitSTA();
|
||||
// original test used this
|
||||
// ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine");
|
||||
// my xp box with a later release of access needed this
|
||||
ActiveXComponent ax = new ActiveXComponent("DAO.PrivateDBEngine.35");
|
||||
// this only works for access files pre-access-2000
|
||||
// this line doesn't work on my xp box in Eclipse
|
||||
// Dispatch db = open(ax, ".\\sample2.mdb");
|
||||
// this works when running in eclipse because the test cases run pwd
|
||||
// project root
|
||||
Dispatch db = open(ax, "samples/com/jacob/samples/access/sample2.mdb");
|
||||
String sql = "select * from MainTable";
|
||||
// make a temporary querydef
|
||||
Dispatch qd = Dispatch.call(db, "CreateQueryDef", "").toDispatch();
|
||||
// set the SQL string on it
|
||||
Dispatch.put(qd, "SQL", sql);
|
||||
Variant result = getByQueryDef(qd);
|
||||
// the 2-d safearray is transposed from what you might expect
|
||||
System.out.println("resulting array is "+result.toSafeArray());
|
||||
close(db);
|
||||
System.out.println("about to call ComThread.Release()");
|
||||
ComThread.Release();
|
||||
}
|
||||
System.out.println("resulting array is " + result.toSafeArray());
|
||||
close(db);
|
||||
System.out.println("about to call ComThread.Release()");
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a database
|
||||
* @param ax
|
||||
* @param fileName
|
||||
* @return dispatch object that was opened
|
||||
*/
|
||||
public static Dispatch open(ActiveXComponent ax, String fileName)
|
||||
{
|
||||
Variant f = new Variant(false);
|
||||
// open the file in read-only mode
|
||||
Variant[] args = new Variant[] {new Variant(fileName), f, f};
|
||||
Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
|
||||
return openDB;
|
||||
}
|
||||
/**
|
||||
* Open a database
|
||||
*
|
||||
* @param ax
|
||||
* @param fileName
|
||||
* @return dispatch object that was opened
|
||||
*/
|
||||
public static Dispatch open(ActiveXComponent ax, String fileName) {
|
||||
Variant f = new Variant(false);
|
||||
// open the file in read-only mode
|
||||
Variant[] args = new Variant[] { new Variant(fileName), f, f };
|
||||
Dispatch openDB = ax.invoke("OpenDatabase", args).toDispatch();
|
||||
return openDB;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a database
|
||||
* @param openDB db to be closed
|
||||
*/
|
||||
public static void close(Dispatch openDB)
|
||||
{
|
||||
Dispatch.call(openDB, "Close");
|
||||
}
|
||||
/**
|
||||
* Close a database
|
||||
*
|
||||
* @param openDB
|
||||
* db to be closed
|
||||
*/
|
||||
public static void close(Dispatch openDB) {
|
||||
Dispatch.call(openDB, "Close");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the values from the recordset
|
||||
* @param recset
|
||||
* @return Variant that is the returned values
|
||||
*/
|
||||
public static Variant getValues(Dispatch recset)
|
||||
{
|
||||
Dispatch.callSub(recset,"moveFirst");
|
||||
Variant vi = new Variant(4096);
|
||||
Variant v = Dispatch.call(recset,"GetRows", vi);
|
||||
return v;
|
||||
}
|
||||
/**
|
||||
* Extract the values from the recordset
|
||||
*
|
||||
* @param recset
|
||||
* @return Variant that is the returned values
|
||||
*/
|
||||
public static Variant getValues(Dispatch recset) {
|
||||
Dispatch.callSub(recset, "moveFirst");
|
||||
Variant vi = new Variant(4096);
|
||||
Variant v = Dispatch.call(recset, "GetRows", vi);
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* should return ?? for the passed in ??
|
||||
* @param qd
|
||||
* @return Variant results of query?
|
||||
*/
|
||||
public static Variant getByQueryDef(Dispatch qd)
|
||||
{
|
||||
// get a reference to the recordset
|
||||
Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
|
||||
// get the values as a safe array
|
||||
String[] cols = getColumns(recset);
|
||||
for(int i=0;i<cols.length;i++)
|
||||
{
|
||||
System.out.print(cols[i]+" ");
|
||||
}
|
||||
System.out.println("");
|
||||
Variant vals = getValues(recset);
|
||||
return vals;
|
||||
}
|
||||
/**
|
||||
* should return ?? for the passed in ??
|
||||
*
|
||||
* @param qd
|
||||
* @return Variant results of query?
|
||||
*/
|
||||
public static Variant getByQueryDef(Dispatch qd) {
|
||||
// get a reference to the recordset
|
||||
Dispatch recset = Dispatch.call(qd, "OpenRecordset").toDispatch();
|
||||
// get the values as a safe array
|
||||
String[] cols = getColumns(recset);
|
||||
for (int i = 0; i < cols.length; i++) {
|
||||
System.out.print(cols[i] + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
Variant vals = getValues(recset);
|
||||
return vals;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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").getInt();
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* 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").getInt();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,120 +1,207 @@
|
||||
package com.jacob.samples.ado;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Command extends Dispatch
|
||||
{
|
||||
public Command()
|
||||
{
|
||||
super("ADODB.Command");
|
||||
}
|
||||
/**
|
||||
* Custom dispatch object to make it easy for us to provide application specific
|
||||
* API.
|
||||
*
|
||||
*/
|
||||
public class Command extends Dispatch {
|
||||
/**
|
||||
* standard constructor
|
||||
*/
|
||||
public Command() {
|
||||
super("ADODB.Command");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to
|
||||
* turn a Dispatch object into a wider object - it must exist
|
||||
* in every wrapper class whose instances may be returned from
|
||||
* method calls wrapped in VT_DISPATCH Variants.
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*
|
||||
* @param dispatchTarget
|
||||
*/
|
||||
public Command(Dispatch dispatchTarget)
|
||||
{
|
||||
public Command(Dispatch dispatchTarget) {
|
||||
super(dispatchTarget);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
{
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
/**
|
||||
* runs the "Properties" command
|
||||
*
|
||||
* @return the properties
|
||||
*/
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public Connection getActiveConnection()
|
||||
{
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
|
||||
}
|
||||
/**
|
||||
* runs the "ActiveConnection" command
|
||||
*
|
||||
* @return a Connection object
|
||||
*/
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void setActiveConnection(Connection ppvObject)
|
||||
{
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
/**
|
||||
* Sets the "ActiveConnection" object
|
||||
*
|
||||
* @param ppvObject
|
||||
* the new connection
|
||||
*/
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public String getCommandText()
|
||||
{
|
||||
return Dispatch.get(this, "CommandText").toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the results from "CommandText"
|
||||
*/
|
||||
public String getCommandText() {
|
||||
return Dispatch.get(this, "CommandText").toString();
|
||||
}
|
||||
|
||||
public void setCommandText(String pbstr)
|
||||
{
|
||||
Dispatch.put(this, "CommandText", pbstr);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pbstr
|
||||
* the new "CommandText"
|
||||
*/
|
||||
public void setCommandText(String pbstr) {
|
||||
Dispatch.put(this, "CommandText", pbstr);
|
||||
}
|
||||
|
||||
public int getCommandTimeout()
|
||||
{
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return the results of "CommandTimeout"
|
||||
*/
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
|
||||
public void setCommandTimeout(int plTimeout)
|
||||
{
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param plTimeout
|
||||
* the new "CommandTimeout"
|
||||
*/
|
||||
public void setCommandTimeout(int plTimeout) {
|
||||
Dispatch.put(this, "CommandTimeout", new Variant(plTimeout));
|
||||
}
|
||||
|
||||
public boolean getPrepared()
|
||||
{
|
||||
return Dispatch.get(this, "Prepared").getBoolean();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return results from "Prepared"
|
||||
*/
|
||||
public boolean getPrepared() {
|
||||
return Dispatch.get(this, "Prepared").getBoolean();
|
||||
}
|
||||
|
||||
public void setPrepared(boolean pfPrepared)
|
||||
{
|
||||
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pfPrepared
|
||||
* the new value for "Prepared"
|
||||
*/
|
||||
public void setPrepared(boolean pfPrepared) {
|
||||
Dispatch.put(this, "Prepared", new Variant(pfPrepared));
|
||||
}
|
||||
|
||||
public Recordset Execute(Variant RecordsAffected, Variant Parameters, int Options)
|
||||
{
|
||||
return (Recordset)Dispatch.call(this, "Execute", RecordsAffected, Parameters, new Variant(Options)).toDispatch();
|
||||
}
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @param RecordsAffected
|
||||
* @param Parameters
|
||||
* @param Options
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute(Variant RecordsAffected, Variant Parameters,
|
||||
int Options) {
|
||||
return (Recordset) Dispatch.call(this, "Execute", RecordsAffected,
|
||||
Parameters, new Variant(Options)).toDispatch();
|
||||
}
|
||||
|
||||
public Recordset Execute()
|
||||
{
|
||||
Variant dummy = new Variant();
|
||||
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
|
||||
}
|
||||
/**
|
||||
* "Execute"s a command
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Recordset Execute() {
|
||||
Variant dummy = new Variant();
|
||||
return new Recordset(Dispatch.call(this, "Execute", dummy).toDispatch());
|
||||
}
|
||||
|
||||
public Variant CreateParameter(String Name, int Type, int Direction, int Size, Variant Value)
|
||||
{
|
||||
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type), new Variant(Direction), new Variant(Size), Value);
|
||||
}
|
||||
/**
|
||||
* creates a parameter
|
||||
*
|
||||
* @param Name
|
||||
* @param Type
|
||||
* @param Direction
|
||||
* @param Size
|
||||
* @param Value
|
||||
* @return
|
||||
*/
|
||||
public Variant CreateParameter(String Name, int Type, int Direction,
|
||||
int Size, Variant Value) {
|
||||
return Dispatch.call(this, "CreateParameter", Name, new Variant(Type),
|
||||
new Variant(Direction), new Variant(Size), Value);
|
||||
}
|
||||
|
||||
// need to wrap Parameters
|
||||
public Variant getParameters()
|
||||
{
|
||||
return Dispatch.get(this, "Parameters");
|
||||
}
|
||||
// need to wrap Parameters
|
||||
/**
|
||||
* @return "Parameters"
|
||||
*/
|
||||
public Variant getParameters() {
|
||||
return Dispatch.get(this, "Parameters");
|
||||
}
|
||||
|
||||
public void setCommandType(int plCmdType)
|
||||
{
|
||||
Dispatch.put(this, "CommandType", new Variant(plCmdType));
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param plCmdType
|
||||
* new "CommandType"
|
||||
*/
|
||||
public void setCommandType(int plCmdType) {
|
||||
Dispatch.put(this, "CommandType", new Variant(plCmdType));
|
||||
}
|
||||
|
||||
public int getCommandType()
|
||||
{
|
||||
return Dispatch.get(this, "CommandType").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return current "CommandType"
|
||||
*/
|
||||
public int getCommandType() {
|
||||
return Dispatch.get(this, "CommandType").getInt();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return "Name"
|
||||
*/
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
|
||||
public void setName(String pbstrName)
|
||||
{
|
||||
Dispatch.put(this, "Name", pbstrName);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param pbstrName
|
||||
* new "Name"
|
||||
*/
|
||||
public void setName(String pbstrName) {
|
||||
Dispatch.put(this, "Name", pbstrName);
|
||||
}
|
||||
|
||||
public int getState()
|
||||
{
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return curent "State"
|
||||
*/
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
/**
|
||||
* cancel whatever it is we're doing
|
||||
*/
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package com.jacob.samples.ado;
|
||||
|
||||
// Enum: CommandTypeEnum
|
||||
|
||||
public interface CommandTypeEnum
|
||||
{
|
||||
public static final int adCmdUnspecified = -1;
|
||||
public static final int adCmdUnknown = 8;
|
||||
public static final int adCmdText = 1;
|
||||
public static final int adCmdTable = 2;
|
||||
public static final int adCmdStoredProc = 4;
|
||||
public static final int adCmdFile = 256;
|
||||
public static final int adCmdTableDirect = 512;
|
||||
public interface CommandTypeEnum {
|
||||
public static final int adCmdUnspecified = -1;
|
||||
public static final int adCmdUnknown = 8;
|
||||
public static final int adCmdText = 1;
|
||||
public static final int adCmdTable = 2;
|
||||
public static final int adCmdStoredProc = 4;
|
||||
public static final int adCmdFile = 256;
|
||||
public static final int adCmdTableDirect = 512;
|
||||
}
|
||||
|
||||
@@ -1,179 +1,151 @@
|
||||
package com.jacob.samples.ado;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Connection extends Dispatch
|
||||
{
|
||||
public Connection()
|
||||
{
|
||||
super("ADODB.Connection");
|
||||
}
|
||||
public class Connection extends Dispatch {
|
||||
public Connection() {
|
||||
super("ADODB.Connection");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to
|
||||
* turn a Dispatch object into a wider object - it must exist
|
||||
* in every wrapper class whose instances may be returned from
|
||||
* method calls wrapped in VT_DISPATCH Variants.
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Connection(Dispatch d)
|
||||
{
|
||||
public Connection(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
// need to wrap Properties
|
||||
public Variant getProperties()
|
||||
{
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
// need to wrap 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").getInt();
|
||||
}
|
||||
public int getCommandTimeout() {
|
||||
return Dispatch.get(this, "CommandTimeout").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getConnectionTimeout() {
|
||||
return Dispatch.get(this, "ConnectionTimeout").getInt();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(Options));
|
||||
}
|
||||
// how to deal with RecordsAffected being output?
|
||||
public Variant Execute(String CommandText, Variant RecordsAffected,
|
||||
int Options) {
|
||||
return Dispatch.call(this, CommandText, RecordsAffected, new Variant(
|
||||
Options));
|
||||
}
|
||||
|
||||
public int BeginTrans()
|
||||
{
|
||||
return Dispatch.call(this, "BeginTrans").getInt();
|
||||
}
|
||||
public int BeginTrans() {
|
||||
return Dispatch.call(this, "BeginTrans").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getIsolationLevel() {
|
||||
return Dispatch.get(this, "IsolationLevel").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getMode() {
|
||||
return Dispatch.get(this, "Mode").getInt();
|
||||
}
|
||||
|
||||
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").getInt();
|
||||
}
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,122 +1,101 @@
|
||||
package com.jacob.samples.ado;
|
||||
import com.jacob.com.*;
|
||||
|
||||
public class Field extends Dispatch
|
||||
{
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Field extends Dispatch {
|
||||
/**
|
||||
* This constructor is used instead of a case operation to
|
||||
* turn a Dispatch object into a wider object - it must exist
|
||||
* in every wrapper class whose instances may be returned from
|
||||
* method calls wrapped in VT_DISPATCH Variants.
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Field(Dispatch d)
|
||||
{
|
||||
public Field(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
{
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getActualSize()
|
||||
{
|
||||
return Dispatch.get(this, "ActualSize").getInt();
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getAttributes()
|
||||
{
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
public int getActualSize() {
|
||||
return Dispatch.get(this, "ActualSize").getInt();
|
||||
}
|
||||
|
||||
public int getDefinedSize()
|
||||
{
|
||||
return Dispatch.get(this, "DefinedSize").getInt();
|
||||
public int getAttributes() {
|
||||
return Dispatch.get(this, "Attributes").getInt();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
public int getDefinedSize() {
|
||||
return Dispatch.get(this, "DefinedSize").getInt();
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return Dispatch.get(this, "Type").getInt();
|
||||
public String getName() {
|
||||
return Dispatch.get(this, "Name").toString();
|
||||
}
|
||||
|
||||
public Variant getValue()
|
||||
{
|
||||
return Dispatch.get(this, "Value");
|
||||
public int getType() {
|
||||
return Dispatch.get(this, "Type").getInt();
|
||||
}
|
||||
|
||||
public void setValue(Variant pvar)
|
||||
{
|
||||
Dispatch.put(this, "Value", pvar);
|
||||
public Variant getValue() {
|
||||
return Dispatch.get(this, "Value");
|
||||
}
|
||||
|
||||
public byte getPrecision()
|
||||
{
|
||||
return Dispatch.get(this, "Precision").getByte();
|
||||
public void setValue(Variant pvar) {
|
||||
Dispatch.put(this, "Value", pvar);
|
||||
}
|
||||
|
||||
public byte getNumericScale()
|
||||
{
|
||||
return Dispatch.get(this, "NumericScale").getByte();
|
||||
public byte getPrecision() {
|
||||
return Dispatch.get(this, "Precision").getByte();
|
||||
}
|
||||
|
||||
public void AppendChunk(Variant Data)
|
||||
{
|
||||
Dispatch.call(this, "AppendChunk", Data);
|
||||
public byte getNumericScale() {
|
||||
return Dispatch.get(this, "NumericScale").getByte();
|
||||
}
|
||||
|
||||
public Variant GetChunk(int Length)
|
||||
{
|
||||
return Dispatch.call(this, "GetChunk", new Variant(Length));
|
||||
public void AppendChunk(Variant Data) {
|
||||
Dispatch.call(this, "AppendChunk", Data);
|
||||
}
|
||||
|
||||
public Variant getOriginalValue()
|
||||
{
|
||||
return Dispatch.get(this, "OriginalValue");
|
||||
public Variant GetChunk(int Length) {
|
||||
return Dispatch.call(this, "GetChunk", new Variant(Length));
|
||||
}
|
||||
|
||||
public Variant getUnderlyingValue()
|
||||
{
|
||||
return Dispatch.get(this, "UnderlyingValue");
|
||||
public Variant getOriginalValue() {
|
||||
return Dispatch.get(this, "OriginalValue");
|
||||
}
|
||||
|
||||
public Variant getDataFormat()
|
||||
{
|
||||
return Dispatch.get(this, "DataFormat");
|
||||
public Variant getUnderlyingValue() {
|
||||
return Dispatch.get(this, "UnderlyingValue");
|
||||
}
|
||||
|
||||
public void setDataFormat(Variant ppiDF)
|
||||
{
|
||||
Dispatch.put(this, "DataFormat", ppiDF);
|
||||
public Variant getDataFormat() {
|
||||
return Dispatch.get(this, "DataFormat");
|
||||
}
|
||||
|
||||
public void setPrecision(byte pb)
|
||||
{
|
||||
Dispatch.put(this, "Precision", new Variant(pb));
|
||||
public void setDataFormat(Variant ppiDF) {
|
||||
Dispatch.put(this, "DataFormat", ppiDF);
|
||||
}
|
||||
|
||||
public void setNumericScale(byte pb)
|
||||
{
|
||||
Dispatch.put(this, "NumericScale", new Variant(pb));
|
||||
public void setPrecision(byte pb) {
|
||||
Dispatch.put(this, "Precision", new Variant(pb));
|
||||
}
|
||||
|
||||
public void setType(int pDataType)
|
||||
{
|
||||
Dispatch.put(this, "Type", new Variant(pDataType));
|
||||
public void setNumericScale(byte pb) {
|
||||
Dispatch.put(this, "NumericScale", new Variant(pb));
|
||||
}
|
||||
|
||||
public void setDefinedSize(int pl)
|
||||
{
|
||||
Dispatch.put(this, "DefinedSize", new Variant(pl));
|
||||
public void setType(int pDataType) {
|
||||
Dispatch.put(this, "Type", new Variant(pDataType));
|
||||
}
|
||||
|
||||
public void setAttributes(int pl)
|
||||
{
|
||||
Dispatch.put(this, "Attributes", new Variant(pl));
|
||||
public void setDefinedSize(int pl) {
|
||||
Dispatch.put(this, "DefinedSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public void setAttributes(int pl) {
|
||||
Dispatch.put(this, "Attributes", new Variant(pl));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,48 +1,43 @@
|
||||
package com.jacob.samples.ado;
|
||||
import com.jacob.com.*;
|
||||
|
||||
public class Fields extends Dispatch
|
||||
{
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Fields extends Dispatch {
|
||||
/**
|
||||
* This constructor is used instead of a case operation to
|
||||
* turn a Dispatch object into a wider object - it must exist
|
||||
* in every wrapper class whose instances may be returned from
|
||||
* method calls wrapped in VT_DISPATCH Variants.
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Fields(Dispatch d)
|
||||
{
|
||||
public Fields(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return Dispatch.get(this, "Count").getInt();
|
||||
public int getCount() {
|
||||
return Dispatch.get(this, "Count").getInt();
|
||||
}
|
||||
|
||||
public Variant _NewEnum()
|
||||
{
|
||||
return Dispatch.call(this, "_NewEnum");
|
||||
public Variant _NewEnum() {
|
||||
return Dispatch.call(this, "_NewEnum");
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
Dispatch.call(this, "Refresh");
|
||||
public void Refresh() {
|
||||
Dispatch.call(this, "Refresh");
|
||||
}
|
||||
|
||||
public Field getItem(int Index)
|
||||
{
|
||||
return new Field(Dispatch.call(this, "Item", new Variant(Index)).toDispatch());
|
||||
public Field getItem(int Index) {
|
||||
return new Field(Dispatch.call(this, "Item", new Variant(Index))
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void Append(String Name, int Type, int DefinedSize, int Attrib)
|
||||
{
|
||||
Dispatch.call(this, "Append", Name, new Variant(Type),
|
||||
new Variant(DefinedSize), new Variant(Attrib));
|
||||
public void Append(String Name, int Type, int DefinedSize, int Attrib) {
|
||||
Dispatch.call(this, "Append", Name, new Variant(Type), new Variant(
|
||||
DefinedSize), new Variant(Attrib));
|
||||
}
|
||||
|
||||
public void Delete(Variant Index)
|
||||
{
|
||||
Dispatch.call(this, "Delete", Index);
|
||||
public void Delete(Variant Index) {
|
||||
Dispatch.call(this, "Delete", Index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,409 +1,342 @@
|
||||
package com.jacob.samples.ado;
|
||||
import com.jacob.com.*;
|
||||
|
||||
public class Recordset extends Dispatch
|
||||
{
|
||||
public Recordset()
|
||||
{
|
||||
super("ADODB.Recordset");
|
||||
}
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
public class Recordset extends Dispatch {
|
||||
public Recordset() {
|
||||
super("ADODB.Recordset");
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used instead of a case operation to
|
||||
* turn a Dispatch object into a wider object - it must exist
|
||||
* in every wrapper class whose instances may be returned from
|
||||
* method calls wrapped in VT_DISPATCH Variants.
|
||||
* This constructor is used instead of a case operation to turn a Dispatch
|
||||
* object into a wider object - it must exist in every wrapper class whose
|
||||
* instances may be returned from method calls wrapped in VT_DISPATCH
|
||||
* Variants.
|
||||
*/
|
||||
public Recordset(Dispatch d)
|
||||
{
|
||||
public Recordset(Dispatch d) {
|
||||
super(d);
|
||||
}
|
||||
|
||||
public Variant getProperties()
|
||||
{
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public int getAbsolutePosition()
|
||||
{
|
||||
return Dispatch.get(this, "AbsolutePosition").getInt();
|
||||
public Variant getProperties() {
|
||||
return Dispatch.get(this, "Properties");
|
||||
}
|
||||
|
||||
public void setAbsolutePosition(int pl)
|
||||
{
|
||||
Dispatch.put(this, "AbsolutePosition", new Variant(pl));
|
||||
public int getAbsolutePosition() {
|
||||
return Dispatch.get(this, "AbsolutePosition").getInt();
|
||||
}
|
||||
|
||||
public Connection getActiveConnection()
|
||||
{
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection").toDispatch());
|
||||
}
|
||||
|
||||
public void setActiveConnection(Connection ppvObject)
|
||||
{
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public void setActiveConnection(Variant ppvObject)
|
||||
{
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public boolean getBOF()
|
||||
{
|
||||
return Dispatch.get(this, "BOF").getBoolean();
|
||||
public void setAbsolutePosition(int pl) {
|
||||
Dispatch.put(this, "AbsolutePosition", new Variant(pl));
|
||||
}
|
||||
|
||||
public Variant getBookmark()
|
||||
{
|
||||
return Dispatch.get(this, "Bookmark");
|
||||
public Connection getActiveConnection() {
|
||||
return new Connection(Dispatch.get(this, "ActiveConnection")
|
||||
.toDispatch());
|
||||
}
|
||||
|
||||
public void setBookmark(Variant pvBookmark)
|
||||
{
|
||||
Dispatch.put(this, "Bookmark", pvBookmark);
|
||||
public void setActiveConnection(Connection ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public int getCacheSize()
|
||||
{
|
||||
return Dispatch.get(this, "CacheSize").getInt();
|
||||
public void setActiveConnection(Variant ppvObject) {
|
||||
Dispatch.put(this, "ActiveConnection", ppvObject);
|
||||
}
|
||||
|
||||
public void setCacheSize(int pl)
|
||||
{
|
||||
Dispatch.put(this, "CacheSize", new Variant(pl));
|
||||
public boolean getBOF() {
|
||||
return Dispatch.get(this, "BOF").getBoolean();
|
||||
}
|
||||
|
||||
public int getCursorType()
|
||||
{
|
||||
return Dispatch.get(this, "CursorType").getInt();
|
||||
public Variant getBookmark() {
|
||||
return Dispatch.get(this, "Bookmark");
|
||||
}
|
||||
|
||||
public void setCursorType(int pl)
|
||||
{
|
||||
Dispatch.put(this, "CursorType", new Variant(pl));
|
||||
public void setBookmark(Variant pvBookmark) {
|
||||
Dispatch.put(this, "Bookmark", pvBookmark);
|
||||
}
|
||||
|
||||
public boolean getEOF()
|
||||
{
|
||||
return Dispatch.get(this, "EOF").getBoolean();
|
||||
}
|
||||
|
||||
public Fields getFields()
|
||||
{
|
||||
return new Fields(Dispatch.get(this, "Fields").toDispatch());
|
||||
public int getCacheSize() {
|
||||
return Dispatch.get(this, "CacheSize").getInt();
|
||||
}
|
||||
|
||||
public int getLockType()
|
||||
{
|
||||
return Dispatch.get(this, "LockType").getInt();
|
||||
public void setCacheSize(int pl) {
|
||||
Dispatch.put(this, "CacheSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public void setLockType(int plLockType)
|
||||
{
|
||||
Dispatch.put(this, "LockType", new Variant(plLockType));
|
||||
public int getCursorType() {
|
||||
return Dispatch.get(this, "CursorType").getInt();
|
||||
}
|
||||
|
||||
public int getMaxRecords()
|
||||
{
|
||||
return Dispatch.get(this, "MaxRecords").getInt();
|
||||
public void setCursorType(int pl) {
|
||||
Dispatch.put(this, "CursorType", new Variant(pl));
|
||||
}
|
||||
|
||||
public void setMaxRecords(int pl)
|
||||
{
|
||||
Dispatch.put(this, "MaxRecords", new Variant(pl));
|
||||
public boolean getEOF() {
|
||||
return Dispatch.get(this, "EOF").getBoolean();
|
||||
}
|
||||
|
||||
public int getRecordCount()
|
||||
{
|
||||
return Dispatch.get(this, "RecordCount").getInt();
|
||||
public Fields getFields() {
|
||||
return new Fields(Dispatch.get(this, "Fields").toDispatch());
|
||||
}
|
||||
|
||||
public void setSource(Object pvSource)
|
||||
{
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
public int getLockType() {
|
||||
return Dispatch.get(this, "LockType").getInt();
|
||||
}
|
||||
|
||||
public void setSource(String pvSource)
|
||||
{
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
public void setLockType(int plLockType) {
|
||||
Dispatch.put(this, "LockType", new Variant(plLockType));
|
||||
}
|
||||
|
||||
public Variant getSource()
|
||||
{
|
||||
return Dispatch.get(this, "Source");
|
||||
public int getMaxRecords() {
|
||||
return Dispatch.get(this, "MaxRecords").getInt();
|
||||
}
|
||||
|
||||
public void AddNew(Variant FieldList, Variant Values)
|
||||
{
|
||||
Dispatch.call(this, "AddNew", FieldList, Values);
|
||||
public void setMaxRecords(int pl) {
|
||||
Dispatch.put(this, "MaxRecords", new Variant(pl));
|
||||
}
|
||||
|
||||
public void CancelUpdate()
|
||||
{
|
||||
Dispatch.call(this, "CancelUpdate");
|
||||
public int getRecordCount() {
|
||||
return Dispatch.get(this, "RecordCount").getInt();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
Dispatch.call(this, "Close");
|
||||
public void setSource(Object pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public void Delete(int AffectRecords)
|
||||
{
|
||||
Dispatch.call(this, "Delete", new Variant(AffectRecords));
|
||||
public void setSource(String pvSource) {
|
||||
Dispatch.put(this, "Source", pvSource);
|
||||
}
|
||||
|
||||
public Variant GetRows(int Rows, Variant Start, Variant Fields)
|
||||
{
|
||||
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
|
||||
public Variant getSource() {
|
||||
return Dispatch.get(this, "Source");
|
||||
}
|
||||
|
||||
public void AddNew(Variant FieldList, Variant Values) {
|
||||
Dispatch.call(this, "AddNew", FieldList, Values);
|
||||
}
|
||||
|
||||
public void CancelUpdate() {
|
||||
Dispatch.call(this, "CancelUpdate");
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
Dispatch.call(this, "Close");
|
||||
}
|
||||
|
||||
public void Delete(int AffectRecords) {
|
||||
Dispatch.call(this, "Delete", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public Variant GetRows(int Rows, Variant Start, Variant Fields) {
|
||||
return Dispatch.call(this, "GetRows", new Variant(Rows), Start, Fields);
|
||||
}
|
||||
|
||||
// get all rows
|
||||
public Variant GetRows()
|
||||
{
|
||||
return Dispatch.call(this, "GetRows");
|
||||
public Variant GetRows() {
|
||||
return Dispatch.call(this, "GetRows");
|
||||
}
|
||||
|
||||
public void Move(int NumRecords, Variant Start)
|
||||
{
|
||||
Dispatch.call(this, "Move", new Variant(NumRecords), Start);
|
||||
public void Move(int NumRecords, Variant Start) {
|
||||
Dispatch.call(this, "Move", new Variant(NumRecords), Start);
|
||||
}
|
||||
|
||||
public void MoveNext()
|
||||
{
|
||||
Dispatch.call(this, "MoveNext");
|
||||
public void MoveNext() {
|
||||
Dispatch.call(this, "MoveNext");
|
||||
}
|
||||
|
||||
public void MovePrevious()
|
||||
{
|
||||
Dispatch.call(this, "MovePrevious");
|
||||
public void MovePrevious() {
|
||||
Dispatch.call(this, "MovePrevious");
|
||||
}
|
||||
|
||||
public void MoveFirst()
|
||||
{
|
||||
Dispatch.call(this, "MoveFirst");
|
||||
public void MoveFirst() {
|
||||
Dispatch.call(this, "MoveFirst");
|
||||
}
|
||||
|
||||
public void MoveLast()
|
||||
{
|
||||
Dispatch.call(this, "MoveLast");
|
||||
public void MoveLast() {
|
||||
Dispatch.call(this, "MoveLast");
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection, int CursorType, int LockType, int Options)
|
||||
{
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(CursorType), new Variant(LockType), new Variant(Options));
|
||||
public void Open(Variant Source, Variant ActiveConnection, int CursorType,
|
||||
int LockType, int Options) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection, new Variant(
|
||||
CursorType), new Variant(LockType), new Variant(Options));
|
||||
}
|
||||
|
||||
public void Open(Variant Source, Variant ActiveConnection)
|
||||
{
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection);
|
||||
public void Open(Variant Source, Variant ActiveConnection) {
|
||||
Dispatch.call(this, "Open", Source, ActiveConnection);
|
||||
}
|
||||
|
||||
public void Requery(int Options)
|
||||
{
|
||||
Dispatch.call(this, "Requery", new Variant(Options));
|
||||
public void Requery(int Options) {
|
||||
Dispatch.call(this, "Requery", new Variant(Options));
|
||||
}
|
||||
|
||||
public void Update(Variant Fields, Variant Values)
|
||||
{
|
||||
Dispatch.call(this, "Update", Fields, Values);
|
||||
public void Update(Variant Fields, Variant Values) {
|
||||
Dispatch.call(this, "Update", Fields, Values);
|
||||
}
|
||||
|
||||
public int getAbsolutePage()
|
||||
{
|
||||
return Dispatch.get(this, "AbsolutePage").getInt();
|
||||
public int getAbsolutePage() {
|
||||
return Dispatch.get(this, "AbsolutePage").getInt();
|
||||
}
|
||||
|
||||
public void setAbsolutePage(int pl)
|
||||
{
|
||||
Dispatch.put(this, "AbsolutePage", new Variant(pl));
|
||||
public void setAbsolutePage(int pl) {
|
||||
Dispatch.put(this, "AbsolutePage", new Variant(pl));
|
||||
}
|
||||
|
||||
public int getEditMode()
|
||||
{
|
||||
return Dispatch.get(this, "EditMode").getInt();
|
||||
public int getEditMode() {
|
||||
return Dispatch.get(this, "EditMode").getInt();
|
||||
}
|
||||
|
||||
public Variant getFilter()
|
||||
{
|
||||
return Dispatch.get(this, "Filter");
|
||||
public Variant getFilter() {
|
||||
return Dispatch.get(this, "Filter");
|
||||
}
|
||||
|
||||
public void setFilter(Variant Criteria)
|
||||
{
|
||||
Dispatch.put(this, "Filter", Criteria);
|
||||
public void setFilter(Variant Criteria) {
|
||||
Dispatch.put(this, "Filter", Criteria);
|
||||
}
|
||||
|
||||
public int getPageCount()
|
||||
{
|
||||
return Dispatch.get(this, "PageCount").getInt();
|
||||
public int getPageCount() {
|
||||
return Dispatch.get(this, "PageCount").getInt();
|
||||
}
|
||||
|
||||
public int getPageSize()
|
||||
{
|
||||
return Dispatch.get(this, "PageSize").getInt();
|
||||
public int getPageSize() {
|
||||
return Dispatch.get(this, "PageSize").getInt();
|
||||
}
|
||||
|
||||
public void setPageSize(int pl)
|
||||
{
|
||||
Dispatch.put(this, "PageSize", new Variant(pl));
|
||||
public void setPageSize(int pl) {
|
||||
Dispatch.put(this, "PageSize", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getSort()
|
||||
{
|
||||
return Dispatch.get(this, "Sort").toString();
|
||||
public String getSort() {
|
||||
return Dispatch.get(this, "Sort").toString();
|
||||
}
|
||||
|
||||
public void setSort(String Criteria)
|
||||
{
|
||||
Dispatch.put(this, "Sort", Criteria);
|
||||
public void setSort(String Criteria) {
|
||||
Dispatch.put(this, "Sort", Criteria);
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return Dispatch.get(this, "Status").getInt();
|
||||
public int getStatus() {
|
||||
return Dispatch.get(this, "Status").getInt();
|
||||
}
|
||||
|
||||
public int getState()
|
||||
{
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
public int getState() {
|
||||
return Dispatch.get(this, "State").getInt();
|
||||
}
|
||||
|
||||
public void UpdateBatch(int AffectRecords)
|
||||
{
|
||||
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
|
||||
public void UpdateBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "UpdateBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public void CancelBatch(int AffectRecords)
|
||||
{
|
||||
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
|
||||
public void CancelBatch(int AffectRecords) {
|
||||
Dispatch.call(this, "CancelBatch", new Variant(AffectRecords));
|
||||
}
|
||||
|
||||
public int getCursorLocation()
|
||||
{
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
public int getCursorLocation() {
|
||||
return Dispatch.get(this, "CursorLocation").getInt();
|
||||
}
|
||||
|
||||
public void setCursorLocation(int pl)
|
||||
{
|
||||
Dispatch.put(this, "CursorLocation", new Variant(pl));
|
||||
public void setCursorLocation(int pl) {
|
||||
Dispatch.put(this, "CursorLocation", new Variant(pl));
|
||||
}
|
||||
|
||||
public Recordset NextRecordset(Variant RecordsAffected)
|
||||
{
|
||||
return new Recordset(Dispatch.call(this, "NextRecordset", RecordsAffected).toDispatch());
|
||||
public Recordset NextRecordset(Variant RecordsAffected) {
|
||||
return new Recordset(Dispatch.call(this, "NextRecordset",
|
||||
RecordsAffected).toDispatch());
|
||||
}
|
||||
|
||||
public boolean Supports(int CursorOptions)
|
||||
{
|
||||
return Dispatch.call(this, "Supports", new Variant(CursorOptions)).getBoolean();
|
||||
public boolean Supports(int CursorOptions) {
|
||||
return Dispatch.call(this, "Supports", new Variant(CursorOptions))
|
||||
.getBoolean();
|
||||
}
|
||||
|
||||
public Variant getCollect(Variant Index)
|
||||
{
|
||||
return Dispatch.get(this, "Collect");
|
||||
public Variant getCollect(Variant Index) {
|
||||
return Dispatch.get(this, "Collect");
|
||||
}
|
||||
|
||||
public void setCollect(Variant Index, Variant pvar)
|
||||
{
|
||||
Dispatch.call(this, "Collect", Index, pvar);
|
||||
public void setCollect(Variant Index, Variant pvar) {
|
||||
Dispatch.call(this, "Collect", Index, pvar);
|
||||
}
|
||||
|
||||
public int getMarshalOptions()
|
||||
{
|
||||
return Dispatch.get(this, "MarshalOptions").getInt();
|
||||
public int getMarshalOptions() {
|
||||
return Dispatch.get(this, "MarshalOptions").getInt();
|
||||
}
|
||||
|
||||
public void setMarshalOptions(int pl)
|
||||
{
|
||||
Dispatch.put(this, "MarshalOptions", new Variant(pl));
|
||||
}
|
||||
|
||||
public void Find(String Criteria, int SkipRecords, int SearchDirection, Variant Start)
|
||||
{
|
||||
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords), new Variant(SearchDirection), Start);
|
||||
public void setMarshalOptions(int pl) {
|
||||
Dispatch.put(this, "MarshalOptions", new Variant(pl));
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Dispatch.call(this, "Cancel");
|
||||
public void Find(String Criteria, int SkipRecords, int SearchDirection,
|
||||
Variant Start) {
|
||||
Dispatch.call(this, "Find", Criteria, new Variant(SkipRecords),
|
||||
new Variant(SearchDirection), Start);
|
||||
}
|
||||
|
||||
public Variant getDataSource()
|
||||
{
|
||||
return Dispatch.get(this, "DataSource");
|
||||
public void Cancel() {
|
||||
Dispatch.call(this, "Cancel");
|
||||
}
|
||||
|
||||
public void setDataSource(Variant ppunkDataSource)
|
||||
{
|
||||
Dispatch.put(this, "DataSource", ppunkDataSource);
|
||||
public Variant getDataSource() {
|
||||
return Dispatch.get(this, "DataSource");
|
||||
}
|
||||
|
||||
public void Save(String FileName, int PersistFormat)
|
||||
{
|
||||
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
|
||||
public void setDataSource(Variant ppunkDataSource) {
|
||||
Dispatch.put(this, "DataSource", ppunkDataSource);
|
||||
}
|
||||
|
||||
public Variant getActiveCommand()
|
||||
{
|
||||
return Dispatch.get(this, "ActiveCommand");
|
||||
public void Save(String FileName, int PersistFormat) {
|
||||
Dispatch.call(this, "Save", FileName, new Variant(PersistFormat));
|
||||
}
|
||||
|
||||
public void setStayInSync(boolean pb)
|
||||
{
|
||||
Dispatch.put(this, "StayInSync", new Variant(pb));
|
||||
public Variant getActiveCommand() {
|
||||
return Dispatch.get(this, "ActiveCommand");
|
||||
}
|
||||
|
||||
public boolean getStayInSync()
|
||||
{
|
||||
return Dispatch.get(this, "StayInSync").getBoolean();
|
||||
public void setStayInSync(boolean pb) {
|
||||
Dispatch.put(this, "StayInSync", new Variant(pb));
|
||||
}
|
||||
|
||||
public String GetString(int StringFormat, int NumRows, String ColumnDelimeter, String RowDelimeter, String NullExpr)
|
||||
{
|
||||
return Dispatch.call(this, "GetString", new Variant(StringFormat),
|
||||
new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr).toString();
|
||||
public boolean getStayInSync() {
|
||||
return Dispatch.get(this, "StayInSync").getBoolean();
|
||||
}
|
||||
|
||||
public String getDataMember()
|
||||
{
|
||||
return Dispatch.get(this, "DataMember").toString();
|
||||
public String GetString(int StringFormat, int NumRows,
|
||||
String ColumnDelimeter, String RowDelimeter, String NullExpr) {
|
||||
return Dispatch.call(this, "GetString", new Variant(StringFormat),
|
||||
new Variant(NumRows), ColumnDelimeter, RowDelimeter, NullExpr)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public void setDataMember(String pl)
|
||||
{
|
||||
Dispatch.put(this, "DataMember", new Variant(pl));
|
||||
public String getDataMember() {
|
||||
return Dispatch.get(this, "DataMember").toString();
|
||||
}
|
||||
|
||||
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2)
|
||||
{
|
||||
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2).getInt();
|
||||
public void setDataMember(String pl) {
|
||||
Dispatch.put(this, "DataMember", new Variant(pl));
|
||||
}
|
||||
|
||||
public Recordset Clone(int LockType)
|
||||
{
|
||||
return new Recordset(Dispatch.call(this, "Clone",
|
||||
new Variant(LockType)).toDispatch());
|
||||
public int CompareBookmarks(Variant Bookmark1, Variant Bookmark2) {
|
||||
return Dispatch.call(this, "CompareBookmarks", Bookmark1, Bookmark2)
|
||||
.getInt();
|
||||
}
|
||||
|
||||
public void Resync(int AffectRecords, int ResyncValues)
|
||||
{
|
||||
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(ResyncValues));
|
||||
public Recordset Clone(int LockType) {
|
||||
return new Recordset(Dispatch
|
||||
.call(this, "Clone", new Variant(LockType)).toDispatch());
|
||||
}
|
||||
|
||||
public void Seek(Variant KeyValues, int SeekOption)
|
||||
{
|
||||
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
|
||||
public void Resync(int AffectRecords, int ResyncValues) {
|
||||
Dispatch.call(this, "Resync", new Variant(AffectRecords), new Variant(
|
||||
ResyncValues));
|
||||
}
|
||||
|
||||
public void setIndex(String pl)
|
||||
{
|
||||
Dispatch.put(this, "Index", new Variant(pl));
|
||||
public void Seek(Variant KeyValues, int SeekOption) {
|
||||
Dispatch.call(this, "Seek", KeyValues, new Variant(SeekOption));
|
||||
}
|
||||
|
||||
public String getIndex()
|
||||
{
|
||||
return Dispatch.get(this, "Index)").toString();
|
||||
public void setIndex(String pl) {
|
||||
Dispatch.put(this, "Index", new Variant(pl));
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
return Dispatch.get(this, "Index)").toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,56 @@
|
||||
package com.jacob.samples.ado;
|
||||
import com.jacob.com.*;
|
||||
|
||||
public class test
|
||||
{
|
||||
public static void printRS(Recordset rs)
|
||||
{
|
||||
Fields fs = rs.getFields();
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
for (int i=0;i<fs.getCount();i++)
|
||||
{
|
||||
System.out.print(fs.getItem(i).getName() + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
public class test {
|
||||
public static void printRS(Recordset rs) {
|
||||
Fields fs = rs.getFields();
|
||||
|
||||
rs.MoveFirst();
|
||||
while (!rs.getEOF())
|
||||
{
|
||||
for(int i=0;i<fs.getCount();i++)
|
||||
{
|
||||
Field f = fs.getItem(i);
|
||||
Variant v = f.getValue();
|
||||
System.out.print(v + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
rs.MoveNext();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
System.out.print(fs.getItem(i).getName() + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
rs.MoveFirst();
|
||||
while (!rs.getEOF()) {
|
||||
for (int i = 0; i < fs.getCount(); i++) {
|
||||
Field f = fs.getItem(i);
|
||||
Variant v = f.getValue();
|
||||
System.out.print(v + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
rs.MoveNext();
|
||||
}
|
||||
}
|
||||
|
||||
// open a recordset directly
|
||||
public static void getRS(String con, String query)
|
||||
{
|
||||
System.out.println("Recordset Open");
|
||||
public static void getRS(String con, String query) {
|
||||
System.out.println("Recordset Open");
|
||||
Recordset rs = new Recordset();
|
||||
rs.Open(new Variant(query), new Variant(con));
|
||||
printRS(rs);
|
||||
printRS(rs);
|
||||
}
|
||||
|
||||
// create connection and command objects and use them
|
||||
// to get a recordset
|
||||
public static void getCommand(String con, String query)
|
||||
{
|
||||
System.out.println("Command+Connection -> Recordset");
|
||||
Connection c = new Connection();
|
||||
c.setConnectionString(con);
|
||||
c.Open();
|
||||
Command comm = new Command();
|
||||
comm.setActiveConnection(c);
|
||||
comm.setCommandType(CommandTypeEnum.adCmdText);
|
||||
comm.setCommandText(query);
|
||||
Recordset rs = comm.Execute();
|
||||
printRS(rs);
|
||||
c.Close();
|
||||
public static void getCommand(String con, String query) {
|
||||
System.out.println("Command+Connection -> Recordset");
|
||||
Connection c = new Connection();
|
||||
c.setConnectionString(con);
|
||||
c.Open();
|
||||
Command comm = new Command();
|
||||
comm.setActiveConnection(c);
|
||||
comm.setCommandType(CommandTypeEnum.adCmdText);
|
||||
comm.setCommandText(query);
|
||||
Recordset rs = comm.Execute();
|
||||
printRS(rs);
|
||||
c.Close();
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
|
||||
String queryStr = "select * from authors";
|
||||
getCommand(connectStr, queryStr);
|
||||
getRS(connectStr, queryStr);
|
||||
public static void main(String[] args) {
|
||||
String connectStr = "DRIVER=SQL Server;SERVER=DANADLER;UID=sa;PWD=;WSID=DANADLER;DATABASE=pubs";
|
||||
String queryStr = "select * from authors";
|
||||
getCommand(connectStr, queryStr);
|
||||
getRS(connectStr, queryStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.jacob.samples.applet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.applet.*;
|
||||
import java.applet.Applet;
|
||||
import java.awt.Button;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Applet test case
|
||||
@@ -38,7 +42,9 @@ public class AppTest extends Applet implements ActionListener {
|
||||
|
||||
/**
|
||||
* action method that receives button actions
|
||||
* @param ev the event
|
||||
*
|
||||
* @param ev
|
||||
* the event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
if (sC == null) {
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
package com.jacob.samples.atl;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
class MultiFaceTest {
|
||||
|
||||
/**
|
||||
* standard main() test program
|
||||
*
|
||||
* @param args
|
||||
* the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// this method has been deprecated as being unreliable.
|
||||
// shutdown should be done through other means
|
||||
// whoever wrote this example should explain what this was intended to do
|
||||
//System.runFinalizersOnExit(true);
|
||||
// whoever wrote this example should explain what this was intended to
|
||||
// do
|
||||
// System.runFinalizersOnExit(true);
|
||||
|
||||
ActiveXComponent mf = new ActiveXComponent("MultiFace.Face");
|
||||
try {
|
||||
|
||||
@@ -1,46 +1,52 @@
|
||||
package com.jacob.samples.office;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Sample test program snagged out of a question on the sun discussion area.
|
||||
* <p>
|
||||
* May need to run with some command line options (including from inside Eclipse).
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
* May need to run with some command line options (including from inside
|
||||
* Eclipse). Look in the docs area at the Jacob usage document for command line
|
||||
* options.
|
||||
*/
|
||||
public class ExcelDispatchTest {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ComThread.InitSTA();
|
||||
|
||||
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
|
||||
try {
|
||||
System.out.println("version="+xl.getProperty("Version"));
|
||||
System.out.println("version="+Dispatch.get(xl, "Version"));
|
||||
Dispatch.put(xl, "Visible", new Variant(true));
|
||||
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
Dispatch workbook = Dispatch.get(workbooks,"Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] {"A1"},
|
||||
new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] {"A2"},
|
||||
new int[1]).toDispatch();
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("a1 from excel:"+Dispatch.get(a1, "Value"));
|
||||
System.out.println("a2 from excel:"+Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main run loop for test program
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
ComThread.InitSTA();
|
||||
|
||||
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
|
||||
try {
|
||||
System.out.println("version=" + xl.getProperty("Version"));
|
||||
System.out.println("version=" + Dispatch.get(xl, "Version"));
|
||||
Dispatch.put(xl, "Visible", new Variant(true));
|
||||
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A2" }, new int[1]).toDispatch();
|
||||
Dispatch.put(a1, "Value", "123.456");
|
||||
Dispatch.put(a2, "Formula", "=A1*2");
|
||||
System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
|
||||
System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
|
||||
Variant f = new Variant(false);
|
||||
Dispatch.call(workbook, "Close", f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
xl.invoke("Quit", new Variant[] {});
|
||||
ComThread.Release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import com.jacob.com.Dispatch;
|
||||
/**
|
||||
* Snippet to show Visio print dialog
|
||||
* <p>
|
||||
* Sample submitted by fatbuttlarry in SourceForge 1803140
|
||||
* as part of bug report
|
||||
* Sample submitted by fatbuttlarry in SourceForge 1803140 as part of bug report
|
||||
* <p>
|
||||
* Tested with Java 6.0SE and MS Office 2003 ** Note: 1010 = VB's
|
||||
* visCmdFilePrint constant
|
||||
@@ -26,8 +25,7 @@ public class VisioPrintTest {
|
||||
// create a blank document
|
||||
Dispatch.call(oDocuments, "Add", "");
|
||||
try {
|
||||
Dispatch.call(oActiveX, "DoCmd", new Integer(1010))
|
||||
.getInt();
|
||||
Dispatch.call(oActiveX, "DoCmd", new Integer(1010)).getInt();
|
||||
System.out.println("User hit the ok button.");
|
||||
} catch (ComFailException e) {
|
||||
System.out.println("User hit the cancel button: " + e);
|
||||
@@ -37,7 +35,12 @@ public class VisioPrintTest {
|
||||
return;
|
||||
}
|
||||
|
||||
/** quick main() to test this */
|
||||
/**
|
||||
* quick main() to test this
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
VisioPrintTest testObject = new VisioPrintTest();
|
||||
testObject.testPrintDialog();
|
||||
|
||||
@@ -14,150 +14,152 @@ import com.jacob.com.Variant;
|
||||
* are sections that could be enhanced
|
||||
*/
|
||||
public class WordDocumentProperties {
|
||||
//Declare word object
|
||||
private ActiveXComponent objWord;
|
||||
// Declare word object
|
||||
private ActiveXComponent objWord;
|
||||
|
||||
//Declare Word Properties
|
||||
private Dispatch custDocprops;
|
||||
// Declare Word Properties
|
||||
private Dispatch custDocprops;
|
||||
|
||||
private Dispatch builtInDocProps;
|
||||
private Dispatch builtInDocProps;
|
||||
|
||||
//the doucments object is important in any real app but this demo doesn't use it
|
||||
//private Dispatch documents;
|
||||
// the doucments object is important in any real app but this demo doesn't
|
||||
// use it
|
||||
// private Dispatch documents;
|
||||
|
||||
private Dispatch document;
|
||||
private Dispatch document;
|
||||
|
||||
private Dispatch wordObject;
|
||||
private Dispatch wordObject;
|
||||
|
||||
/**
|
||||
* Empty Constructor
|
||||
*
|
||||
*/
|
||||
public WordDocumentProperties() {
|
||||
}
|
||||
/**
|
||||
* Empty Constructor
|
||||
*
|
||||
*/
|
||||
public WordDocumentProperties() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a document
|
||||
*
|
||||
* @param filename
|
||||
*/
|
||||
public void open(String filename) {
|
||||
//Instantiate objWord
|
||||
objWord = new ActiveXComponent("Word.Application");
|
||||
/**
|
||||
* Opens a document
|
||||
*
|
||||
* @param filename
|
||||
*/
|
||||
public void open(String filename) {
|
||||
// Instantiate objWord
|
||||
objWord = new ActiveXComponent("Word.Application");
|
||||
|
||||
//Assign a local word object
|
||||
wordObject = objWord.getObject();
|
||||
// Assign a local word object
|
||||
wordObject = objWord.getObject();
|
||||
|
||||
//Create a Dispatch Parameter to hide the document that is opened
|
||||
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(false));
|
||||
// Create a Dispatch Parameter to hide the document that is opened
|
||||
Dispatch.put(wordObject, "Visible", new Variant(false));
|
||||
|
||||
//Instantiate the Documents Property
|
||||
Dispatch documents = objWord.getProperty("Documents").toDispatch();
|
||||
// Instantiate the Documents Property
|
||||
Dispatch documents = objWord.getProperty("Documents").toDispatch();
|
||||
|
||||
//Open a word document, Current Active Document
|
||||
document = Dispatch.call(documents, "Open", filename).toDispatch();
|
||||
}
|
||||
// Open a word document, Current Active Document
|
||||
document = Dispatch.call(documents, "Open", filename).toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA CustomDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectCustomDocumentProperitiesMode() {
|
||||
//Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
custDocprops = Dispatch.get(document, "CustomDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
/**
|
||||
* Creates an instance of the VBA CustomDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectCustomDocumentProperitiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
custDocprops = Dispatch.get(document, "CustomDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the VBA BuiltInDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectBuiltinPropertiesMode() {
|
||||
//Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
/**
|
||||
* Creates an instance of the VBA BuiltInDocumentProperties property
|
||||
*
|
||||
*/
|
||||
public void selectBuiltinPropertiesMode() {
|
||||
// Create CustomDocumentProperties and BuiltInDocumentProperties
|
||||
// properties
|
||||
builtInDocProps = Dispatch.get(document, "BuiltInDocumentProperties")
|
||||
.toDispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a document
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
//Close object
|
||||
Dispatch.call(document, "Close");
|
||||
}
|
||||
/**
|
||||
* Closes a document
|
||||
*
|
||||
*/
|
||||
public void close() {
|
||||
// Close object
|
||||
Dispatch.call(document, "Close");
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Property Name is passed in
|
||||
*
|
||||
* @param cusPropName
|
||||
* @return String - Custom property value
|
||||
*/
|
||||
public String getCustomProperty(String cusPropName) {
|
||||
try {
|
||||
cusPropName = Dispatch.call((Dispatch) custDocprops, "Item",
|
||||
cusPropName).toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
cusPropName = null;
|
||||
}
|
||||
/**
|
||||
* Custom Property Name is passed in
|
||||
*
|
||||
* @param cusPropName
|
||||
* @return String - Custom property value
|
||||
*/
|
||||
public String getCustomProperty(String cusPropName) {
|
||||
try {
|
||||
cusPropName = Dispatch.call(custDocprops, "Item", cusPropName)
|
||||
.toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
cusPropName = null;
|
||||
}
|
||||
|
||||
return cusPropName;
|
||||
}
|
||||
return cusPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Built In Property Name is passed in
|
||||
*
|
||||
* @param builtInPropName
|
||||
* @return String - Built in property value
|
||||
*/
|
||||
public String getBuiltInProperty(String builtInPropName) {
|
||||
try {
|
||||
builtInPropName = Dispatch.call((Dispatch) builtInDocProps, "Item",
|
||||
builtInPropName).toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
builtInPropName = null;
|
||||
}
|
||||
/**
|
||||
* Built In Property Name is passed in
|
||||
*
|
||||
* @param builtInPropName
|
||||
* @return String - Built in property value
|
||||
*/
|
||||
public String getBuiltInProperty(String builtInPropName) {
|
||||
try {
|
||||
builtInPropName = Dispatch.call(builtInDocProps, "Item",
|
||||
builtInPropName).toString();
|
||||
} catch (ComException e) {
|
||||
// Do nothing
|
||||
builtInPropName = null;
|
||||
}
|
||||
|
||||
return builtInPropName;
|
||||
}
|
||||
return builtInPropName;
|
||||
}
|
||||
|
||||
/**
|
||||
* simple main program that gets some properties and prints them out
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//Instantiate the class
|
||||
WordDocumentProperties jacTest = new WordDocumentProperties();
|
||||
/**
|
||||
* simple main program that gets some properties and prints them out
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Instantiate the class
|
||||
WordDocumentProperties jacTest = new WordDocumentProperties();
|
||||
|
||||
//Open the word doc
|
||||
jacTest.open("\\\\Saturn\\documentstorage\\s.doc");
|
||||
// Open the word doc
|
||||
jacTest.open("\\\\Saturn\\documentstorage\\s.doc");
|
||||
|
||||
//Set Custom Properties
|
||||
jacTest.selectCustomDocumentProperitiesMode();
|
||||
// Set Custom Properties
|
||||
jacTest.selectCustomDocumentProperitiesMode();
|
||||
|
||||
//Set Built In Properties
|
||||
jacTest.selectBuiltinPropertiesMode();
|
||||
// Set Built In Properties
|
||||
jacTest.selectBuiltinPropertiesMode();
|
||||
|
||||
//Get custom Property Value
|
||||
String custValue = jacTest.getCustomProperty("Information Source");
|
||||
// Get custom Property Value
|
||||
String custValue = jacTest.getCustomProperty("Information Source");
|
||||
|
||||
//Get built in prroperty Property Value
|
||||
String builtInValue = jacTest.getBuiltInProperty("Author");
|
||||
// Get built in prroperty Property Value
|
||||
String builtInValue = jacTest.getBuiltInProperty("Author");
|
||||
|
||||
//Close Word Doc
|
||||
jacTest.close();
|
||||
// Close Word Doc
|
||||
jacTest.close();
|
||||
|
||||
//Output data
|
||||
System.out.println("Document Val One: " + custValue);
|
||||
System.out.println("Document Author: " + builtInValue);
|
||||
// Output data
|
||||
System.out.println("Document Val One: " + custValue);
|
||||
System.out.println("Document Author: " + builtInValue);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,65 +5,76 @@ package com.jacob.samples.outlook;
|
||||
* Christopher Brind <christopher.brind@morse.com>
|
||||
*/
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* sample class to show simple outlook manipulation
|
||||
*/
|
||||
public class Outlook {
|
||||
|
||||
private static String pad(int i) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
private static String pad(int i) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while(sb.length() < i) {
|
||||
sb.append(' ');
|
||||
}
|
||||
while (sb.length() < i) {
|
||||
sb.append(' ');
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void recurseFolders(int iIndent, Dispatch o) {
|
||||
|
||||
private static void recurseFolders(int iIndent, Dispatch o) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
|
||||
// System.out.println("oFolders=" + oFolders);
|
||||
if (oFolders == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (o == null) return;
|
||||
Dispatch oFolders = Dispatch.get(o, "Folders").toDispatch();
|
||||
// System.out.println("oFolders=" + oFolders);
|
||||
if (oFolders == null) return;
|
||||
Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
|
||||
do {
|
||||
Object oFolderName = Dispatch.get(oFolder, "Name");
|
||||
if (null == oFolderName) {
|
||||
break;
|
||||
}
|
||||
|
||||
Dispatch oFolder = Dispatch.get(oFolders, "GetFirst").toDispatch();
|
||||
do {
|
||||
Object oFolderName = Dispatch.get(oFolder, "Name");
|
||||
if (null == oFolderName) {
|
||||
break;
|
||||
}
|
||||
System.out.println(pad(iIndent) + oFolderName);
|
||||
recurseFolders(iIndent + 3, oFolder);
|
||||
|
||||
System.out.println(pad(iIndent) + oFolderName);
|
||||
recurseFolders(iIndent + 3, oFolder);
|
||||
oFolder = Dispatch.get(oFolders, "GetNext").toDispatch();
|
||||
} while (true);
|
||||
|
||||
oFolder = Dispatch.get(oFolders, "GetNext").toDispatch();
|
||||
} while(true);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* standard run loop
|
||||
*
|
||||
* @param asArgs
|
||||
* command line arguments
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void main(String asArgs[]) throws Exception {
|
||||
System.out.println("Outlook: IN");
|
||||
|
||||
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
|
||||
try {
|
||||
System.out.println("version=" + axOutlook.getProperty("Version"));
|
||||
|
||||
public static void main(String asArgs[]) throws Exception {
|
||||
System.out.println("Outlook: IN");
|
||||
Dispatch oOutlook = axOutlook.getObject();
|
||||
System.out.println("version=" + Dispatch.get(oOutlook, "Version"));
|
||||
|
||||
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
|
||||
try {
|
||||
System.out.println("version="+axOutlook.getProperty("Version"));
|
||||
Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
|
||||
System.out.println("oNameSpace=" + oNameSpace);
|
||||
|
||||
Dispatch oOutlook = axOutlook.getObject();
|
||||
System.out.println("version="+Dispatch.get(oOutlook, "Version"));
|
||||
recurseFolders(0, oNameSpace);
|
||||
|
||||
Dispatch oNameSpace = axOutlook.getProperty("Session").toDispatch();
|
||||
System.out.println("oNameSpace=" + oNameSpace);
|
||||
|
||||
recurseFolders(0, oNameSpace);
|
||||
|
||||
} finally {
|
||||
axOutlook.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
axOutlook.invoke("Quit", new Variant[] {});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,41 +10,49 @@ import com.jacob.com.Variant;
|
||||
/**
|
||||
* Example VB script that grabs hard drive properties.
|
||||
* <p>
|
||||
* Source Forge posting http://sourceforge.net/forum/forum.php?thread_id=1785936&forum_id=375946
|
||||
* Source Forge posting
|
||||
* http://sourceforge.net/forum/forum.php?thread_id=1785936&forum_id=375946
|
||||
* <p>
|
||||
* Enhance by clay_shooter with info from http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx
|
||||
* Enhance by clay_shooter with info from
|
||||
* http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx
|
||||
*
|
||||
* @author qstephenson
|
||||
*
|
||||
* @author qstephenson
|
||||
*
|
||||
*/
|
||||
public class DiskUtils {
|
||||
|
||||
/** formatters aren't thread safe but the sample only has one thread */
|
||||
private static DecimalFormat sizeFormatter = new DecimalFormat("###,###,###,###");
|
||||
private static DecimalFormat sizeFormatter = new DecimalFormat(
|
||||
"###,###,###,###");
|
||||
|
||||
/** a pointer to the scripting file system object */
|
||||
private ActiveXComponent fileSystemApp = null;
|
||||
|
||||
|
||||
/** the dispatch that points at the drive this DiskUtil operates against */
|
||||
private Dispatch myDrive = null;
|
||||
|
||||
|
||||
/**
|
||||
* Standard constructor
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against.
|
||||
*/
|
||||
public DiskUtils(String drive){
|
||||
public DiskUtils(String drive) {
|
||||
setUp(drive);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* open the connection to the scripting object
|
||||
*
|
||||
* @param drive
|
||||
* the drive to run the test against
|
||||
*/
|
||||
public void setUp(String drive){
|
||||
if (fileSystemApp == null){
|
||||
ComThread.InitSTA();
|
||||
fileSystemApp = new ActiveXComponent(
|
||||
"Scripting.FileSystemObject");
|
||||
public void setUp(String drive) {
|
||||
if (fileSystemApp == null) {
|
||||
ComThread.InitSTA();
|
||||
fileSystemApp = new ActiveXComponent("Scripting.FileSystemObject");
|
||||
myDrive = Dispatch.call(fileSystemApp, "GetDrive", drive)
|
||||
.toDispatch();
|
||||
.toDispatch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,58 +62,61 @@ public class DiskUtils {
|
||||
public void tearDown() {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convenience method
|
||||
*
|
||||
* @return driver serial number
|
||||
*/
|
||||
public int getSerialNumber() {
|
||||
return Dispatch.get(myDrive, "SerialNumber").getInt();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
* We go through these formatting hoops so we can make the size string pretty.
|
||||
* We wouldn't have to do that if we didn't mind long strings with Exxx at the end
|
||||
* or the fact that the value returned can vary in size based on the size of the disk.
|
||||
* Convenience method. We go through these formatting hoops so we can make
|
||||
* the size string pretty. We wouldn't have to do that if we didn't mind
|
||||
* long strings with Exxx at the end or the fact that the value returned can
|
||||
* vary in size based on the size of the disk.
|
||||
*
|
||||
* @return driver total size of the disk
|
||||
*/
|
||||
public String getTotalSize() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "TotalSize");
|
||||
if (returnValue.getvt() == Variant.VariantDouble){
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt){
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: "+returnValue.getvt();
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
* We wouldn't have to do that if we didn't mind long strings with Exxx at the end
|
||||
* or the fact that the value returned can vary in size based on the size of the disk.
|
||||
* Convenience method. We wouldn't have to do that if we didn't mind long
|
||||
* strings with Exxx at the end or the fact that the value returned can vary
|
||||
* in size based on the size of the disk.
|
||||
*
|
||||
* @return driver free size of the disk
|
||||
*/
|
||||
public String getFreeSpace() {
|
||||
Variant returnValue = Dispatch.get(myDrive, "FreeSpace");
|
||||
if (returnValue.getvt() == Variant.VariantDouble){
|
||||
if (returnValue.getvt() == Variant.VariantDouble) {
|
||||
return sizeFormatter.format(returnValue.getDouble());
|
||||
} else if (returnValue.getvt() == Variant.VariantInt){
|
||||
} else if (returnValue.getvt() == Variant.VariantInt) {
|
||||
return sizeFormatter.format(returnValue.getInt());
|
||||
} else {
|
||||
return "Don't know type: "+returnValue.getvt();
|
||||
return "Don't know type: " + returnValue.getvt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return file system on the drive
|
||||
*/
|
||||
public String getFileSystemType() {
|
||||
//figure ot the actual variant type
|
||||
//Variant returnValue = Dispatch.get(myDrive, "FileSystem");
|
||||
//System.out.println(returnValue.getvt());
|
||||
// figure ot the actual variant type
|
||||
// Variant returnValue = Dispatch.get(myDrive, "FileSystem");
|
||||
// System.out.println(returnValue.getvt());
|
||||
return Dispatch.get(myDrive, "FileSystem").getString();
|
||||
}
|
||||
|
||||
@@ -116,17 +127,26 @@ public class DiskUtils {
|
||||
public String getVolumeName() {
|
||||
return Dispatch.get(myDrive, "VolumeName").getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple main program that creates a DiskUtils object and queries for the C: drive
|
||||
* Simple main program that creates a DiskUtils object and queries for the
|
||||
* C: drive
|
||||
*
|
||||
* @param args
|
||||
* standard command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//DiskUtils utilConnection = new DiskUtils("F");
|
||||
// DiskUtils utilConnection = new DiskUtils("F");
|
||||
DiskUtils utilConnection = new DiskUtils("C");
|
||||
System.out.println("Disk serial number is: "+ utilConnection.getSerialNumber());
|
||||
System.out.println("FileSystem is: "+ utilConnection.getFileSystemType());
|
||||
System.out.println("Volume Name is: "+ utilConnection.getVolumeName());
|
||||
System.out.println("Disk total size is: "+ utilConnection.getTotalSize());
|
||||
System.out.println("Disk free space is: "+ utilConnection.getFreeSpace());
|
||||
System.out.println("Disk serial number is: "
|
||||
+ utilConnection.getSerialNumber());
|
||||
System.out.println("FileSystem is: "
|
||||
+ utilConnection.getFileSystemType());
|
||||
System.out.println("Volume Name is: " + utilConnection.getVolumeName());
|
||||
System.out.println("Disk total size is: "
|
||||
+ utilConnection.getTotalSize());
|
||||
System.out.println("Disk free space is: "
|
||||
+ utilConnection.getFreeSpace());
|
||||
utilConnection.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,27 @@ import com.jacob.com.Variant;
|
||||
* fold, spindled and mutilated by clay_shooter
|
||||
*
|
||||
* @author chris_knowles
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SystemMonitor {
|
||||
|
||||
/**
|
||||
* example run loop method called by main()
|
||||
*/
|
||||
public void runMonitor() {
|
||||
|
||||
ActiveXComponent wmi = null;
|
||||
wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
|
||||
// no connection parameters means to connect to the local machine
|
||||
Variant conRet = wmi.invoke("ConnectServer");
|
||||
// the author liked the ActiveXComponent api style over the Dispatch style
|
||||
// the author liked the ActiveXComponent api style over the Dispatch
|
||||
// style
|
||||
ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch());
|
||||
|
||||
// the WMI supports a query language.
|
||||
String query = "select CategoryString, Message, TimeGenerated, User, Type "
|
||||
+ "from Win32_NtLogEvent "
|
||||
+ "where Logfile = 'Application' and TimeGenerated > '20070915000000.000000-***'";
|
||||
+ "from Win32_NtLogEvent "
|
||||
+ "where Logfile = 'Application' and TimeGenerated > '20070915000000.000000-***'";
|
||||
Variant vCollection = wmiconnect
|
||||
.invoke("ExecQuery", new Variant(query));
|
||||
|
||||
@@ -40,7 +44,7 @@ public class SystemMonitor {
|
||||
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
resultString = "";
|
||||
item = enumVariant.Next().toDispatch();
|
||||
item = enumVariant.nextElement().toDispatch();
|
||||
String categoryString = Dispatch.call(item, "CategoryString")
|
||||
.toString();
|
||||
String messageString = Dispatch.call(item, "Message").toString();
|
||||
@@ -48,17 +52,21 @@ public class SystemMonitor {
|
||||
.toString();
|
||||
String eventUser = Dispatch.call(item, "User").toString();
|
||||
String eventType = Dispatch.call(item, "Type").toString();
|
||||
resultString += "TimeGenerated: "+ timeGenerated
|
||||
+ " Category: " + categoryString
|
||||
+ " User: " + eventUser
|
||||
+ " EventType: "+ eventType
|
||||
+ " Message:" + messageString;
|
||||
resultString += "TimeGenerated: " + timeGenerated + " Category: "
|
||||
+ categoryString + " User: " + eventUser + " EventType: "
|
||||
+ eventType + " Message:" + messageString;
|
||||
System.out.println(resultString);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sample's main program
|
||||
*
|
||||
* @param args
|
||||
* command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SystemMonitor utilConnection = new SystemMonitor();
|
||||
utilConnection.runMonitor();
|
||||
|
||||
@@ -1,85 +1,121 @@
|
||||
package com.jacob.samples.visio;
|
||||
|
||||
import com.jacob.com.*;
|
||||
import com.jacob.activeX.*;
|
||||
import java.io.File;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.DispatchEvents;
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
*
|
||||
*
|
||||
* This class represents the visio app itself
|
||||
*/
|
||||
public class VisioApp extends ActiveXComponent {
|
||||
|
||||
/**
|
||||
* constructor that spins up Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public VisioApp() throws VisioException {
|
||||
super("Visio.Application");
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
public VisioApp() throws VisioException {
|
||||
super("Visio.Application");
|
||||
setVisible(false);
|
||||
}
|
||||
/**
|
||||
* creates a DispatchEvents object to register o as a listener
|
||||
*
|
||||
* @param o
|
||||
*/
|
||||
public void addEventListener(VisioEventListener o) {
|
||||
DispatchEvents events = new DispatchEvents(this, o);
|
||||
if (events == null) {
|
||||
System.out
|
||||
.println("You should never get null back when creating a DispatchEvents object");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a DispatchEvents boject to register o as a listener
|
||||
* @param o
|
||||
*/
|
||||
public void addEventListener(VisioEventListener o) {
|
||||
DispatchEvents events = new DispatchEvents(this, o);
|
||||
if (events == null){
|
||||
System.out.println("You should never get null back when creating a DispatchEvents object");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* opens the passed in file in Visio
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void open(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent documents = new ActiveXComponent(getProperty(
|
||||
"Documents").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
documents.invoke("Open", args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* tells Visio to save the drawing
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void save() throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Save");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void open(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent documents = new ActiveXComponent(getProperty("Documents").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
documents.invoke("Open",args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* terminates Visio
|
||||
*/
|
||||
public void quit() {
|
||||
System.out.println("Received quit()");
|
||||
// there can't be any open documents for this to work
|
||||
// you'll get a visio error if you don't close them
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActiveDocument").toDispatch());
|
||||
document.invoke("Close");
|
||||
invoke("Quit");
|
||||
}
|
||||
|
||||
public void save() throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty("ActiveDocument").toDispatch());
|
||||
document.invoke("Save");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* runs the Visio export command
|
||||
*
|
||||
* @param f
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void export(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty(
|
||||
"ActivePage").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
document.invoke("Export", args);
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* terminates visio
|
||||
*/
|
||||
public void quit() {
|
||||
System.out.println("Received quit()");
|
||||
// there can't be any open documents for this to work
|
||||
// you'll get a visio error if you don't close them
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty("ActiveDocument").toDispatch());
|
||||
document.invoke("Close");
|
||||
invoke("Quit");
|
||||
}
|
||||
|
||||
public void export(File f) throws VisioException {
|
||||
try {
|
||||
ActiveXComponent document = new ActiveXComponent(getProperty("ActivePage").toDispatch());
|
||||
Variant[] args = new Variant[1];
|
||||
args[0] = new Variant(f.getPath());
|
||||
document.invoke("Export",args);
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisible(boolean b) throws VisioException {
|
||||
try {
|
||||
setProperty("Visible",new Variant(b));
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* makes Visio visible so the user can watch
|
||||
*
|
||||
* @param b
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void setVisible(boolean b) throws VisioException {
|
||||
try {
|
||||
setProperty("Visible", new Variant(b));
|
||||
} catch (Exception e) {
|
||||
throw new VisioException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,120 +1,180 @@
|
||||
package com.jacob.samples.visio;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
*
|
||||
*
|
||||
* This singleton isolates the demo app from the Visio instance object so that
|
||||
* you can't try and send messages to a dead Visio instance after quit() has been
|
||||
* called. Direct consumption of VisioApp would mean you could quit but would
|
||||
* still have a handle to the no longer connected application proxy
|
||||
* you can't try and send messages to a dead Visio instance after quit() has
|
||||
* been called. Direct consumption of VisioApp would mean you could quit but
|
||||
* would still have a handle to the no longer connected application proxy
|
||||
*
|
||||
*/
|
||||
public class VisioAppFacade {
|
||||
|
||||
private VisioApp app;
|
||||
private static VisioAppFacade instance;
|
||||
|
||||
private VisioApp app;
|
||||
private static VisioAppFacade instance;
|
||||
/** extension for image files */
|
||||
public static final String IMAGE_EXT = ".jpg";
|
||||
/** extension for visio files */
|
||||
public static final String VISIO_EXT = ".vsd";
|
||||
/** the buffer size when we want to read stuff in */
|
||||
public static final int BUFFER_SIZE = 2048;
|
||||
|
||||
public static final String IMAGE_EXT = ".jpg";
|
||||
public static final String VISIO_EXT = ".vsd";
|
||||
public static final int BUFFER_SIZE = 2048;
|
||||
|
||||
private VisioAppFacade() throws VisioException {
|
||||
this.app = new VisioApp();
|
||||
/**
|
||||
* Wrapper around Visio
|
||||
*
|
||||
* @throws VisioException
|
||||
*/
|
||||
private VisioAppFacade() throws VisioException {
|
||||
this.app = new VisioApp();
|
||||
app.addEventListener(new VisioEventAdapter(app));
|
||||
}
|
||||
}
|
||||
|
||||
public static VisioAppFacade getInstance() throws VisioException {
|
||||
if (instance == null) {
|
||||
instance = new VisioAppFacade();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* @return the singleton instance of Visio
|
||||
* @throws VisioException
|
||||
*/
|
||||
public static VisioAppFacade getInstance() throws VisioException {
|
||||
if (instance == null) {
|
||||
instance = new VisioAppFacade();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public byte[] createPreview(byte[] visioData) throws VisioException {
|
||||
byte[] preview;
|
||||
File tmpFile;
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
OutputStream out = new FileOutputStream(tmpFile);
|
||||
out.write(visioData);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
/**
|
||||
* creates a preview in a temp file and returns the raw data.
|
||||
*
|
||||
* @param visioData
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(byte[] visioData) throws VisioException {
|
||||
byte[] preview;
|
||||
File tmpFile;
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
OutputStream out = new FileOutputStream(tmpFile);
|
||||
out.write(visioData);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
|
||||
public byte[] createPreview(File visioFile) throws VisioException {
|
||||
try {
|
||||
File imageFile;
|
||||
imageFile = getTempImageFile();
|
||||
app.open(visioFile);
|
||||
app.export(imageFile);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
FileInputStream fin = new FileInputStream(imageFile);
|
||||
copy(fin, bout);
|
||||
fin.close();
|
||||
imageFile.delete();
|
||||
bout.close();
|
||||
return bout.toByteArray();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* reads a preview from a saved file
|
||||
*
|
||||
* @param visioFile
|
||||
* @return raw preview data
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(File visioFile) throws VisioException {
|
||||
try {
|
||||
File imageFile;
|
||||
imageFile = getTempImageFile();
|
||||
app.open(visioFile);
|
||||
app.export(imageFile);
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
FileInputStream fin = new FileInputStream(imageFile);
|
||||
copy(fin, bout);
|
||||
fin.close();
|
||||
imageFile.delete();
|
||||
bout.close();
|
||||
return bout.toByteArray();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buff = new byte[BUFFER_SIZE];
|
||||
int read;
|
||||
do {
|
||||
read = in.read(buff);
|
||||
if (read > 0) {
|
||||
out.write(buff,0,read);
|
||||
}
|
||||
} while (read > 0);
|
||||
}
|
||||
private void copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buff = new byte[BUFFER_SIZE];
|
||||
int read;
|
||||
do {
|
||||
read = in.read(buff);
|
||||
if (read > 0) {
|
||||
out.write(buff, 0, read);
|
||||
}
|
||||
} while (read > 0);
|
||||
}
|
||||
|
||||
public byte[] createPreview(InputStream in) throws VisioException {
|
||||
byte[] preview;
|
||||
//byte[] buff = new byte[2048];
|
||||
//int read = 0;
|
||||
OutputStream out;
|
||||
File tmpFile;
|
||||
/**
|
||||
* creates a preview from an input stream
|
||||
*
|
||||
* @param in
|
||||
* @return byte contents of the preview stream
|
||||
* @throws VisioException
|
||||
*/
|
||||
public byte[] createPreview(InputStream in) throws VisioException {
|
||||
byte[] preview;
|
||||
// byte[] buff = new byte[2048];
|
||||
// int read = 0;
|
||||
OutputStream out;
|
||||
File tmpFile;
|
||||
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
out = new FileOutputStream(tmpFile);
|
||||
copy(in, out);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
try {
|
||||
tmpFile = getTempVisioFile();
|
||||
out = new FileOutputStream(tmpFile);
|
||||
copy(in, out);
|
||||
out.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new VisioException(ioe);
|
||||
}
|
||||
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
preview = createPreview(tmpFile);
|
||||
tmpFile.delete();
|
||||
return preview;
|
||||
}
|
||||
|
||||
public void editDiagram(File f) throws VisioException {
|
||||
app.open(f);
|
||||
app.setVisible(true);
|
||||
}
|
||||
/**
|
||||
* opens the file in Visio and makes the editor visible
|
||||
*
|
||||
* @param f
|
||||
* the reference to the Visio file to be opened
|
||||
* @throws VisioException
|
||||
*/
|
||||
public void editDiagram(File f) throws VisioException {
|
||||
app.open(f);
|
||||
app.setVisible(true);
|
||||
}
|
||||
|
||||
private File getTempVisioFile() throws IOException {
|
||||
return File.createTempFile("java",VISIO_EXT);
|
||||
}
|
||||
/**
|
||||
* creates a temporary viso file
|
||||
*
|
||||
* @return created visio temporary file
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempVisioFile() throws IOException {
|
||||
return File.createTempFile("java", VISIO_EXT);
|
||||
}
|
||||
|
||||
private File getTempImageFile() throws IOException {
|
||||
return File.createTempFile("java",IMAGE_EXT);
|
||||
}
|
||||
/**
|
||||
* creates a temporary image file and returns the File object
|
||||
*
|
||||
* @return the created image file object
|
||||
* @throws IOException
|
||||
*/
|
||||
private File getTempImageFile() throws IOException {
|
||||
return File.createTempFile("java", IMAGE_EXT);
|
||||
}
|
||||
|
||||
public void quit() {
|
||||
app.quit();
|
||||
instance = null;
|
||||
}
|
||||
/** exit visio */
|
||||
public void quit() {
|
||||
app.quit();
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,177 +1,197 @@
|
||||
package com.jacob.samples.visio;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import com.jacob.com.ComThread;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
* <p>
|
||||
* This file contains the main() that runs the demo
|
||||
* <p>
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
* <p>
|
||||
* This file contains the main() that runs the demo
|
||||
* <p>
|
||||
* Look in the docs area at the Jacob usage document for command line
|
||||
* options.
|
||||
*/
|
||||
public class VisioDemo extends JFrame implements ActionListener, WindowListener {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
JButton chooseButton;
|
||||
JButton openButton;
|
||||
JPanel buttons;
|
||||
JButton openButton;
|
||||
JPanel buttons;
|
||||
|
||||
ImageIcon theImage;
|
||||
JLabel theLabel; // the icon on the page is actually this button's icon
|
||||
ImageIcon theImage;
|
||||
JLabel theLabel; // the icon on the page is actually this button's icon
|
||||
|
||||
File selectedFile;
|
||||
/** everyone should get this through getVisio() */
|
||||
private VisioAppFacade visioProxy = null;
|
||||
File selectedFile;
|
||||
/** everyone should get this through getVisio() */
|
||||
private VisioAppFacade visioProxy = null;
|
||||
|
||||
// put this up here so it remembers where we were on the last choose
|
||||
JFileChooser chooser = null;
|
||||
|
||||
// put this up here so it remembers where we were on the last choose
|
||||
JFileChooser chooser = null;
|
||||
|
||||
public class VisioFileFilter extends FileFilter {
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()){
|
||||
return true;
|
||||
} else {
|
||||
return (f.getName().toUpperCase().endsWith(".VSD"));
|
||||
}
|
||||
}
|
||||
public class VisioFileFilter extends FileFilter {
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory()) {
|
||||
return true;
|
||||
} else {
|
||||
return (f.getName().toUpperCase().endsWith(".VSD"));
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "Visio Drawings";
|
||||
}
|
||||
}
|
||||
public String getDescription() {
|
||||
return "Visio Drawings";
|
||||
}
|
||||
}
|
||||
|
||||
public VisioDemo() {
|
||||
super("Visio in Swing POC");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
buttons = new JPanel();
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
chooseButton = new JButton("Choose file to display");
|
||||
openButton = new JButton("Open file chosen file in Visio");
|
||||
chooseButton.addActionListener(this);
|
||||
openButton.addActionListener(this);
|
||||
buttons.add(chooseButton);
|
||||
buttons.add(openButton);
|
||||
getContentPane().add(buttons, BorderLayout.SOUTH);
|
||||
theLabel = new JLabel("");
|
||||
getContentPane().add(theLabel, BorderLayout.CENTER);
|
||||
addWindowListener(this);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setSize(640,480);
|
||||
this.setVisible(true);
|
||||
}
|
||||
public VisioDemo() {
|
||||
super("Visio in Swing POC");
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
buttons = new JPanel();
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
chooseButton = new JButton("Choose file to display");
|
||||
openButton = new JButton("Open file chosen file in Visio");
|
||||
chooseButton.addActionListener(this);
|
||||
openButton.addActionListener(this);
|
||||
buttons.add(chooseButton);
|
||||
buttons.add(openButton);
|
||||
getContentPane().add(buttons, BorderLayout.SOUTH);
|
||||
theLabel = new JLabel("");
|
||||
getContentPane().add(theLabel, BorderLayout.CENTER);
|
||||
addWindowListener(this);
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setSize(640, 480);
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
SwingUtilities.invokeLater(new Runnable(){
|
||||
public void run(){
|
||||
ComThread.InitSTA();
|
||||
VisioDemo poc = new VisioDemo();
|
||||
ComThread.Release();
|
||||
if (poc == null){
|
||||
System.out.println("poc== null? That should never happen!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void main(String args[]) throws Exception {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
ComThread.InitSTA();
|
||||
VisioDemo poc = new VisioDemo();
|
||||
ComThread.Release();
|
||||
if (poc == null) {
|
||||
System.out.println("poc== null? That should never happen!");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == chooseButton) {
|
||||
pickFile();
|
||||
} else if (e.getSource() == openButton) {
|
||||
try {
|
||||
openFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Awesome!");
|
||||
}
|
||||
}
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == chooseButton) {
|
||||
pickFile();
|
||||
} else if (e.getSource() == openButton) {
|
||||
try {
|
||||
openFile();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Awesome!");
|
||||
}
|
||||
}
|
||||
|
||||
private void pickFile() {
|
||||
try {
|
||||
chooser = new JFileChooser();
|
||||
// comment this out if you want it to always go to myDocuments
|
||||
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
|
||||
chooser.setFileFilter(new VisioFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(this);
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
selectedFile = chooser.getSelectedFile();
|
||||
showSelectedFilePreview();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void pickFile() {
|
||||
try {
|
||||
chooser = new JFileChooser();
|
||||
// comment this out if you want it to always go to myDocuments
|
||||
chooser
|
||||
.setCurrentDirectory(new File(System
|
||||
.getProperty("user.dir")));
|
||||
chooser.setFileFilter(new VisioFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
selectedFile = chooser.getSelectedFile();
|
||||
showSelectedFilePreview();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* use this private method instead of initializing on boot up so that instance
|
||||
* and all listeners are created in this thread (event thread) rather than root thread
|
||||
* @return
|
||||
*/
|
||||
private VisioAppFacade getVisio(){
|
||||
if (visioProxy == null){
|
||||
try {
|
||||
visioProxy = VisioAppFacade.getInstance();
|
||||
} catch (VisioException ve){
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
}
|
||||
return visioProxy;
|
||||
}
|
||||
private void showSelectedFilePreview() throws VisioException {
|
||||
if (selectedFile != null) {
|
||||
byte[] image = getVisio().createPreview(selectedFile);
|
||||
theImage = new ImageIcon(image);
|
||||
theLabel.setIcon(theImage);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* use this private method instead of initializing on boot up so that
|
||||
* instance and all listeners are created in this thread (event thread)
|
||||
* rather than root thread
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private VisioAppFacade getVisio() {
|
||||
if (visioProxy == null) {
|
||||
try {
|
||||
visioProxy = VisioAppFacade.getInstance();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
}
|
||||
return visioProxy;
|
||||
}
|
||||
|
||||
private void openFile() throws VisioException {
|
||||
try {
|
||||
getVisio().editDiagram(selectedFile);
|
||||
showSelectedFilePreview();
|
||||
} catch (VisioException ve){
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
private void showSelectedFilePreview() throws VisioException {
|
||||
if (selectedFile != null) {
|
||||
byte[] image = getVisio().createPreview(selectedFile);
|
||||
theImage = new ImageIcon(image);
|
||||
theLabel.setIcon(theImage);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void openFile() throws VisioException {
|
||||
try {
|
||||
getVisio().editDiagram(selectedFile);
|
||||
showSelectedFilePreview();
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.out.println("WINDOW CLOSED");
|
||||
if (visioProxy != null){
|
||||
visioProxy.quit();
|
||||
}
|
||||
}
|
||||
public void windowClosing(WindowEvent e){
|
||||
}
|
||||
public void windowActivated(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeactivated(WindowEvent e){
|
||||
}
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.out.println("WINDOW CLOSED");
|
||||
if (visioProxy != null) {
|
||||
visioProxy.quit();
|
||||
}
|
||||
}
|
||||
|
||||
public void windowDeiconified(WindowEvent e){
|
||||
}
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent e){
|
||||
System.out.println("Fooboo");
|
||||
}
|
||||
public void windowOpened(WindowEvent e){
|
||||
}
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(WindowEvent e) {
|
||||
System.out.println("Fooboo");
|
||||
}
|
||||
|
||||
public void windowOpened(WindowEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,68 @@
|
||||
package com.jacob.samples.visio;
|
||||
import com.jacob.com.*;
|
||||
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
*
|
||||
* You can subclass this class and only implement the methods you're interested in
|
||||
*
|
||||
* You can subclass this class and only implement the methods you're interested
|
||||
* in
|
||||
*/
|
||||
public class VisioEventAdapter implements VisioEventListener {
|
||||
|
||||
VisioApp app = null;
|
||||
|
||||
public VisioEventAdapter(VisioApp pApp){
|
||||
|
||||
public VisioEventAdapter(VisioApp pApp) {
|
||||
app = pApp;
|
||||
System.out.println("Event listener constructed");
|
||||
}
|
||||
|
||||
public void BeforeQuit(Variant[] args){ }
|
||||
|
||||
public void DocumentChanged(Variant[] args){
|
||||
System.out.println("documentChanged()");
|
||||
}
|
||||
public void BeforeQuit(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentCloseCanceled(Variant[] args){ }
|
||||
public void DocumentChanged(Variant[] args) {
|
||||
System.out.println("documentChanged()");
|
||||
}
|
||||
|
||||
public void DocumentCreated(Variant[] args){ }
|
||||
public void DocumentCloseCanceled(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentOpened(Variant[] args){
|
||||
System.out.println("DocumentOpened()");
|
||||
}
|
||||
public void DocumentCreated(Variant[] args) {
|
||||
}
|
||||
|
||||
public void DocumentSaved(Variant[] args){ }
|
||||
public void DocumentOpened(Variant[] args) {
|
||||
System.out.println("DocumentOpened()");
|
||||
}
|
||||
|
||||
public void DocumentSavedAs(Variant[] args){ }
|
||||
public void DocumentSaved(Variant[] args) {
|
||||
}
|
||||
|
||||
public Variant QueryCancelDocumentClose(Variant[] args){
|
||||
System.out.println("QueryCancelDocumentClose()");
|
||||
return new Variant(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* we don't actually let it quit. We block it so
|
||||
* that we don't have to relaunch when we look at a new document
|
||||
*/
|
||||
public Variant QueryCancelQuit(Variant[] args) {
|
||||
// these may throw VisioException
|
||||
System.out.println("Saving document, hiding and telling visio not to quit");
|
||||
try {
|
||||
app.save();
|
||||
app.setVisible(false);
|
||||
} catch (VisioException ve){
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
return new Variant(true);
|
||||
}
|
||||
public void DocumentSavedAs(Variant[] args) {
|
||||
}
|
||||
|
||||
public Variant QueryCancelDocumentClose(Variant[] args) {
|
||||
System.out.println("QueryCancelDocumentClose()");
|
||||
return new Variant(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* we don't actually let it quit. We block it so that we don't have to
|
||||
* relaunch when we look at a new document
|
||||
*/
|
||||
public Variant QueryCancelQuit(Variant[] args) {
|
||||
// these may throw VisioException
|
||||
System.out
|
||||
.println("Saving document, hiding and telling visio not to quit");
|
||||
try {
|
||||
app.save();
|
||||
app.setVisible(false);
|
||||
} catch (VisioException ve) {
|
||||
System.out.println("ailed to openFile()");
|
||||
ve.printStackTrace();
|
||||
}
|
||||
return new Variant(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.jacob.samples.visio;
|
||||
import com.jacob.com.*;
|
||||
|
||||
|
||||
import com.jacob.com.Variant;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
*
|
||||
* There are many more Visio events available. See the Microsoft
|
||||
* Office SDK documentation. To receive an event, add a method to this interface
|
||||
* whose name matches the event name and has only one parameter, Variant[].
|
||||
* The JACOB library will use reflection to call that method when an event is received.
|
||||
*
|
||||
* There are many more Visio events available. See the Microsoft Office SDK
|
||||
* documentation. To receive an event, add a method to this interface whose name
|
||||
* matches the event name and has only one parameter, Variant[]. The JACOB
|
||||
* library will use reflection to call that method when an event is received.
|
||||
*/
|
||||
public interface VisioEventListener {
|
||||
|
||||
public void BeforeQuit(Variant[] args);
|
||||
public void BeforeQuit(Variant[] args);
|
||||
|
||||
public void DocumentChanged(Variant[] args);
|
||||
public void DocumentChanged(Variant[] args);
|
||||
|
||||
public void DocumentCloseCanceled(Variant[] args);
|
||||
public void DocumentCloseCanceled(Variant[] args);
|
||||
|
||||
public void DocumentCreated(Variant[] args);
|
||||
public void DocumentCreated(Variant[] args);
|
||||
|
||||
public void DocumentOpened(Variant[] args);
|
||||
public void DocumentOpened(Variant[] args);
|
||||
|
||||
public void DocumentSaved(Variant[] args);
|
||||
public void DocumentSaved(Variant[] args);
|
||||
|
||||
public void DocumentSavedAs(Variant[] args);
|
||||
public void DocumentSavedAs(Variant[] args);
|
||||
|
||||
public Variant QueryCancelQuit(Variant[] args);
|
||||
public Variant QueryCancelQuit(Variant[] args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package com.jacob.samples.visio;
|
||||
|
||||
/**
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in event handlers
|
||||
* Created as part of sourceforge 1386454 to demonstrate returning values in
|
||||
* event handlers
|
||||
*
|
||||
* @author miles@rowansoftware.net
|
||||
*
|
||||
* This extends runtime exception so that we can be sloppy and not put catch blocks everywhere
|
||||
*
|
||||
* This extends runtime exception so that we can be sloppy and not put catch
|
||||
* blocks everywhere
|
||||
*/
|
||||
public class VisioException extends Exception {
|
||||
/**
|
||||
/**
|
||||
* Totally dummy value to make Eclipse quit complaining
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public VisioException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public VisioException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public VisioException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user