diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html
index 1057648..812def0 100644
--- a/docs/ReleaseNotes.html
+++ b/docs/ReleaseNotes.html
@@ -10,6 +10,15 @@
(Feedback wanted)
+
+ Variants
+
+ - Variant now accept Java Dates in the constructor.
+
- Redundant constructors removed
+
- Experimental toJavaObject() method added that automatically
+ converts to appropriate java type
+
+
Event Callbacks
-
Tracked Changes
@@ -32,6 +40,11 @@
| 1340233 |
Null Program Id in Dispatch Constructor does bad things to VM |
+
+ | 1341763 |
+ Removed Variant serializable interface because it is not
+ actually serializable on 2000/xp |
+
| |
|
@@ -54,6 +67,14 @@
1185167 |
Provide methods to connect to running instance. |
+
+ | 959381 |
+ Auto variant to object conversion method method added to Variant. |
+
+
+ | 1341779 |
+ Variant should accept java.util.Date in Variant(Object) constructor |
+
@@ -82,6 +103,7 @@
Variants
- Automatic conversion between Windows Time and Java Date is now supported
+ in Variant object.
diff --git a/src/com/jacob/com/ComException.java b/src/com/jacob/com/ComException.java
index af0e175..d20c3de 100644
--- a/src/com/jacob/com/ComException.java
+++ b/src/com/jacob/com/ComException.java
@@ -22,9 +22,12 @@ package com.jacob.com;
/**
* Standard exception thrown by com jni code when there is a problem
*/
-public abstract class ComException extends RuntimeException {
+public abstract class ComException extends JacobException
+{
// Fields
- /** TODO: what is this field */
+ /** COM code initializes this filed with an appropriate return code
+ * that was returned by the underlying com code
+ **/
protected int hr;
/** TODO: what is this field */
protected int m_helpContext;
diff --git a/src/com/jacob/com/Dispatch.java b/src/com/jacob/com/Dispatch.java
index 7d7e34b..ee5729c 100644
--- a/src/com/jacob/com/Dispatch.java
+++ b/src/com/jacob/com/Dispatch.java
@@ -397,10 +397,10 @@ public class Dispatch extends JacobObject
* @param dispatchTarget
* @param name
* @param val
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public static void put_Casesensitive(Dispatch dispatchTarget, String name, Object val) {
- throw new ComNotImplementedException("not implemented yet");
+ throw new NotImplementedException("not implemented yet");
}
/*============================================================
@@ -453,11 +453,11 @@ public class Dispatch extends JacobObject
* @param name
* @param values
* @return never returns anything because
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public static Variant callN_CaseSensitive(Dispatch dispatchTarget, String name,
Object[] values) {
- throw new ComNotImplementedException("not implemented yet");
+ throw new NotImplementedException("not implemented yet");
}
/**
@@ -1282,10 +1282,10 @@ public class Dispatch extends JacobObject
* @param dispatchTarget
* @param name
* @return Variant never returned
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public static Variant get_CaseSensitive(Dispatch dispatchTarget, String name) {
- throw new ComNotImplementedException("not implemented yet");
+ throw new NotImplementedException("not implemented yet");
}
}
\ No newline at end of file
diff --git a/src/com/jacob/com/JacobException.java b/src/com/jacob/com/JacobException.java
new file mode 100644
index 0000000..82a14d9
--- /dev/null
+++ b/src/com/jacob/com/JacobException.java
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+/**
+ * The parent class of all Jacob exceptions.
+ * They all used to be based off of RuntimeException or ComException
+ * but it was decided to base them all off of one owned by this project.
+ */
+public class JacobException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1637125318746002715L;
+
+ /**
+ * Default constructor.
+ * Calls super with a "No Message Provided" string
+ */
+ public JacobException(){
+ super("No Message Provided");
+ }
+
+ /**
+ * standard constructor
+ * @param message
+ */
+ public JacobException(String message){
+ super(message);
+ }
+}
diff --git a/src/com/jacob/com/ComNotImplementedException.java b/src/com/jacob/com/NotImplementedException.java
similarity index 91%
rename from src/com/jacob/com/ComNotImplementedException.java
rename to src/com/jacob/com/NotImplementedException.java
index dda260c..5b41a6e 100644
--- a/src/com/jacob/com/ComNotImplementedException.java
+++ b/src/com/jacob/com/NotImplementedException.java
@@ -25,7 +25,7 @@ package com.jacob.com;
* This is a subclass of ComException so callers can still just catch
* ComException.
*/
-public class ComNotImplementedException extends ComException {
+public class NotImplementedException extends JacobException {
/**
*
@@ -35,7 +35,7 @@ public class ComNotImplementedException extends ComException {
/**
* @param description
*/
- public ComNotImplementedException(String description) {
+ public NotImplementedException(String description) {
super(description);
}
diff --git a/src/com/jacob/com/Variant.java b/src/com/jacob/com/Variant.java
index 251e541..b86e23c 100644
--- a/src/com/jacob/com/Variant.java
+++ b/src/com/jacob/com/Variant.java
@@ -19,6 +19,7 @@
*/
package com.jacob.com;
+import java.io.Serializable;
import java.util.Date;
/**
@@ -162,28 +163,28 @@ public class Variant extends JacobObject {
/**
* @deprecated superceded by SafeArray
* @param in doesn't matter because this method does nothing
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public void putVariantArray(Variant[] in) {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @return never returns anything
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public Variant[] getVariantArray() {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @param in doesn't matter because this method does nothing
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public void putByteArray(Object in) {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
@@ -291,10 +292,10 @@ public class Variant extends JacobObject {
/**
* @deprecated superceded by SafeArray
* @return never returns anything
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public Object toCharArray() {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
@@ -495,10 +496,10 @@ public class Variant extends JacobObject {
/**
* @deprecated superceded by SafeArray
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public void putCharArray(Object in) {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
public native float getFloat();
@@ -515,18 +516,18 @@ public class Variant extends JacobObject {
/**
* @deprecated superceded by SafeArray
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public void putVariantArrayRef(Variant[] in) {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public Variant[] getVariantArrayRef() {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
public native void changeType(short in);
@@ -621,6 +622,12 @@ public class Variant extends JacobObject {
putFloatRef(((Float) o).floatValue());
else
putFloat(((Float) o).floatValue());
+ } else if (o instanceof Date){
+ if (fByRef){
+ putDateRef((Date) o);
+ } else {
+ putDate((Date)o);
+ }
} else if (o instanceof SafeArray) {
if (fByRef)
putSafeArrayRef((SafeArray) o);
@@ -689,19 +696,19 @@ public class Variant extends JacobObject {
/**
* @deprecated superceded by SafeArray
* @return
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public Variant[] toVariantArray() {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
/**
* @deprecated superceded by SafeArray
* @return
- * @throws com.jacob.com.ComNotImplementedException
+ * @throws com.jacob.com.NotImplementedException
*/
public Object toByteArray() {
- throw new ComNotImplementedException("Not implemented");
+ throw new NotImplementedException("Not implemented");
}
static {
@@ -769,4 +776,94 @@ public class Variant extends JacobObject {
*/
public native void SerializationReadFromBytes(byte[] ba);
+ /*=====================================================================
+ *
+ *
+ *=====================================================================*/
+ /**
+ * Convert a JACOB Variant value to a Java object (type conversions).
+ * provided in Sourceforge feature request 959381
+ *
+ * @param variant Variant with value to get and convert.
+ * @return Corresponding Java type object.
+ * @throws Exception if conversion failed.
+ */
+ protected Object toJavaObject() throws JacobException {
+ Object result = null;
+
+ short type = this.getvt(); //variant type
+
+ if (type >= Variant.VariantArray) { //array returned?
+ SafeArray array = null;
+ type = (short) (type - Variant.VariantArray);
+ array = this.toSafeArray(false);
+ //result = toJava(array);
+ result = array;
+ } else { //non-array object returned
+ switch (type) {
+ case Variant.VariantEmpty : //0
+ case Variant.VariantNull : //1
+ break;
+ case Variant.VariantShort : //2
+ result = new Short(this.getShort());
+ break;
+ case Variant.VariantInt : //3
+ result = new Integer(this.getInt());
+ break;
+ case Variant.VariantFloat : //4
+ result = new Float(this.getFloat());
+ break;
+ case Variant.VariantDouble : //5
+ result = new Double(this.getDouble());
+ break;
+ case Variant.VariantCurrency : //6
+ result = new Long(this.getCurrency());
+ break;
+ case Variant.VariantDate : //7
+ result = this.getJavaDate();
+ break;
+ case Variant.VariantString : //8
+ result = this.getString();
+ break;
+ case Variant.VariantDispatch : //9
+ result = this.getDispatchRef();
+ break;
+ case Variant.VariantError : //10
+ result = new NotImplementedException("Not implemented: VariantError");
+ break;
+ case Variant.VariantBoolean : //11
+ result = new Boolean(this.getBoolean
+ ());
+ break;
+ case Variant.VariantVariant : //12
+ result = new NotImplementedException("Not implemented: VariantVariant");
+ break;
+ case Variant.VariantObject : //13
+ result = new NotImplementedException("Not implemented: VariantObject");
+ break;
+ case Variant.VariantByte : //17
+ result = new NotImplementedException("Not implemented: VariantByte");
+ break;
+ case Variant.VariantTypeMask : //4095
+ result = new NotImplementedException("Not implemented: VariantTypeMask");
+ break;
+ case Variant.VariantArray : //8192
+ result = new NotImplementedException("Not implemented: VariantArray");
+ break;
+ case Variant.VariantByref : //16384
+ result = new NotImplementedException("Not implemented: VariantByref");
+ break;
+ default :
+ result = new NotImplementedException("Unknown return type: " + type);
+ result = this;
+ break;
+ }//switch (type)
+
+ if (result instanceof JacobException) {
+ throw (JacobException) result;
+ }
+ }
+
+ return result;
+ }//toJava()
}
\ No newline at end of file
diff --git a/src/com/jacob/com/WrongThreadException.java b/src/com/jacob/com/WrongThreadException.java
index 6561f6d..9de5685 100644
--- a/src/com/jacob/com/WrongThreadException.java
+++ b/src/com/jacob/com/WrongThreadException.java
@@ -22,7 +22,7 @@ package com.jacob.com;
/**
* thrown in util.cpp
*/
-public class WrongThreadException extends RuntimeException {
+public class WrongThreadException extends JacobException {
/**
* identifier generated by Eclipse
*/
@@ -33,7 +33,7 @@ public class WrongThreadException extends RuntimeException {
*
*/
public WrongThreadException() {
- super();
+ super("No Message Provided.");
}
/**
diff --git a/unittest/com/jacob/com/DateUtilitiesTest.java b/unittest/com/jacob/com/DateUtilitiesTest.java
index b30b9ab..cd3720b 100644
--- a/unittest/com/jacob/com/DateUtilitiesTest.java
+++ b/unittest/com/jacob/com/DateUtilitiesTest.java
@@ -22,9 +22,9 @@ public class DateUtilitiesTest {
double comTimeForNow = DateUtilities.convertDateToWindowsTime(now);
Date retrievedNow = DateUtilities.convertWindowsTimeToDate(comTimeForNow);
if (!now.equals(retrievedNow)){
- System.out.println("Variant Date Test failed " +now+ " != " +retrievedNow );
+ System.out.println("DateUtilities Date Test failed " +now+ " != " +retrievedNow );
} else {
- System.out.println("Variant Date Test passed");
+ System.out.println("DateUtilities Date Test passed");
}
// this is a magic time in the windows world
@@ -38,6 +38,7 @@ public class DateUtilitiesTest {
} else {
System.out.println("Beginning of windows time test passed");
}
+
}
diff --git a/unittest/com/jacob/com/VariantDateTest.java b/unittest/com/jacob/com/VariantDateTest.java
index 558ff8e..4f02050 100644
--- a/unittest/com/jacob/com/VariantDateTest.java
+++ b/unittest/com/jacob/com/VariantDateTest.java
@@ -22,8 +22,34 @@ public class VariantDateTest {
if (!now.equals(retrievedNow)){
System.out.println("Variant Date Test failed " +now+ " != " +retrievedNow );
} else {
- System.out.println("Variant Date Test passed");
+ //System.out.println("Variant Date Test passed");
}
+
+ for ( int i = 0; i < 30000; i++){
+ Variant dateVariant = new Variant(now);
+ retrievedNow = dateVariant.getJavaDate();
+ if (!now.equals(retrievedNow)){
+ System.out.println("Variant Date Test (1) failed " +now+ " != " +retrievedNow );
+ } else {
+ //System.out.println("Variant Date Test (1) passed");
+ }
+ // verify auto typecasting works
+ retrievedNow = (Date)dateVariant.toJavaObject();
+ if (!now.equals(retrievedNow)){
+ System.out.println("Variant Date Test (2) failed " +now+ " != " +retrievedNow );
+ } else {
+ //System.out.println("Variant Date Test (2) passed "+retrievedNow);
+ }
+
+ Variant intVariant = new Variant(4);
+ Object variantReturn = intVariant.toJavaObject();
+ // degenerate test to make sure date isn't always returned
+ if (variantReturn instanceof Date ){
+ System.out.println("int variant returned date");
+ }
+ }
+ System.out.print("Test finished. All tests passed if no errors before this line");
+
}
}