List of usage examples for org.springframework.core.annotation AnnotationUtils getAnnotationAttributes
public static AnnotationAttributes getAnnotationAttributes(@Nullable AnnotatedElement annotatedElement, Annotation annotation)
From source file:org.dataconservancy.packaging.tool.ser.SerializationAnnotationUtil.java
/** * Answers a {@code Map} of {@link PropertyDescriptor} instances, which are used to reflectively access the * {@link Serialize serializable} streams on {@code annotatedClass} instances. * <p>// ww w . jav a2 s .c o m * Use of {@code PropertyDescriptor} is simply a convenience in lieu of the use of underlying Java reflection. * </p> * <p> * This method looks for fields annotated by the {@code Serialize} annotation on the {@code annotatedClass}. * A {@code PropertyDescriptor} is created for each field, and is keyed by the {@code StreamId} in the returned * {@code Map}. * </p> * * @param annotatedClass the class to scan for the presense of {@code @Serialize} * @return a Map of PropertyDescriptors keyed by their StreamId. */ public static Map<StreamId, PropertyDescriptor> getStreamDescriptors(Class annotatedClass) { HashMap<StreamId, PropertyDescriptor> results = new HashMap<>(); Arrays.stream(annotatedClass.getDeclaredFields()) .filter(candidateField -> AnnotationUtils.getAnnotation(candidateField, Serialize.class) != null) .forEach(annotatedField -> { AnnotationAttributes attributes = AnnotationUtils.getAnnotationAttributes(annotatedField, AnnotationUtils.getAnnotation(annotatedField, Serialize.class)); StreamId streamId = (StreamId) attributes.get("streamId"); PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(PackageState.class, annotatedField.getName()); results.put(streamId, descriptor); }); return results; }
From source file:com.haulmont.cuba.core.sys.MetadataLoader.java
protected void initMetaAnnotations(MetaClass metaClass) { for (Annotation annotation : metaClass.getJavaClass().getAnnotations()) { MetaAnnotation metaAnnotation = AnnotationUtils.findAnnotation(annotation.getClass(), MetaAnnotation.class); if (metaAnnotation != null) { String name = annotation.annotationType().getName(); Map<String, Object> attributes = new LinkedHashMap<>( AnnotationUtils.getAnnotationAttributes(metaClass.getJavaClass(), annotation)); metaClass.getAnnotations().put(name, attributes); Object propagateToSubclasses = attributes.get("propagateToSubclasses"); if (propagateToSubclasses == null || Boolean.TRUE.equals(propagateToSubclasses)) { for (MetaClass descMetaClass : metaClass.getDescendants()) { Annotation descAnnotation = descMetaClass.getJavaClass() .getAnnotation(annotation.annotationType()); if (descAnnotation == null) { descMetaClass.getAnnotations().put(name, attributes); }//ww w .j a va2 s.c om } } } } }
From source file:com.haulmont.cuba.core.sys.MetaModelLoader.java
protected void loadPropertyAnnotations(MetaProperty metaProperty, AnnotatedElement annotatedElement) { for (Annotation annotation : annotatedElement.getAnnotations()) { MetaAnnotation metaAnnotation = AnnotationUtils.findAnnotation(annotation.getClass(), MetaAnnotation.class); if (metaAnnotation != null) { Map<String, Object> attributes = new LinkedHashMap<>( AnnotationUtils.getAnnotationAttributes(annotatedElement, annotation)); metaProperty.getAnnotations().put(annotation.annotationType().getName(), attributes); }//from w w w. jav a 2 s. c o m } com.haulmont.chile.core.annotations.MetaProperty metaPropertyAnnotation = annotatedElement .getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class); if (metaPropertyAnnotation != null) { String[] related = metaPropertyAnnotation.related(); if (!(related.length == 1 && related[0].equals(""))) { metaProperty.getAnnotations().put("relatedProperties", Joiner.on(',').join(related)); } } loadBeanValidationAnnotations(metaProperty, annotatedElement); }