1 16 package com.google.gwt.dev.shell; 17 18 import java.lang.reflect.Field ; 19 import java.lang.reflect.Member ; 20 import java.lang.reflect.Method ; 21 22 25 public class JavaDispatchImpl implements JavaDispatch { 26 27 private final CompilingClassLoader classLoader; 28 29 private final Object target; 30 31 36 public JavaDispatchImpl(CompilingClassLoader ccl) { 37 classLoader = ccl; 38 target = null; 39 } 40 41 49 public JavaDispatchImpl(CompilingClassLoader ccl, Object target) { 50 if (target == null) { 51 throw new NullPointerException ("target cannot be null"); 52 } 53 54 classLoader = ccl; 55 this.target = target; 56 } 57 58 62 public Field getField(int dispId) { 63 return (Field ) getMember(dispId); 64 } 65 66 71 public Object getFieldValue(int dispId) { 72 Field field = (Field ) getMember(dispId); 73 try { 74 return field.get(target); 75 } catch (IllegalAccessException e) { 76 e.printStackTrace(); 78 throw new RuntimeException (e); 79 } 80 } 81 82 86 public Method getMethod(int dispId) { 87 return (Method ) getMember(dispId); 88 } 89 90 public Object getTarget() { 91 return target; 92 } 93 94 98 public boolean isField(int dispId) { 99 if (dispId < 0) { 100 return false; 101 } 102 103 return getMember(dispId) instanceof Field ; 104 } 105 106 110 public boolean isMethod(int dispId) { 111 if (dispId < 0) { 112 return false; 113 } 114 115 return getMember(dispId) instanceof Method ; 116 } 117 118 123 public void setFieldValue(int dispId, Object value) { 124 Field field = (Field ) getMember(dispId); 125 try { 126 field.set(target, value); 127 } catch (IllegalAccessException e) { 128 e.printStackTrace(); 130 throw new RuntimeException (e); 131 } 132 } 133 134 138 protected Member getMember(int dispId) { 139 DispatchClassInfo clsInfo = classLoader.getClassInfoByDispId(dispId); 140 return clsInfo.getMember(dispId); 141 } 142 } 143 | Popular Tags |