Example usage for com.google.gwt.dev.shell.designtime MethodAdaptor needsThis

List of usage examples for com.google.gwt.dev.shell.designtime MethodAdaptor needsThis

Introduction

In this page you can find the example usage for com.google.gwt.dev.shell.designtime MethodAdaptor needsThis.

Prototype

boolean needsThis

To view the source code for com.google.gwt.dev.shell.designtime MethodAdaptor needsThis.

Click Source Link

Usage

From source file:com.google.gdt.eclipse.designer.ie.jsni.IDispatchProxy.java

License:Open Source License

@Override
protected Variant invoke(int dispId, int flags, Variant[] params)
        throws HResultException, InstantiationException, InvocationTargetException {
    ClassLoader classLoader = classLoaderRef.get();
    if (classLoader == null) {
        throw new RuntimeException("Invalid class loader.");
    }/*from   w ww  .  j a  va  2 s  . c  om*/
    DispatchIdOracle dispIdOracle = dispIdOracleRef.get();
    if (dispIdOracle == null) {
        throw new RuntimeException("Invalid dispatch oracle.");
    }
    try {
        // GWT 2: called static scope with dispId as parameter
        if (dispId == 0 && (flags & COM.DISPATCH_METHOD) != 0 && params.length >= 2) {
            Variant dispIdVar = params[0]; // zero is dispId, next should be null (as 'this') for static context
            dispId = dispIdVar.getInt();
            if (javaDispatch.isMethod(dispId)) {
                MethodAdaptor method = javaDispatch.getMethod(dispId);
                Object target = getTarget();
                Object jthis = method.needsThis()
                        ? JsValueGlue.get(new JsValueIE6(params[1]), classLoader, method.getDeclaringClass(),
                                "this")
                        : null;
                Variant[] otherParams = new Variant[params.length - 2];
                System.arraycopy(params, 2, otherParams, 0, otherParams.length);
                return callMethod(classLoader, dispIdOracle, jthis, otherParams, method);
            }
        }
        // Whatever the caller asks for, try to find it via reflection.
        //
        if (dispId == DISPID_MAGIC_GETGLOBALREF && myGlobalRef != 0) {
            // Handle specially.
            //
            return new Variant(myGlobalRef);
        } else if (dispId == 0) {
            if ((flags & COM.DISPATCH_METHOD) != 0) {
                // implicit call -- "m()"
                // not supported -- fall through to unsupported failure
            } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) {
                // implicit toString -- "'foo' + m"
                return new Variant(getTarget().toString());
            }
        } else if (dispId > 0) {
            if (javaDispatch.isMethod(dispId)) {
                MethodAdaptor method = javaDispatch.getMethod(dispId);
                if ((flags & COM.DISPATCH_METHOD) != 0) {
                    // This is a method call.
                    return callMethod(classLoader, dispIdOracle, getTarget(), params, method);
                } else if (flags == COM.DISPATCH_PROPERTYGET) {
                    // The function is being accessed as a property.
                    AccessibleObject obj = method.getUnderlyingObject();
                    IDispatchImpl dispMethod = (IDispatchImpl) WrappersCache.getWrapperForObject(classLoader,
                            obj);
                    if (dispMethod == null || dispMethod.refCount < 1) {
                        dispMethod = new MethodDispatch(classLoader, dispIdOracle, method);
                        WrappersCache.putWrapperForObject(classLoader, obj, dispMethod);
                    }
                    IDispatch disp = new IDispatch(dispMethod.getAddress());
                    disp.AddRef();
                    return new Variant(disp);
                }
            } else if (javaDispatch.isField(dispId)) {
                Field field = javaDispatch.getField(dispId);
                if (flags == COM.DISPATCH_PROPERTYGET) {
                    return SwtOleGlue.convertObjectToVariant(classLoader, dispIdOracle, field.getType(),
                            javaDispatch.getFieldValue(dispId));
                } else if ((flags & (COM.DISPATCH_PROPERTYPUT | COM.DISPATCH_PROPERTYPUTREF)) != 0) {
                    javaDispatch.setFieldValue(dispId, JsValueGlue.get(new JsValueIE6(params[0]), classLoader,
                            field.getType(), "Setting field '" + field.getName() + "'"));
                    return new Variant();
                }
            }
        } else {
            // The specified member id is out of range.
            throw new HResultException(COM.DISP_E_MEMBERNOTFOUND);
        }
    } catch (IllegalArgumentException e) {
        // should never, ever happen
        e.printStackTrace();
        throw new HResultException(e);
    }
    System.err.println("IDispatchProxy cannot be invoked with flags: " + Integer.toHexString(flags));
    throw new HResultException(COM.E_NOTSUPPORTED);
}