/** * Clone a set of AttributeDescriptors. * * @param refs a set of AttributeDescriptors * @return cloned set of AttributeDescriptors */ protected static Set<AttributeDescriptor> cloneAttributeDescriptors( Set<AttributeDescriptor> refs) { Set<AttributeDescriptor> copy = new HashSet<AttributeDescriptor>(); for (AttributeDescriptor ref : refs) { copy.add(new AttributeDescriptor(ref.getName(), ref.getType())); } return copy; }
/** * Clone a set of AttributeDescriptors. * * @param refs a set of AttributeDescriptors * @return cloned set of AttributeDescriptors */ protected static Set<AttributeDescriptor> cloneAttributeDescriptors( Set<AttributeDescriptor> refs) { Set<AttributeDescriptor> copy = new HashSet<AttributeDescriptor>(); for (AttributeDescriptor ref : refs) { copy.add(new AttributeDescriptor(ref.getName(), ref.getType())); } return copy; }
/** * Generates code for a single attribute. * * @param attr the AttributeDescriptor * @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(AttributeDescriptor attr, boolean field) { StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Attr: " + attr.getClassDescriptor().getName() + "." + attr.getName() + ENDL) .append(INDENT + "protected ") .append(attr.getType()) .append(" ") .append(attr.getName()) .append(";" + ENDL); } sb.append(generateGetSet(attr, field)) .append(ENDL); return sb.toString(); }
/** * Generates code for a single attribute. * * @param attr the AttributeDescriptor * @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(AttributeDescriptor attr, boolean field) { StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Attr: " + attr.getClassDescriptor().getName() + "." + attr.getName() + ENDL) .append(INDENT + "protected ") .append(attr.getType()) .append(" ") .append(attr.getName()) .append(";" + ENDL); } sb.append(generateGetSet(attr, field)) .append(ENDL); return sb.toString(); }
if (attribute.getType().startsWith("java.")) { sb.append(INDENT + INDENT) .append("if (" + attribute.getName() + " != null) {\n") .append(INDENT + INDENT + INDENT) .append("sb.append(\"" + DELIM + "a" + field.getName() + DELIM + "\")"); if ("java.util.Date".equals(attribute.getType())) { sb.append(".append(" + attribute.getName() + ".getTime());\n"); } else if ("java.lang.String".equals(attribute.getType())) { sb.append(";\n") .append(INDENT + INDENT + INDENT) .append("String string = " + attribute.getName() + ";\n") .append(INDENT + INDENT + INDENT) .append("while (string != null) {\n") .append("}\n"); } else { sb.append(".append(" + attribute.getName() + ");\n"); .getType())) { sb.append(INDENT + INDENT) .append("if (" + attribute.getName() + " != null) {\n") .append(INDENT + INDENT + INDENT) .append("sb.append(\"" + DELIM + "a" + field.getName() + DELIM + "\" + ") .append(attribute.getName() + ".getDbDescription());\n") .append(INDENT + INDENT) .append("}\n");
/** * Merge the attributes of a target model class descriptor <code>original</code> with * the attributes present in class descriptor <code>merge</code>. Returns a new set of * AttributeDescriptors. * * @param original the target model class descriptor * @param merge the additions * @return new set of AttributeDescriptors * @throws ModelMergerException if an error occurs during model mergining */ public static Set<AttributeDescriptor> mergeAttributes(ClassDescriptor original, ClassDescriptor merge) throws ModelMergerException { for (AttributeDescriptor merg : merge.getAttributeDescriptors()) { // nb: does not look for references in superclasses/superinterfaces AttributeDescriptor orig = original.getAttributeDescriptorByName(merg.getName()); if (orig != null) { if (!merg.getType().equals(orig.getType())) { String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between attributes: " + fldName + ":" + merg.getType() + " != " + fldName + ":" + orig.getType()); } } } Set<AttributeDescriptor> newSet = new HashSet<AttributeDescriptor>(); newSet.addAll(cloneAttributeDescriptors(original.getAttributeDescriptors())); newSet.addAll(cloneAttributeDescriptors(merge.getAttributeDescriptors())); return newSet; }
Class fieldClass = (Class) fieldClasses.get(columnIndex); Object typedObject = TypeUtil.stringToObject(fieldClass, rowValue); o.setFieldValue(columnAD.getName(), typedObject);
Class fieldClass = (Class) fieldClasses.get(columnIndex); Object typedObject = TypeUtil.stringToObject(fieldClass, rowValue); o.setFieldValue(columnAD.getName(), typedObject);
/** * Merge the attributes of a target model class descriptor <code>original</code> with * the attributes present in class descriptor <code>merge</code>. Returns a new set of * AttributeDescriptors. * * @param original the target model class descriptor * @param merge the additions * @return new set of AttributeDescriptors * @throws ModelMergerException if an error occurs during model mergining */ public static Set<AttributeDescriptor> mergeAttributes(ClassDescriptor original, ClassDescriptor merge) throws ModelMergerException { for (AttributeDescriptor merg : merge.getAttributeDescriptors()) { // nb: does not look for references in superclasses/superinterfaces AttributeDescriptor orig = original.getAttributeDescriptorByName(merg.getName()); if (orig != null) { if (!merg.getType().equals(orig.getType())) { String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between attributes: " + fldName + ":" + merg.getType() + " != " + fldName + ":" + orig.getType()); } } } Set<AttributeDescriptor> newSet = new HashSet<AttributeDescriptor>(); newSet.addAll(cloneAttributeDescriptors(original.getAttributeDescriptors())); newSet.addAll(cloneAttributeDescriptors(merge.getAttributeDescriptors())); return newSet; }
retval.fieldNames[colNo] = field.getName(); retval.fields[colNo] = field; colNo++;
retval.fieldNames[colNo] = field.getName(); retval.fields[colNo] = field; colNo++;
for (AttributeDescriptor desc : getAllAttributeDescriptors()) { ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), terseClass(desc.getType()), (cld == this ? "" : "from " + terseClass(cld.getName()))});
for (AttributeDescriptor desc : getAllAttributeDescriptors()) { ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), terseClass(desc.getType()), (cld == this ? "" : "from " + terseClass(cld.getName()))});