1 28 29 package com.caucho.es; 30 31 import com.caucho.util.IntMap; 32 33 import java.util.HashMap ; 34 35 38 public class ESBeanWrapper extends ESBase { 39 static ESId CALL = ESId.intern("call"); 40 protected static ESId LENGTH = ESId.intern("length"); 41 42 public int set; 43 public IntMap hasDispatch; 44 public IntMap setDispatch; 45 public IntMap []subGets; 46 public IntMap []subSets; 47 public HashMap methods; 48 public IntMap methodDispatch; 49 50 protected Object value; 51 protected String name; 52 ESString []formals; 53 int length; 54 public int n = -3; 55 int newN; 56 57 protected ESBeanWrapper() 58 { 59 } 60 61 public long getVersionId() 62 { 63 return 0; 64 } 65 66 private String decompile() 67 { 68 StringBuffer sbuf = new StringBuffer (); 69 70 sbuf.append("function "); 71 sbuf.append(name); 72 sbuf.append("("); 73 for (int i = 0; formals != null && i < formals.length; i++) { 74 if (i != 0) 75 sbuf.append(", "); 76 sbuf.append(formals[i]); 77 } 78 79 sbuf.append(") "); 80 81 sbuf.append("{ "); 82 sbuf.append("[native code]"); 83 sbuf.append(" }"); 84 85 return sbuf.toString(); 86 } 87 88 public ESString toStr() throws ESException 89 { 90 if (n == -1) 91 return ESString.create(value == null ? "null" : value.toString()); 92 else 93 return ESString.create(decompile()); 94 } 95 96 public double toNum() throws ESException 97 { 98 if (value instanceof Number ) 99 return ((Number ) value).doubleValue(); 100 else 101 throw new ESException("no number: " + getClass().getName()); 102 } 103 104 public ESBase getProperty(ESString name) throws Throwable 105 { 106 ESBase value = hasProperty(name); 107 108 if (value != null) 109 return value; 110 else 111 return esEmpty; 112 } 113 114 public ESBase hasProperty(ESString name) throws Throwable 115 { 116 return null; 117 } 118 119 public ESString toSource(IntMap map, boolean isLoopPath) throws ESException 120 { 121 if (isLoopPath) 122 return null; 123 else 124 return toStr(); 125 } 126 127 public ESBase toPrimitive(int hint) throws ESException 128 { 129 if (value instanceof ESBase) 130 return (ESBase) value; 131 else 132 return toStr(); 133 } 134 135 public Object toJavaObject() 136 { 137 return value != null ? value : this; 138 } 139 140 public boolean toBoolean() 141 { 142 return true; 143 } 144 145 protected ESBeanWrapper dup() 146 { 147 throw new UnsupportedOperationException (); 148 } 149 150 protected ESBeanWrapper dup(int set) 151 { 152 ESBeanWrapper child = dup(); 153 154 child.value = value; 155 child.set = set; 156 child.hasDispatch = subGets[set]; 157 child.setDispatch = subSets[set]; 158 child.subGets = subGets; 159 child.subSets = subSets; 160 child.methods = methods; 161 162 return child; 163 } 164 165 public ESBeanWrapper wrap(Object value) 166 { 167 throw new RuntimeException (); 168 } 169 170 public ESBeanWrapper wrapStatic() 171 { 172 throw new RuntimeException (); 173 } 174 175 public boolean ecmaEquals(ESBase b) 176 { 177 if (! (b instanceof ESBeanWrapper)) 178 return false; 179 else 180 return value.equals(((ESBeanWrapper) b).value); 181 } 182 183 public Object copy(HashMap refs) 184 { 185 return this; 186 } 187 188 public ESBase typeof() 189 { 190 return ESString.create("object"); 191 } 192 193 public ESBase call(Call eval, int length, int n) throws Throwable 194 { 195 throw new ESNullException(toStr() + " is not a function"); 196 } 197 198 public ESBase call(Call eval, int length) throws Throwable 199 { 200 return call(eval, length, n); 201 } 202 203 public ESBase call(Call eval, int length, ESString key) throws Throwable 204 { 205 int n = methodDispatch.get(key); 206 if (n < 0) 207 throw new ESUndefinedException(getClass().getName() + ": undefined call `" + key + "'"); 208 209 return call(eval, length, n); 210 } 211 212 public ESBase construct(Call eval, int length) throws Throwable 213 { 214 if (n != newN) { 215 throw new ESException("cannot create " + name); 216 } 217 218 ESBase value = call(eval, length); 219 220 if (value == esUndefined || value == null) 221 throw new ESException("cannot create " + name); 222 223 return value; 224 } 225 226 public boolean isModified() 227 { 228 return true; 229 } 230 } 231 | Popular Tags |