/** * 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; }
/** * 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(); }
public void testToString() throws Exception { AttributeDescriptor attr = new AttributeDescriptor("attr", "int"); String expected = "<attribute name=\"attr\" type=\"int\"/>"; assertEquals(expected, attr.toString()); } }
/** * Return a List of Class objects corresponding to the fields returned by * getColumnFieldDescriptors(). * @return the Class objects */ public List getColumnFieldClasses() { if (columnFieldClasses == null) { columnFieldClasses = new ArrayList(); for (int i = 0; i < columnFieldDescriptors.size(); i++) { AttributeDescriptor ad = (AttributeDescriptor) columnFieldDescriptors.get(i); if (ad == null) { columnFieldClasses.add(null); } else { String className = ad.getType(); columnFieldClasses.add(TypeUtil.instantiate(className)); } } } return columnFieldClasses; } }
private Set<AttributeDescriptor> getAttributes() { Set<AttributeDescriptor> attributes = new HashSet<AttributeDescriptor>(); AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); AttributeDescriptor atd2 = new AttributeDescriptor("atd2", "java.lang.Integer"); attributes.add(atd1); attributes.add(atd2); return attributes; }
Class fieldClass = (Class) fieldClasses.get(columnIndex); Object typedObject = TypeUtil.stringToObject(fieldClass, rowValue); o.setFieldValue(columnAD.getName(), typedObject);
public void testEquals() throws Exception { AttributeDescriptor attr1 = new AttributeDescriptor("name1", "int"); AttributeDescriptor attr2 = new AttributeDescriptor("name1", "int"); AttributeDescriptor attr3 = new AttributeDescriptor("name2", "int"); AttributeDescriptor attr4 = new AttributeDescriptor("name1", "float"); assertEquals(attr1, attr2); assertEquals(attr1.hashCode(), attr2.hashCode()); assertFalse(attr1.equals(attr3)); assertFalse(attr1.equals(attr4)); }
public void testRelationType() throws Exception { AttributeDescriptor attr = new AttributeDescriptor("name", "int"); assertEquals(FieldDescriptor.NOT_RELATION, attr.relationType()); }
if (field instanceof AttributeDescriptor) { AttributeDescriptor attr = (AttributeDescriptor) field; if (attr.isPrimitive() || attr.isNumeric()) { sb.append("=\" + " + field.getName() + " + \""); } else {
.getType()).get(((QueryField) newFirstOrderBy) .getFieldName()); if (desc.isPrimitive()) { hasNulls = false;
/** * Return a List of Class objects corresponding to the fields returned by * getColumnFieldDescriptors(). * @return the Class objects */ public List getColumnFieldClasses() { if (columnFieldClasses == null) { columnFieldClasses = new ArrayList(); for (int i = 0; i < columnFieldDescriptors.size(); i++) { AttributeDescriptor ad = (AttributeDescriptor) columnFieldDescriptors.get(i); if (ad == null) { columnFieldClasses.add(null); } else { String className = ad.getType(); columnFieldClasses.add(TypeUtil.instantiate(className)); } } } return columnFieldClasses; } }
public void testConstructorEmptyName() throws Exception { try { new AttributeDescriptor("", "int"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
Class fieldClass = (Class) fieldClasses.get(columnIndex); Object typedObject = TypeUtil.stringToObject(fieldClass, rowValue); o.setFieldValue(columnAD.getName(), typedObject);
if (field instanceof AttributeDescriptor) { AttributeDescriptor attr = (AttributeDescriptor) field; if (attr.isPrimitive() || attr.isNumeric()) { sb.append("=\" + " + field.getName() + " + \""); } else {
.getType()).get(((QueryField) newFirstOrderBy) .getFieldName()); if (desc.isPrimitive()) { hasNulls = false;
/** * 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; }
/** * 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 (field instanceof AttributeDescriptor) { AttributeDescriptor attribute = (AttributeDescriptor) field; if ("boolean".equals(attribute.getType())) { sb.append("return Boolean.TYPE;\n"); } else if ("short".equals(attribute.getType())) { sb.append("return Short.TYPE;\n"); } else if ("int".equals(attribute.getType())) { sb.append("return Integer.TYPE;\n"); } else if ("long".equals(attribute.getType())) { sb.append("return Long.TYPE;\n"); } else if ("float".equals(attribute.getType())) { sb.append("return Float.TYPE;\n"); } else if ("double".equals(attribute.getType())) { sb.append("return Double.TYPE;\n"); } else { sb.append("return " + attribute.getType() + ".class;\n");
/** * 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; }