Top Description Inners Fields Constructors Methods
com.sun.jna.platform.win32.COM.util

public Class Factory

extends ObjectFactory
Class Inheritance
Imports
com.sun.jna.platform.win32.COM.COMException, .IDispatch, .IDispatchCallback, com.sun.jna.platform.win32.COM.util.annotation.ComObject, com.sun.jna.platform.win32.Guid, .OaIdl, .OleAuto, .Variant, .WinDef, .WinNT, com.sun.jna.ptr.IntByReference, java.lang.reflect.InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.util.concurrent.Callable, .ExecutionException, .TimeoutException

Factory is intended as a simpler to use version of ObjectFactory.

The Factory abstracts the necessity to handle COM threading by introducing a dispatching thread, that is correctly COM initialized and is used to handle all outgoing calls.

Note

Remember to call factory.getComThread().terminate() at some appropriate point, when the factory is not used anymore

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private ComThread

Constructor Summary

AccessConstructor and Description
public
public
Factory(ComThread comThread)

Method Summary

Modifier and TypeMethod and Description
private static void
appendStacktrace(Exception caughtException, Throwable toBeThrown)

Append the stack trace available via caughtException to the stack trace of toBeThrown.

pack-priv IDispatchCallback
public <T> T
createObject(final Class<T> comInterface)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.createObject.

Creates a new COM object (CoCreateInstance) for the given progId and returns a ProxyObject for the given interface.
public <T> T
createProxy(Class<T> comInterface, IDispatch dispatch)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.createProxy.

Creates a ProxyObject for the given interface and IDispatch pointer.
pack-priv Guid.GUID
public <T> T
fetchObject(final Class<T> comInterface)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.fetchObject.

Gets and existing COM object (GetActiveObject) for the given progId and returns a ProxyObject for the given interface.
public ComThread
public IRunningObjectTable
getRunningObjectTable()

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.getRunningObjectTable.

CoInitialize must be called be fore this method.
private <T> T
runInComThread(Callable<T> callable)

Inherited from com.sun.jna.platform.win32.COM.util.ObjectFactory:
disposeAllfinalizegetLCIDregistersetLCIDunregister

Field Detail

comThreadback to summary
private ComThread comThread

Constructor Detail

Factoryback to summary
public Factory()
Factoryback to summary
public Factory(ComThread comThread)

Method Detail

appendStacktraceback to summary
private static void appendStacktrace(Exception caughtException, Throwable toBeThrown)

Append the stack trace available via caughtException to the stack trace of toBeThrown. The combined stack trace is reassigned to toBeThrown

createDispatchCallbackback to summary
pack-priv IDispatchCallback createDispatchCallback(Class<?> comEventCallbackInterface, IComEventCallbackListener comEventCallbackListener)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.createDispatchCallback.

Annotations
@Override
createObjectback to summary
public <T> T createObject(final Class<T> comInterface)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.createObject.

Doc from com.sun.jna.platform.win32.COM.util.ObjectFactory.createObject.

Creates a new COM object (CoCreateInstance) for the given progId and returns a ProxyObject for the given interface.

Annotations
@Override
createProxyback to summary
public <T> T createProxy(Class<T> comInterface, IDispatch dispatch)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.createProxy.

Doc from com.sun.jna.platform.win32.COM.util.ObjectFactory.createProxy.

Creates a ProxyObject for the given interface and IDispatch pointer.

Annotations
@Override
discoverClsIdback to summary
pack-priv Guid.GUID discoverClsId(final ComObject annotation)

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.discoverClsId.

Annotations
@Override
fetchObjectback to summary
public <T> T fetchObject(final Class<T> comInterface) throws COMException

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.fetchObject.

Doc from com.sun.jna.platform.win32.COM.util.ObjectFactory.fetchObject.

Gets and existing COM object (GetActiveObject) for the given progId and returns a ProxyObject for the given interface.

Annotations
@Override
getComThreadback to summary
public ComThread getComThread()
getRunningObjectTableback to summary
public IRunningObjectTable getRunningObjectTable()

