protected Variant invoke(int dispId, int flags, Variant[] params)
throws HResultException, InvocationTargetException {
if (dispId == 0 && (flags & COM.DISPATCH_PROPERTYGET) != 0) {
// MAGIC: this is the default property, let's just do toString()
return new Variant(toString());
} else if (dispId == 1) {
if ((flags & COM.DISPATCH_METHOD) != 0) {
try {
if (params.length < 3) {
reportIncorrectInvocation("gwtOnLoad", 3, params.length);
throw new HResultException(COM.E_INVALIDARG);
}
IDispatch frameWnd = (params[0].getType() == COM.VT_DISPATCH)
? params[0].getDispatch() : null;
String moduleName = (params[1].getType() == COM.VT_BSTR)
? params[1].getString() : null;
String version = (params[2].getType() == COM.VT_BSTR)
? params[2].getString() : null;
boolean success = gwtOnLoad(frameWnd, moduleName, version);
// boolean return type
return new Variant(success);
} catch (SWTException e) {
throw new HResultException(COM.E_INVALIDARG);
}
} else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) {
// property get on the method itself
try {
Method gwtOnLoadMethod = getClass().getMethod("gwtOnLoad",
new Class[] {IDispatch.class, String.class, String.class});
MethodAdaptor methodAdaptor = new MethodAdaptor(gwtOnLoadMethod);
IDispatchImpl funcObj = new MethodDispatch(null, methodAdaptor);
IDispatch disp = new IDispatch(funcObj.getAddress());
disp.AddRef();
return new Variant(disp);
} catch (Exception e) {
// just return VT_EMPTY
return new Variant();
}
}
throw new HResultException(COM.E_NOTSUPPORTED);
} else if (dispId == 2) {
if ((flags & COM.DISPATCH_METHOD) != 0) {
try {
if (params.length < 1) {
reportIncorrectInvocation("initModule", 1, params.length);
throw new HResultException(COM.E_INVALIDARG);
}
String moduleName = (params[0].getType() == COM.VT_BSTR)
? params[0].getString() : null;
boolean reload = initModule(moduleName);
// boolean return type
return new Variant(reload);
} catch (SWTException e) {
throw new HResultException(COM.E_INVALIDARG);
}
} else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) {
// property get on the method itself
try {
Method gwtOnLoadMethod = getClass().getMethod("initModule",
new Class[] {String.class});
MethodAdaptor methodAdaptor = new MethodAdaptor(gwtOnLoadMethod);
IDispatchImpl funcObj = new MethodDispatch(null, methodAdaptor);
IDispatch disp = new IDispatch(funcObj.getAddress());
disp.AddRef();
return new Variant(disp);
} catch (Exception e) {
// just return VT_EMPTY
return new Variant();
}
}
throw new HResultException(COM.E_NOTSUPPORTED);
}