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.openengsb.connector.serviceacl.internal.ServiceAclServiceImpl.java
@Override public Access checkAccess(String user, Object object) { if (!(object instanceof MethodInvocation)) { return Access.ABSTAINED; }//from w w w .j ava 2s . c om MethodInvocation methodInvocation = (MethodInvocation) object; Anonymous public1 = AnnotationUtils.findAnnotation(methodInvocation.getMethod(), Anonymous.class); if (public1 != null) { return Access.GRANTED; } Collection<ServicePermission> permissions; try { permissions = userManager.getAllPermissionsForUser(user, ServicePermission.class); } catch (UserNotFoundException e) { LOGGER.warn("user not found in acl-connector", e); return Access.ABSTAINED; } if (hasServiceTypeAccess(permissions, methodInvocation)) { return Access.GRANTED; } return Access.ABSTAINED; }
From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java
private void registerDependendEntities(ComponentDataBinder binder, Class clazz, String path) { Object ann = AnnotationUtils.findAnnotation(clazz, Entity.class); if (ann == null) return;//from w w w . j ava 2s . c o m for (Field field : clazz.getDeclaredFields()) { String propPath = path + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + field.getName(); if (field.getType().equals(String.class)) { binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true)); if (logger.isInfoEnabled()) { logger.info("Registered nullable StringEditor for " + propPath); } } else { // here we need to prevent infinte recursions for example if a user contains a user contains a user ... Integer depth = StringUtils.countOccurrencesOf(path, PropertyAccessor.NESTED_PROPERTY_SEPARATOR); if (depth <= maxDepth) { registerDependendEntities(binder, field.getType(), propPath); } } } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.ComponentUtils.java
/** * /*from w w w . j a v a 2s. co m*/ * @param * @return * * @param token * @return */ public static Object getModel(ComponentToken token) { if (token == null) { return null; } Object model = null; Object unwrapped = ModelUtils.unwrapIfNecessary(token.getComponent()); if (null != AnnotationUtils.findAnnotation(unwrapped.getClass(), Entity.class)) { model = unwrapped; } if (model == null) { model = ModelUtils.unwrapIfNecessary(getModelFromList(token)); } return model; }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.configuration.SegmentConfiguration.java
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { Class<?> ec = getEntityClass(); if (ec != null) { Entity ann = AnnotationUtils.findAnnotation(ec, Entity.class); Assert.notNull(ann, "Segment Configuration for Segment '" + getBeanName() + "' specifies Class '" + ec + "' which is not a vaild Entity class"); if (getFilterClass() == null) { if (FilterDefinition.class.isAssignableFrom(ec)) { setFilterClass((Class<FilterDefinition>) ec); }/* w ww . jav a 2 s.co m*/ } } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.configuration.TargetConfiguration.java
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { Assert.notNull(to);//ww w.j a va 2 s.c o m Assert.notNull(to.getBeanName()); if (entityClass == null) { entityClass = to.getEntityClass(); } if (filterClass == null) { filterClass = to.getFilterClass(); } Class<?> ec = entityClass; Class<?> fc = filterClass; if (ec != null) { Entity ann = AnnotationUtils.findAnnotation(ec, Entity.class); Assert.notNull(ann, "Chain Configuration for '" + getChainNameDisplay() + "' specifies Class '" + getEntityClass() + "' which is not a vaild Entity class"); if (fc == null) { if (FilterDefinition.class.isAssignableFrom(ec)) { setFilterClass((Class<FilterDefinition>) ec); } } logger.info(getClass().getSimpleName() + " " + getChainNameDisplay() + " for entity class '" + entityClass + "'"); } if (fc != null) { if (filterInitMethod != null) { Assert.notNull(ReflectionUtils.findMethod(getFilterClass(), filterInitMethod), "Chain configuration for '" + getChainNameDisplay() + "' specifies an invalid filter initialization ('" + filterInitMethod + "') for filter class '" + filterClass + "'"); } logger.info(getClass().getSimpleName() + " " + getChainNameDisplay() + " for filter class '" + filterClass + "'"); } if (commandFactory == null) { Assert.notNull(pageHolderFactory, getClass().getSimpleName() + " " + getChainNameDisplay() + " has neither commandFactory nor a pageHolderFactory defined. You need to declare one of both"); commandFactory = createCommandFactory(); if (commandFactory instanceof AbstractCommandFactory) { AbstractCommandFactory acf = (AbstractCommandFactory) commandFactory; acf.setPageHolderFactory(pageHolderFactory); acf.setApplicationContext(context); } } setDisabledActions(new ActionConfiguration(Arrays.asList(this.disabled))); }
From source file:org.springbyexample.mvc.method.annotation.ServiceHandlerMapping.java
/** * Register handler./*from w ww . j a v a 2 s. c om*/ */ private void registerHandler(Class<?> marshallingServiceClass, Method method) { ApplicationContext ctx = getApplicationContext(); RestResource restResource = AnnotationUtils.findAnnotation(marshallingServiceClass, RestResource.class); Class<?> serviceClass = restResource.service(); RestRequestResource restRequestResource = AnnotationUtils.findAnnotation(method, RestRequestResource.class); boolean export = (restRequestResource != null ? restRequestResource.export() : true); boolean relative = (restRequestResource != null ? restRequestResource.relative() : true); if (export) { Class<?> handlerServiceClass = serviceClass; String methodName = method.getName(); Class<?>[] paramTypes = method.getParameterTypes(); if (restRequestResource != null) { // explicit service specified if (restRequestResource.service() != ServiceValueConstants.DEFAULT_SERVICE_CLASS) { handlerServiceClass = restRequestResource.service(); } // explicit method name specified if (StringUtils.hasText(restRequestResource.methodName())) { methodName = restRequestResource.methodName(); } } Object handler = ctx.getBean(handlerServiceClass); Method serviceMethod = ClassUtils.getMethod(handlerServiceClass, methodName, paramTypes); RequestMappingInfo mapping = getMappingForMethod(method, marshallingServiceClass); if (relative) { List<String> patterns = new ArrayList<String>(); for (String pattern : mapping.getPatternsCondition().getPatterns()) { // add REST resource path prefix to URI, // if relative path is just '/' add an empty string patterns.add(restResource.path() + (!"/".equals(pattern) ? pattern : "")); } // create a new mapping based on the patterns (patterns are unmodifiable in existing RequestMappingInfo) mapping = new RequestMappingInfo( new PatternsRequestCondition(patterns.toArray(ArrayUtils.EMPTY_STRING_ARRAY), getUrlPathHelper(), getPathMatcher(), useSuffixPatternMatch(), useTrailingSlashMatch()), mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(), mapping.getCustomCondition()); } // need to set param types to use in createHandlerMethod before calling registerHandlerMethod restBridgedMethod = BridgeMethodResolver.findBridgedMethod(method); // mapping is key, HandlerMethod is value registerHandlerMethod(handler, serviceMethod, mapping); processConverters(restRequestResource, mapping, serviceMethod); } }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { Class<?> targetClass = AopUtils.getTargetClass(bean); Collection<RabbitListener> classLevelListeners = findListenerAnnotations(targetClass); final boolean hasClassLevelListeners = classLevelListeners.size() > 0; final List<Method> multiMethods = new ArrayList<Method>(); ReflectionUtils.doWithMethods(targetClass, method -> { for (RabbitListener rabbitListener : findListenerAnnotations(method)) { processAmqpListener(rabbitListener, method, bean, beanName); }/*from w w w . jav a 2s.com*/ if (hasClassLevelListeners) { RabbitHandler rabbitHandler = AnnotationUtils.findAnnotation(method, RabbitHandler.class); if (rabbitHandler != null) { multiMethods.add(method); } } }, ReflectionUtils.USER_DECLARED_METHODS); if (hasClassLevelListeners) { processMultiMethodListeners(classLevelListeners, multiMethods, bean, beanName); } return bean; }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
private Collection<RabbitListener> findListenerAnnotations(Class<?> clazz) { Set<RabbitListener> listeners = new HashSet<RabbitListener>(); RabbitListener ann = AnnotationUtils.findAnnotation(clazz, RabbitListener.class); if (ann != null) { listeners.add(ann);//from w ww. j ava 2s.c om } RabbitListeners anns = AnnotationUtils.findAnnotation(clazz, RabbitListeners.class); if (anns != null) { listeners.addAll(Arrays.asList(anns.value())); } return listeners; }
From source file:org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor.java
private Collection<RabbitListener> findListenerAnnotations(Method method) { Set<RabbitListener> listeners = new HashSet<RabbitListener>(); RabbitListener ann = AnnotationUtils.findAnnotation(method, RabbitListener.class); if (ann != null) { listeners.add(ann);/*from w w w.jav a 2s . c o m*/ } RabbitListeners anns = AnnotationUtils.findAnnotation(method, RabbitListeners.class); if (anns != null) { listeners.addAll(Arrays.asList(anns.value())); } return listeners; }
From source file:org.springframework.amqp.rabbit.test.RepeatProcessor.java
public Statement apply(final Statement base, FrameworkMethod method, final Object target) { Repeat repeat = AnnotationUtils.findAnnotation(method.getMethod(), Repeat.class); if (repeat == null) { return base; }//w w w .j a v a2 s . c o m final int repeats = repeat.value(); if (repeats <= 1) { return base; } initializeIfNecessary(target); if (concurrency <= 0) { return new Statement() { @Override public void evaluate() throws Throwable { try { for (int i = 0; i < repeats; i++) { try { base.evaluate(); } catch (Throwable t) { throw new IllegalStateException( "Failed on iteration: " + i + " of " + repeats + " (started at 0)", t); } } } finally { finalizeIfNecessary(target); } } }; } return new Statement() { @Override public void evaluate() throws Throwable { List<Future<Boolean>> results = new ArrayList<Future<Boolean>>(); ExecutorService executor = Executors.newFixedThreadPool(concurrency); CompletionService<Boolean> completionService = new ExecutorCompletionService<Boolean>(executor); try { for (int i = 0; i < repeats; i++) { final int count = i; results.add(completionService.submit(new Callable<Boolean>() { public Boolean call() { try { base.evaluate(); } catch (Throwable t) { throw new IllegalStateException("Failed on iteration: " + count, t); } return true; } })); } for (int i = 0; i < repeats; i++) { Future<Boolean> future = completionService.take(); assertTrue("Null result from completer", future.get()); } } finally { executor.shutdownNow(); finalizeIfNecessary(target); } } }; }