List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:grails.util.GrailsClassUtils.java
/** * Checks to see if a class is marked with @grails.artefact.Enhanced and if the enhancedFor * attribute of the annotation contains a specific feature name * * @param controllerClass The class to inspect * @param featureName The name of a feature to check for * @return true if controllerClass is marked with Enhanced and the enhancedFor attribute includes featureName, otherwise returns false * @see Enhanced/*w w w .j av a 2 s . com*/ * @see Enhanced#enhancedFor() */ public static Boolean hasBeenEnhancedForFeature(final Class<?> controllerClass, final String featureName) { boolean hasBeenEnhanced = false; final Enhanced enhancedAnnotation = controllerClass.getAnnotation(Enhanced.class); if (enhancedAnnotation != null) { final String[] enhancedFor = enhancedAnnotation.enhancedFor(); if (enhancedFor != null) { hasBeenEnhanced = GrailsArrayUtils.contains(enhancedFor, featureName); } } return hasBeenEnhanced; }
From source file:org.os890.ds.addon.remote.impl.server.ServiceConfigUpdateTask.java
private void createCacheEntryFor(Class<?> beanClass) { Path path = beanClass.getAnnotation(Path.class); if (path != null) { ObjectMapper objectMapper = new ObjectMapper(); for (Method method : beanClass.getDeclaredMethods()) { Path methodPath = method.getAnnotation(Path.class); if (methodPath != null) { try { ServiceDescriptor serviceDescriptor = ServiceDescriptorFactory.create(methodPath.value(), path.value()); String serviceDescriptorAsJson = objectMapper.writeValueAsString(serviceDescriptor); Cache<String, String> cache = cacheProvider.getCache(); String cachedValue = cache.get(serviceDescriptor.getKey()); if (!serviceDescriptorAsJson.equals(cachedValue)) { cache.put(serviceDescriptor.getKey(), serviceDescriptorAsJson); }/*w w w. j ava2s . c om*/ LOG.fine("cached endpoint descriptor: " + serviceDescriptor.getKey() + " -> " + serviceDescriptorAsJson); } catch (JsonProcessingException e) { throw ExceptionUtils.throwAsRuntimeException(e); } } } } }
From source file:pl.bristleback.server.bristle.action.client.ClientActionClasses.java
public ClientActionClassInformation getClientActionClass(Class<?> actionClass) { ClientActionClass clientActionClassAnnotation = actionClass.getAnnotation(ClientActionClass.class); if (clientActionClassAnnotation == null) { throw new ClientActionException(ClientActionClass.class.getSimpleName() + " annotation not found in " + actionClass.getName() + " class."); }// w w w . j a va2 s .c o m String actionClassName = getActionClassName(actionClass, clientActionClassAnnotation); return actionClasses.get(actionClassName); }
From source file:com.kurento.kmf.content.internal.recorder.RecorderHandlerServlet.java
/** * Look for {@link HttpRecorderService} annotation in the handler class and * check whether or not it is using JSON control protocol. * /*from w w w . j a v a 2 s. co m*/ * @return JSON Control Protocol strategy (true|false) */ @Override protected boolean getUseJsonControlProtocol(Class<?> handlerClass) throws ServletException { return handlerClass.getAnnotation(HttpRecorderService.class).useControlProtocol(); }
From source file:com.impetus.kundera.metadata.processor.CacheableAnnotationProcessor.java
@Override public final void process(final Class<?> entityClass, EntityMetadata metadata) { Cacheable cacheable = (Cacheable) entityClass.getAnnotation(Cacheable.class); if (null != cacheable) { metadata.setCacheable(cacheable.value()); }//from www . j a va 2s . c o m }
From source file:net.firejack.platform.core.validation.constraint.RuleMapper.java
protected void onContextRefreshed(ContextRefreshedEvent event) { ApplicationContext context = event.getApplicationContext(); Map<String, Object> beans = context.getBeansWithAnnotation(RuleSource.class); for (Object bean : beans.values()) { Class<?> clazz = bean.getClass(); RuleSource ruleSource = clazz.getAnnotation(RuleSource.class); if (ruleSource != null) { if (StringUtils.isNotBlank(ruleSource.value())) { CONSTRAINT_LOCATIONS.put(ruleSource.value(), clazz); }/*from w w w . j a v a 2 s . c o m*/ } } }
From source file:com.bstek.dorado.config.text.TextParserHelper.java
private void collectXmlNodeInfo(TextSectionInfo textSectionInfo, Class<?> type) { TextSection textSection = type.getAnnotation(TextSection.class); if (textSection == null) { return;/*from www . j a va 2 s. c om*/ } textSectionInfo.addSourceType(type); if (StringUtils.isNotEmpty(textSection.parser())) { textSectionInfo.setParser(textSection.parser()); } }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Finds an initial objects factory method and its dependent classes from the * specified object creator class.//from ww w . ja v a2 s . c om * * @author paouelle * * @param clazz the non-<code>null</code> object creator class * @return the initial objects factory method and its set of dependenc classes * or <code>null</code> if none configured * @throws IllegalArgumentException if the initial objects method is not * properly defined */ private static Pair<Method, Class<?>[]> findInitial(Class<?> clazz) { final InitialObjects io = clazz.getAnnotation(InitialObjects.class); if (io != null) { final String mname = io.staticMethod(); try { Method m; try { // first look for one with a map for suffixes m = clazz.getMethod(mname, Map.class); // validate that if suffixes are defined, the method expects a Map<String, String> // to provide the values for the suffixes when initializing objects final Class<?>[] cparms = m.getParameterTypes(); // should always be 1 as we used only 1 class in getMethod() if (cparms.length != 1) { throw new IllegalArgumentException( "expecting one Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } // should always be a map as we used a Map to find the method if (!Map.class.isAssignableFrom(cparms[0])) { throw new IllegalArgumentException("expecting parameter for initial objects method '" + mname + "' to be of type Map<String, String> in class: " + clazz.getSimpleName()); } final Type[] tparms = m.getGenericParameterTypes(); // should always be 1 as we used only 1 class in getMethod() if (tparms.length != 1) { // should always be 1 as it was already tested above throw new IllegalArgumentException( "expecting one Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } if (tparms[0] instanceof ParameterizedType) { final ParameterizedType ptype = (ParameterizedType) tparms[0]; // maps will always have 2 arguments for (final Type atype : ptype.getActualTypeArguments()) { final Class<?> aclazz = ReflectionUtils.getRawClass(atype); if (String.class != aclazz) { throw new IllegalArgumentException( "expecting a Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } } } else { throw new IllegalArgumentException( "expecting a Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } } catch (NoSuchMethodException e) { // fallback to one with no map m = clazz.getMethod(mname); } // validate the method is static if (!Modifier.isStatic(m.getModifiers())) { throw new IllegalArgumentException("initial objects method '" + mname + "' is not static in class: " + clazz.getSimpleName()); } // validate the return type is an array final Class<?> type = m.getReturnType(); if (!type.isArray()) { throw new IllegalArgumentException("initial objects method '" + mname + "' doesn't return an array in class: " + clazz.getSimpleName()); } return Pair.of(m, io.dependsOn()); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "missing initial objects method '" + mname + "' in class: " + clazz.getSimpleName(), e); } } return null; }
From source file:core.commonapp.domain.InformationContext.java
/** * Get bean for given interface./*from w w w. j a va 2s.com*/ * * The interface is required to have the <code>Service</code> annotation. * * @param beanInterface * @return */ public Object getBean(Class beanInterface) { InformationBean bean = (InformationBean) beanInterface.getAnnotation(InformationBean.class); if (bean == null) { throw new IllegalArgumentException("No bean found for interface " + beanInterface.getName()); } return getBean(bean.beanName()); }
From source file:sk.seges.test.jms.SpringJMSSuite.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a 2 s . co m protected void setManagers(Class<?> klass) { ContextConfiguration annotation = klass.getAnnotation(ContextConfiguration.class); if (annotation != null) { context = new ClassPathXmlApplicationContext(annotation.locations()); } else { context = new ClassPathXmlApplicationContext("context.xml"); } SpringProviderConfiguration providerConfiguration = klass.getAnnotation(SpringProviderConfiguration.class); if (providerConfiguration != null) { managers = (List<JMSProviderManager>) context.getBean(providerConfiguration.managersListName()); } else { managers = (List<JMSProviderManager>) context.getBean(JMS_PROVIDER_MANAGERS); } }