use of com.sun.jna.platform.win32.COM.util.annotation.ComMethod in project jna by java-native-access.
the class ProxyObject method invoke.
// --------------------- InvocationHandler -----------------------------
@Override
public Object invoke(final Object proxy, final java.lang.reflect.Method method, final Object[] args) throws Throwable {
boolean declaredAsInterface = (method.getAnnotation(ComMethod.class) != null) || (method.getAnnotation(ComProperty.class) != null);
if ((!declaredAsInterface) && (method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(IRawDispatchHandle.class) || method.getDeclaringClass().equals(com.sun.jna.platform.win32.COM.util.IUnknown.class) || method.getDeclaringClass().equals(com.sun.jna.platform.win32.COM.util.IDispatch.class) || method.getDeclaringClass().equals(IConnectionPoint.class))) {
try {
return method.invoke(this, args);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
}
Class<?> returnType = method.getReturnType();
boolean isVoid = Void.TYPE.equals(returnType);
ComProperty prop = method.getAnnotation(ComProperty.class);
if (null != prop) {
int dispId = prop.dispId();
if (isVoid) {
if (dispId != -1) {
this.setProperty(new DISPID(dispId), args[0]);
return null;
} else {
String propName = this.getMutatorName(method, prop);
this.setProperty(propName, args[0]);
return null;
}
} else {
if (dispId != -1) {
return this.getProperty(returnType, new DISPID(dispId), args);
} else {
String propName = this.getAccessorName(method, prop);
return this.getProperty(returnType, propName, args);
}
}
}
ComMethod meth = method.getAnnotation(ComMethod.class);
if (null != meth) {
Object[] fullLengthArgs = unfoldWhenVarargs(method, args);
int dispId = meth.dispId();
if (dispId != -1) {
return this.invokeMethod(returnType, new DISPID(dispId), fullLengthArgs);
} else {
String methName = this.getMethodName(method, meth);
return this.invokeMethod(returnType, methName, fullLengthArgs);
}
}
return null;
}
Aggregations