List of usage examples for org.springframework.context.annotation ClassPathScanningCandidateComponentProvider addIncludeFilter
public void addIncludeFilter(TypeFilter includeFilter)
From source file:com.ocs.dynamo.ui.auth.DefaultPermissionCheckerImpl.java
@PostConstruct public void postConstruct() { // scan the class path for all classes annotated with @SpringView ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( true);/*w ww .ja va 2 s .c o m*/ provider.addIncludeFilter(new AnnotationTypeFilter(SpringView.class)); Set<BeanDefinition> views = provider.findCandidateComponents(basePackage); for (BeanDefinition d : views) { try { Class<?> clazz = Class.forName(d.getBeanClassName()); SpringView view = clazz.getAnnotation(SpringView.class); // store the permissions both under the bean name and the view // name - unfortunately these // don't always have to match but there is no way to tell this // to the authentication framework! Authorized auth = clazz.getAnnotation(Authorized.class); if (auth != null && auth.roles().length > 0) { int p = d.getBeanClassName().lastIndexOf("."); permissions.put(d.getBeanClassName().substring(p + 1), Arrays.asList(auth.roles())); editOnly.put(d.getBeanClassName().substring(p + 1), auth.editOnly()); permissions.put(view.name(), Arrays.asList(auth.roles())); editOnly.put(view.name(), auth.editOnly()); } } catch (ClassNotFoundException e) { LOG.error(e.getMessage(), e); } } }
From source file:org.zalando.stups.spring.cloud.netflix.feign.OAuth2FeignClientsRegsitrar.java
@Override public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, final BeanDefinitionRegistry registry) { Set<String> basePackages = getBasePackages(importingClassMetadata); ClassPathScanningCandidateComponentProvider scanner = getScanner(); scanner.addIncludeFilter(new AnnotationTypeFilter(FeignClient.class)); scanner.setResourceLoader(this.resourceLoader); for (String basePackage : basePackages) { Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage); for (BeanDefinition candidateComponent : candidateComponents) { if (candidateComponent instanceof AnnotatedBeanDefinition) { // verify annotated class is an interface AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent; AnnotationMetadata annotationMetadata = beanDefinition.getMetadata(); Assert.isTrue(annotationMetadata.isInterface(), "@FeignClient can only be specified on an interface"); BeanDefinitionHolder holder = createBeanDefinition(annotationMetadata); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); }//from w ww. j a v a 2s . c o m } } }
From source file:com.googlecode.objectify.spring.ObjectifyFactoryBean.java
protected List<Class<?>> doScan() { List<Class<?>> classes = new ArrayList<Class<?>>(); String[] basePackages = StringUtils.tokenizeToStringArray(this.basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); for (String basePackage : basePackages) { if (this.logger.isInfoEnabled()) { this.logger.info("Scanning package [" + basePackage + "]"); }//from w ww . j a va2s . c om ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Entity.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class)); Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { Class<?> clazz = ClassUtils.resolveClassName(candidate.getBeanClassName(), ClassUtils.getDefaultClassLoader()); classes.add(clazz); } } return classes; }
From source file:com.consol.citrus.admin.executor.ClasspathTestExecutor.java
/** * Finds all test cases in classpath starting in given base package. Searches for * **.class files extending AbstractTestNGCitrusTest superclass. * //from w w w . ja va 2 s .co m * @param basePackage * @return */ private List<String> findTestsInClasspath(String basePackage) { List<String> testCaseNames = new ArrayList<String>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false, new StandardServletEnvironment()); scanner.addIncludeFilter(new CitrusTestTypeFilter()); Set<BeanDefinition> findings = scanner.findCandidateComponents(basePackage); for (BeanDefinition bean : findings) { testCaseNames.add(bean.getBeanClassName()); } return testCaseNames; }
From source file:it.geosolutions.geobatch.annotations.ActionServicePostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean.getClass().equals(AliasRegistry.class)) { AliasRegistry aliasRegistry = (AliasRegistry) bean; ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( true);/*from w ww. ja v a2s . c om*/ scanner.addIncludeFilter(new AnnotationTypeFilter(Action.class)); for (BeanDefinition bd : scanner.findCandidateComponents("it.geosolutions")) { try { Class actionClass = Class.forName(bd.getBeanClassName()); Action annotation = (Action) actionClass.getAnnotation(Action.class); if (annotation != null) { Class<? extends ActionConfiguration> configurationClass = annotation.configurationClass(); String alias = configurationClass.getSimpleName(); if (annotation.configurationAlias() != null && !annotation.configurationAlias().isEmpty()) { alias = annotation.configurationAlias(); } aliasRegistry.putAlias(alias, configurationClass); if (annotation.aliases() != null) { for (Class a : annotation.aliases()) { if (NullType.class == a) continue; aliasRegistry.putAlias(a.getSimpleName(), a); } } if (annotation.implicitCollections() != null) { for (String ic : annotation.implicitCollections()) { if (ic == null || ic.isEmpty()) continue; aliasRegistry.putImplicitCollection(ic, configurationClass); } } GenericActionService asr = new GenericActionService( annotation.configurationClass().getSimpleName(), actionClass); asr.setApplicationContext(applicationContext); actionList.add(asr); } } catch (Exception e) { e.printStackTrace(); } } } return bean; }
From source file:com._4dconcept.springframework.data.marklogic.config.AbstractMarklogicConfiguration.java
private Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException { String basePackage = getMappingBasePackage(); Set<Class<?>> initialEntitySet = new HashSet<>(); if (StringUtils.hasText(basePackage)) { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false);/*www . j a v a 2s . c o m*/ componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) { String beanClassName = candidate.getBeanClassName(); if (beanClassName != null) { initialEntitySet.add(ClassUtils.forName(beanClassName, AbstractMarklogicConfiguration.class.getClassLoader())); } } } return initialEntitySet; }
From source file:org.datamongo.jira.datamongo1064.mapper.EmbeddedObjectTypeInformationMapper.java
/** * Scans the mapping base package for classes annotated with {@link Embeddable}. * /*from w ww. j a v a2 s.c om*/ * @see #getMappingBasePackage() * @return * @throws ClassNotFoundException */ protected Map<Class<?>, String> getInitialEntitySet() throws ClassNotFoundException { String[] basePackage = this.basePackage; Map<Class<?>, String> initialEntitySet = new HashMap<Class<?>, String>(); if (basePackage != null) { for (String packageBase : basePackage) { if (StringUtils.hasText(packageBase)) { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Embeddable.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(packageBase)) { Class<?> forName = ClassUtils.forName(candidate.getBeanClassName(), AbstractMongoConfiguration.class.getClassLoader()); String alias = forName.getAnnotation(TypeAlias.class) != null ? forName.getAnnotation(TypeAlias.class).value() : forName.getName(); initialEntitySet.put(forName, alias); } } } } return initialEntitySet; }
From source file:com.newtranx.util.cassandra.spring.MapperScannerConfigurer.java
@SuppressWarnings("unused") // compiler bug? @Override//w w w . ja v a2 s .com public void postProcessBeanFactory(ConfigurableListableBeanFactory context) throws BeansException { synchronized (lock) { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AnnotationTypeFilter(Table.class)); for (BeanDefinition bd : scanner.findCandidateComponents(basePackage)) { Class<?> entityCls; try { entityCls = Class.forName(bd.getBeanClassName()); } catch (ClassNotFoundException e) { throw new AssertionError(e); } log.info("Creating proxy mapper for entity: " + entityCls.getName()); CassandraMapper annotation = entityCls.getAnnotation(CassandraMapper.class); Mapper<?> bean = createProxy(Mapper.class, new MyInterceptor(entityCls, annotation.singleton())); String beanName; if (annotation == null) beanName = StringUtils.uncapitalize(entityCls.getSimpleName()) + "Mapper"; else beanName = annotation.value(); context.registerSingleton(beanName, bean); log.info("Bean registed, name=" + beanName + ", bean=" + bean.toString()); } } }
From source file:com.deq.spring.ObjectifyFactoryBean.java
protected List<Class<?>> doScan() { final List<Class<?>> classes = new ArrayList<Class<?>>(); final String[] basePackages = StringUtils.tokenizeToStringArray(basePackage, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); for (final String basePackage : basePackages) { if (logger.isInfoEnabled()) { logger.info("Scanning package [" + basePackage + "]"); }/*w w w .j a v a2 s . c o m*/ final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Entity.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Subclass.class)); scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class)); final Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage); for (final BeanDefinition candidate : candidates) { final Class<?> clazz = ClassUtils.resolveClassName(candidate.getBeanClassName(), ClassUtils.getDefaultClassLoader()); classes.add(clazz); } } return classes; }
From source file:io.acme.solution.application.conf.CommandBusConfigurer.java
@PostConstruct private void setup() { Queue currentQueue = null;//from ww w . jav a 2 s. c o m String currentCommandType = null; SimpleMessageListenerContainer currentContainer = null; MessageListenerAdapter currentAdapter = null; final RabbitAdmin rabbitAdmin = this.context.getBean("commandBusRabbitAdmin", RabbitAdmin.class); final ConnectionFactory connectionFactory = this.context.getBean("commandBusConnectionFactory", ConnectionFactory.class); final TopicExchange exchange = this.context.getBean("commandExchange", TopicExchange.class); final MessageConverter converter = this.context.getBean("commandBusMessageConverter", MessageConverter.class); final Map<String, CommandHandler> commandHandlersRegistry = CommandHandlerUtils .buildCommandHandlersRegistry(this.handlerBasePackage, this.context); final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AssignableTypeFilter(Command.class)); for (BeanDefinition bean : scanner.findCandidateComponents(this.commandBasePackage)) { currentCommandType = bean.getBeanClassName().substring(bean.getBeanClassName().lastIndexOf('.') + 1); rabbitAdmin.declareQueue(currentQueue = new Queue(this.queuePrefix + currentCommandType)); rabbitAdmin.declareBinding(BindingBuilder.bind(currentQueue).to(exchange).with(currentCommandType)); if (commandHandlersRegistry.containsKey(bean.getBeanClassName())) { currentAdapter = new MessageListenerAdapter(commandHandlersRegistry.get(bean.getBeanClassName()), converter); currentContainer = new SimpleMessageListenerContainer(connectionFactory); currentContainer.setMessageListener(currentAdapter); currentContainer.setQueues(currentQueue); currentContainer.start(); } } }