/** Generates the make method. */ private void generateMake(JavaWriter out) throws IOException { ArrayList<AmberField> fields = _embeddableType.getFields(); out.println(); out.println("public static " + getClassName() + " __caucho_make("); for (int i = 0; i < fields.size(); i++) { AmberField prop = fields.get(i); out.print(" " + prop.getJavaTypeName() + " a" + i); if (i + 1 < fields.size()) out.println(","); } out.println(")"); out.println("{"); out.pushDepth(); out.println(getClassName() + " bean = new " + getClassName() + "();"); for (int i = 0; i < fields.size(); i++) { AmberField prop = fields.get(i); out.println(prop.generateSuperSetter("bean", "a" + i) + ";"); } out.println("return bean;"); out.popDepth(); out.println("}"); }
/** Generates the get field method. */ private void generateGetField(JavaWriter out) throws IOException { out.println(); out.println("public Object __caucho_get_field(int index)"); out.println("{"); out.pushDepth(); out.println("switch (index) {"); out.pushDepth(); ArrayList<AmberField> fields = _embeddableType.getFields(); for (int i = 0; i < fields.size(); i++) { AmberField prop = fields.get(i); if (!(prop instanceof PropertyField)) break; out.println("case " + i + ":"); out.println(" return " + prop.generateSuperGetter("this") + ";"); out.println(); } out.println("default:"); out.println(" throw new IllegalStateException(\"invalid index: \" + index);"); out.popDepth(); out.println("}"); out.popDepth(); out.println("}"); }
/** Generates the initialization. */ private void generateInit(JavaWriter out) throws IOException { String className = getClassName(); int p = className.lastIndexOf('.'); if (p > 0) className = className.substring(p + 1); ArrayList<AmberField> fields = _embeddableType.getFields(); for (Constructor ctor : _embeddableType.getBeanClass().getConstructors()) { out.println(); // XXX: s/b actual access type? out.print("public "); out.print(className); out.print("("); Class[] args = ctor.getParameterTypes(); for (int i = 0; i < args.length; i++) { if (i != 0) out.print(", "); out.printClass(args[i]); out.print(" a" + i); } out.println(")"); out.println("{"); out.pushDepth(); out.print("super("); for (int i = 0; i < args.length; i++) { if (i != 0) out.print(", "); out.print("a" + i); } out.println(");"); for (AmberField field : fields) { field.generatePostConstructor(out); } out.popDepth(); out.println("}"); } }