List of usage examples for org.springframework.core.type ClassMetadata getClassName
String getClassName();
From source file:lodsve.core.condition.SpringBootCondition.java
private static String getClassOrMethodName(AnnotatedTypeMetadata metadata) { if (metadata instanceof ClassMetadata) { ClassMetadata classMetadata = (ClassMetadata) metadata; return classMetadata.getClassName(); }/*w ww . jav a 2 s. c om*/ MethodMetadata methodMetadata = (MethodMetadata) metadata; return methodMetadata.getDeclaringClassName() + "#" + methodMetadata.getMethodName(); }
From source file:org.jfaster.mango.plugin.spring.MangoDaoScanner.java
private List<Class<?>> findMangoDaoClasses() { try {/*from ww w .j a v a2 s . c o m*/ List<Class<?>> daos = new ArrayList<Class<?>>(); ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver); for (String locationPattern : locationPatterns) { Resource[] rs = resourcePatternResolver.getResources(locationPattern); for (Resource r : rs) { MetadataReader reader = metadataReaderFactory.getMetadataReader(r); AnnotationMetadata annotationMD = reader.getAnnotationMetadata(); if (annotationMD.hasAnnotation(DB.class.getName())) { ClassMetadata clazzMD = reader.getClassMetadata(); daos.add(Class.forName(clazzMD.getClassName())); } } } return daos; } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java
@Override protected List<Class<?>> getClasses(Resource[] resources) { List<Class<?>> result = super.getClasses(resources); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader; try { metadataReader = metadataReaderFactory.getMetadataReader(resource); } catch (IOException e) { throw new RuntimeException("Unable to read metadata resource", e); }//from ww w. j a v a 2 s . c om AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); boolean isAnnotated = isEntityClass(annotationMetadata) || isEmbeddableClass(annotationMetadata); if (isAnnotated) { ClassMetadata classMetadata = metadataReader.getClassMetadata(); Class c = ReflectionHelper.getClass(classMetadata.getClassName()); result.add(c); } } } return result; }
From source file:com.haulmont.cuba.client.testsupport.CubaClientTestCase.java
protected List<String> getClasses(Resource[] resources) { List<String> classNames = new ArrayList<>(); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader; try { metadataReader = metadataReaderFactory.getMetadataReader(resource); } catch (IOException e) { throw new RuntimeException("Unable to read metadata resource", e); }/*w w w .j a v a2s . c om*/ AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName()) || annotationMetadata.isAnnotated(MappedSuperclass.class.getName()) || annotationMetadata.isAnnotated(Entity.class.getName())) { ClassMetadata classMetadata = metadataReader.getClassMetadata(); classNames.add(classMetadata.getClassName()); } } } return classNames; }
From source file:com.sxj.jsonrpc.client.spring.AutoJsonRpcClientProxyCreator.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext); DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory; String resolvedPath = resolvePackageToScan(); LOG.debug(format("Scanning '%s' for JSON-RPC service interfaces.", resolvedPath)); try {/*from ww w . j av a 2 s .com*/ for (Resource resource : applicationContext.getResources(resolvedPath)) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); ClassMetadata classMetadata = metadataReader.getClassMetadata(); AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); String jsonRpcPathAnnotation = JsonRpcService.class.getName(); if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) { String className = classMetadata.getClassName(); String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation) .get("value"); boolean useNamedParams = (Boolean) annotationMetadata .getAnnotationAttributes(jsonRpcPathAnnotation).get("useNamedParams"); LOG.debug(format("Found JSON-RPC service to proxy [%s] on path '%s'.", className, path)); registerJsonProxyBean(dlbf, className, path, useNamedParams); } } } } catch (IOException e) { throw new RuntimeException(format("Cannot scan package '%s' for classes.", resolvedPath), e); } }
From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcClientProxyCreator.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(applicationContext); DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory; String resolvedPath = resolvePackageToScan(); LOG.debug(format("Scanning '%s' for JSON-RPC service interfaces.", resolvedPath)); try {// www .j a v a2s . co m for (Resource resource : applicationContext.getResources(resolvedPath)) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); ClassMetadata classMetadata = metadataReader.getClassMetadata(); AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); String jsonRpcPathAnnotation = JsonRpcService.class.getName(); if (annotationMetadata.isAnnotated(jsonRpcPathAnnotation)) { String className = classMetadata.getClassName(); String path = (String) annotationMetadata.getAnnotationAttributes(jsonRpcPathAnnotation) .get("value"); boolean useNamedParams = (Boolean) annotationMetadata .getAnnotationAttributes(jsonRpcPathAnnotation).get("useNamedParams"); LOG.debug(format("Found JSON-RPC service to proxy [%s] on path '%s'.", className, path)); registerJsonProxyBean(dlbf, className, path, useNamedParams); } } } } catch (IOException e) { throw new RuntimeException(format("Cannot scan package '%s' for classes.", resolvedPath), e); } }
From source file:org.syncope.core.rest.controller.ConfigurationController.java
@PreAuthorize("hasRole('CONFIGURATION_LIST')") @RequestMapping(method = RequestMethod.GET, value = "/validators") public ModelAndView getValidators() { CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory(); Set<String> validators = new HashSet<String>(); try {//from ww w.ja v a2s . com for (Resource resource : resResolver .getResources("classpath:org/syncope/core/persistence/validation/" + "attrvalue/*.class")) { ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource) .getClassMetadata(); if (ArrayUtils.contains(metadata.getInterfaceNames(), Validator.class.getName()) || AbstractValidator.class.getName().equals(metadata.getSuperClassName())) { try { Class jobClass = Class.forName(metadata.getClassName()); if (!Modifier.isAbstract(jobClass.getModifiers())) { validators.add(jobClass.getName()); } } catch (ClassNotFoundException e) { LOG.error("Could not load class {}", metadata.getClassName(), e); } } } } catch (IOException e) { LOG.error("While searching for class implementing {}", Validator.class.getName(), e); } return new ModelAndView().addObject(validators); }
From source file:com.haulmont.cuba.core.config.AppPropertiesLocator.java
protected Set<Class> findConfigInterfaces() { if (interfacesCache == null) { synchronized (this) { if (interfacesCache == null) { log.trace("Locating config interfaces"); Set<String> cache = new HashSet<>(); for (String rootPackage : metadata.getRootPackages()) { String packagePrefix = rootPackage.replace(".", "/") + "/**/*.class"; String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + packagePrefix; Resource[] resources; try { resources = resourcePatternResolver.getResources(packageSearchPath); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader = metadataReaderFactory .getMetadataReader(resource); ClassMetadata classMetadata = metadataReader.getClassMetadata(); if (classMetadata.isInterface()) { for (String intf : classMetadata.getInterfaceNames()) { if (Config.class.getName().equals(intf)) { cache.add(classMetadata.getClassName()); break; } }//w w w. jav a 2 s . com } } } } catch (IOException e) { throw new RuntimeException("Error searching for Config interfaces", e); } } log.trace("Found config interfaces: {}", cache); interfacesCache = cache; } } } return interfacesCache.stream().map(ReflectionHelper::getClass).collect(Collectors.toSet()); }
From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java
protected List<Class<?>> getClasses(Resource[] resources) { List<Class<?>> annotated = new ArrayList<>(); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader; try { metadataReader = metadataReaderFactory.getMetadataReader(resource); } catch (IOException e) { throw new RuntimeException("Unable to read metadata resource", e); }/*from ww w.ja v a2s. c o m*/ AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName())) { ClassMetadata classMetadata = metadataReader.getClassMetadata(); Class c = ReflectionHelper.getClass(classMetadata.getClassName()); annotated.add(c); } } } return annotated; }