/** * Generates code for a single collection. * * @param col the CollectionDescriptor * @param field true if the class should have the associated field, or false if the field is in * the superclass * @return java code */ protected String generate(CollectionDescriptor col, boolean field) { String type = "java.util.Set<" + col.getReferencedClassName() + ">"; String impl = "java.util.HashSet<" + col.getReferencedClassName() + ">"; StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Col: " + col.getClassDescriptor().getName() + "." + col.getName() + ENDL) .append(INDENT) .append("protected ") .append(type) .append(" ") .append(col.getName()) .append(" = new ") .append(impl) .append("();" + ENDL); } sb.append(generateGetSet(col, field)) .append(ENDL); return sb.toString(); }
/** * Generates code for a single collection. * * @param col the CollectionDescriptor * @param field true if the class should have the associated field, or false if the field is in * the superclass * @return java code */ protected String generate(CollectionDescriptor col, boolean field) { String type = "java.util.Set<" + col.getReferencedClassName() + ">"; String impl = "java.util.HashSet<" + col.getReferencedClassName() + ">"; StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Col: " + col.getClassDescriptor().getName() + "." + col.getName() + ENDL) .append(INDENT) .append("protected ") .append(type) .append(" ") .append(col.getName()) .append(" = new ") .append(impl) .append("();" + ENDL); } sb.append(generateGetSet(col, field)) .append(ENDL); return sb.toString(); }
.append("if (\"" + field.getName() + "\".equals(fieldName)) {\n") .append(INDENT + INDENT + INDENT) .append("return " + ((CollectionDescriptor) field).getReferencedClassName() + ".class;\n") .append(INDENT + INDENT)
.append("if (\"" + field.getName() + "\".equals(fieldName)) {\n") .append(INDENT + INDENT + INDENT) .append("return " + ((CollectionDescriptor) field).getReferencedClassName() + ".class;\n") .append(INDENT + INDENT)
.append(INDENT + INDENT + INDENT) .append(fieldName + ".add((" + ((CollectionDescriptor) field).getReferencedClassName() + ") element);\n") .append(INDENT + INDENT)
.append(INDENT + INDENT + INDENT) .append(fieldName + ".add((" + ((CollectionDescriptor) field).getReferencedClassName() + ") element);\n") .append(INDENT + INDENT)
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
/** * Return the java type of a particular field. * @param field descriptor for the field in question * @return the java type */ protected String getType(FieldDescriptor field) { String type = null; if (field instanceof AttributeDescriptor) { type = ((AttributeDescriptor) field).getType(); } else if (field instanceof CollectionDescriptor) { type = "java.util.Set<" + ((CollectionDescriptor) field).getReferencedClassName() + ">"; } else { type = ((ReferenceDescriptor) field).getReferencedClassDescriptor().getName(); } return type; }
/** * Return the java type of a particular field. * @param field descriptor for the field in question * @return the java type */ protected String getType(FieldDescriptor field) { String type = null; if (field instanceof AttributeDescriptor) { type = ((AttributeDescriptor) field).getType(); } else if (field instanceof CollectionDescriptor) { type = "java.util.Set<" + ((CollectionDescriptor) field).getReferencedClassName() + ">"; } else { type = ((ReferenceDescriptor) field).getReferencedClassDescriptor().getName(); } return type; }
CollectionDescriptor coll = (CollectionDescriptor) field; sb.append(INDENT + INDENT) .append(fieldName + " = new ProxyCollection<" + coll.getReferencedClassName() + ">(os, this, \"" + fieldName + "\", " + coll.getReferencedClassName() + ".class);\n");
CollectionDescriptor coll = (CollectionDescriptor) field; sb.append(INDENT + INDENT) .append(fieldName + " = new ProxyCollection<" + coll.getReferencedClassName() + ">(os, this, \"" + fieldName + "\", " + coll.getReferencedClassName() + ".class);\n");
colls.put(c.getName(), col); col.put("name", c.getName()); String type = c.getReferencedClassName(); col.put("referencedType", type.substring(type.lastIndexOf(".") + 1)); String revref = c.getReverseReferenceFieldName();
colls.put(c.getName(), col); col.put("name", c.getName()); String type = c.getReferencedClassName(); col.put("referencedType", type.substring(type.lastIndexOf(".") + 1)); String revref = c.getReverseReferenceFieldName();
if (!merg.getReferencedClassName().equals(orig.getReferencedClassName())) { String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between collection types: " + fldName + ":" + merg.getReferencedClassName() + " != " + fldName + ":" + orig.getReferencedClassName());
if (!merg.getReferencedClassName().equals(orig.getReferencedClassName())) { String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between collection types: " + fldName + ":" + merg.getReferencedClassName() + " != " + fldName + ":" + orig.getReferencedClassName());
ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), "collection of " + terseClass(desc.getReferencedClassName()), (cld == this ? "" : "from " + terseClass(cld.getName()))});
ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), "collection of " + terseClass(desc.getReferencedClassName()), (cld == this ? "" : "from " + terseClass(cld.getName()))});