Skip to content

Commit 93869e7

Browse files
committed
Update for Jinx 2 release
Jinx 2 has a new form for ExcelArgumentConverter methods that can register converters for any class using an upper bound type parameter constraint. This lets us convert the new Jinx IUnknown type to the Com4j wrapper types automatically via an argument converter. It also allows us to use the new safer form of ExcelAddIn.getApplication.
1 parent 971c624 commit 93869e7

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

examples/pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.exceljava</groupId>
77
<artifactId>jinx-com4j-root</artifactId>
8-
<version>1.0-SNAPSHOT</version>
8+
<version>1.1-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -16,6 +16,7 @@
1616
<plugin>
1717
<groupId>org.apache.maven.plugins</groupId>
1818
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.8.1</version>
1920
<configuration>
2021
<source>1.8</source>
2122
<target>1.8</target>
@@ -27,12 +28,12 @@
2728
<dependency>
2829
<groupId>com.exceljava</groupId>
2930
<artifactId>jinx-com4j</artifactId>
30-
<version>1.0-SNAPSHOT</version>
31+
<version>1.1-SNAPSHOT</version>
3132
</dependency>
3233
<dependency>
3334
<groupId>com.exceljava</groupId>
3435
<artifactId>jinx</artifactId>
35-
<version>1.6.0</version>
36+
<version>2.0.0-beta1</version>
3637
</dependency>
3738
</dependencies>
3839
</project>

jinx-com4j/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.exceljava</groupId>
77
<artifactId>jinx-com4j-root</artifactId>
8-
<version>1.0-SNAPSHOT</version>
8+
<version>1.1-SNAPSHOT</version>
99
<relativePath>..</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>com.exceljava</groupId>
2828
<artifactId>jinx</artifactId>
29-
<version>[1.0.0,)</version>
29+
<version>2.0.0-beta1</version>
3030
</dependency>
3131
<!-- com4j -->
3232
<dependency>
@@ -47,6 +47,7 @@
4747
<plugin>
4848
<groupId>org.apache.maven.plugins</groupId>
4949
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>3.8.1</version>
5051
<configuration>
5152
<source>1.8</source>
5253
<target>1.8</target>
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
package com.exceljava.com4j;
22

33
import com.exceljava.jinx.ExcelAddIn;
4+
import com.exceljava.jinx.ExcelArgumentConverter;
5+
import com.exceljava.jinx.IUnknown;
46
import com.exceljava.com4j.excel._Application;
57
import com4j.COM4J;
68
import com4j.Com4jObject;
7-
import com4j.ComThread;
8-
import com4j.ROT;
9+
910

1011
/**
1112
* Bridge between the Jinx add-in and com4j.
1213
* Used for obtaining com4j COM wrappers from code running in Excel using Jinx.
1314
*/
1415
public class JinxBridge {
15-
16-
private static final ThreadLocal<_Application> xlApp = new ThreadLocal<_Application>() {
17-
public _Application initialValue() {
18-
return null;
19-
}
20-
};
21-
2216
/**
2317
* Gets the Excel Application object for the current Excel process.
2418
*
@@ -34,7 +28,24 @@ public _Application initialValue() {
3428
* @return An Excel Application instance.
3529
*/
3630
public static _Application getApplication(ExcelAddIn xl) {
37-
Com4jObject unk = COM4J.wrapSta(Com4jObject.class, xl.getExcelApplication());
38-
return unk.queryInterface(_Application.class);
31+
return xl.getExcelApplication(_Application.class);
32+
}
33+
34+
/**
35+
* Converts IUnknown to any Com4jObject type.
36+
*
37+
* This allows Com4jObjects to be used as method arguments where
38+
* an IUnknown would be passed by Jinx. For example, in the
39+
* ribbon actions.
40+
*
41+
* @param unk IUnknown instance.
42+
* @param cls Class of type to cast to.
43+
* @param <T> Type to cast to.
44+
* @return IUnknown instance cast to a Com4jObject instance.
45+
*/
46+
@ExcelArgumentConverter
47+
public static <T extends Com4jObject> T convertIUnknown(IUnknown unk, Class<T> cls) {
48+
Com4jObject obj = COM4J.wrapSta(Com4jObject.class, unk.getPointer(true));
49+
return obj.queryInterface(cls);
3950
}
4051
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Classes to be loaded by the Jinx Add-In
3+
#
4+
com.exceljava.com4j.JinxBridge
5+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.exceljava</groupId>
77
<artifactId>jinx-com4j-root</artifactId>
88
<packaging>pom</packaging>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.1-SNAPSHOT</version>
1010
<modules>
1111
<module>examples</module>
1212
<module>jinx-com4j</module>

0 commit comments

Comments
 (0)