Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Copyright (c) 2014 Dr David H. Akehurst (itemis), All Rights Reserved
*
* The contents of this file is dual-licensed under 2
* alternative Open Source/Free licenses: LGPL 2.1 or later and
* Apache License 2.0. (starting with JNA version 4.0.0).
*
* You can freely decide which license you want to apply to
* the project.
*
* You may obtain a copy of the LGPL License at:
*
* http://www.gnu.org/licenses/licenses.html
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "LGPL2.1".
*
* You may obtain a copy of the Apache License at:
*
* http://www.apache.org/licenses/
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "AL2.0".
*/
package com.sun.jna.platform.win32.COM.util;
import com.sun.jna.platform.win32.COM.COMException;
import com.sun.jna.platform.win32.COM.IDispatch;
import com.sun.jna.platform.win32.COM.IDispatchCallback;
import com.sun.jna.platform.win32.COM.util.annotation.ComObject;
import com.sun.jna.platform.win32.Guid;
import com.sun.jna.platform.win32.OaIdl;
import com.sun.jna.platform.win32.OleAuto;
import com.sun.jna.platform.win32.Variant;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.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
*/
public class Factory extends ObjectFactory {
private ComThread comThread;
public Factory() {
this(new ComThread("Default Factory COM Thread", 5000, new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
//ignore
}
}));
}
public Factory(ComThread comThread) {
this.comThread = comThread;
}
private class ProxyObject2 implements InvocationHandler {
private final Object delegate;
public ProxyObject2(Object delegate) {
this.delegate = delegate;
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (args != null) {
for (int i = 0; i < args.length; i++) {
if (args[i] != null
&& Proxy.isProxyClass(args[i].getClass())) {
InvocationHandler ih = Proxy.getInvocationHandler(args[i]);
if (ih instanceof ProxyObject2) {
args[i] = ((ProxyObject2) ih).delegate;
}
}
}
}
return runInComThread(new Callable