List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation
@Nullable public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType)
From source file:org.jspringbot.spring.KeywordUtils.java
/** * Retrieves the KeywordInfo of the given keyword. * * @param keyword keyword name// ww w . j a v a2 s. c o m * @param context Spring application context * @param beanMap keyword name to bean name mapping * @return KeywordInfo object or null if unavailable */ public static KeywordInfo getKeywordInfo(String keyword, ApplicationContext context, Map<String, String> beanMap) { Object bean = context.getBean(beanMap.get(keyword)); return AnnotationUtils.findAnnotation(bean.getClass(), KeywordInfo.class); }
From source file:com.gopivotal.cloudfoundry.test.support.runner.BuildpackClassRunner.java
private Set<String> getExcludedApplicationNames(Method method) { Set<String> names = new HashSet<>(); names.addAll(nullSafeValue(AnnotationUtils.findAnnotation(method, ExcludedApplications.class))); names.addAll(nullSafeValue(/*from w ww . j a v a2 s .c o m*/ AnnotationUtils.findAnnotation(method.getDeclaringClass(), ExcludedApplications.class))); return names; }
From source file:org.impalaframework.extension.mvc.annotation.handler.AnnotationHandlerMethodResolver.java
private Method getHandlerMethod(String lookupPath, String methodLookupPath, HttpServletRequest request) { for (Method handlerMethod : getHandlerMethods()) { RequestMapping mapping = AnnotationUtils.findAnnotation(handlerMethod, RequestMapping.class); String[] values = mapping.value(); if (values[0].equals(lookupPath)) { RequestMethod[] method = mapping.method(); if (method != null && method.length > 0) { for (RequestMethod requestMethod : method) { if (request.getMethod().equals(requestMethod.toString())) { pathMethodCache.put(methodLookupPath, handlerMethod); return handlerMethod; }/*from w ww . jav a 2 s . co m*/ } } else { pathMethodCache.put(methodLookupPath, handlerMethod); return handlerMethod; } } } return null; }
From source file:py.una.pol.karaku.test.cucumber.DatabasePopulatorCucumberExecutionListener.java
@Override public void beforeTestClass(TestContext testContext) throws Exception { super.beforeTestClass(testContext); final Sequences sequences = AnnotationUtils.findAnnotation(testContext.getTestClass(), Sequences.class); if ((sequences != null) && (sequences.value() != null) && (sequences.value().length > 0)) { DatabaseUtils.executeDDL(SEQUENCE_CONSTRUCTOR, getApplicationContext(testContext), sequences.value()); }//from w ww . j a v a 2s .co m SQLFiles sqlFiles = AnnotationUtils.findAnnotation(testContext.getTestClass(), SQLFiles.class); executeSQLFiles(testContext, sqlFiles); }
From source file:org.fenixedu.bennu.spring.portal.PortalHandlerMapping.java
private void registerFunctionalities(Collection<Object> values) { for (Object bean : values) { Class<?> type = bean.getClass(); SpringFunctionality model = AnnotationUtils.findAnnotation(type, SpringFunctionality.class); RequestMapping mapping = AnnotationUtils.findAnnotation(type, RequestMapping.class); if (mapping == null) { throw new Error("Functionality type " + type.getName() + " does not declare a @RequestMapping!"); }//from www .j a v a2s .co m Application app = applicationClasses.get(model.app()); String path = extractPath(mapping, type); LocalizedString title = getLocalized(model.title()); Functionality functionality = new Functionality(SpringPortalBackend.BACKEND_KEY, "/" + path, path.replace('/', '-'), model.accessGroup().equals(DELEGATE) ? app.getAccessGroup() : model.accessGroup(), title, model.description().equals(DELEGATE) ? title : getLocalized(model.description())); app.addFunctionality(functionality); functionalities.put(type, functionality); } }
From source file:edu.umn.msi.tropix.common.jobqueue.jobprocessors.BaseExecutableJobProcessorFactoryImpl.java
/** * This method is responsible for returning fresh new jobs ready to be preprocessed. *//*from w w w. j a v a 2 s . co m*/ public final T create(final JobProcessorConfiguration config) { final T instance = createAndInitialize(); final StagingDirectory stagingDirectory = getAndSetupStagingDirectory(config); if (requireGlobusCredential) { final Credential credential = config.getCredential(); Preconditions.checkState(credential != null, "Valid globus credential required, but no credential found."); final GlobusCredential globusCredential = credential.getGlobusCredential(); Preconditions.checkState(globusCredential != null, "Valid globus credential required, but credential has no associated globus credential."); Preconditions.checkState(globusCredential.getTimeLeft() > 0, "Valid globus credential required, but credential is timed-out."); } // Create jobDescription final JobDescriptionType jobDescription = new JobDescriptionType(); final JobType jobType = AnnotationUtils.findAnnotation(getClass(), JobType.class); JobDescriptionUtils.setJobType(jobDescription, jobType.value()); JobDescriptionUtils.setStagingDirectory(jobDescription, stagingDirectory.getAbsolutePath()); JobDescriptionUtils.setExecutionType(jobDescription, executionType); JobDescriptionUtils.setProxy(jobDescription, config.getCredential()); // Repeatedly having issues where programs are blocking presumably because they cannot write to standard out, // so I am adding defaults for standard out and standard error. Individual JobProcessor can override these. jobDescription.setStdout(Directories.buildAbsolutePath(stagingDirectory, DEFAULT_STANDARD_OUT_FILE_NAME)); jobDescription.setStderr(Directories.buildAbsolutePath(stagingDirectory, DEFAULT_STANDARD_ERROR_FILE_NAME)); jobDescription.setDirectory(workingDirectory); jobDescription.setExecutable(applicationPath); instance.setJobDescription(jobDescription); instance.setStagingDirectory(stagingDirectory); return instance; }
From source file:com.github.philippn.springremotingautoconfigure.client.annotation.HttpInvokerProxyFactoryBeanRegistrar.java
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { Set<String> basePackages = new HashSet<>(); for (String beanName : registry.getBeanDefinitionNames()) { BeanDefinition definition = registry.getBeanDefinition(beanName); if (definition.getBeanClassName() != null) { try { Class<?> resolvedClass = ClassUtils.forName(definition.getBeanClassName(), null); EnableHttpInvokerAutoProxy autoProxy = AnnotationUtils.findAnnotation(resolvedClass, EnableHttpInvokerAutoProxy.class); if (autoProxy != null) { if (autoProxy.basePackages().length > 0) { Collections.addAll(basePackages, autoProxy.basePackages()); } else { basePackages.add(resolvedClass.getPackage().getName()); }/*from w ww . j a v a 2s .c o m*/ } } catch (ClassNotFoundException e) { throw new IllegalStateException("Unable to inspect class " + definition.getBeanClassName() + " for @EnableHttpInvokerAutoProxy annotations"); } } } ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false) { /* (non-Javadoc) * @see org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider#isCandidateComponent(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) */ @Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent(); } }; scanner.addIncludeFilter(new AnnotationTypeFilter(RemoteExport.class)); for (String basePackage : basePackages) { for (BeanDefinition definition : scanner.findCandidateComponents(basePackage)) { if (definition.getBeanClassName() != null) { try { Class<?> resolvedClass = ClassUtils.forName(definition.getBeanClassName(), null); setupProxy(resolvedClass, registry); } catch (ClassNotFoundException e) { throw new IllegalStateException("Unable to inspect class " + definition.getBeanClassName() + " for @RemoteExport annotations"); } } } } }
From source file:com.github.wnameless.spring.papertrail.PaperTrailService.java
private EnablePaperTrail getEnablePaperTrailAnno() { String clz = appCtx.getBeanNamesForAnnotation(EnablePaperTrail.class)[0]; Annotation anno = AnnotationUtils.findAnnotation(appCtx.getBean(clz).getClass(), EnablePaperTrail.class); return (EnablePaperTrail) anno; }
From source file:org.shredzone.cilla.plugin.social.manager.SocialHandlerManager.java
/** * Process a bookmark handler./*from www .j a va2 s .c o m*/ * * @param bean * Spring bean of the {@link SocialHandler} * @param method * Method annotated with {@link SocialBookmark} * @param bookmarkAnno * the {@link SocialBookmark} annotation itself * @param blacklistSet * Set of blacklisted social handlers */ private void processBookmarkHandler(Object bean, Method method, SocialBookmark bookmarkAnno, Set<String> blacklistSet) { SocialHandlerInvoker invoker = applicationContext.getBean(SocialHandlerInvoker.class); invoker.setBean(bean); invoker.setMethod(method); Priority priorityAnno = AnnotationUtils.findAnnotation(method, Priority.class); if (priorityAnno != null) { invoker.setPriority(priorityAnno.value()); } String name = bookmarkAnno.name(); if (!StringUtils.hasText(name)) { name = method.getName(); if (name.endsWith("SocialBookmark")) { name = name.substring(0, name.length() - "SocialBookmark".length()); } } invoker.setName(name); if (StringUtils.hasText(bookmarkAnno.icon())) { invoker.setIcon(bookmarkAnno.icon()); } if (!blacklistSet.contains(invoker.getIdentifier())) { if (invokers.contains(invoker)) { throw new IllegalStateException("Invoker '" + invoker.getIdentifier() + "' defined twice"); } invokers.add(invoker); log.info("Registered Social Bookmark {} (priority {})", invoker.getIdentifier(), invoker.getPriority()); } else { log.info("Ignored blacklisted Social Bookmark {}", invoker.getIdentifier()); } }
From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandler.java
@Override protected MappingInformation getMappingForMethod(Method method, Class<?> handlerType) { MessageMapping messageMappingAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class); if (messageMappingAnnotation == null) { return null; }/*from w w w . ja v a 2s . co m*/ if (messageMappingAnnotation.value().length < 1) { throw new IllegalStateException("@MessageMapping annotation must have at least one destination"); } Set<String> logicalResourceIds = new HashSet<>(messageMappingAnnotation.value().length); logicalResourceIds.addAll(Arrays.asList(messageMappingAnnotation.value())); return new MappingInformation(logicalResourceIds); }