Package org.eclipse.swt.ole.win32

Examples of org.eclipse.swt.ole.win32.OLE


    // Convert it to a variant (if the return type is void, return
    // a VT_EMPTY variant -- 'undefined' in JavaScript).
    //
    Class returnType = method.getReturnType();
    if (returnType.equals(Void.TYPE)) {
      return new Variant();
    }
    return SwtOleGlue.convertObjectToVariant(cl, returnType, result);
  }
View Full Code Here


  private int Invoke(int dispIdMember, int riid, int lcid, int dwFlags,
      int pDispParams, int pVarResult, int pExcepInfo, int pArgErr) {

    HResultException ex = null;
    Variant[] vArgs = null;
    Variant result = null;
    try {
      vArgs = extractVariantArrayFromDispParamsPtr(pDispParams);
      result = invoke(dispIdMember, dwFlags, vArgs);
      if (pVarResult != 0) {
        Variant.win32_copy(pVarResult, result);
      }
    } catch (HResultException e) {
      // Log to the console for detailed examination.
      //
      e.printStackTrace();
      ex = e;

    } catch (InvocationTargetException e) {
      // If we get here, it means an exception is being thrown from
      // Java back into JavaScript

      Throwable t = e.getTargetException();
      ex = new HResultException(t);
      ModuleSpace.setThrownJavaException(t);
    } catch (Exception e) {
      // Log to the console for detailed examination.
      //
      e.printStackTrace();
      ex = new HResultException(e);
    } finally {
      // We allocated variants for all arguments, so we must dispose them all.
      //
      for (int i = 0; i < vArgs.length; ++i) {
        if (vArgs[i] != null) {
          vArgs[i].dispose();
        }
      }

      if (result != null) {
        result.dispose();
      }
    }

    if (ex != null) {
      // Set up an exception for IE to throw.
View Full Code Here

      // 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)) {
          Method method = javaDispatch.getMethod(dispId);
          if ((flags & COM.DISPATCH_METHOD) != 0) {
            // This is a method call.
            return callMethod(classLoader, getTarget(), params, method);
          } else if (flags == COM.DISPATCH_PROPERTYGET) {
            // The function is being accessed as a property.
            IDispatchImpl funcObj = new MethodDispatch(classLoader, method);
            IDispatch disp = new IDispatch(funcObj.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,
                field.getType(), javaDispatch.getFieldValue(dispId));
          } else if ((flags & (COM.DISPATCH_PROPERTYPUT | COM.DISPATCH_PROPERTYPUTREF)) != 0) {
            javaDispatch.setFieldValue(dispId, JsValueGlue.get(new JsValueIE6(
                params[0]), 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);
View Full Code Here

        if ((flags & COM.DISPATCH_METHOD) != 0) {
          // implicit call -- "m()"
          return callMethod(classLoader, null, params, method);
        } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) {
          // implicit toString -- "'foo' + m"
          return new Variant(toString());
        }
        break;
      case 1:
        // "m.toString()"
        if ((flags & (COM.DISPATCH_METHOD | COM.DISPATCH_PROPERTYGET)) != 0) {
          return new Variant(toString());
        }
        break;
      case 2:
        // "m.call(thisObj, arg)"
        if ((flags & COM.DISPATCH_METHOD) != 0) {
          /*
           * 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]),
              method.getDeclaringClass(), "this");
          Variant[] otherParams = new Variant[params.length - 1];
          System.arraycopy(params, 1, otherParams, 0, otherParams.length);
          return callMethod(classLoader, jthis, otherParams, method);
        }
        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);
View Full Code Here

      window = new OleAutomation(frameWnd);
      int[] dispID = window.getIDsOfNames(new String[] { propName });
      if (dispID == null) {
        throw new RuntimeException("No such property " + propName);
      }
      Variant value = null;
      try {
        value = window.getProperty(dispID[0]);
        return value.getInt();
      } finally {
        if (value != null) {
          value.dispose();
        }
      }
    } finally {
      if (window != null) {
        window.dispose();
View Full Code Here

      window = new OleAutomation(frameWnd);
      int[] dispID = window.getIDsOfNames(new String[] { propName });
      if (dispID == null) {
        throw new RuntimeException("No such property " + propName);
      }
      Variant value = null;
      try {
        value = new Variant(intValue);
        window.setProperty(dispID[0], value);
      } finally {
        if (value != null) {
          value.dispose();
        }
      }
    } finally {
      if (window != null) {
        window.dispose();
View Full Code Here

    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 {
            IDispatch frameWnd = (params[0].getType() == COM.VT_DISPATCH)
                ? params[0].getDispatch() : null;
            String moduleName = (params[1].getType() == COM.VT_BSTR)
                ? params[1].getString() : null;
            boolean success = gwtOnLoad(frameWnd, moduleName);

            // 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});
            IDispatchImpl funcObj = new MethodDispatch(null, gwtOnLoadMethod);
            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);
      }
View Full Code Here

   * @return the return value of the JavaScript function
   */
  protected static Variant doInvokeOnWindow(OleAutomation window, String name,
      Variant[] vArgs) {
    OleAutomation funcObj = null;
    Variant funcObjVar = null;
    try {

      // Get the function object and its 'call' method.
      //
      int[] ids = window.getIDsOfNames(new String[] {name});
      if (ids == null) {
        throw new RuntimeException(
            "Could not find a native method with the signature '" + name + "'");
      }
      int functionId = ids[0];
      funcObjVar = window.getProperty(functionId);
      funcObj = funcObjVar.getAutomation();
      int callDispId = funcObj.getIDsOfNames(new String[] {"call"})[0];

      // Invoke it and return the result.
      //
      return funcObj.invoke(callDispId, vArgs);

    } finally {
      if (funcObjVar != null) {
        funcObjVar.dispose();
      }

      if (funcObj != null) {
        funcObj.dispose();
      }
View Full Code Here

    // a new top-level function.
    //
    String newScript = createNativeMethodInjector(jsniSignature, paramNames, js);
    try {
      // TODO: somehow insert file/line info into the script
      Variant result = execute(newScript);
      if (result != null) {
        result.dispose();
      }
    } catch (RuntimeException e) {
      throw new RuntimeException(file + "(" + line
          + "): Failed to create JSNI method with signature '" + jsniSignature
          + "'", e);
View Full Code Here

      for (int i = 0; i < len; ++i) {
        vArgs[i + 1] = SwtOleGlue.convertObjectToVariant(
            getIsolatedClassLoader(), types[i], args[i]);
      }

      Variant result = doInvokeOnWindow(window, name, vArgs);
      try {
        return new JsValueIE6(result);
      } finally {
        if (result != null) {
          result.dispose();
        }
      }
    } finally {
      // We allocated variants for all arguments, so we must dispose them all.
      //
View Full Code Here

TOP

Related Classes of org.eclipse.swt.ole.win32.OLE

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.