private void processFeatureAnnotations(AnnotationMetadata metadata) { try { for (String annotationType : metadata.getAnnotationTypes()) { MetadataReader metadataReader = new SimpleMetadataReaderFactory().getMetadataReader(annotationType); if (metadataReader.getAnnotationMetadata().isAnnotated(FeatureAnnotation.class.getName())) { Map<String, Object> annotationAttributes = metadataReader .getAnnotationMetadata() .getAnnotationAttributes(FeatureAnnotation.class.getName(), true); // TODO SPR-7420: this is where we can catch user-defined types and avoid instantiating // them for STS purposes FeatureAnnotationParser processor = (FeatureAnnotationParser) BeanUtils.instantiateClass( Class.forName((String) annotationAttributes.get("parser"))); FeatureSpecification spec = processor.process(metadata); spec.execute(this.specificationContext); } } } catch (BeanDefinitionParsingException ex) { throw ex; } catch (Exception ex) { // TODO SPR-7420: what exception to throw? throw new RuntimeException(ex); } }
/** * Derive a bean name from one of the annotations on the class. * * @param annotatedDef the annotation-aware bean definition * @return the bean name, or <code>null</code> if none is found */ protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata amd = annotatedDef.getMetadata(); Set<String> types = amd.getAnnotationTypes(); String beanName = null; for (String type : types) { Map<String, Object> attributes = amd.getAnnotationAttributes(type); if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) { String value = (String) attributes.get("value"); if (StringUtils.hasLength(value)) { if (beanName != null && !value.equals(beanName)) { throw new IllegalStateException( "Stereotype annotations suggest inconsistent " + "component names: '" + beanName + "' versus '" + value + "'"); } beanName = value; } } } return beanName; }