List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
private void collectTableUpdatesAnnotations(SparseArray<List<String>> versionUpdates, Class<?> clazz) { if (clazz.isAnnotationPresent(ModelUpdate.class)) { addUpdateIfNeeded(versionUpdates, clazz.getAnnotation(ModelUpdate.class)); } else if (clazz.isAnnotationPresent(ModelUpdates.class)) { ModelUpdates updates = clazz.getAnnotation(ModelUpdates.class); for (ModelUpdate update : updates.value()) { addUpdateIfNeeded(versionUpdates, update); }//w w w . ja va 2 s . co m } }
From source file:cn.wanghaomiao.seimi.core.SeimiContext.java
private void init() { String[] targetPkgs = { "crawlers", "queues", "interceptors", "cn.wanghaomiao.seimi" }; seimiScanner = new SeimiScanner(this); Set<Class<?>> aladdin = seimiScanner.scan(targetPkgs, Crawler.class, Queue.class, Interceptor.class); applicationContext = this; crawlers = new HashSet<>(); hasUsedQuene = new HashSet<>(); interceptors = new LinkedList<>(); crawlerModelContext = new HashMap<>(); List<Class<?>> registList = new LinkedList<>(); for (Class cls : aladdin) { if (BaseSeimiCrawler.class.isAssignableFrom(cls)) { Crawler c = (Crawler) cls.getAnnotation(Crawler.class); hasUsedQuene.add(c.queue()); crawlers.add(cls);//from w w w .j a v a 2s . c o m registList.add(cls); } else if (SeimiInterceptor.class.isAssignableFrom(cls)) { registList.add(cls); } } //seimiQueuecontext for (Class cls : aladdin) { if (SeimiQueue.class.isAssignableFrom(cls) && hasUsedQuene.contains(cls)) { registList.add(cls); } } //? seimiScanner.regist(registList); //?? for (Class cls : aladdin) { if (SeimiInterceptor.class.isAssignableFrom(cls)) { interceptors.add((SeimiInterceptor) applicationContext.getBean(cls)); } } Collections.sort(interceptors, new Comparator<SeimiInterceptor>() { //????88,66,11 @Override public int compare(SeimiInterceptor o1, SeimiInterceptor o2) { return o1.getWeight() > o2.getWeight() ? -1 : 1; } }); }
From source file:com.lonepulse.robozombie.executor.HttpClientDirectory.java
/** * <p>Registers an instance of {@link HttpClient} under the given {@link Class} of the endpoint * definition. If an {@link HttpClient} already exists under the given endpoint, <i>no attempt * will be made to replace the existing instance</i>.</p> * //from ww w.j a va2 s . c o m * @param endpoint * the {@link Class} of the endpoint whose {@link HttpClient} is added to the directory * <br><br> * @param httpClient * the {@link HttpClient} which to be registered under the given endpoint definition * <br><br> * @return the {@link HttpClient} which was registered under the given endpoint definition * <br><br> * @since 1.3.0 */ @Override public synchronized HttpClient bind(Class<?> endpoint, HttpClient httpClient) { String configClassName = endpoint.isAnnotationPresent(Config.class) ? endpoint.getAnnotation(Config.class).value().getName() : Zombie.Configuration.class.getName(); String endpointClassName = endpoint.getName(); if (!DIRECTORY.containsKey(configClassName)) { DIRECTORY.put(configClassName, httpClient); } if (!ENDPOINT_CONFIGS.containsKey(endpointClassName)) { ENDPOINT_CONFIGS.put(endpointClassName, configClassName); } return lookup(endpoint); }
From source file:com.amazonaws.services.dynamodbv2.datamodeling.AttributeEncryptor.java
private boolean handleUnknownAttributes(Class<?> clazz) { return clazz.getAnnotation(HandleUnknownAttributes.class) != null; }
From source file:com.baidu.terminator.register.ProtocolRegisterImpl.java
private void scanPipelineFactory() { AnnotationScanner<ChannelPipelineFactory> channelPipelineFactoryScanner = new AnnotationScanner<ChannelPipelineFactory>( DEFAULT_PIPELINEFACTORY_PACKAGE, PipelineFactory.class); List<Class<? extends ChannelPipelineFactory>> cpfClasses = channelPipelineFactoryScanner .scanAnnotatedClass();//from www . j a v a2s . co m for (Class<? extends ChannelPipelineFactory> clazz : cpfClasses) { PipelineFactory pf = clazz.getAnnotation(PipelineFactory.class); String protocol = pf.protocol(); protocolChannelPipelineFactoryMap.put(protocol, clazz); } }
From source file:de.codesourcery.spring.contextrewrite.AnnotationParser.java
/** * Parse rewrite annotations./*from w w w.j a va 2 s .c o m*/ * * @param clazz class whose annotations should be parsed. This method will also parse parent classes and merge any rewriting annotations it encounters * according to the rules described in {@link RewriteConfig#getRules()}. * * @return rewriting configuration * @throws NoSuchElementException if neither the input class nor any of its parents had a {@link ContextConfiguration} annotation. */ public RewriteConfig parse(Class<?> clazz) throws NoSuchElementException { Validate.notNull(clazz, "clazz must not be NULL"); RewriteConfig first = null; RewriteConfig previous = null; Class<?> currentClass = clazz; while (currentClass != Object.class) { final Optional<ContextConfiguration> ctxConfiguration = Optional .ofNullable(currentClass.getAnnotation(ContextConfiguration.class)); final RewriteConfig config = new RewriteConfig(currentClass); if (ctxConfiguration.isPresent()) { config.setContextPath(ctxConfiguration.get().value()); config.setDebug(ctxConfiguration.get().debug()); config.setDumpXML(ctxConfiguration.get().dumpRewrittenXML()); } config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(ReplaceRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(RemoveRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(InsertElementRule.class))); config.addRules(XMLRewrite.wrap(currentClass.getAnnotationsByType(InsertAttributeRule.class))); if (ctxConfiguration.isPresent() || config.hasRules()) { if (previous != null) { previous.setParent(config); } previous = config; if (first == null) { first = config; } } currentClass = currentClass.getSuperclass(); } if (first == null) { throw new NoSuchElementException("Found no @" + ContextConfiguration.class.getName() + " annotation on " + clazz.getName() + " or any of its super classes"); } return first; }
From source file:org.codehaus.griffon.plugins.AbstractGriffonPluginManager.java
public String getPluginPathForClass(Class<? extends Object> theClass) { if (theClass != null) { org.codehaus.griffon.plugins.metadata.GriffonPlugin ann = theClass .getAnnotation(org.codehaus.griffon.plugins.metadata.GriffonPlugin.class); if (ann != null) { return getPluginPath(ann.name()); }//w ww . ja va 2s. co m } return null; }
From source file:org.excalibur.service.deployment.server.ApplicationServer.java
protected void registerThisInstanceServices(final Class<?> serviceClass, final Environment environment, ApplicationConfig application) throws Exception { final String servicePath = serviceClass.getAnnotation(Path.class).value(); ServiceInstance<ServiceDetails> instance = ServiceInstance.<ServiceDetails>builder() .name(thisInstance.getName() + servicePath).payload(new ServiceDetails()) .port(environment.getProperty("org.excalibur.server.port", Integer.class, 8080)) .uriSpec(application.getUriSpec(servicePath.substring(1))).build(); services.add(instance);//w w w . j a v a 2 s . c o m this.serviceDiscovery.registerService(instance); }
From source file:com.sixt.service.framework.injection.TracingModule.java
@SuppressWarnings("unchecked") private Object findTracingPlugin(Injector injector) { Object retval = null;//from ww w.j a v a 2s. c om String pluginName = serviceProperties.getProperty("tracing"); if (StringUtils.isBlank(pluginName)) { logger.debug("no tracing plugin set, defaulting to 'noop'"); pluginName = "noop"; } if (plugins == null) { plugins = new FastClasspathScanner().scan().getNamesOfClassesWithAnnotation(TracingPlugin.class); } boolean found = false; for (String plugin : plugins) { try { @SuppressWarnings("unchecked") Class<? extends TracingPlugin> pluginClass = (Class<? extends TracingPlugin>) Class.forName(plugin); TracingPlugin anno = pluginClass.getAnnotation(TracingPlugin.class); if (anno != null && pluginName.equals(anno.name())) { retval = injector.getInstance(pluginClass); found = true; break; } } catch (ClassNotFoundException e) { logger.error("Tracing plugin not found", e); } } if (!found) { logger.warn("Tracing plugin '{}' was not found in the class path", pluginName); } return retval; }
From source file:net.lojika.jedis.dao.impl.AbstractJedisDao.java
public AbstractJedisDao(Class<T> modelClass) { this.modelClass = modelClass; JedisModel jedisModel = modelClass.getAnnotation(JedisModel.class); if (jedisModel == null && !modelClass.equals(String.class)) { throw new RuntimeException("Model must be Sring or JedisModel"); }/*from w w w . j ava2 s . co m*/ modelName = jedisModel == null ? DEFAULT_MODEL_NAME : jedisModel.name(); if (modelName.indexOf('.') >= 0) { throw new RuntimeException("Model name can not contain '.'"); } }