Example #1
0
  /**
   * Returns an array containing the available subtypes of the specified type, first looking to
   * subtypes listed in the annotation, then attempting to find a method using reflection.
   */
  protected Class<?>[] getSubtypes(Class<?> type) {
    ArrayList<Class<?>> types = new ArrayList<Class<?>>();

    // start with the null class, if allowed
    boolean nullable = getAnnotation().nullable();
    if (nullable) {
      types.add(null);
    }

    // look for a subtype annotation and add its types
    EditorTypes ownAnnotation = getAnnotation(EditorTypes.class);
    EditorTypes annotation =
        (ownAnnotation == null) ? type.getAnnotation(EditorTypes.class) : ownAnnotation;
    if (annotation != null) {
      addSubtypes(annotation, types);
    }

    // get the config key and add the config types
    String key = (annotation == null) ? type.getName() : annotation.key();
    if (StringUtil.isBlank(key)) {
      if (annotation == ownAnnotation) {
        Member member = getMember();
        key = member.getDeclaringClass().getName() + "." + member.getName();
      } else {
        key = type.getName();
      }
    }
    Class<?>[] ctypes = _configTypes.get(key);
    if (ctypes != null) {
      Collections.addAll(types, ctypes);
    }

    // if we don't have at least one non-null class, add the type itself
    if (types.size() == (nullable ? 1 : 0)) {
      types.add(type);
    }

    // convert to array, return
    return types.toArray(new Class<?>[types.size()]);
  }
Example #2
0
 /** Finds the editor message bundle for the supplied class. */
 protected static String findMessageBundle(Class<?> clazz) {
   EditorMessageBundle annotation = clazz.getAnnotation(EditorMessageBundle.class);
   if (annotation != null) {
     return annotation.value();
   }
   Class<?> eclazz = clazz.getEnclosingClass();
   if (eclazz != null) {
     return getMessageBundle(eclazz);
   }
   String name = clazz.getName();
   int idx;
   while ((idx = name.lastIndexOf('.')) != -1) {
     name = name.substring(0, idx);
     Package pkg = Package.getPackage(name);
     if (pkg != null) {
       annotation = pkg.getAnnotation(EditorMessageBundle.class);
       if (annotation != null) {
         return annotation.value();
       }
     }
   }
   return EditorMessageBundle.DEFAULT;
 }
Example #3
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()]);
  }