Fork me on GitHub

Commons GenericsUtil

org.onehippo.forge.utilities.commons.GenericsUtil

Static utility class to get and set generically typed JCR property values. It has the following methods:

  <T> T getPropertyValue(Property property, Class<T> clazz)
  <T> T getPropertyValue(Node node, String path, Class<T> clazz)
  <T> Collection<T> getPropertyValues(Property property, Class<? extends Collection> clazz, Class<T> genericType)
  <T> Collection<T> getPropertyValues(Node node, String path, Class<? extends Collection> clazz, Class<T> genericType)
  <T> T getValue(Value value, Class<T> clazz)

  void setProperty(Node node, String relativePath, Object object)
  <T> void setPropertyValues(Property property, Collection<T> values)
  <T> void setPropertyValues(Node node, String relativePath, Collection<T> values)

  Value createValue(Object object)

  List<Class<?>> getActualTypeParameters(Field field)
  <T extends Annotation> T getGenericAnnotation(Field field, int parameterIndex, Class<T> annotationClazz)