Overrides com.sun.jna.platform.win32.COM.util.ObjectFactory.getRunningObjectTable.

Doc from com.sun.jna.platform.win32.COM.util.ObjectFactory.getRunningObjectTable.

CoInitialize must be called be fore this method. Either explicitly or implicitly via other methods.

Returns:IRunningObjectTable

running object table

Annotations
@Override
runInComThreadback to summary
private <T> T runInComThread(Callable<T> callable)
com.sun.jna.platform.win32.COM.util back to summary

private Class Factory.CallbackProxy2

extends CallbackProxy
Class Inheritance

Field Summary

Inherited from com.sun.jna.platform.win32.COM.util.CallbackProxy:
comEventCallbackInterfacecomEventCallbackListenerdispatchListenerdsipIdMapfactorylistenedToRiid

Constructor Summary

AccessConstructor and Description
public
CallbackProxy2(ObjectFactory factory, Class<?> comEventCallbackInterface, IComEventCallbackListener comEventCallbackListener)

Method Summary

Modifier and TypeMethod and Description
public WinNT.HRESULT
Invoke(OaIdl.DISPID
Identifies the member. Use GetIDsOfNames or the object's documentation to obtain the dispatch identifier.
dispIdMember
,
Guid.REFIID
Reserved for future use. Must be IID_NULL.
riid
,
WinDef.LCID
The locale context in which to interpret arguments. The lcid is used by the GetIDsOfNames function, and is also passed to Invoke to allow the object to interpret its arguments specific to a locale.

Applications that do not support multiple national languages can ignore this parameter. For more information, refer to Supporting Multiple National Languages and Exposing ActiveX Objects.

lcid
,
WinDef.WORD
Flags describing the context of the Invoke call. DISPATCH_METHOD The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag can be set. DISPATCH_PROPERTYGET The member is retrieved as a property or data member. DISPATCH_PROPERTYPUT The member is changed as a property or data member. DISPATCH_PROPERTYPUTREF The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.
wFlags
,
OleAuto.DISPPARAMS.ByReference
Pointer to a DISPPARAMS structure containing an array of arguments, an array of argument DISPIDs for named arguments, and counts for the number of elements in the arrays.
pDispParams
,
Variant.VARIANT.ByReference
Pointer to the location where the result is to be stored, or NULL if the caller expects no result. This argument is ignored if DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYPUTREF is specified.
pVarResult
,
OaIdl.EXCEPINFO.ByReference
Pointer to a structure that contains exception information. This structure should be filled in if DISP_E_EXCEPTION is returned. Can be NULL.
pExcepInfo
,
IntByReference
The index within rgvarg of the first argument that has an error. Arguments are stored in pDispParams->rgvarg in reverse order, so the first argument is the one with the highest index in the array. This parameter is returned only when the resulting return value is DISP_E_TYPEMISMATCH or DISP_E_PARAMNOTFOUND. This argument can be set to null. For details, see Returning Errors.
puArgErr
)

Overrides com.sun.jna.platform.win32.COM.util.CallbackProxy.Invoke.

Implements com.sun.jna.platform.win32.COM.IDispatch.Invoke.

Provides access to properties and methods exposed by an object.
Inherited from com.sun.jna.platform.win32.COM.util.CallbackProxy:
AddRefGetIDsOfNamesgetPointerGetTypeInfoGetTypeInfoCountinvokeOnThreadQueryInterfaceRelease

Constructor Detail

CallbackProxy2back to summary
public CallbackProxy2(ObjectFactory factory, Class<?> comEventCallbackInterface, IComEventCallbackListener comEventCallbackListener)

Method Detail

Invokeback to summary
public WinNT.HRESULT Invoke(OaIdl.DISPID dispIdMember, Guid.REFIID riid, WinDef.LCID lcid, WinDef.WORD wFlags, OleAuto.DISPPARAMS.ByReference pDispParams, Variant.VARIANT.ByReference pVarResult, OaIdl.EXCEPINFO.ByReference pExcepInfo, IntByReference puArgErr)

Overrides com.sun.jna.platform.win32.COM.util.CallbackProxy.Invoke.

