Skip to content
Type-safe proxy for J-Interop
Branch: master
Clone or download
Latest commit 55890fe Jun 28, 2013
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main/java/org/kohsuke/jinterop Added boolean unmarshalling. Feb 21, 2009
.gitignore
README.md
pom.xml

README.md

J-Interop Typesafe Proxy

This small library allows you to access IDispatch COM objects through type-safe Java interfaces by using j-interop underneath.

Usage

First, you define an interface that designates methods and properties available on the COM objects you want to talk to. Looking at the type libraries of those COM objects will help you determine the signatures. For example,

public interface SWbemLocator extends JIProxy {
    SWbemServices ConnectServer(String server, String namespace, String user, String password) throws JIException;
    SWbemServices ConnectServer(String server, String namespace, String user, String password, String locale, String authority, int securityFlags, Object objwbemNamedValueSet) throws JIException;
}

Your interface must extend JIProxy to indicate that it is a type-safe proxy to IDispatch. Methods should also throw JIException which comes from j-interop. The method names must match those defined by COM objects (hence the non-camel convention), and method parameters have to match the parameters defined by COM objects, too.

If the IDispatch interface defines properties, you need to use @Property annotation to mark them.

public interface SWbemObjectSet extends JIProxy, Iterable<SWbemObject> {
    @Property
    int Count() throws JIException;
    IJIDispatch Item(String path/*?*/) throws JIException;
}

The above example also shows the use of Iterable<T> in the proxy interface, which is converted to the calls to IEnumVARIANT COM interface.

Given those type-safe interfaces, you can wrap an IJIDispatch or IJIComObject into this proxy as follows:

IJIComObject o = ...;
SWbemLocator loc = JInteropInvocationHandler.wrap(SWbemLocator.class,o)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.