List of usage examples for com.google.gwt.dev.shell.designtime MethodAdaptor MethodAdaptor
public MethodAdaptor(Method m)
From source file:com.google.gdt.eclipse.designer.ie.jsni.MethodDispatch.java
License:Open Source License
@Override protected Variant invoke(int id, int flags, Variant[] params) throws HResultException, InstantiationException, InvocationTargetException { ClassLoader classLoader = classLoaderRef.get(); if (classLoader == null) { throw new RuntimeException("Invalid class loader."); }//from www. ja va 2 s .c om DispatchIdOracle dispIdOracle = dispIdOracleRef.get(); if (dispIdOracle == null) { throw new RuntimeException("Invalid dispatch oracle."); } switch (id) { case 0: // An implicit access. if ((flags & COM.DISPATCH_METHOD) != 0) { // implicit call -- "m()" return callMethod(classLoader, dispIdOracle, null, params, method); } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) { // implicit toString -- "'foo' + m" return new Variant(toString()); } break; case 1: // toString if ((flags & COM.DISPATCH_METHOD) != 0) { // "m.toString()" return new Variant(toString()); } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) { // "m.toString" MethodAdaptor toStringMethod; try { toStringMethod = new MethodAdaptor(Object.class.getDeclaredMethod("toString")); } catch (Throwable e) { throw new RuntimeException("Failed to get Object.toString() method", e); } AccessibleObject obj = toStringMethod.getUnderlyingObject(); IDispatchImpl dispMethod = (IDispatchImpl) WrappersCache.getWrapperForObject(classLoader, obj); if (dispMethod == null || dispMethod.refCount < 1) { dispMethod = new MethodDispatch(classLoader, dispIdOracle, toStringMethod); WrappersCache.putWrapperForObject(classLoader, obj, dispMethod); } IDispatch disp = new IDispatch(dispMethod.getAddress()); disp.AddRef(); return new Variant(disp); } break; case 2: // call if ((flags & COM.DISPATCH_METHOD) != 0) { // "m.call(thisObj, arg)" /* * First param must be a this object of the correct type (for instance * methods). If method is static, it can be null. */ Object jthis = JsValueGlue.get(new JsValueIE6(params[0]), classLoader, method.getDeclaringClass(), "this"); Variant[] otherParams = new Variant[params.length - 1]; System.arraycopy(params, 1, otherParams, 0, otherParams.length); return callMethod(classLoader, dispIdOracle, jthis, otherParams, method); } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) { // "m.call" // TODO: not supported } break; case 3: // apply // TODO: not supported break; case IDispatchProxy.DISPID_MAGIC_GETGLOBALREF: // We are NOT in fact a "wrapped Java Object", but we don't want to // throw an exception for being asked. return new Variant(0); default: // The specified member id is out of range. throw new HResultException(COM.DISP_E_MEMBERNOTFOUND); } throw new HResultException(COM.E_NOTSUPPORTED); }