cleaned up variant serialization code. Its still broken. There just isn't as much of it now.
This commit is contained in:
@@ -89,7 +89,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_QueryInterface
|
|||||||
* and connects to it. does special code if the progid
|
* and connects to it. does special code if the progid
|
||||||
* is of the alternate format (with ":")
|
* is of the alternate format (with ":")
|
||||||
**/
|
**/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstanceNative
|
||||||
(JNIEnv *env, jobject _this, jstring _progid)
|
(JNIEnv *env, jobject _this, jstring _progid)
|
||||||
{
|
{
|
||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
@@ -155,7 +155,7 @@ doDisp:
|
|||||||
* attempts to connect to an running instance of the requested program
|
* attempts to connect to an running instance of the requested program
|
||||||
* This exists solely for the factory method connectToActiveInstance.
|
* This exists solely for the factory method connectToActiveInstance.
|
||||||
**/
|
**/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstanceNative
|
||||||
(JNIEnv *env, jobject _this, jstring _progid)
|
(JNIEnv *env, jobject _this, jstring _progid)
|
||||||
{
|
{
|
||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
@@ -197,7 +197,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstance
|
|||||||
* starts up a new instance of the requested program (progId).
|
* starts up a new instance of the requested program (progId).
|
||||||
* This exists solely for the factory method connectToActiveInstance.
|
* This exists solely for the factory method connectToActiveInstance.
|
||||||
**/
|
**/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstanceNative
|
||||||
(JNIEnv *env, jobject _this, jstring _progid)
|
(JNIEnv *env, jobject _this, jstring _progid)
|
||||||
{
|
{
|
||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_QueryInterface
|
|||||||
* Method: createInstance
|
* Method: createInstance
|
||||||
* Signature: (Ljava/lang/String;)V
|
* Signature: (Ljava/lang/String;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstanceNative
|
||||||
(JNIEnv *, jobject, jstring);
|
(JNIEnv *, jobject, jstring);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -46,7 +46,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstance
|
|||||||
* Method: getActiveInstance
|
* Method: getActiveInstance
|
||||||
* Signature: (Ljava/lang/String;)V
|
* Signature: (Ljava/lang/String;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstanceNative
|
||||||
(JNIEnv *, jobject, jstring);
|
(JNIEnv *, jobject, jstring);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -54,7 +54,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstance
|
|||||||
* Method: coCreateInstance
|
* Method: coCreateInstance
|
||||||
* Signature: (Ljava/lang/String;)V
|
* Signature: (Ljava/lang/String;)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstance
|
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstanceNative
|
||||||
(JNIEnv *, jobject, jstring);
|
(JNIEnv *, jobject, jstring);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -100,9 +100,15 @@ void zeroVariant(JNIEnv *env, jobject _this)
|
|||||||
env->SetIntField(_this, jf, (unsigned int)0);
|
env->SetIntField(_this, jf, (unsigned int)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Save
|
|
||||||
(JNIEnv *env, jobject _this, jobject outStream)
|
/**
|
||||||
{
|
* This is the core of the old Save method.
|
||||||
|
* It copies this variant to a byte stream.
|
||||||
|
* The unmarshalling part of this doesn't work but it was left in
|
||||||
|
* with the hope that someone will want to fix this later
|
||||||
|
**/
|
||||||
|
JNIEXPORT jbyteArray JNICALL Java_com_jacob_com_Variant_SerializationWriteToBytes
|
||||||
|
(JNIEnv *env, jobject _this){
|
||||||
VARIANT *v = extractVariant(env, _this);
|
VARIANT *v = extractVariant(env, _this);
|
||||||
if (v)
|
if (v)
|
||||||
{
|
{
|
||||||
@@ -119,68 +125,35 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Save
|
|||||||
env->SetByteArrayRegion(ba, 0, size, pBuf);
|
env->SetByteArrayRegion(ba, 0, size, pBuf);
|
||||||
// and delete the original memory
|
// and delete the original memory
|
||||||
delete [] pBuf;
|
delete [] pBuf;
|
||||||
|
return ba;
|
||||||
//java code: DataOutputStream dos = new DataOutputStream(outStream);
|
} else {
|
||||||
jclass dosCls = env->FindClass("java/io/DataOutputStream");
|
jbyteArray ba = env->NewByteArray(0);
|
||||||
jmethodID dosCons =
|
return ba;
|
||||||
env->GetMethodID(dosCls, "<init>", "(Ljava/io/OutputStream;)V");
|
}
|
||||||
jmethodID dosWriteInt =
|
|
||||||
env->GetMethodID(dosCls, "writeInt", "(I)V");
|
|
||||||
jmethodID dosWriteBytes =
|
|
||||||
env->GetMethodID(dosCls, "write", "([B)V");
|
|
||||||
jobject dos = env->NewObject(dosCls, dosCons, outStream);
|
|
||||||
// write the size into the stream
|
|
||||||
env->CallVoidMethod(dos, dosWriteInt, size);
|
|
||||||
// write the buffer into the stream
|
|
||||||
env->CallVoidMethod(dos, dosWriteBytes, ba);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Load
|
/**
|
||||||
(JNIEnv *env, jobject _this, jobject inStream)
|
* This is the core of the old Load method. It is broken because the
|
||||||
{
|
* unmarshalling code doesn't work under 2000/XP.
|
||||||
|
*
|
||||||
|
* It probably needs a custom handler.
|
||||||
|
**/
|
||||||
|
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes
|
||||||
|
(JNIEnv *env, jobject _this, jbyteArray ba){
|
||||||
|
|
||||||
VARIANT *v = extractVariant(env, _this);
|
VARIANT *v = extractVariant(env, _this);
|
||||||
if (!v)
|
if (v){
|
||||||
{
|
|
||||||
// since the default constructor is not called when serializing in
|
|
||||||
// I need to init the underlying VARIANT
|
|
||||||
jclass clazz = env->GetObjectClass(_this);
|
|
||||||
jfieldID jf = env->GetFieldID( clazz, VARIANT_FLD, "I");
|
|
||||||
v = new VARIANT();
|
|
||||||
VariantInit(v);
|
|
||||||
env->SetIntField(_this, jf, (unsigned int)v);
|
|
||||||
}
|
|
||||||
if (v)
|
|
||||||
{
|
|
||||||
//java code: DataInputStream dis = new DataInputStream(outStream);
|
|
||||||
jclass disCls = env->FindClass("java/io/DataInputStream");
|
|
||||||
jmethodID disCons =
|
|
||||||
env->GetMethodID(disCls, "<init>", "(Ljava/io/InputStream;)V");
|
|
||||||
jmethodID disReadInt =
|
|
||||||
env->GetMethodID(disCls, "readInt", "()I");
|
|
||||||
jmethodID disReadBytes =
|
|
||||||
env->GetMethodID(disCls, "readFully", "([B)V");
|
|
||||||
jobject dis = env->NewObject(disCls, disCons, inStream);
|
|
||||||
|
|
||||||
// read in the size from the input stream
|
|
||||||
jint size = env->CallIntMethod(dis, disReadInt);
|
|
||||||
// allocate a byte array of this size
|
|
||||||
jbyteArray ba = env->NewByteArray(size);
|
|
||||||
// read it in from the input stream
|
|
||||||
env->CallVoidMethod(dis, disReadBytes, ba);
|
|
||||||
if ( size > 0 )
|
|
||||||
{
|
|
||||||
// get a buffer from it
|
// get a buffer from it
|
||||||
jbyte *pBuf = env->GetByteArrayElements(ba, 0);
|
jbyte *pBuf = env->GetByteArrayElements(ba, 0);
|
||||||
// unmarshall the Variant from the buffer
|
// unmarshall the Variant from the buffer
|
||||||
DWORD flags = MSHCTX_LOCAL;
|
DWORD flags = MSHCTX_LOCAL;
|
||||||
|
printf("about to unmarshall array elements\n");
|
||||||
VARIANT_UserUnmarshal(&flags, (unsigned char *)pBuf, v);
|
VARIANT_UserUnmarshal(&flags, (unsigned char *)pBuf, v);
|
||||||
// release the byte array
|
// release the byte array
|
||||||
|
printf("about to release array elements\n");
|
||||||
env->ReleaseByteArrayElements(ba, pBuf, 0);
|
env->ReleaseByteArrayElements(ba, pBuf, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toInt
|
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toInt
|
||||||
(JNIEnv *env, jobject _this)
|
(JNIEnv *env, jobject _this)
|
||||||
@@ -947,12 +920,6 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getObjectRef
|
|
||||||
(JNIEnv *env, jobject _this)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByteRef
|
JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByteRef
|
||||||
(JNIEnv *env, jobject _this)
|
(JNIEnv *env, jobject _this)
|
||||||
|
|||||||
@@ -489,14 +489,6 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getErrorRef
|
|||||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef
|
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef
|
||||||
(JNIEnv *, jobject);
|
(JNIEnv *, jobject);
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: com_jacob_com_Variant
|
|
||||||
* Method: getObjectRef
|
|
||||||
* Signature: ()Ljava/lang/Object;
|
|
||||||
*/
|
|
||||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getObjectRef
|
|
||||||
(JNIEnv *, jobject);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: com_jacob_com_Variant
|
* Class: com_jacob_com_Variant
|
||||||
* Method: getByteRef
|
* Method: getByteRef
|
||||||
@@ -601,21 +593,11 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_release
|
|||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_init
|
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_init
|
||||||
(JNIEnv *, jobject);
|
(JNIEnv *, jobject);
|
||||||
|
|
||||||
/*
|
JNIEXPORT jbyteArray JNICALL Java_com_jacob_com_Variant_SerializationWriteToBytes
|
||||||
* Class: com_jacob_com_Variant
|
(JNIEnv *, jobject);
|
||||||
* Method: Save
|
|
||||||
* Signature: (Ljava/io/OutputStream;)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Save
|
|
||||||
(JNIEnv *, jobject, jobject);
|
|
||||||
|
|
||||||
/*
|
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes
|
||||||
* Class: com_jacob_com_Variant
|
(JNIEnv *, jobject, jbyteArray);
|
||||||
* Method: Load
|
|
||||||
* Signature: (Ljava/io/InputStream;)V
|
|
||||||
*/
|
|
||||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_Load
|
|
||||||
(JNIEnv *, jobject, jobject);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: com_jacob_com_Variant
|
* Class: com_jacob_com_Variant
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ public class AppTest extends Applet implements ActionListener {
|
|||||||
|
|
||||||
ActiveXComponent sC = null;
|
ActiveXComponent sC = null;
|
||||||
|
|
||||||
Dispatch sControl = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* startup method
|
* startup method
|
||||||
*/
|
*/
|
||||||
@@ -46,10 +44,9 @@ public class AppTest extends Applet implements ActionListener {
|
|||||||
if (sC == null) {
|
if (sC == null) {
|
||||||
String lang = "VBScript";
|
String lang = "VBScript";
|
||||||
sC = new ActiveXComponent("ScriptControl");
|
sC = new ActiveXComponent("ScriptControl");
|
||||||
sControl = sC.getObject();
|
Dispatch.put(sC, "Language", lang);
|
||||||
Dispatch.put(sControl, "Language", lang);
|
|
||||||
}
|
}
|
||||||
Variant v = Dispatch.call(sControl, "Eval", in.getText());
|
Variant v = Dispatch.call(sC, "Eval", in.getText());
|
||||||
out.setText(v.toString());
|
out.setText(v.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.jacob.samples.office;
|
package com.jacob.samples.office;
|
||||||
|
|
||||||
import com.jacob.activeX.ActiveXComponent;
|
import com.jacob.activeX.ActiveXComponent;
|
||||||
import com.jacob.com.ComFailException;
|
import com.jacob.com.ComException;
|
||||||
import com.jacob.com.Dispatch;
|
import com.jacob.com.Dispatch;
|
||||||
import com.jacob.com.Variant;
|
import com.jacob.com.Variant;
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public class WordDocumentProperties {
|
|||||||
try {
|
try {
|
||||||
cusPropName = Dispatch.call((Dispatch) custDocprops, "Item",
|
cusPropName = Dispatch.call((Dispatch) custDocprops, "Item",
|
||||||
cusPropName).toString();
|
cusPropName).toString();
|
||||||
} catch (ComFailException e) {
|
} catch (ComException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
cusPropName = null;
|
cusPropName = null;
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ public class WordDocumentProperties {
|
|||||||
try {
|
try {
|
||||||
builtInPropName = Dispatch.call((Dispatch) builtInDocProps, "Item",
|
builtInPropName = Dispatch.call((Dispatch) builtInDocProps, "Item",
|
||||||
builtInPropName).toString();
|
builtInPropName).toString();
|
||||||
} catch (ComFailException e) {
|
} catch (ComException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
builtInPropName = null;
|
builtInPropName = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.jacob.samples.test;
|
|||||||
import com.jacob.com.*;
|
import com.jacob.com.*;
|
||||||
import com.jacob.activeX.*;
|
import com.jacob.activeX.*;
|
||||||
|
|
||||||
public class safearray
|
public class SafeArrayViaExcel
|
||||||
{
|
{
|
||||||
public static void main(java.lang.String[] args)
|
public static void main(java.lang.String[] args)
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,8 @@ public class safearray
|
|||||||
SafeArray sAProdText;
|
SafeArray sAProdText;
|
||||||
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
|
||||||
System.out.println("have workbooks");
|
System.out.println("have workbooks");
|
||||||
Dispatch workbook = Dispatch.call(workbooks, "Open", "d:\\jacob_15\\samples\\test\\jacobtest.xls").toDispatch();
|
Dispatch workbook = Dispatch.call(workbooks, "Open", "d:\\jacob\\samples\\test\\ExcelSafeArray" +
|
||||||
|
".xls").toDispatch();
|
||||||
System.out.println("Opened File - jacobtest.xls\n");
|
System.out.println("Opened File - jacobtest.xls\n");
|
||||||
Dispatch sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
|
Dispatch sheet = Dispatch.get(workbook,"ActiveSheet").toDispatch();
|
||||||
cell = Dispatch.invoke(sheet,"Range",Dispatch.Get,new Object[] {"A1:D1000"},new int[1]).toDispatch();
|
cell = Dispatch.invoke(sheet,"Range",Dispatch.Get,new Object[] {"A1:D1000"},new int[1]).toDispatch();
|
||||||
Binary file not shown.
@@ -266,7 +266,7 @@ class test
|
|||||||
printArray(bback);
|
printArray(bback);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// this should throw ComFailException
|
// this should throw ComException
|
||||||
bba2.fromCharArray(new char[] {'a'});
|
bba2.fromCharArray(new char[] {'a'});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.jacob.samples.test;
|
|
||||||
|
|
||||||
import com.jacob.com.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
class varSerTest
|
|
||||||
{
|
|
||||||
public static void main(String[] args) throws Exception
|
|
||||||
{
|
|
||||||
Variant vs1 = new Variant("hi");
|
|
||||||
Variant vs2 = new Variant(123.456);
|
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream("foo.foo");
|
|
||||||
vs1.Save(fos);
|
|
||||||
vs2.Save(fos);
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
Variant vl1 = new Variant();
|
|
||||||
Variant vl2 = new Variant();
|
|
||||||
FileInputStream fis = new FileInputStream("foo.foo");
|
|
||||||
vl1.Load(fis);
|
|
||||||
vl2.Load(fis);
|
|
||||||
System.out.println(vl1);
|
|
||||||
System.out.println(vl2);
|
|
||||||
|
|
||||||
// same thing with serialization
|
|
||||||
|
|
||||||
fos = new FileOutputStream("foo.ser");
|
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
||||||
oos.writeObject(vs1);
|
|
||||||
oos.writeObject(vs2);
|
|
||||||
oos.close();
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
|
|
||||||
fis = new FileInputStream("foo.ser");
|
|
||||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
|
||||||
|
|
||||||
Variant vss1, vss2;
|
|
||||||
|
|
||||||
vss1 = (Variant)ois.readObject();
|
|
||||||
vss2 = (Variant)ois.readObject();
|
|
||||||
ois.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
System.out.println(vss1);
|
|
||||||
System.out.println(vss2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -101,7 +101,7 @@ public class ActiveXComponent extends Dispatch {
|
|||||||
ActiveXComponent mCreatedDispatch = null;
|
ActiveXComponent mCreatedDispatch = null;
|
||||||
try {
|
try {
|
||||||
mCreatedDispatch = new ActiveXComponent();
|
mCreatedDispatch = new ActiveXComponent();
|
||||||
mCreatedDispatch.coCreateInstanceJava(pRequestedProgramId);
|
mCreatedDispatch.coCreateInstance(pRequestedProgramId);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
mCreatedDispatch =null;
|
mCreatedDispatch =null;
|
||||||
if (JacobObject.isDebugEnabled()){
|
if (JacobObject.isDebugEnabled()){
|
||||||
@@ -130,7 +130,7 @@ public class ActiveXComponent extends Dispatch {
|
|||||||
ActiveXComponent mCreatedDispatch = null;
|
ActiveXComponent mCreatedDispatch = null;
|
||||||
try {
|
try {
|
||||||
mCreatedDispatch = new ActiveXComponent();
|
mCreatedDispatch = new ActiveXComponent();
|
||||||
mCreatedDispatch.getActiveInstanceJava(pRequestedProgramId);
|
mCreatedDispatch.getActiveInstance(pRequestedProgramId);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
mCreatedDispatch =null;
|
mCreatedDispatch =null;
|
||||||
if (JacobObject.isDebugEnabled()){
|
if (JacobObject.isDebugEnabled()){
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
package com.jacob.com;
|
package com.jacob.com;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COM Fail Exception class raise dwhen there is a problem
|
* COM Fail Exception class raised when there is a problem
|
||||||
*/
|
*/
|
||||||
public class ComFailException extends ComException {
|
public class ComFailException extends ComException {
|
||||||
/**
|
/**
|
||||||
|
|||||||
43
src/com/jacob/com/ComNotImplementedException.java
Normal file
43
src/com/jacob/com/ComNotImplementedException.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||||
|
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||||
|
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package com.jacob.com;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown by java APIs that are not implemented either because
|
||||||
|
* they were never implemented or because they are bieng deprecated
|
||||||
|
* This is a subclass of ComException so callers can still just catch
|
||||||
|
* ComException.
|
||||||
|
*/
|
||||||
|
public class ComNotImplementedException extends ComException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -9169900832852356445L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param description
|
||||||
|
*/
|
||||||
|
public ComNotImplementedException(String description) {
|
||||||
|
super(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -157,7 +157,7 @@ public class Dispatch extends JacobObject
|
|||||||
public Dispatch(String requestedProgramId) {
|
public Dispatch(String requestedProgramId) {
|
||||||
programId = requestedProgramId;
|
programId = requestedProgramId;
|
||||||
if (programId != null && !"".equals(programId)){
|
if (programId != null && !"".equals(programId)){
|
||||||
createInstance(requestedProgramId);
|
createInstanceNative(requestedProgramId);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Dispatch(String) does not accept null or an empty string as a parameter");
|
"Dispatch(String) does not accept null or an empty string as a parameter");
|
||||||
@@ -176,7 +176,7 @@ public class Dispatch extends JacobObject
|
|||||||
*
|
*
|
||||||
* @param progid
|
* @param progid
|
||||||
*/
|
*/
|
||||||
private native void createInstance(String progid);
|
private native void createInstanceNative(String progid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* native call getActiveInstance only used by the constructor with the same parm
|
* native call getActiveInstance only used by the constructor with the same parm
|
||||||
@@ -190,15 +190,18 @@ public class Dispatch extends JacobObject
|
|||||||
*
|
*
|
||||||
* @param progid
|
* @param progid
|
||||||
*/
|
*/
|
||||||
private native void getActiveInstance(String progid);
|
private native void getActiveInstanceNative(String progid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around the native method
|
* Wrapper around the native method
|
||||||
* @param progid
|
* @param progid
|
||||||
*/
|
*/
|
||||||
protected void getActiveInstanceJava(String progid){
|
protected void getActiveInstance(String pProgramIdentifier){
|
||||||
this.programId = progid;
|
if (pProgramIdentifier == null || "".equals(pProgramIdentifier)){
|
||||||
getActiveInstance(progid);
|
throw new IllegalArgumentException("program id is required");
|
||||||
|
}
|
||||||
|
this.programId = pProgramIdentifier;
|
||||||
|
getActiveInstanceNative(pProgramIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,15 +216,18 @@ public class Dispatch extends JacobObject
|
|||||||
*
|
*
|
||||||
* @param progid
|
* @param progid
|
||||||
*/
|
*/
|
||||||
private native void coCreateInstance(String progid);
|
private native void coCreateInstanceNative(String progid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around the native method
|
* Wrapper around the native method
|
||||||
* @param progid
|
* @param pProgramIdentifier
|
||||||
*/
|
*/
|
||||||
protected void coCreateInstanceJava(String progid){
|
protected void coCreateInstance(String pProgramIdentifier){
|
||||||
this.programId = progid;
|
if (pProgramIdentifier == null || "".equals(pProgramIdentifier)){
|
||||||
coCreateInstance(progid);
|
throw new IllegalArgumentException("program id is required");
|
||||||
|
}
|
||||||
|
this.programId = pProgramIdentifier;
|
||||||
|
coCreateInstanceNative(pProgramIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,11 +397,10 @@ public class Dispatch extends JacobObject
|
|||||||
* @param dispatchTarget
|
* @param dispatchTarget
|
||||||
* @param name
|
* @param name
|
||||||
* @param val
|
* @param val
|
||||||
* @throws ClassCastException
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
* because???
|
|
||||||
*/
|
*/
|
||||||
public static void put_Casesensitive(Dispatch dispatchTarget, String name, Object val) {
|
public static void put_Casesensitive(Dispatch dispatchTarget, String name, Object val) {
|
||||||
throw new ClassCastException("not implemented yet");
|
throw new ComNotImplementedException("not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*============================================================
|
/*============================================================
|
||||||
@@ -447,12 +452,12 @@ public class Dispatch extends JacobObject
|
|||||||
* @param dispatchTarget
|
* @param dispatchTarget
|
||||||
* @param name
|
* @param name
|
||||||
* @param values
|
* @param values
|
||||||
* @return never returns anything because throws ClassCastException
|
* @return never returns anything because
|
||||||
* because not implemented yet
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public static Variant callN_CaseSensitive(Dispatch dispatchTarget, String name,
|
public static Variant callN_CaseSensitive(Dispatch dispatchTarget, String name,
|
||||||
Object[] values) {
|
Object[] values) {
|
||||||
throw new ClassCastException("not implemented yet");
|
throw new ComNotImplementedException("not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1273,13 +1278,14 @@ public class Dispatch extends JacobObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* not implemented , will throw class cast exception
|
* not implemented yet
|
||||||
* @param dispatchTarget
|
* @param dispatchTarget
|
||||||
* @param name
|
* @param name
|
||||||
* @return Variant never returned
|
* @return Variant never returned
|
||||||
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public static Variant get_CaseSensitive(Dispatch dispatchTarget, String name) {
|
public static Variant get_CaseSensitive(Dispatch dispatchTarget, String name) {
|
||||||
throw new ClassCastException("not implemented yet");
|
throw new ComNotImplementedException("not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ public class DispatchEvents extends JacobObject {
|
|||||||
* @param progId optional program id. most folks don't need this either
|
* @param progId optional program id. most folks don't need this either
|
||||||
* @param typeLib optional parameter for those programs that don't register their type libs (like Excel)
|
* @param typeLib optional parameter for those programs that don't register their type libs (like Excel)
|
||||||
*/
|
*/
|
||||||
protected native void init3(Dispatch src, Object sink, String progId, String typeLib);
|
private native void init3(Dispatch src, Object sink, String progId, String typeLib);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* now private so only this object can asccess
|
* now private so only this object can asccess
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ import java.util.Date;
|
|||||||
/**
|
/**
|
||||||
* The multi-format data type used for all call backs and most communications
|
* The multi-format data type used for all call backs and most communications
|
||||||
* between Java and COM. It provides a single class that can handle all data
|
* between Java and COM. It provides a single class that can handle all data
|
||||||
* types
|
* types.
|
||||||
|
* <p>
|
||||||
|
* This object no longer implements Serializable because serialization is broken
|
||||||
|
* (and has been since 2000/xp). The underlying
|
||||||
|
* marshalling/unmarshalling code is broken in the JNI layer.
|
||||||
*/
|
*/
|
||||||
public class Variant extends JacobObject implements java.io.Serializable {
|
public class Variant extends JacobObject {
|
||||||
/**
|
/**
|
||||||
* Use this constant for optional parameters
|
* Use this constant for optional parameters
|
||||||
*/
|
*/
|
||||||
@@ -157,31 +161,29 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @param in
|
* @param in doesn't matter because this method does nothing
|
||||||
* doesn't matter because this method does nothing
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
*/
|
||||||
public void putVariantArray(Variant[] in) {
|
public void putVariantArray(Variant[] in) {
|
||||||
throw new ComFailException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @return never returns
|
* @return never returns anything
|
||||||
* @throws com.jacob.com.ComFailException
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public Variant[] getVariantArray() {
|
public Variant[] getVariantArray() {
|
||||||
throw new ComFailException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @param in
|
* @param in doesn't matter because this method does nothing
|
||||||
* doesn't matter because this method does nothing
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
*/
|
||||||
public void putByteArray(Object in) {
|
public void putByteArray(Object in) {
|
||||||
throw new ComFailException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -287,12 +289,12 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
public native String getStringRef();
|
public native String getStringRef();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return never returns anything
|
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
* @deprecated superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
|
* @return never returns anything
|
||||||
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public Object toCharArray() {
|
public Object toCharArray() {
|
||||||
throw new ComFailException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -427,10 +429,6 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
|
|
||||||
public native double getDouble();
|
public native double getDouble();
|
||||||
|
|
||||||
public Object getObject() {
|
|
||||||
return toDispatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public native void putCurrency(long in);
|
public native void putCurrency(long in);
|
||||||
|
|
||||||
/** puts an object into the */
|
/** puts an object into the */
|
||||||
@@ -470,8 +468,6 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
|
|
||||||
public native boolean getBooleanRef();
|
public native boolean getBooleanRef();
|
||||||
|
|
||||||
public native Object getObjectRef();
|
|
||||||
|
|
||||||
public native byte getByteRef();
|
public native byte getByteRef();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,11 +494,11 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
public native void noParam();
|
public native void noParam();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @throws com.jacob.com.ComFailException
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public void putCharArray(Object in) {
|
public void putCharArray(Object in) {
|
||||||
throw new ComFailException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public native float getFloat();
|
public native float getFloat();
|
||||||
@@ -518,19 +514,19 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @throws com.jacob.com.ComFailException
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public void putVariantArrayRef(Variant[] in) {
|
public void putVariantArrayRef(Variant[] in) {
|
||||||
throw new ClassCastException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* superceded by SafeArray
|
* @deprecated superceded by SafeArray
|
||||||
* @throws com.jacob.com.ComFailException
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
*/
|
*/
|
||||||
public Variant[] getVariantArrayRef() {
|
public Variant[] getVariantArrayRef() {
|
||||||
throw new ClassCastException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public native void changeType(short in);
|
public native void changeType(short in);
|
||||||
@@ -555,7 +551,7 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor that calls init() and then putXXX()
|
* Constructor that accepts a primitive rather than an object
|
||||||
* @param in
|
* @param in
|
||||||
*/
|
*/
|
||||||
public Variant(int in) {
|
public Variant(int in) {
|
||||||
@@ -564,7 +560,7 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor that calls init() and then putXXX()
|
* Constructor that accepts a primitive rather than an object
|
||||||
* @param in
|
* @param in
|
||||||
*/
|
*/
|
||||||
public Variant(double in) {
|
public Variant(double in) {
|
||||||
@@ -573,7 +569,7 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor that calls init() and then putXXX()
|
* Constructor that accepts a primitive rather than an object
|
||||||
* @param in
|
* @param in
|
||||||
*/
|
*/
|
||||||
public Variant(boolean in) {
|
public Variant(boolean in) {
|
||||||
@@ -582,32 +578,9 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor that calls init() and then putXXX()
|
* Convenience constructor that calls the main one with
|
||||||
* @param in
|
* a byRef value of false
|
||||||
*/
|
* @param in object to be made into variant
|
||||||
public Variant(String in) {
|
|
||||||
init();
|
|
||||||
putString(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor that calls init() and then putSafeArrayXXX()
|
|
||||||
* @param in
|
|
||||||
* @param fByRef is this data by reference or not?
|
|
||||||
*/
|
|
||||||
public Variant(SafeArray in, boolean fByRef) {
|
|
||||||
init();
|
|
||||||
if (fByRef) {
|
|
||||||
putSafeArrayRef(in);
|
|
||||||
} else {
|
|
||||||
putSafeArray(in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* constructor that calls two parameter constructor
|
|
||||||
* with 1st parameter as object and 2nd parameter as false
|
|
||||||
* @param in
|
|
||||||
*/
|
*/
|
||||||
public Variant(Object in) {
|
public Variant(Object in) {
|
||||||
this(in, false);
|
this(in, false);
|
||||||
@@ -661,45 +634,6 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* wierd constructor that is no longer supported
|
|
||||||
* @param in
|
|
||||||
* @param in1
|
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
|
||||||
public Variant(int in, int in1) {
|
|
||||||
throw new ComFailException("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wierd constructor that is no longer supported
|
|
||||||
* @param in
|
|
||||||
* @param in1
|
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
|
||||||
public Variant(int in, boolean in1) {
|
|
||||||
throw new ComFailException("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wierd constructor that is no longer supported
|
|
||||||
* @param in
|
|
||||||
* @param in1
|
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
|
||||||
public Variant(int in, double in1) {
|
|
||||||
throw new ComFailException("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wierd constructor that is no longer supported
|
|
||||||
* @param in
|
|
||||||
* @param in1
|
|
||||||
* @throws com.jacob.com.ComFailException
|
|
||||||
*/
|
|
||||||
public Variant(int in, Object in1) {
|
|
||||||
throw new ComFailException("Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
public native short getvt();
|
public native short getvt();
|
||||||
|
|
||||||
@@ -752,14 +686,22 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// superceded by SafeArray
|
/**
|
||||||
|
* @deprecated superceded by SafeArray
|
||||||
|
* @return
|
||||||
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
|
*/
|
||||||
public Variant[] toVariantArray() {
|
public Variant[] toVariantArray() {
|
||||||
throw new ClassCastException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
// superceded by SafeArray
|
/**
|
||||||
|
* @deprecated superceded by SafeArray
|
||||||
|
* @return
|
||||||
|
* @throws com.jacob.com.ComNotImplementedException
|
||||||
|
*/
|
||||||
public Object toByteArray() {
|
public Object toByteArray() {
|
||||||
throw new ClassCastException("Not implemented");
|
throw new ComNotImplementedException("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -772,7 +714,14 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
private void writeObject(java.io.ObjectOutputStream oos) {
|
private void writeObject(java.io.ObjectOutputStream oos) {
|
||||||
try {
|
try {
|
||||||
Save(oos);
|
byte[] ourBytes = SerializationWriteToBytes();
|
||||||
|
int count = ourBytes.length;
|
||||||
|
if (JacobObject.isDebugEnabled()){
|
||||||
|
JacobObject.debug("writing out "+count+" bytes");
|
||||||
|
}
|
||||||
|
oos.writeInt(count);
|
||||||
|
oos.write(ourBytes);
|
||||||
|
//Save(oos);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -784,7 +733,18 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
private void readObject(java.io.ObjectInputStream ois) {
|
private void readObject(java.io.ObjectInputStream ois) {
|
||||||
try {
|
try {
|
||||||
Load(ois);
|
// Load will do this if we don't but lets do it
|
||||||
|
// from here so that the variant is set up exactly
|
||||||
|
// the same as the ones not created from a stream
|
||||||
|
init();
|
||||||
|
int numBytes = ois.readInt();
|
||||||
|
byte[] ourBytes = new byte[numBytes];
|
||||||
|
if (JacobObject.isDebugEnabled()){
|
||||||
|
JacobObject.debug("reading in "+numBytes+" bytes");
|
||||||
|
}
|
||||||
|
ois.read(ourBytes);
|
||||||
|
SerializationReadFromBytes(ourBytes);
|
||||||
|
//Load(ois);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -796,8 +756,17 @@ public class Variant extends JacobObject implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
public native boolean isNull();
|
public native boolean isNull();
|
||||||
|
|
||||||
public native void Save(java.io.OutputStream os) throws java.io.IOException;
|
/**
|
||||||
|
* this is supposed to create a byte array that represents the underlying
|
||||||
|
* variant object struct
|
||||||
|
*/
|
||||||
|
public native byte[] SerializationWriteToBytes();
|
||||||
|
|
||||||
public native void Load(java.io.InputStream is) throws java.io.IOException;
|
/**
|
||||||
|
* this is supposed to cause the underlying variant object struct to
|
||||||
|
* be rebuilt from a previously serialized byte array.
|
||||||
|
* @param ba
|
||||||
|
*/
|
||||||
|
public native void SerializationReadFromBytes(byte[] ba);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.jacob.com;
|
package com.jacob.com;
|
||||||
|
|
||||||
import com.jacob.activeX.ActiveXComponent;
|
import com.jacob.activeX.ActiveXComponent;
|
||||||
import com.jacob.com.ComFailException;
|
|
||||||
import com.jacob.com.DispatchEvents;
|
import com.jacob.com.DispatchEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +59,7 @@ public class ExcelEventTest extends InvocationProxy {
|
|||||||
Dispatch.call(workbook, "Close", f);
|
Dispatch.call(workbook, "Close", f);
|
||||||
axc.invoke("Quit", new Variant[] {});
|
axc.invoke("Quit", new Variant[] {});
|
||||||
|
|
||||||
} catch (ComFailException cfe) {
|
} catch (ComException cfe) {
|
||||||
cfe.printStackTrace();
|
cfe.printStackTrace();
|
||||||
System.out.println("Failed to attach to " + pid + ": "
|
System.out.println("Failed to attach to " + pid + ": "
|
||||||
+ cfe.getMessage());
|
+ cfe.getMessage());
|
||||||
|
|||||||
61
unittest/com/jacob/com/VariantSerializationTest.java
Normal file
61
unittest/com/jacob/com/VariantSerializationTest.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package com.jacob.com;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies serialization works for variants.
|
||||||
|
* Variant serialization is BROKEN and has been since 1.7
|
||||||
|
* <pre>-Djava.library.path=d:/jacob/release</pre>
|
||||||
|
*/
|
||||||
|
class VariantSerializationTest {
|
||||||
|
|
||||||
|
static Variant vs1 = new Variant("hi");
|
||||||
|
static Variant vs2 = new Variant(123.456);
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
doJustSerialization();
|
||||||
|
compareVariantBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void compareVariantBytes() throws Exception{
|
||||||
|
System.out.println("compareVariantBytes");
|
||||||
|
Variant var1 = new Variant("hello");
|
||||||
|
Variant var2 = new Variant("hello");
|
||||||
|
byte[] var1Bytes = var1.SerializationWriteToBytes();
|
||||||
|
byte[] var2Bytes = var2.SerializationWriteToBytes();
|
||||||
|
for ( int i = 0 ; i < var1Bytes.length; i++){
|
||||||
|
if (var1Bytes[i]!=var2Bytes[i]){
|
||||||
|
System.out.println("variant strings differ at position "+i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("two strings return identical serialization data");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doJustSerialization() throws Exception {
|
||||||
|
System.out.println("doJustSerialization");
|
||||||
|
// same thing with serialization
|
||||||
|
FileOutputStream fos;
|
||||||
|
FileInputStream fis;
|
||||||
|
fos = new FileOutputStream("foo.ser");
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(vs1);
|
||||||
|
//oos.writeObject(vs2);
|
||||||
|
oos.close();
|
||||||
|
fos.close();
|
||||||
|
|
||||||
|
fis = new FileInputStream("foo.ser");
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
|
|
||||||
|
Variant vss1 = null;
|
||||||
|
Variant vss2 = null;
|
||||||
|
|
||||||
|
vss1 = (Variant) ois.readObject();
|
||||||
|
//vss2 = (Variant) ois.readObject();
|
||||||
|
ois.close();
|
||||||
|
fis.close();
|
||||||
|
|
||||||
|
System.out.println(vss1);
|
||||||
|
System.out.println(vss2);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package com.jacob.samples.test;
|
package com.jacob.com;
|
||||||
|
|
||||||
import com.jacob.com.*;
|
/**
|
||||||
|
* runs through some of the get and set methods on Variant
|
||||||
class variant_test {
|
*/
|
||||||
|
class VariantTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//deprecated
|
//deprecated
|
||||||
//System.runFinalizersOnExit(true);
|
//System.runFinalizersOnExit(true);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.jacob.com;
|
package com.jacob.com;
|
||||||
|
|
||||||
import com.jacob.activeX.ActiveXComponent;
|
import com.jacob.activeX.ActiveXComponent;
|
||||||
import com.jacob.com.ComFailException;
|
import com.jacob.com.ComException;
|
||||||
import com.jacob.com.DispatchEvents;
|
import com.jacob.com.DispatchEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,7 +51,7 @@ public class WordEventTest extends InvocationProxy {
|
|||||||
}
|
}
|
||||||
axc.invoke("Quit", new Variant[] {});
|
axc.invoke("Quit", new Variant[] {});
|
||||||
|
|
||||||
} catch (ComFailException cfe) {
|
} catch (ComException cfe) {
|
||||||
cfe.printStackTrace();
|
cfe.printStackTrace();
|
||||||
System.out.println("Failed to attach to " + pid + ": "
|
System.out.println("Failed to attach to " + pid + ": "
|
||||||
+ cfe.getMessage());
|
+ cfe.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user