Implements com.sun.jna.platform.win32.COM.IDispatch.Invoke.

Doc from com.sun.jna.platform.win32.COM.IDispatch.Invoke.

Provides access to properties and methods exposed by an object. The dispatch function DispInvoke provides a standard implementation of Invoke.

Parameters
dispIdMember:OaIdl.DISPID

Identifies the member. Use GetIDsOfNames or the object's documentation to obtain the dispatch identifier.

riid:Guid.REFIID

Reserved for future use. Must be IID_NULL.

lcid:WinDef.LCID

The locale context in which to interpret arguments. The lcid is used by the GetIDsOfNames function, and is also passed to Invoke to allow the object to interpret its arguments specific to a locale.

Applications that do not support multiple national languages can ignore this parameter. For more information, refer to Supporting Multiple National Languages and Exposing ActiveX Objects.

wFlags:WinDef.WORD

Flags describing the context of the Invoke call. DISPATCH_METHOD The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag can be set. DISPATCH_PROPERTYGET The member is retrieved as a property or data member. DISPATCH_PROPERTYPUT The member is changed as a property or data member. DISPATCH_PROPERTYPUTREF The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.

pDispParams:OleAuto.DISPPARAMS.ByReference

Pointer to a DISPPARAMS structure containing an array of arguments, an array of argument DISPIDs for named arguments, and counts for the number of elements in the arrays.

pVarResult:Variant.VARIANT.ByReference

Pointer to the location where the result is to be stored, or NULL if the caller expects no result. This argument is ignored if DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYPUTREF is specified.

pExcepInfo:OaIdl.EXCEPINFO.ByReference

Pointer to a structure that contains exception information. This structure should be filled in if DISP_E_EXCEPTION is returned. Can be NULL.

puArgErr:IntByReference

The index within rgvarg of the first argument that has an error. Arguments are stored in pDispParams->rgvarg in reverse order, so the first argument is the one with the highest index in the array. This parameter is returned only when the resulting return value is DISP_E_TYPEMISMATCH or DISP_E_PARAMNOTFOUND. This argument can be set to null. For details, see Returning Errors.

Returns:WinNT.HRESULT

This method can return one of these values. S_OK Success. DISP_E_BADPARAMCOUNT The number of elements provided to DISPPARAMS is different from the number of arguments accepted by the method or property. DISP_E_BADVARTYPE One of the arguments in DISPPARAMS is not a valid variant type. DISP_E_EXCEPTION The application needs to raise an exception. In this case, the structure passed in pexcepinfo should be filled in. DISP_E_MEMBERNOTFOUND The requested member does not exist. DISP_E_NONAMEDARGS This implementation of IDispatch does not support named arguments. DISP_E_OVERFLOW One of the arguments in DISPPARAMS could not be coerced to the specified type. DISP_E_PARAMNOTFOUND One of the parameter IDs does not correspond to a parameter on the method. In this case, puArgErr is set to the first argument that contains the error. DISP_E_TYPEMISMATCH One or more of the arguments could not be coerced. The index of the first parameter with the incorrect type within rgvarg is returned in puArgErr. DISP_E_UNKNOWNINTERFACE The interface identifier passed in riid is not IID_NULL. DISP_E_UNKNOWNLCID The member being invoked interprets string arguments according to the LCID, and the LCID is not recognized. If the LCID is not needed to interpret arguments, this error should not be returned DISP_E_PARAMNOTOPTIONAL A required parameter was omitted.

Annotations
@Override
com.sun.jna.platform.win32.COM.util back to summary

private Class Factory.ProxyObject2

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler

Field Summary

Modifier and TypeField and Description
private final Object

Constructor Summary

AccessConstructor and Description
public
ProxyObject2(Object delegate)

Method Summary

Modifier and TypeMethod and Description
public Object
invoke(final Object
the proxy instance that the method was invoked on
proxy
,
final Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
final Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final Object delegate

Constructor Detail

ProxyObject2back to summary
public ProxyObject2(Object delegate)

Method Detail

invokeback to summary
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.