/** * 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; } }
/** * 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; } }
/** * 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(); }
sb.append(DatabaseUtil.getColumnName(ad)); sb.append(" "); sb.append(db.getColumnTypeString(Class.forName(ad.getType()))); needsComma = true;
sb.append(DatabaseUtil.getColumnName(ad)); sb.append(" "); sb.append(db.getColumnTypeString(Class.forName(ad.getType()))); needsComma = true;
/** * 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; }
/** * 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; }
/** * 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; }
/** * Return the type of the last element in the path, regardless of whether it is an attribute * or a class. * @return the Class of the last element */ public Class<?> getEndType() { Class<?> retval = null; if (endFld != null && endFld.isAttribute()) { retval = Util.getClassFromString(((AttributeDescriptor) endFld).getType()); } else { retval = getLastClassDescriptor().getType(); } return retval; }
/** * Return the type of the last element in the path, regardless of whether it is an attribute * or a class. * @return the Class of the last element */ public Class<?> getEndType() { Class<?> retval = null; if (endFld != null && endFld.isAttribute()) { retval = Util.getClassFromString(((AttributeDescriptor) endFld).getType()); } else { retval = getLastClassDescriptor().getType(); } return retval; }
/** * Method to set up chromosome fields for helping */ public ChromosomeLocationHelper() { Model model = Model.getInstanceByName("genomic"); if (model == null) { throw new RuntimeException("No genomic model is available"); } ClassDescriptor chr = model.getClassDescriptorByName("Chromosome"); if (chr == null) { throw new RuntimeException("This genomic model does not contain Chromosomes"); } ClassDescriptor org = model.getClassDescriptorByName("Organism"); if (org == null) { throw new RuntimeException("This genomic model does not contain Organisms"); } AttributeDescriptor taxonDesc = org.getAttributeDescriptorByName("taxonId"); taxonIdsAreStrings = "java.lang.String".equals(taxonDesc.getType()); chromosome = new QueryClass(chr.getType()); organism = new QueryClass(org.getType()); chrIdField = new QueryField(chromosome, "primaryIdentifier"); taxonIdField = new QueryField(organism, "taxonId"); }
/** * Attach the model. Throws IllegalArgumentExceptions if node doesn't map onto the model. * * @param model model to attach * @throws IllegalArgumentException if class or field are not found in the model */ public void setModel(Model model) { ClassDescriptor cld = model.getClassDescriptorByName(getParentType()); if (cld == null) { throw new IllegalArgumentException("No class '" + getParentType() + "' found in model '" + model.getName() + "'."); } fd = cld.getFieldDescriptorByName(fieldName); if (fd == null) { throw new IllegalArgumentException("Class '" + cld.getName() + "' does not have field '" + fieldName + "'."); } type = TypeUtil.unqualifiedName(fd.isAttribute() ? ((AttributeDescriptor) fd).getType() : ((ReferenceDescriptor) fd) .getReferencedClassDescriptor().getName()); attribute = fd.isAttribute(); reference = fd.isReference(); collection = fd.isCollection(); this.model = model; }
/** * Attach the model. Throws IllegalArgumentExceptions if node doesn't map onto the model. * * @param model model to attach * @throws IllegalArgumentException if class or field are not found in the model */ public void setModel(Model model) { ClassDescriptor cld = model.getClassDescriptorByName(getParentType()); if (cld == null) { throw new IllegalArgumentException("No class '" + getParentType() + "' found in model '" + model.getName() + "'."); } fd = cld.getFieldDescriptorByName(fieldName); if (fd == null) { throw new IllegalArgumentException("Class '" + cld.getName() + "' does not have field '" + fieldName + "'."); } type = TypeUtil.unqualifiedName(fd.isAttribute() ? ((AttributeDescriptor) fd).getType() : ((ReferenceDescriptor) fd) .getReferencedClassDescriptor().getName()); attribute = fd.isAttribute(); reference = fd.isReference(); collection = fd.isCollection(); this.model = model; }
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()))});