1 16 package com.google.gwt.dev.shell.ie; 17 18 import com.google.gwt.dev.shell.CompilingClassLoader; 19 import com.google.gwt.dev.shell.JsValueGlue; 20 21 import org.eclipse.swt.internal.ole.win32.COM; 22 import org.eclipse.swt.ole.win32.Variant; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 27 48 class MethodDispatch extends IDispatchImpl { 49 50 private final CompilingClassLoader classLoader; 51 52 private final Method method; 53 54 public MethodDispatch(CompilingClassLoader classLoader, Method method) { 55 this.classLoader = classLoader; 56 this.method = method; 57 } 58 59 public String toString() { 60 return "\nfunction " + method.toString() + "(){\n [native code]\n}\n"; 61 } 62 63 68 protected void getIDsOfNames(String [] names, int[] ids) 69 throws HResultException { 70 if (names[0].equalsIgnoreCase("toString")) { 71 ids[0] = 1; 72 } else if (names[0].equalsIgnoreCase("call")) { 73 ids[0] = 2; 74 } else { 75 throw new HResultException(IDispatchProxy.DISP_E_UNKNOWNNAME); 76 } 77 } 78 79 82 protected Variant invoke(int id, int flags, Variant[] params) 83 throws HResultException, InvocationTargetException { 84 switch (id) { 85 case 0: 86 if ((flags & COM.DISPATCH_METHOD) != 0) { 87 return callMethod(classLoader, null, params, method); 89 } else if ((flags & COM.DISPATCH_PROPERTYGET) != 0) { 90 return new Variant(toString()); 92 } 93 break; 94 case 1: 95 if ((flags & (COM.DISPATCH_METHOD | COM.DISPATCH_PROPERTYGET)) != 0) { 97 return new Variant(toString()); 98 } 99 break; 100 case 2: 101 if ((flags & COM.DISPATCH_METHOD) != 0) { 103 107 Object jthis = JsValueGlue.get(new JsValueIE6(params[0]), 108 method.getDeclaringClass(), "this"); 109 Variant[] otherParams = new Variant[params.length - 1]; 110 System.arraycopy(params, 1, otherParams, 0, otherParams.length); 111 return callMethod(classLoader, jthis, otherParams, method); 112 } 113 break; 114 case IDispatchProxy.DISPID_MAGIC_GETGLOBALREF: 115 return new Variant(0); 118 default: 119 throw new HResultException(COM.DISP_E_MEMBERNOTFOUND); 121 } 122 throw new HResultException(COM.E_NOTSUPPORTED); 123 } 124 } 125 | Popular Tags |