List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.khs.sherpa.processor.RestfulRequestProcessor.java
public String getEndpoint(HttpServletRequest request) { Map<String, Object> map = applicationContext.getEndpointTypes(); Collection<Method> methods = new HashSet<Method>(); for (Entry<String, Object> entry : map.entrySet()) { Collection<Method> m = Reflections.getAllMethods(entry.getValue().getClass(), Predicates.and(ReflectionUtils.withAnnotation(Action.class), SherpaPredicates.withActionMappingPattern(UrlUtil.getPath(request)))); methods.addAll(m);/*from ww w . java 2 s. c om*/ } method = MethodUtil.validateHttpMethods(methods.toArray(new Method[] {}), request.getMethod()); if (method != null) { Class<?> type = method.getDeclaringClass(); if (type.isAnnotationPresent(Endpoint.class)) { if (StringUtils.isNotEmpty(type.getAnnotation(Endpoint.class).value())) { return type.getAnnotation(Endpoint.class).value(); } } return type.getSimpleName(); } throw new SherpaEndpointNotFoundException("no endpoint for url [" + UrlUtil.getPath(request) + "]"); }
From source file:org.springdata.ehcache.mapping.BasicEhcachePersistentEntity.java
@SuppressWarnings("unchecked") public BasicEhcachePersistentEntity(TypeInformation<T> typeInformation) { super(typeInformation); this.parser = new SpelExpressionParser(); this.context = new StandardEvaluationContext(); Class<T> rawType = typeInformation.getType(); if (rawType.isAnnotationPresent(Entity.class)) { Entity annotation = rawType.getAnnotation(Entity.class); this.cacheName = StringUtils.hasText(annotation.cacheName()) ? annotation.cacheName() : null; } else {//from w w w. j a va 2 s . co m this.cacheName = null; } if (this.cacheName == null) { throw new BeanInitializationException( "entity class " + rawType + " does not specify cache name by Cache annotation"); } if (DataSerializable.class.isAssignableFrom(rawType)) { serializer = new DataSerializer<T>(); deserializer = new DataDeserializer<T>(rawType); } else { serializer = (Serializer<T>) new DefaultSerializer(); deserializer = (Deserializer<T>) new DefaultDeserializer(); } }
From source file:org.xwiki.job.internal.xstream.SafeArrayConverter.java
/** * @param item the item to serialize/*from w ww .j a v a 2s . c om*/ * @return true of the item looks like a component */ private boolean isComponent(Object item) { if (item != null) { List<Class<?>> interfaces = ClassUtils.getAllInterfaces(item.getClass()); for (Class<?> iface : interfaces) { if (iface.isAnnotationPresent(Role.class)) { return true; } } } return false; }
From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java
@Override @Transactional/*from www . ja va 2s.c om*/ public void delete(T entity) { logger.trace("----->MyRepositoryImpl.delete(T entity)"); Assert.notNull(entity, "The entity must not be null!"); Class<?> clazz = entity.getClass(); if (clazz.isAnnotationPresent(LogicallyDelete.class)) { LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class); Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz()); Field field = ReflectionUtils.findField(entity.getClass(), logicallyDelete.name()); ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, entity, value); save(entity); } else { super.delete(entity); } }
From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java
@Override @Transactional//from w ww . j av a 2s .co m public void delete(ID[] ids) { logger.trace("----->MyRepositoryImpl.delete(ID[] ids)"); String qlString; Class<T> clazz = ei.getJavaType(); if (clazz.isAnnotationPresent(LogicallyDelete.class)) { LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class); Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz()); qlString = String.format(STATE_DELETE_QUERY_STRING, ei.getEntityName(), logicallyDelete.name(), value); } else { qlString = String.format(DELETE_QUERY_STRING, ei.getEntityName()); } logger.debug("......qlString:={}", qlString); Query query = em.createQuery(qlString); query.setParameter(1, Arrays.asList(ids)); query.executeUpdate(); }
From source file:org.nobel.highriseapi.mapper.SimpleXmlHttpMessageConverter.java
@Override public boolean canWrite(Class<?> clazz, MediaType mediaType) { return clazz.isAnnotationPresent(Root.class) && canWrite(mediaType); }
From source file:io.github.resilience4j.ratelimiter.autoconfigure.RateLimiterAspect.java
private RateLimiter getRateLimiterAnnotation(ProceedingJoinPoint proceedingJoinPoint) { RateLimiter rateLimiter = null;//from w w w .jav a 2 s .c o m Class<?> targetClass = proceedingJoinPoint.getTarget().getClass(); if (targetClass.isAnnotationPresent(RateLimiter.class)) { rateLimiter = targetClass.getAnnotation(RateLimiter.class); if (rateLimiter == null) { rateLimiter = targetClass.getDeclaredAnnotation(RateLimiter.class); } if (rateLimiter == null) { logger.debug("TargetClass has no declared annotation 'RateLimiter'"); } } return rateLimiter; }
From source file:org.openengsb.ui.common.DomainAuthorizationStrategy.java
private boolean hasSecurityAnnotation(Class<? extends IRequestableComponent> class1) { return class1.isAnnotationPresent(SecurityAttribute.class) || class1.isAnnotationPresent(SecurityAttributes.class); }
From source file:org.springframework.beans.factory.config.DeprecatedBeanWarner.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { if (isLogEnabled()) { String[] beanNames = beanFactory.getBeanDefinitionNames(); for (String beanName : beanNames) { String nameToLookup = beanName; if (beanFactory.isFactoryBean(beanName)) { nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName; }/*www . ja va2 s.c o m*/ Class<?> beanType = beanFactory.getType(nameToLookup); if (beanType != null) { Class<?> userClass = ClassUtils.getUserClass(beanType); if (userClass.isAnnotationPresent(Deprecated.class)) { BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); logDeprecatedBean(beanName, beanType, beanDefinition); } } } } }
From source file:org.jacpfx.vertx.spring.SpringVerticleFactory.java
private Verticle createVerticle(final Class<?> clazz, ClassLoader classLoader) throws Exception { if (clazz.isAnnotationPresent(SpringVerticle.class)) { return createSpringVerticle(clazz, classLoader); } else if (Verticle.class.isAssignableFrom(clazz)) { // init a non spring verticle, but this should not happen final Verticle verticle = Verticle.class.cast(clazz.newInstance()); verticle.init(vertx, vertx.getOrCreateContext()); return verticle; }/* ww w .j a v a 2 s. com*/ return null; }