List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:de.jackwhite20.japs.client.sub.impl.SubscriberImpl.java
private String getChannelFromAnnotation(Class<?> clazz) { if (!clazz.isAnnotationPresent(Channel.class)) { throw new IllegalArgumentException( "the handler class " + clazz.getSimpleName() + " has no 'Channel' annotation"); }/*w w w . j av a2 s .c om*/ String channel = clazz.getAnnotation(Channel.class).value(); if (channel.isEmpty()) { throw new IllegalStateException( "value of the 'Channel' annotation of class " + clazz.getSimpleName() + " is empty"); } return channel; }
From source file:org.codehaus.enunciate.modules.jersey.EnunciateJAXBContextResolver.java
public JAXBContext getContext(Class<?> objectType) { if (types.contains(objectType)) { return context; } else if (objectType.isAnnotationPresent(XmlRootElement.class)) { //if this is a root element, we'll do our best to apply our namespace prefix mapper. try {//from www.jav a2 s . c om JAXBContext context = JAXBContext.newInstance(objectType); if (this.prefixMapper != null) { context = new DelegatingJAXBContext(context) { @Override public Marshaller createMarshaller() throws JAXBException { Marshaller marshaller = super.createMarshaller(); try { marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", prefixMapper); } catch (PropertyException e) { //fall through... } return marshaller; } }; } return context; } catch (Exception e) { //fall through... } } return null; }
From source file:com.cottsoft.thrift.framework.server.ThriftMultiBinaryServerFactory.java
/** * ?Service implSpring bean???@Service???? * // w ww . j a va 2 s .c o m * @param thriftServiceImplClass * @return */ private String getServiceImplBeanName(Class<?> thriftServiceImplClass) { if (thriftServiceImplClass.isAnnotationPresent(Service.class)) { Service serviceAnnotation = (Service) thriftServiceImplClass.getAnnotation(Service.class); String value = serviceAnnotation.value(); if (StringUtils.isEmpty(value)) { return StringUtils.uncapitalize(thriftServiceImplClass.getSimpleName()); } else { return value; } } else { return StringUtils.uncapitalize(thriftServiceImplClass.getSimpleName()); } }
From source file:jofc2.OFC.java
/** * ??/* w w w .java 2s . com*/ * @param c */ private void doAlias(Class<?> c) { /** * */ if (c.isAnnotationPresent(Alias.class)) { converter.alias(c.getAnnotation(Alias.class).value(), c); } /** * ?? */ for (Field f : c.getDeclaredFields()) { if (f.isAnnotationPresent(Alias.class)) { if (f.getAnnotation(Alias.class).value().equals("")) { System.out.println(f.getName()); } converter.aliasField(f.getAnnotation(Alias.class).value(), c, f.getName()); } } }
From source file:org.jsconf.core.ConfigurationFactory.java
public ConfigurationFactory withBean(Class<?> bean) { if (bean.isAnnotationPresent(ConfigurationProperties.class)) { ConfigurationProperties cf = bean.getAnnotation(ConfigurationProperties.class); return withBean(cf.value(), bean, cf.id(), cf.proxy()); }/*w w w .j ava 2s .c om*/ throw new BeanInitializationException( String.format("Missing @ConfigurationProperties annotation on class %s", bean)); }
From source file:com.cognifide.qa.bb.cumber.Bobcumber.java
/** * Constructor called by JUnit./* www.j a v a2s .co m*/ * * @param clazz the class with the @RunWith annotation. * @throws java.io.IOException if there is a problem * @throws org.junit.runners.model.InitializationError if there is another problem */ public Bobcumber(Class<?> clazz) throws InitializationError, IOException { super(clazz); statisticsHelper = new StatisticsHelper(); storeFailedResults = clazz.isAnnotationPresent(StoreFailedResults.class); if (storeFailedResults) { featureFile = createFile(clazz.getAnnotation(StoreFailedResults.class).value()); String statisticsFilePath = properties.getProperty(ConfigKeys.BOBCAT_REPORT_STATISTICS_PATH); statisticsFile = createFile(statisticsFilePath); } isItFailedTestsRerun = clazz.isAnnotationPresent(FailedTestsRunner.class); }
From source file:de.Keyle.MyPet.api.util.hooks.PluginHookManager.java
/** * register new hooks here. A hook needs the {@link PluginHookName} annotation to be accepted. * * @param hookClass the hook class/*from w w w . ja va 2s . c o m*/ */ public void registerHook(Class<? extends PluginHook> hookClass) { if (hookClass.isAnnotationPresent(PluginHookName.class)) { PluginHookName hookNameAnnotation = hookClass.getAnnotation(PluginHookName.class); String pluginName = hookNameAnnotation.value(); if (!hookNameAnnotation.classPath().equalsIgnoreCase("")) { if (!isPluginAvailable(pluginName, hookNameAnnotation.classPath())) { return; } } else { if (!isPluginAvailable(pluginName)) { return; } } try { PluginHook hook = hookClass.newInstance(); registeredHooks.add(hook); } catch (Throwable e) { MyPetApi.getLogger() .warning("Error occured while enabling " + pluginName + " (" + Bukkit.getPluginManager().getPlugin(pluginName).getDescription().getVersion() + ") hook."); e.printStackTrace(); } } }
From source file:com.wavemaker.tools.apidocs.tools.parser.impl.ReflectionModelParser.java
protected Model parseClass(Class<?> classToScan) { ModelImpl model = new ModelImpl(); model.name(DataTypeUtil.getName(classToScan)); if (classToScan.isAnnotationPresent(ApiModel.class)) { model.setDescription(classToScan.getAnnotation(ApiModel.class).description()); }/*from w ww .j a va2 s .c o m*/ model.setProperties(getModelProperties(classToScan)); model.setRequired(findRequiredFields(model.getProperties())); return model; }
From source file:com.neelo.glue.ApplicationModule.java
public void register(Class<?> resourceClass) { log.info("Registering: " + resourceClass.getName()); Resource resource = null;//from w w w. ja va 2 s .co m if (resourceClass.isAnnotationPresent(Resource.class)) { resource = resourceClass.getAnnotation(Resource.class); } else { log.warn("Class not registerd. Missing " + Resource.class.getSimpleName() + " annotation"); return; } ResourceBuilder builder = new ResourceBuilder(resourceClass, resource.path(), resource.layout()); Method[] methods = resourceClass.getDeclaredMethods(); for (Method method : methods) { if (method.isAnnotationPresent(Get.class)) { Get get = method.getAnnotation(Get.class); RouteBuilder route = builder.get(method, get.path(), get.content()); route.setLayout(StringUtils.isNotBlank(get.layout()) ? get.layout() : resource.layout()); if (StringUtils.isNotBlank(get.name())) route.setName(get.name()); routes.add(route); } else if (method.isAnnotationPresent(Post.class)) { Post post = method.getAnnotation(Post.class); RouteBuilder route = builder.post(method, post.path(), post.content()); route.setLayout(StringUtils.isNotBlank(post.layout()) ? post.layout() : resource.layout()); if (StringUtils.isNotBlank(post.name())) route.setName(post.name()); routes.add(route); } } }
From source file:org.lavajug.streamcaster.plugins.AnnotationPluginManager.java
/** * return a new instance of the default PluginManager * * @param classLoader containing plugins class * @param searchPath where to find plugins classes */// ww w . ja v a 2 s.com public AnnotationPluginManager(ClassLoader classLoader, String... searchPath) { this.plugins = new HashMap<>(); try { for (Class<?> clazz : Reflexion.getClassesAnnotatedWith(SourcePlugin.class)) { if (clazz.isAnnotationPresent(SourcePlugin.class)) { SourcePlugin ann = clazz.getAnnotation(SourcePlugin.class); plugins.put(ann.value(), clazz); } } } catch (IOException | URISyntaxException ex) { Logger.getLogger(AnnotationPluginManager.class.getName()).log(Level.SEVERE, null, ex); } }