0001: /*
0002: * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
0003: *
0004: * This file is part of Resin(R) Open Source
0005: *
0006: * Each copy or derived work must preserve the copyright notice and this
0007: * notice unmodified.
0008: *
0009: * Resin Open Source is free software; you can redistribute it and/or modify
0010: * it under the terms of the GNU General Public License as published by
0011: * the Free Software Foundation; either version 2 of the License, or
0012: * (at your option) any later version.
0013: *
0014: * Resin Open Source is distributed in the hope that it will be useful,
0015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
0017: * of NON-INFRINGEMENT. See the GNU General Public License for more
0018: * details.
0019: *
0020: * You should have received a copy of the GNU General Public License
0021: * along with Resin Open Source; if not, write to the
0022: * Free SoftwareFoundation, Inc.
0023: * 59 Temple Place, Suite 330
0024: * Boston, MA 02111-1307 USA
0025: *
0026: * @author Scott Ferguson
0027: */
0028:
0029: package com.caucho.es.wrapper;
0030:
0031: import com.caucho.es.ESArrayWrapper;
0032: import com.caucho.es.ESBase;
0033: import com.caucho.es.ESBeanWrapper;
0034: import com.caucho.es.Global;
0035: import com.caucho.java.JavaCompiler;
0036: import com.caucho.loader.SimpleLoader;
0037: import com.caucho.log.Log;
0038: import com.caucho.server.util.CauchoSystem;
0039: import com.caucho.util.CharBuffer;
0040: import com.caucho.util.IntMap;
0041: import com.caucho.vfs.JarPath;
0042: import com.caucho.vfs.MergePath;
0043: import com.caucho.vfs.Path;
0044: import com.caucho.vfs.Vfs;
0045: import com.caucho.vfs.WriteStream;
0046:
0047: import java.beans.PropertyDescriptor;
0048: import java.io.IOException;
0049: import java.lang.reflect.Constructor;
0050: import java.lang.reflect.Field;
0051: import java.lang.reflect.Method;
0052: import java.lang.reflect.Modifier;
0053: import java.net.URL;
0054: import java.util.ArrayList;
0055: import java.util.HashMap;
0056: import java.util.Iterator;
0057: import java.util.Map;
0058: import java.util.logging.Logger;
0059:
0060: public class Wrapper {
0061: private static final Integer LOCK = new Integer(0);
0062: private static final Logger log = Log.open(Wrapper.class);
0063:
0064: private String name;
0065: private String javaClassName;
0066: private Class cl;
0067: private boolean isPublic;
0068: private Path dest;
0069: private WriteStream os;
0070: private ClassLoader loader;
0071: private JavaCompiler compiler;
0072:
0073: private ESBeanInfo beanInfo;
0074: private IntMap hasDispatch;
0075: private IntMap staticHasDispatch;
0076: private IntMap setDispatch;
0077: private IntMap staticSetDispatch;
0078: private IntMap methodDispatch;
0079: private IntMap staticMethodDispatch;
0080: private HashMap namedProperties;
0081:
0082: private ArrayList overloadDispatch;
0083:
0084: private int depth;
0085: private boolean isNewline;
0086: private Class esBase;
0087:
0088: /**
0089: * Creates the instance of the wrapper generator.
0090: *
0091: * @param resin the global parent object
0092: * @param cl the class to wrap.
0093: */
0094: private Wrapper(Global resin, Class cl) {
0095: name = cl.getName().replace('/', '.');
0096:
0097: MergePath mergePath = new MergePath();
0098: mergePath.addClassPath(cl.getClassLoader());
0099: Path destClass = mergePath.lookup(name.replace('.', '/')
0100: + ".class");
0101:
0102: // technically, need to resort to dynamic. This is a cheat.
0103: if (!destClass.exists() && cl.getInterfaces().length > 0) {
0104: cl = cl.getInterfaces()[0];
0105: name = cl.getName().replace('/', '.');
0106: }
0107:
0108: javaClassName = toJavaClassName(name);
0109:
0110: CharBuffer cb = new CharBuffer();
0111: for (int i = 0; i < name.length(); i++) {
0112: char ch = name.charAt(i);
0113:
0114: if (ch == '$')
0115: cb.append("_0");
0116: else if (ch == '_')
0117: cb.append("__");
0118: else
0119: cb.append(ch);
0120: }
0121:
0122: name = "_jsbean." + cb + "_es";
0123:
0124: this .cl = cl;
0125:
0126: isPublic = Modifier.isPublic(cl.getModifiers());
0127:
0128: //this.loader = resin.getParentLoader();
0129: loader = cl.getClassLoader();
0130:
0131: compiler = JavaCompiler.create(loader);
0132: //compiler.setEncoding("utf8");
0133: Path workPath = CauchoSystem.getWorkPath();
0134:
0135: dest = workPath.lookup(name.replace('.', '/') + ".java");
0136:
0137: hasDispatch = new IntMap();
0138: staticHasDispatch = new IntMap();
0139: setDispatch = new IntMap();
0140: staticSetDispatch = new IntMap();
0141: methodDispatch = new IntMap();
0142: staticMethodDispatch = new IntMap();
0143: namedProperties = new HashMap();
0144:
0145: overloadDispatch = new ArrayList();
0146:
0147: try {
0148: esBase = Class.forName("com.caucho.es.ESBase");
0149: } catch (Exception e) {
0150: }
0151: }
0152:
0153: public static ESBase[] bean(Global resin, Class cl)
0154: throws Throwable {
0155: Wrapper wrapper = null;
0156:
0157: if (cl.isArray()) {
0158: ESBase arrayWrapper = ESArrayWrapper.wrapper(resin, cl);
0159: return new ESBase[] {
0160: arrayWrapper.getProperty("CONSTRUCTOR"),
0161: arrayWrapper };
0162: }
0163:
0164: synchronized (LOCK) {
0165: wrapper = new Wrapper(resin, cl);
0166: ESBeanWrapper beanWrapper = wrapper.wrap();
0167: beanWrapper.n = 0;
0168:
0169: return new ESBase[] { beanWrapper.wrapStatic(), beanWrapper };
0170: }
0171: }
0172:
0173: /**
0174: * Creates the wrapper for a class
0175: */
0176: private ESBeanWrapper wrap() throws Throwable {
0177: dest.getParent().mkdirs();
0178:
0179: Path workPath = CauchoSystem.getWorkPath();
0180: Path destClass = workPath.lookup(name.replace('.', '/')
0181: + ".class");
0182:
0183: ClassLoader beanLoader;
0184: beanLoader = SimpleLoader.create(loader, CauchoSystem
0185: .getWorkPath(), name);
0186: ESBeanWrapper wrapper;
0187:
0188: try {
0189: Class cl = CauchoSystem.loadClass(name, false, beanLoader);
0190: wrapper = (ESBeanWrapper) cl.newInstance();
0191:
0192: if (!wrapper.isModified()
0193: && wrapper.getVersionId() == CauchoSystem
0194: .getVersionId())
0195: return wrapper;
0196: } catch (Throwable e) {
0197: }
0198:
0199: destClass.remove();
0200: os = dest.openWrite();
0201:
0202: beanInfo = ESIntrospector.getBeanInfo(cl);
0203:
0204: try {
0205: printHeader();
0206: printConstructors();
0207: printHasProperty();
0208: printSetProperty();
0209: printKeys();
0210: printDeletes();
0211: printMethods();
0212: printInit();
0213: printFooter();
0214: } finally {
0215: os.close();
0216: }
0217:
0218: compiler.compile(name.replace('.', '/') + ".java", null);
0219:
0220: beanLoader = SimpleLoader.create(loader, CauchoSystem
0221: .getWorkPath(), name);
0222:
0223: try {
0224: Class cl = CauchoSystem.loadClass(name, false, beanLoader);
0225: wrapper = (ESBeanWrapper) cl.newInstance();
0226: } catch (NoClassDefFoundError e) {
0227: e.printStackTrace();
0228: throw e;
0229: }
0230:
0231: return wrapper;
0232: }
0233:
0234: private long getSourceLastModified(Class cl) {
0235: long lastModified = 0;
0236: String classPath;
0237:
0238: URL resource = null;
0239: String clName = cl.getName().replace('.', '/') + ".class";
0240: String name;
0241:
0242: if (loader != null)
0243: resource = loader.getResource(clName);
0244:
0245: String fileName = resource != null ? resource.toExternalForm()
0246: : null;
0247:
0248: // XXX: need to implement jar: filesystem
0249: if (resource == null || fileName.startsWith("systemresource:")
0250: || fileName.startsWith("jar:"))
0251: return getClassPathLastModified(cl);
0252:
0253: Path path = Vfs.lookup(fileName);
0254:
0255: if (path != null && path.canRead())
0256: return path.getLastModified();
0257: else
0258: return 0;
0259: }
0260:
0261: private long getClassPathLastModified(Class cl) {
0262: String clName = cl.getName().replace('.', '/') + ".class";
0263:
0264: String classPath = System.getProperty("java.class.path");
0265:
0266: char sep = CauchoSystem.getPathSeparatorChar();
0267: int head = 0;
0268: int tail;
0269: for (; (tail = classPath.indexOf(sep, head)) >= 0; head = tail + 1) {
0270: String name = classPath.substring(head, tail);
0271: Path path = Vfs.lookupNative(name);
0272:
0273: if (name.endsWith(".jar") || name.endsWith(".zip"))
0274: path = JarPath.create(path);
0275:
0276: if (path != null && path.lookup(clName).canRead()) {
0277: return path.lookup(clName).getLastModified();
0278: }
0279: }
0280:
0281: String name = classPath.substring(head);
0282: Path path = Vfs.lookupNative(name);
0283:
0284: if (name.endsWith(".jar") || name.endsWith(".zip"))
0285: path = JarPath.create(path);
0286:
0287: if (path != null && path.lookup(clName).canRead())
0288: return path.lookup(clName).getLastModified();
0289:
0290: return 0;
0291: }
0292:
0293: private void printHeader() throws IOException {
0294: int p = name.lastIndexOf('.');
0295: String pkg = name.substring(0, p);
0296: String clName = name.substring(p + 1);
0297:
0298: println("package " + pkg + ";");
0299: println("import com.caucho.es.*;");
0300: Iterator iter = beanInfo.getNonPkgClasses().iterator();
0301: while (iter.hasNext()) {
0302: String name = (String) iter.next();
0303: println("import " + name + ";");
0304: }
0305: println();
0306: println("public class " + clName + " extends ESBeanWrapper {");
0307: pushDepth();
0308: if (isPublic)
0309: println("private " + javaClassName + " _value;");
0310:
0311: println();
0312: println("public long getVersionId() { return "
0313: + CauchoSystem.getVersionId() + "L; }");
0314:
0315: println();
0316: println("protected ESBeanWrapper dup()");
0317: println("{");
0318: println(" return new " + clName + "();");
0319: println("}");
0320:
0321: println();
0322: println("public ESBeanWrapper wrap(Object value)");
0323: println("{");
0324: pushDepth();
0325: println("if (value == null) throw new NullPointerException();");
0326: println(name + " child = new " + name + "();");
0327: println("child.value = value;");
0328: if (isPublic)
0329: println("child._value = (" + javaClassName + ") value;");
0330: println("child.hasDispatch = instanceHasDispatch;");
0331: println("child.setDispatch = instanceSetDispatch;");
0332: println("child.methodDispatch = instanceMethodDispatch;");
0333: println("child.n = -1;");
0334: println("return child;");
0335: popDepth();
0336: println("}");
0337:
0338: println();
0339: println("public ESBeanWrapper wrapStatic()");
0340: println("{");
0341: pushDepth();
0342: println(name + " child = new " + name + "();");
0343: println("child.hasDispatch = staticHasDispatch;");
0344: println("child.setDispatch = staticSetDispatch;");
0345: println("child.methodDispatch = staticMethodDispatch;");
0346: println("child.n = -2;");
0347: println("child.name = \"" + javaClassName + "\";");
0348: println("try {");
0349: println(" child.value = Class.forName(child.name);");
0350: println("} catch (Exception e) {}");
0351: println("return child;");
0352: popDepth();
0353: println("}");
0354:
0355: println();
0356: println("public Class getJavaType()");
0357: println("{");
0358: pushDepth();
0359: println("return value.getClass();");
0360: popDepth();
0361: println("}");
0362: }
0363:
0364: private void printConstructors() throws IOException {
0365: println();
0366: println("public ESBase construct(Call call, int length)");
0367: println(" throws Throwable");
0368: println("{");
0369: pushDepth();
0370: println("if (n != -2)");
0371: println(" throw new ESException(\"can't create `"
0372: + javaClassName + "'\");");
0373: println();
0374:
0375: if (printMethodConstructor()) {
0376: popDepth();
0377: println("}");
0378: return;
0379: }
0380:
0381: ArrayList overload = beanInfo.getConstructors();
0382: if (Modifier.isAbstract(cl.getModifiers()))
0383: overload = null;
0384:
0385: if (overload == null || overload.size() == 0) {
0386: println(" throw new ESException(\"can't create `"
0387: + javaClassName + "'\");");
0388: } else {
0389:
0390: Constructor last = null;
0391: for (int i = 0; i < overload.size(); i++) {
0392: if (overload.get(i) instanceof Constructor)
0393: last = (Constructor) overload.get(i);
0394: }
0395:
0396: for (int i = 0; i < overload.size(); i++) {
0397: Object o = overload.get(i);
0398: if (!(o instanceof Constructor))
0399: continue;
0400:
0401: Constructor constructor = (Constructor) o;
0402: if (constructor != last) {
0403: println("if (length <= " + i + ")");
0404: print(" ");
0405: }
0406:
0407: print("return wrap(new " + javaClassName + "(");
0408: Class[] param = constructor.getParameterTypes();
0409: for (int j = 0; j < param.length; j++) {
0410: if (j > 0)
0411: print(", ");
0412:
0413: printArgToJava(param[j], j);
0414: }
0415: println("));");
0416: }
0417:
0418: if (last == null)
0419: println("throw new ESException(\"can't create `"
0420: + javaClassName + "'\");");
0421: }
0422:
0423: popDepth();
0424: println("}");
0425: }
0426:
0427: private boolean printMethodConstructor() throws IOException {
0428: ArrayList overload = (ArrayList) beanInfo._staticMethodMap
0429: .get("create");
0430: if (overload != null) {
0431: printMethod(Integer.MIN_VALUE, "create", overload, null);
0432: return true;
0433: } else
0434: return false;
0435: }
0436:
0437: /**
0438: * Print the code for accessing properties.
0439: */
0440: private void printHasProperty() throws IOException {
0441: println();
0442: println("public ESBase hasProperty(ESString name)");
0443: println(" throws Throwable");
0444: println("{");
0445: pushDepth();
0446: println("ESBase temp;");
0447: println("switch (hasDispatch.get(name)) {");
0448:
0449: PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
0450:
0451: int index = 1;
0452: for (int i = 0; i < props.length; i++) {
0453: if (props[i] instanceof NamedPropertyDescriptor)
0454: index = doHasNamedProperty(index,
0455: (NamedPropertyDescriptor) props[i]);
0456: else if (props[i] instanceof ESIndexedPropertyDescriptor)
0457: index = doHasIndexProperty(index,
0458: (ESIndexedPropertyDescriptor) props[i]);
0459: else if (props[i] instanceof ESPropertyDescriptor)
0460: index = doHasProperty(index,
0461: (ESPropertyDescriptor) props[i]);
0462: else
0463: throw new RuntimeException();
0464: }
0465: println("default:");
0466: println(" return ESBase.esEmpty;");
0467: println("}");
0468: popDepth();
0469: println("}");
0470: }
0471:
0472: private int doHasIndexProperty(int i,
0473: ESIndexedPropertyDescriptor prop) throws IOException {
0474: Named named = new Named(prop.getName(), namedProperties.size());
0475: int n = named.n;
0476:
0477: namedProperties.put(prop.getName(), named);
0478: hasDispatch.put(prop.getName(), i);
0479:
0480: println("case " + i + ":");
0481: pushDepth();
0482: println("if (name" + n + " == null) {");
0483: println(" name" + n + " = new " + name + "();");
0484: println(" name" + n + ".value = value;");
0485: if (isPublic)
0486: println(" name" + n + "._value = _value;");
0487: println(" name" + n + ".hasDispatch = has" + n + ";");
0488: println(" name" + n + ".setDispatch = set" + n + ";");
0489: println(" name" + n + ".delId = " + n + ";");
0490: println("}");
0491: println("return name" + n + ";");
0492: popDepth();
0493:
0494: i += 1;
0495:
0496: ESMethodDescriptor md = prop.getESReadMethod();
0497: if (md == null)
0498: return i;
0499:
0500: println("case " + i + ":");
0501: pushDepth();
0502: named.get = i;
0503:
0504: ESMethodDescriptor size = prop.getESSizeMethod();
0505:
0506: if (size != null) {
0507: println("if (name.equals(LENGTH)) {");
0508: pushDepth();
0509: Method method = size.getMethod();
0510: Class resultClass = method.getReturnType();
0511: print("return ");
0512: startJavaToES(resultClass);
0513: startProp(size);
0514: print(")");
0515: endJavaToES(resultClass);
0516: println(";");
0517: popDepth();
0518: println("} else {");
0519: pushDepth();
0520: }
0521: Method method = md.getMethod();
0522: Class resultClass = method.getReturnType();
0523: print("return ");
0524: startJavaToES(resultClass);
0525: int p = startProp(md);
0526: if (p > 0)
0527: print(", ");
0528: print("name.toInt32())");
0529: endJavaToES(resultClass);
0530: println(";");
0531: if (size != null) {
0532: popDepth();
0533: println("}");
0534: }
0535:
0536: popDepth();
0537:
0538: return i + 1;
0539: }
0540:
0541: private int doHasNamedProperty(int i, NamedPropertyDescriptor prop)
0542: throws IOException {
0543: Named named = new Named(prop.getName(), namedProperties.size());
0544: int n = named.n;
0545:
0546: namedProperties.put(prop.getName(), named);
0547: hasDispatch.put(prop.getName(), i);
0548:
0549: println("case " + i + ":");
0550: pushDepth();
0551: println("if (name" + n + " == null) {");
0552: println(" name" + n + " = new " + name + "();");
0553: println(" name" + n + ".value = value;");
0554: if (isPublic)
0555: println(" name" + n + "._value = _value;");
0556: println(" name" + n + ".hasDispatch = has" + n + ";");
0557: println(" name" + n + ".setDispatch = set" + n + ";");
0558: println(" name" + n + ".delId = " + n + ";");
0559: println("}");
0560: println("return name" + n + ";");
0561: popDepth();
0562:
0563: i += 1;
0564:
0565: ESMethodDescriptor md = prop.getNamedReadMethod();
0566: if (md == null)
0567: return i;
0568:
0569: println("case " + i + ":");
0570: pushDepth();
0571: named.get = i;
0572:
0573: Method method = md.getMethod();
0574: if (Modifier.isStatic(method.getModifiers())
0575: && !md.isStaticVirtual())
0576: staticHasDispatch.put(prop.getName(), i - 1);
0577:
0578: Class resultClass = method.getReturnType();
0579: print("return ");
0580: startJavaToES(resultClass);
0581: int p = startProp(md);
0582: if (p > 0)
0583: print(", ");
0584: print("name.toJavaString())");
0585: endJavaToES(resultClass);
0586: println(";");
0587: popDepth();
0588:
0589: return i + 1;
0590: }
0591:
0592: private int doHasProperty(int i, ESPropertyDescriptor prop)
0593: throws IOException {
0594: Field field = prop.getESField();
0595: ESMethodDescriptor md = prop.getESReadMethod();
0596:
0597: if (field != null && !Modifier.isPublic(field.getModifiers()))
0598: field = null;
0599:
0600: if (md == null && field == null)
0601: return i;
0602:
0603: hasDispatch.put(prop.getName(), i);
0604:
0605: println("case " + i + ":");
0606: pushDepth();
0607:
0608: if (field != null) {
0609: Class resultClass = field.getType();
0610: print("return ");
0611: startJavaToES(resultClass);
0612: if (isPublic
0613: && field.getDeclaringClass().getName().equals(
0614: cl.getName()))
0615: print("_value.");
0616: else if (Modifier.isStatic(field.getModifiers()))
0617: print(toJavaClassName(field.getDeclaringClass()
0618: .getName())
0619: + ".");
0620: else
0621: print("(("
0622: + toJavaClassName(field.getDeclaringClass()
0623: .getName()) + ") value).");
0624: print(field.getName());
0625: endJavaToES(resultClass);
0626: println(";");
0627: popDepth();
0628:
0629: if (Modifier.isStatic(field.getModifiers()))
0630: staticHasDispatch.put(prop.getName(), i);
0631:
0632: return i + 1;
0633: }
0634:
0635: Method method = md.getMethod();
0636:
0637: if (Modifier.isStatic(method.getModifiers())
0638: && !md.isStaticVirtual())
0639: staticHasDispatch.put(prop.getName(), i);
0640:
0641: print("return ");
0642:
0643: Class resultClass = method.getReturnType();
0644:
0645: startJavaToES(resultClass);
0646: int p = startProp(md);
0647: print(")");
0648: endJavaToES(resultClass);
0649: println(";");
0650: popDepth();
0651:
0652: return i + 1;
0653: }
0654:
0655: private void printSetProperty() throws IOException {
0656: println();
0657: println("public void setProperty(ESString name, ESBase newValue)");
0658: println(" throws Throwable");
0659: println("{");
0660: pushDepth();
0661: println("ESBase temp;");
0662: println("switch (setDispatch.get(name)) {");
0663:
0664: PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
0665:
0666: int index = 0;
0667: for (int i = 0; i < props.length; i++) {
0668: if (props[i] instanceof NamedPropertyDescriptor) {
0669: index = doSetNamedProperty(index,
0670: (NamedPropertyDescriptor) props[i]);
0671: } else if (props[i] instanceof ESIndexedPropertyDescriptor) {
0672: index = doSetIndexProperty(index,
0673: (ESIndexedPropertyDescriptor) props[i]);
0674: } else if (props[i] instanceof ESPropertyDescriptor)
0675: index = doSetProperty(index,
0676: (ESPropertyDescriptor) props[i]);
0677: else
0678: throw new RuntimeException();
0679: }
0680: println("default:");
0681: println(" return;");
0682: println("}");
0683: popDepth();
0684: println("}");
0685: }
0686:
0687: private int doSetNamedProperty(int i, NamedPropertyDescriptor prop)
0688: throws IOException {
0689: Named named = (Named) namedProperties.get(prop.getName());
0690: if (named == null)
0691: return i;
0692:
0693: int n = named.n;
0694:
0695: ESMethodDescriptor md = prop.getNamedWriteMethod();
0696: if (md == null)
0697: return i;
0698:
0699: println("case " + i + ":");
0700: pushDepth();
0701: named.set = i;
0702:
0703: int p = startProp(md);
0704: Class[] param = md.getParameterTypes();
0705:
0706: if (p != 0)
0707: print(", ");
0708: print("name.toJavaString(), ");
0709: printValueToJava(param[1], "newValue");
0710: println(");");
0711:
0712: println("return;");
0713: popDepth();
0714:
0715: return i + 1;
0716: }
0717:
0718: private int doSetIndexProperty(int i,
0719: ESIndexedPropertyDescriptor prop) throws IOException {
0720: Named named = (Named) namedProperties.get(prop.getName());
0721: if (named == null)
0722: return i;
0723:
0724: int n = named.n;
0725:
0726: ESMethodDescriptor md = prop.getESWriteMethod();
0727: if (md == null)
0728: return i;
0729:
0730: println("case " + i + ":");
0731: pushDepth();
0732: named.set = i;
0733:
0734: int p = startProp(md);
0735: Class[] param = md.getParameterTypes();
0736:
0737: if (p != 0)
0738: print(", ");
0739: print("name.toInt32(), ");
0740: printValueToJava(param[1], "newValue");
0741: println(");");
0742:
0743: println("return;");
0744: popDepth();
0745:
0746: return i + 1;
0747: }
0748:
0749: private int doSetProperty(int i, ESPropertyDescriptor prop)
0750: throws IOException {
0751: ESMethodDescriptor md = prop.getESWriteMethod();
0752: Field field = prop.getESField();
0753: if (field != null && Modifier.isFinal(field.getModifiers()))
0754: field = null;
0755:
0756: if (md == null && field == null)
0757: return i;
0758:
0759: println("case " + i + ":");
0760: pushDepth();
0761:
0762: setDispatch.put(prop.getName(), i);
0763:
0764: if (field != null) {
0765: Class resultClass = field.getType();
0766: if (isPublic)
0767: print("_value.");
0768: else
0769: print("((" + field.getDeclaringClass().getName()
0770: + ") value).");
0771: print(field.getName());
0772: print(" = ");
0773: printValueToJava(resultClass, "newValue");
0774: println(";");
0775: println("return;");
0776: popDepth();
0777: return i + 1;
0778: }
0779:
0780: Method method = md.getMethod();
0781:
0782: if (Modifier.isStatic(method.getModifiers())
0783: && !md.isStaticVirtual())
0784: staticSetDispatch.put(prop.getName(), i);
0785:
0786: Class[] param = md.getParameterTypes();
0787:
0788: int p = startProp(md);
0789: if (p != 0)
0790: print(", ");
0791: printValueToJava(param[0], "newValue");
0792: println(");");
0793:
0794: println("return;");
0795:
0796: popDepth();
0797:
0798: return i + 1;
0799: }
0800:
0801: private void printKeys() throws IOException {
0802: println();
0803: println("public java.util.Iterator keys()");
0804: println(" throws Throwable");
0805: println("{");
0806: pushDepth();
0807: println("switch (delId) {");
0808:
0809: ESMethodDescriptor md = beanInfo.iterator;
0810: if (md != null) {
0811: println("case -1:");
0812: print(" return Call.toESIterator(");
0813: startProp(md);
0814: println("));");
0815: }
0816:
0817: PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
0818: for (int i = 0; i < props.length; i++) {
0819: if (props[i] instanceof NamedPropertyDescriptor)
0820: printNamedKey((NamedPropertyDescriptor) props[i]);
0821: }
0822:
0823: println("default:");
0824: println(" return super.keys();");
0825: println("}");
0826: popDepth();
0827: println("}");
0828: }
0829:
0830: private void printNamedKey(NamedPropertyDescriptor prop)
0831: throws IOException {
0832: ESMethodDescriptor md = prop.getNamedIteratorMethod();
0833: if (md == null)
0834: return;
0835:
0836: Named named = (Named) namedProperties.get(prop.getName());
0837: println("case " + named.n + ":");
0838: pushDepth();
0839: print("return Call.toESIterator(");
0840: int p = startProp(md);
0841: println("));");
0842: popDepth();
0843: }
0844:
0845: private void printDeletes() throws IOException {
0846: println();
0847: println("public ESBase delete(ESString key)");
0848: println(" throws Throwable");
0849: println("{");
0850: pushDepth();
0851: println("switch (delId) {");
0852:
0853: PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
0854: for (int i = 0; i < props.length; i++) {
0855: if (props[i] instanceof NamedPropertyDescriptor)
0856: printNamedDelete((NamedPropertyDescriptor) props[i]);
0857: }
0858:
0859: println("default:");
0860: println(" return ESBoolean.FALSE;");
0861: println("}");
0862: popDepth();
0863: println("}");
0864: }
0865:
0866: private void printNamedDelete(NamedPropertyDescriptor prop)
0867: throws IOException {
0868: ESMethodDescriptor md = prop.getNamedRemoveMethod();
0869: if (md == null)
0870: return;
0871:
0872: Named named = (Named) namedProperties.get(prop.getName());
0873: println("case " + named.n + ":");
0874: pushDepth();
0875: int p = startProp(md);
0876: if (p > 0)
0877: print(", ");
0878: println("key.toJavaString());");
0879: println("return ESBoolean.TRUE;");
0880: popDepth();
0881: }
0882:
0883: /**
0884: * Prints all the accessible methods in this object.
0885: */
0886: private void printMethods() throws IOException {
0887: println();
0888: println("public ESBase call(Call call, int length, int n)");
0889: println(" throws Throwable");
0890: println("{");
0891: pushDepth();
0892: println("ESBase temp;");
0893: println("switch (n) {");
0894:
0895: ArrayList overload = (ArrayList) beanInfo._methodMap
0896: .get("call");
0897: if (overload != null)
0898: printMethod(-1, "call", overload, null);
0899:
0900: // Print the constructor (code -2)
0901: ArrayList create = (ArrayList) beanInfo._staticMethodMap
0902: .get("create");
0903: ArrayList call = (ArrayList) beanInfo._staticMethodMap
0904: .get("call");
0905: if (create != null)
0906: printMethod(-2, "create", create, null);
0907: else if (call != null)
0908: printMethod(-2, "call", create, null);
0909: else {
0910: println("case -2:");
0911: println(" return construct(call, length);");
0912: }
0913:
0914: Iterator iter = beanInfo._methodMap.entrySet().iterator();
0915: int i = 0;
0916: while (iter.hasNext()) {
0917: Map.Entry entry = (Map.Entry) iter.next();
0918: overload = (ArrayList) entry.getValue();
0919: String name = (String) entry.getKey();
0920:
0921: i = printMethod(i, name, overload, methodDispatch);
0922: }
0923:
0924: iter = beanInfo._staticMethodMap.entrySet().iterator();
0925: while (iter.hasNext()) {
0926: Map.Entry entry = (Map.Entry) iter.next();
0927: overload = (ArrayList) entry.getValue();
0928: String name = (String) entry.getKey();
0929:
0930: i = printMethod(i, name, overload, staticMethodDispatch);
0931: }
0932:
0933: println("}");
0934: println("return ESBase.esUndefined;");
0935: popDepth();
0936: println("}");
0937: }
0938:
0939: /**
0940: * Prints a method in a method dispatch.
0941: */
0942: private int printMethod(int i, String name, ArrayList overload,
0943: IntMap dispatch) throws IOException {
0944: ESMethodDescriptor[] last = null;
0945:
0946: if (overload == null)
0947: return i;
0948:
0949: for (int j = 0; j < overload.size(); j++) {
0950: last = (ESMethodDescriptor[]) overload.get(j);
0951: }
0952:
0953: if (last == null) {
0954: return i;
0955: }
0956:
0957: if (i > -100) {
0958: println("case " + i + ":");
0959: pushDepth();
0960: if (dispatch != null)
0961: dispatch.put(name, i++);
0962: }
0963:
0964: if (overload.size() > 2) {
0965: ESMethodDescriptor[] mds = (ESMethodDescriptor[]) overload
0966: .get(2);
0967:
0968: for (int j = 0; mds != null && j < mds.length; j++) {
0969: Class[] cl = mds[j].getParameterTypes();
0970: int p = cl.length - 2;
0971:
0972: if (cl[0].getName().equals("com.caucho.es.Call")
0973: && cl[1].getName().equals("int")) {
0974: printMethod(mds[j], dispatch == null);
0975: popDepth();
0976: return i;
0977: }
0978: }
0979: }
0980:
0981: for (int j = 0; j < overload.size(); j++) {
0982: Object o = overload.get(j);
0983:
0984: if (o == null)
0985: continue;
0986:
0987: ESMethodDescriptor[] mds = (ESMethodDescriptor[]) o;
0988: if (mds != last) {
0989: println("if (length <= " + j + ") {");
0990: pushDepth();
0991: }
0992:
0993: if (mds.length == 1)
0994: printMethod(mds[0], dispatch == null);
0995: else {
0996: String var = "dispatch" + overloadDispatch.size();
0997:
0998: overloadDispatch.add(mds);
0999:
1000: println("switch (" + var + ".select(call, length)) {");
1001: for (int k = 0; k < mds.length; k++) {
1002: println("case " + k + ":");
1003: pushDepth();
1004: printMethod(mds[k], dispatch == null);
1005: popDepth();
1006: }
1007:
1008: println("default:");
1009: println(" throw new ESException(\"no matching method "
1010: + mds[0].getName() + "\");");
1011: println("}");
1012: }
1013:
1014: if (mds != last) {
1015: popDepth();
1016: println("}");
1017: }
1018: }
1019:
1020: if (i > -100) {
1021: popDepth();
1022: }
1023:
1024: return i;
1025: }
1026:
1027: /**
1028: * Print a single method based on a method descriptor. The arguments
1029: * are assumed to come from a Call object.
1030: *
1031: * @param md the method descriptor.
1032: */
1033: private void printMethod(ESMethodDescriptor md, boolean isProp)
1034: throws IOException {
1035: boolean hasThrowable = hasException(md.getMethod()
1036: .getExceptionTypes(), Throwable.class);
1037:
1038: /*
1039: if (hasThrowable) {
1040: println("try {");
1041: pushDepth();
1042: }
1043: */
1044:
1045: Class returnCl = md.getReturnType();
1046: if (!returnCl.getName().equals("void")) {
1047: print("return ");
1048: startJavaToES(returnCl);
1049: }
1050:
1051: Class[] param = md.getParameterTypes();
1052:
1053: int p;
1054:
1055: if (isProp)
1056: p = startProp(md);
1057: else
1058: p = startCall(md);
1059:
1060: if (param.length == 2
1061: && param[0].getName().equals("com.caucho.es.Call")
1062: && param[1].getName().equals("int")) {
1063: if (p > 0)
1064: print(", ");
1065: print("call, length");
1066: } else {
1067: for (int j = 0; j < param.length; j++) {
1068: if (j + p > 0)
1069: print(", ");
1070:
1071: printArgToJava(param[j], j);
1072: }
1073: }
1074:
1075: if (returnCl.getName().equals("void")) {
1076: println(");");
1077: println("return ESBase.esUndefined;");
1078: } else {
1079: print(")");
1080: endJavaToES(returnCl);
1081: println(";");
1082: }
1083:
1084: /*
1085: if (hasThrowable) {
1086: popDepth();
1087: println("} catch (Exception e) {");
1088: println(" throw e;");
1089: println("} catch (RuntimeException e) {");
1090: println(" throw e;");
1091: println("} catch (Error e) {");
1092: println(" throw e;");
1093: println("} catch (Throwable e) {");
1094: println(" throw new com.caucho.es.ESException(String.valueOf(e));");
1095: println("}");
1096: }
1097: */
1098: }
1099:
1100: private boolean hasException(Class[] exn, Class cl) {
1101: for (int i = 0; i < exn.length; i++)
1102: if (exn[i].isAssignableFrom(cl))
1103: return true;
1104:
1105: return false;
1106: }
1107:
1108: /**
1109: * Starts a method call that overloads a property.
1110: */
1111: private int startProp(ESMethodDescriptor md) throws IOException {
1112: Method method = md.getMethod();
1113:
1114: int p = 0;
1115: if (md.isStaticVirtual()) {
1116: print(md.getMethodClassName());
1117: print(".");
1118: print(md.getMethod().getName());
1119: if (isPublic)
1120: print("(_value");
1121: else
1122: print("((" + toJavaClassName(md.getObjectClassName())
1123: + ") value");
1124: p = 1;
1125: } else if (Modifier.isStatic(method.getModifiers())) {
1126: print(md.getMethodClassName());
1127: print(".");
1128: print(md.getMethod().getName());
1129: print("(");
1130: } else {
1131: if (isPublic)
1132: print("_value.");
1133: else
1134: print("((" + toJavaClassName(md.getObjectClassName())
1135: + ") value).");
1136: print(md.getMethod().getName());
1137: print("(");
1138: }
1139:
1140: return p;
1141: }
1142:
1143: private int startCall(ESMethodDescriptor md) throws IOException {
1144: Method method = md.getMethod();
1145:
1146: int p = 0;
1147: if (md.isStaticVirtual()) {
1148: print(toJavaClassName(md.getMethodClassName()));
1149: print(".");
1150: print(md.getMethod().getName());
1151: print("((" + md.getObjectClassName()
1152: + ") call.getThisWrapper()");
1153: p = 1;
1154: } else if (Modifier.isStatic(method.getModifiers())) {
1155: print(toJavaClassName(md.getMethodClassName()));
1156: print(".");
1157: print(md.getMethod().getName());
1158: print("(");
1159: } else {
1160: print("((" + toJavaClassName(md.getObjectClassName())
1161: + ") call.getThisWrapper()).");
1162: print(md.getMethod().getName());
1163: print("(");
1164: }
1165:
1166: return p;
1167: }
1168:
1169: private void startJavaToES(Class cl) throws IOException {
1170: String name = cl.getName();
1171:
1172: switch (classTypes.get(name)) {
1173: case T_V:
1174: //addJsUndefinedRef();
1175: break;
1176:
1177: case T_Z:
1178: print("ESBoolean.create(");
1179: break;
1180:
1181: case T_C:
1182: print("ESString.createFromCharCode(");
1183: break;
1184:
1185: case T_B:
1186: case T_S:
1187: case T_I:
1188: case T_L:
1189: case T_F:
1190: case T_D:
1191: print("ESNumber.create(");
1192: break;
1193:
1194: case T_STRING:
1195: print("ESString.toStr(");
1196: break;
1197:
1198: default:
1199: if (esBase.isAssignableFrom(cl))
1200: print("((temp = ");
1201: else
1202: print("Global.wrap(");
1203: break;
1204: }
1205: }
1206:
1207: private void endJavaToES(Class cl) throws IOException {
1208: String name = cl.getName();
1209:
1210: switch (classTypes.get(name)) {
1211: case T_V:
1212: //addJsUndefinedRef();
1213: break;
1214:
1215: case T_Z:
1216: case T_C:
1217: case T_B:
1218: case T_S:
1219: case T_I:
1220: case T_L:
1221: case T_F:
1222: case T_D:
1223: case T_STRING:
1224: print(")");
1225: break;
1226:
1227: default:
1228: if (esBase.isAssignableFrom(cl))
1229: print(") == null ? ESBase.esNull : temp)");
1230: else
1231: print(")");
1232: break;
1233: }
1234: }
1235:
1236: private void printValueToJava(Class cl, String value)
1237: throws IOException {
1238: String name = cl.getName();
1239:
1240: switch (classTypes.get(name)) {
1241: case T_V:
1242: throw new RuntimeException();
1243:
1244: case T_Z:
1245: print(value + ".toBoolean()");
1246: break;
1247:
1248: case T_C:
1249: print("(char) " + value + ".toStr().carefulCharAt(0)");
1250: break;
1251:
1252: case T_B:
1253: print("(byte) " + value + ".toInt32()");
1254: break;
1255:
1256: case T_S:
1257: print("(short) " + value + ".toInt32()");
1258: break;
1259:
1260: case T_I:
1261: print(value + ".toInt32()");
1262: break;
1263:
1264: case T_L:
1265: print("(long)" + value + ".toNum()");
1266: break;
1267:
1268: case T_F:
1269: print("(float)" + value + ".toNum()");
1270: break;
1271:
1272: case T_D:
1273: print(value + ".toNum()");
1274: break;
1275:
1276: case T_STRING:
1277: print("(" + value + ").toJavaString()");
1278: break;
1279:
1280: default:
1281: if (cl.isAssignableFrom(esBase))
1282: print(value);
1283: else if (esBase.isAssignableFrom(cl)) {
1284: print("(");
1285: printClassType(cl);
1286: print(") " + value);
1287: } else {
1288: print("(");
1289: printClassType(cl);
1290: print(") " + value + ".toJavaObject()");
1291: }
1292: break;
1293: }
1294: }
1295:
1296: private void printArgToJava(Class cl, int i) throws IOException {
1297: String name = cl.getName();
1298:
1299: switch (classTypes.get(name)) {
1300: case T_V:
1301: throw new RuntimeException();
1302:
1303: case T_Z:
1304: print("call.getArg(" + i + ", length).toBoolean()");
1305: break;
1306:
1307: case T_C:
1308: print("(char) call.getArg(" + i
1309: + ", length).toStr().carefulCharAt(0)");
1310: break;
1311:
1312: case T_B:
1313: print("(byte) call.getArgInt32(" + i + ", length)");
1314: break;
1315:
1316: case T_S:
1317: print("(short) call.getArgInt32(" + i + ", length)");
1318: break;
1319:
1320: case T_I:
1321: print("call.getArgInt32(" + i + ", length)");
1322: break;
1323:
1324: case T_L:
1325: print("(long) call.getArgNum(" + i + ", length)");
1326: break;
1327:
1328: case T_F:
1329: print("(float)call.getArgNum(" + i + ", length)");
1330: break;
1331:
1332: case T_D:
1333: print("call.getArgNum(" + i + ", length)");
1334: break;
1335:
1336: case T_STRING:
1337: print("call.getArgString(" + i + ", length)");
1338: break;
1339:
1340: default:
1341: if (cl.isAssignableFrom(esBase)
1342: && !cl.getName().equals("java.lang.Object"))
1343: print("call.getArg(" + i + ", length)");
1344: else if (esBase.isAssignableFrom(cl)) {
1345: print("(");
1346: printClassType(cl);
1347: print(") ");
1348: print("call.getArg(" + i + ", length)");
1349: } else {
1350: print("(");
1351: printClassType(cl);
1352: print(") call.getArgObject(" + i + ", length)");
1353: }
1354: break;
1355: }
1356: }
1357:
1358: private void printClassType(Class cl) throws IOException {
1359: if (cl.isArray()) {
1360: printClassType(cl.getComponentType());
1361: print("[]");
1362: } else {
1363: print(cl.getName().replace('$', '.'));
1364: }
1365: }
1366:
1367: private void printInit() throws IOException {
1368: println("private int delId = -1;");
1369: println();
1370: println("private static com.caucho.util.IntMap instanceHasDispatch;");
1371: println("private static com.caucho.util.IntMap instanceSetDispatch;");
1372: println("private static com.caucho.util.IntMap instanceMethodDispatch;");
1373: println("private static com.caucho.util.IntMap staticMethodDispatch;");
1374: println("private static com.caucho.util.IntMap staticHasDispatch;");
1375: println("private static com.caucho.util.IntMap staticSetDispatch;");
1376: Iterator iter = namedProperties.values().iterator();
1377: while (iter.hasNext()) {
1378: Named named = (Named) iter.next();
1379: println(name + " name" + named.n + ";");
1380: print("private static ConstIntMap has" + named.n);
1381: println(" = new ConstIntMap(" + named.get + ");");
1382: print("private static ConstIntMap set" + named.n);
1383: println(" = new ConstIntMap(" + named.set + ");");
1384: }
1385:
1386: for (int i = 0; i < overloadDispatch.size(); i++) {
1387: print("private static com.caucho.es.wrapper.MethodDispatcher dispatch"
1388: + i);
1389: println(" = new com.caucho.es.wrapper.MethodDispatcher(new Class[][] {");
1390: pushDepth();
1391:
1392: ESMethodDescriptor[] mds;
1393: mds = (ESMethodDescriptor[]) overloadDispatch.get(i);
1394:
1395: for (int j = 0; j < mds.length; j++) {
1396: print("new Class[] {");
1397:
1398: Class[] param = mds[j].getParameterTypes();
1399:
1400: for (int k = 0; k < param.length; k++) {
1401: printClass(param[k]);
1402: print(", ");
1403: }
1404: println("},");
1405: }
1406: popDepth();
1407: println("});");
1408: }
1409:
1410: println();
1411: println("static { _init(); }");
1412:
1413: println();
1414: println("public boolean isModified()");
1415: println("{");
1416: pushDepth();
1417: com.caucho.make.ClassDependency dep = new com.caucho.make.ClassDependency(
1418: cl);
1419: println("try {");
1420: println(" Class cl = Class.forName(\""
1421: + cl.getName()
1422: + "\", false, Thread.currentThread().getContextClassLoader());");
1423: println(" return new com.caucho.make.ClassDependency(cl, "
1424: + dep.getDigest() + "L).isModified();");
1425: println("} catch (Throwable e) {");
1426: println(" return true;");
1427: println("}");
1428: popDepth();
1429: println("}");
1430:
1431: println();
1432: println("private static void _init()");
1433: println("{");
1434:
1435: pushDepth();
1436: println("instanceHasDispatch = new com.caucho.util.IntMap();");
1437: iter = hasDispatch.iterator();
1438: while (iter.hasNext()) {
1439: String key = (String) iter.next();
1440:
1441: println("instanceHasDispatch.put(ESId.intern(\"" + key
1442: + "\"), " + hasDispatch.get(key) + ");");
1443: }
1444:
1445: println();
1446: println("staticHasDispatch = new com.caucho.util.IntMap();");
1447: iter = staticHasDispatch.iterator();
1448: while (iter.hasNext()) {
1449: String key = (String) iter.next();
1450:
1451: println("staticHasDispatch.put(ESId.intern(\"" + key
1452: + "\"), " + staticHasDispatch.get(key) + ");");
1453: }
1454:
1455: println();
1456: println("instanceSetDispatch = new com.caucho.util.IntMap();");
1457: iter = setDispatch.iterator();
1458: while (iter.hasNext()) {
1459: String key = (String) iter.next();
1460:
1461: println("instanceSetDispatch.put(ESId.intern(\"" + key
1462: + "\"), " + setDispatch.get(key) + ");");
1463: }
1464:
1465: println();
1466: println("staticSetDispatch = new com.caucho.util.IntMap();");
1467: iter = staticSetDispatch.iterator();
1468: while (iter.hasNext()) {
1469: String key = (String) iter.next();
1470:
1471: println("staticSetDispatch.put(ESId.intern(\"" + key
1472: + "\"), " + staticSetDispatch.get(key) + ");");
1473: }
1474:
1475: println();
1476: println("instanceMethodDispatch = new com.caucho.util.IntMap();");
1477: iter = methodDispatch.iterator();
1478: while (iter.hasNext()) {
1479: String key = (String) iter.next();
1480:
1481: println("instanceMethodDispatch.put(ESId.intern(\"" + key
1482: + "\"), " + methodDispatch.get(key) + ");");
1483: }
1484:
1485: println();
1486: println("staticMethodDispatch = new com.caucho.util.IntMap();");
1487: iter = staticMethodDispatch.iterator();
1488: while (iter.hasNext()) {
1489: String key = (String) iter.next();
1490:
1491: println("staticMethodDispatch.put(ESId.intern(\"" + key
1492: + "\"), " + staticMethodDispatch.get(key) + ");");
1493: }
1494:
1495: popDepth();
1496: println("}");
1497: }
1498:
1499: private void printClass(Class cl) throws IOException {
1500: if (!cl.isArray()) {
1501: print(cl.getName() + ".class");
1502: return;
1503: }
1504:
1505: print("(new ");
1506: printArrayClass(cl.getComponentType());
1507: print("[0]).getClass()");
1508: }
1509:
1510: private void printArrayClass(Class cl) throws IOException {
1511: if (cl.isArray()) {
1512: printArrayClass(cl.getComponentType());
1513: print("[]");
1514: } else
1515: print(cl.getName());
1516: }
1517:
1518: private void printFooter() throws IOException {
1519: popDepth();
1520: println("}");
1521: }
1522:
1523: private void pushDepth() {
1524: depth += 2;
1525: }
1526:
1527: private void popDepth() {
1528: depth -= 2;
1529: }
1530:
1531: private void print(String s) throws IOException {
1532: if (isNewline)
1533: printDepth();
1534: os.print(s);
1535: }
1536:
1537: private void println(String s) throws IOException {
1538: if (isNewline)
1539: printDepth();
1540: os.println(s);
1541: isNewline = true;
1542: }
1543:
1544: private void println() throws IOException {
1545: if (isNewline)
1546: printDepth();
1547: os.println();
1548: isNewline = true;
1549: }
1550:
1551: private void printDepth() throws IOException {
1552: for (int i = 0; i < depth; i++)
1553: os.print(' ');
1554: isNewline = false;
1555: }
1556:
1557: private String toJavaClassName(String name) {
1558: CharBuffer cb = CharBuffer.allocate();
1559: for (int i = 0; i < name.length(); i++) {
1560: char ch = name.charAt(i);
1561:
1562: if (ch == '$' && i > 0 && name.charAt(i - 1) != '.')
1563: cb.append(".");
1564: else
1565: cb.append(ch);
1566: }
1567: return cb.close();
1568: }
1569:
1570: static HashMap<String, String> classNames;
1571: static {
1572: classNames = new HashMap<String, String>();
1573: classNames.put("void", "V");
1574: classNames.put("boolean", "Z");
1575: classNames.put("byte", "B");
1576: classNames.put("short", "S");
1577: classNames.put("char", "C");
1578: classNames.put("int", "I");
1579: classNames.put("long", "J");
1580: classNames.put("float", "F");
1581: classNames.put("double", "D");
1582: }
1583:
1584: static IntMap classTypes;
1585: static final int T_V = 0;
1586: static final int T_Z = T_V + 1;
1587: static final int T_B = T_Z + 1;
1588: static final int T_S = T_B + 1;
1589: static final int T_C = T_S + 1;
1590: static final int T_I = T_C + 1;
1591: static final int T_L = T_I + 1;
1592: static final int T_F = T_L + 1;
1593: static final int T_D = T_F + 1;
1594: static final int T_STRING = T_D + 1;
1595: static {
1596: classTypes = new IntMap();
1597: classTypes.put("void", T_V);
1598: classTypes.put("boolean", T_Z);
1599: classTypes.put("byte", T_B);
1600: classTypes.put("short", T_S);
1601: classTypes.put("char", T_C);
1602: classTypes.put("int", T_I);
1603: classTypes.put("long", T_L);
1604: classTypes.put("float", T_F);
1605: classTypes.put("double", T_D);
1606: classTypes.put("java.lang.String", T_STRING);
1607: }
1608:
1609: static class Named {
1610: String name;
1611: int n;
1612: int get = -1;
1613: int set = -1;
1614: int keys = -1;
1615: int remove = -1;
1616:
1617: Named(String name, int n) {
1618: this.name = name;
1619: this.n = n;
1620: }
1621: }
1622: }
|