List of usage examples for org.springframework.core.type AnnotationMetadata getInterfaceNames
String[] getInterfaceNames();
From source file:nz.co.senanque.validationengine.metadata.AnnotationsMetadataFactory.java
private void scanPackageForDomainObjects(String basePackage, Set<Class<ValidationObject>> domainObjects) throws ClassNotFoundException { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( true) {//from ww w .j a va 2 s.co m private String iface = ValidationObject.class.getCanonicalName(); /** * Check if the class has the right annotation * @param metadataReader the ASM ClassReader for the class * @return whether the class qualifies as a candidate component */ protected boolean isCandidateComponent(MetadataReader metadataReader) throws IOException { AnnotationMetadata metadata = metadataReader.getAnnotationMetadata(); for (String n : metadata.getInterfaceNames()) { if (iface.equals(n)) { return true; } } return false; } /** * Determine whether the given bean definition qualifies as candidate. * <p>The default implementation checks whether the class is concrete * (i.e. not abstract and not an interface). Can be overridden in subclasses. * @param beanDefinition the bean definition to check * @return whether the bean definition qualifies as a candidate component */ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return (beanDefinition.getMetadata().isConcrete() && beanDefinition.getMetadata().isIndependent()); } }; Set<BeanDefinition> components = provider.findCandidateComponents(basePackage.replace('.', '/')); ClassLoader cl = Thread.currentThread().getContextClassLoader(); for (BeanDefinition component : components) { @SuppressWarnings("unchecked") Class<ValidationObject> class_ = (Class<ValidationObject>) Class.forName(component.getBeanClassName(), true, cl); domainObjects.add(class_); } }
From source file:nz.co.senanque.validationengine.metadata.AnnotationsMetadataFactory.java
private void scanPackageForValidators(String basePackage, Map<Class<? extends Annotation>, Class<? extends FieldValidator<Annotation>>> validators) throws ClassNotFoundException { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( true) {/*from w ww. j a va 2 s . co m*/ private String iface = FieldValidator.class.getCanonicalName(); /** * Check if the class has the right annotation * @param metadataReader the ASM ClassReader for the class * @return whether the class qualifies as a candidate component */ protected boolean isCandidateComponent(MetadataReader metadataReader) throws IOException { AnnotationMetadata metadata = metadataReader.getAnnotationMetadata(); for (String n : metadata.getInterfaceNames()) { if (iface.equals(n)) { return true; } } return false; } /** * Determine whether the given bean definition qualifies as candidate. * <p>The default implementation checks whether the class is concrete * (i.e. not abstract and not an interface). Can be overridden in subclasses. * @param beanDefinition the bean definition to check * @return whether the bean definition qualifies as a candidate component */ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return (beanDefinition.getMetadata().isConcrete() && beanDefinition.getMetadata().isIndependent()); } }; // String basePackage = "nz/co/senanque/validationengine/fieldvalidators";//nz.co.senanque.validationengine.fieldvalidators Set<BeanDefinition> components = provider.findCandidateComponents(basePackage.replace('.', '/')); for (BeanDefinition component : components) { @SuppressWarnings("unchecked") Class<? extends FieldValidator<Annotation>> class_ = (Class<? extends FieldValidator<Annotation>>) Class .forName(component.getBeanClassName()); Type[] types = class_.getGenericInterfaces(); ParameterizedType t0 = (ParameterizedType) types[0]; @SuppressWarnings("unchecked") Class<? extends Annotation> p = (Class<? extends Annotation>) t0.getActualTypeArguments()[0]; validators.put(p, class_); } }