Exemplo n.º 1
0
  /** 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()]);
  }