/** * Returns an array containing the categories to which the supplied class's properties are * assigned. */ public static String[] getCategories(Class<?> clazz) { String[] categories = _categories.get(clazz); if (categories == null) { categories = ArrayUtil.EMPTY_STRING; for (Property prop : getProperties(clazz)) { String category = prop.getAnnotation().category(); if (!ListUtil.contains(categories, category)) { categories = ArrayUtil.append(categories, category); } } if (DynamicallyEditable.class.isAssignableFrom(clazz)) { if (!ListUtil.contains(categories, "")) { categories = ArrayUtil.append(categories, ""); } } _categories.put(clazz, categories); } return categories; }
/** Creates and returns the list of properties for the supplied class. */ protected static Property[] createProperties(Class<?> clazz) { // get the list of properties ArrayList<Property> properties = new ArrayList<Property>(); createProperties(clazz, properties); // sort the properties by weight Collections.sort(properties, WEIGHT_COMP); // if the class has a property order attribute, move the listed properties // to the beginning in the desired order PropertyOrder order = clazz.getAnnotation(PropertyOrder.class); if (order != null) { int index = 0; for (String name : order.value()) { int oindex = index; for (int ii = index, nn = properties.size(); ii < nn; ii++) { Property property = properties.get(ii); if (property.getName().equals(name)) { properties.remove(ii); properties.add(index++, property); break; } } if (index == oindex) { log.warning( "Missing property in order annotation [class=" + clazz.getName() + ", property=" + name + "]."); } } } // return an array with the results return properties.toArray(new Property[properties.size()]); }
public int compare(Property p1, Property p2) { return Double.compare(p1.getAnnotation().weight(), p2.getAnnotation().weight()); }