List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration.java
/** * Returns the class configuration of the given {@code klass}. * * @param klass the class/*from w w w .j a va2 s .co m*/ * @param browser the browser version * @return the class configuration */ public static ClassConfiguration getClassConfiguration(final Class<? extends HtmlUnitScriptable> klass, final BrowserVersion browser) { if (browser != null) { final String expectedBrowserName; if (browser.isIE()) { expectedBrowserName = "IE"; } else if (browser.isFirefox()) { expectedBrowserName = "FF"; } else if (browser.isEdge()) { expectedBrowserName = "EDGE"; } else { expectedBrowserName = "CHROME"; } final float browserVersionNumeric = browser.getBrowserVersionNumeric(); final String hostClassName = klass.getName(); final JsxClasses jsxClasses = klass.getAnnotation(JsxClasses.class); if (jsxClasses != null) { if (klass.getAnnotation(JsxClass.class) != null) { throw new RuntimeException( "Invalid JsxClasses/JsxClass annotation; class '" + hostClassName + "' has both."); } final JsxClass[] jsxClassValues = jsxClasses.value(); final Set<Class<?>> domClasses = new HashSet<>(); boolean isJsObject = false; boolean isDefinedInStandardsMode = false; String className = null; for (int i = 0; i < jsxClassValues.length; i++) { final JsxClass jsxClass = jsxClassValues[i]; if (jsxClass != null && isSupported(jsxClass.browsers(), expectedBrowserName, browserVersionNumeric)) { domClasses.add(jsxClass.domClass()); if (jsxClass.isJSObject()) { isJsObject = true; } if (jsxClass.isDefinedInStandardsMode()) { isDefinedInStandardsMode = true; } if (!jsxClass.className().isEmpty()) { className = jsxClass.className(); } } } final ClassConfiguration classConfiguration = new ClassConfiguration(klass, domClasses.toArray(new Class<?>[0]), isJsObject, isDefinedInStandardsMode, className); process(classConfiguration, hostClassName, expectedBrowserName, browserVersionNumeric); return classConfiguration; } final JsxClass jsxClass = klass.getAnnotation(JsxClass.class); if (jsxClass != null && isSupported(jsxClass.browsers(), expectedBrowserName, browserVersionNumeric)) { final Set<Class<?>> domClasses = new HashSet<>(); final Class<?> domClass = jsxClass.domClass(); if (domClass != null && domClass != Object.class) { domClasses.add(domClass); } String className = jsxClass.className(); if (className.isEmpty()) { className = null; } final ClassConfiguration classConfiguration = new ClassConfiguration(klass, domClasses.toArray(new Class<?>[0]), jsxClass.isJSObject(), jsxClass.isDefinedInStandardsMode(), className); process(classConfiguration, hostClassName, expectedBrowserName, browserVersionNumeric); return classConfiguration; } } return null; }
From source file:org.apache.aries.blueprint.plugin.model.SpringTransactionFactory.java
TransactionalDef create(Class<?> clazz) { Transactional transactional = clazz.getAnnotation(Transactional.class); return transactional != null ? new TransactionalDef("*", txTypeNames.get(transactional.propagation())) : null;//from w w w .ja v a 2 s .c om }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * /* w ww.j a va2 s. c o m*/ * ?annotationClass * * @param targetClass * Class * @param annotationClass * Class * * @return List */ public static <T extends Annotation> List<T> getAnnotations(Class targetClass, Class annotationClass) { Assert.notNull(targetClass, "targetClass?"); Assert.notNull(annotationClass, "annotationClass?"); List<T> result = new ArrayList<T>(); Annotation annotation = targetClass.getAnnotation(annotationClass); if (annotation != null) { result.add((T) annotation); } Constructor[] constructors = targetClass.getDeclaredConstructors(); // ? CollectionUtils.addAll(result, getAnnotations(constructors, annotationClass).iterator()); Field[] fields = targetClass.getDeclaredFields(); // ? CollectionUtils.addAll(result, getAnnotations(fields, annotationClass).iterator()); Method[] methods = targetClass.getDeclaredMethods(); // ? CollectionUtils.addAll(result, getAnnotations(methods, annotationClass).iterator()); for (Class<?> superClass = targetClass.getSuperclass(); superClass == null || superClass == Object.class; superClass = superClass.getSuperclass()) { List<T> temp = getAnnotations(superClass, annotationClass); if (CollectionUtils.isNotEmpty(temp)) { CollectionUtils.addAll(result, temp.iterator()); } } return result; }
From source file:com.makariev.dynamodb.config.base.SpringBaseRepositoryLoader.java
@Override public boolean isSupported(Class checkClass) { return null != checkClass.getAnnotation(Entity.class); }
From source file:com.helpinput.spring.registinerceptor.ProxybeanRegistInterceptor.java
@Override public boolean getCondition(Class<?> clz) { return clz.getAnnotation(Parent.class) != null; }
From source file:com.capgemini.boot.core.factory.internal.DefaultAnnotationStrategy.java
private SettingBackedBeanFactory getAnnotationFromFactory(Class<?> factoryClass) { return factoryClass.getAnnotation(getFactoryClassAnnotation()); }
From source file:ditl.graphs.cli.GraphOptions.java
private GraphOptions(Class<? extends Trace<?>> klass) { name = klass.getAnnotation(Trace.Type.class).value(); }
From source file:net.paulgray.bbrest.mixins.MixinJacksonHttpMessageConverter.java
public MixinJacksonHttpMessageConverter(String[] basePackages) { for (String pkg : basePackages) { Reflections reflections = new Reflections(pkg); Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(AutoMixin.class); for (Class<?> mixin : annotated) { AutoMixin am = mixin.getAnnotation(AutoMixin.class); for (Class toMix : am.value()) { this.getObjectMapper().addMixInAnnotations(toMix, mixin); }//from w ww . j a va 2 s .co m } } /* for (Map.Entry<Class, Class> entry : mixins.entrySet()) { Class key = entry.getKey(); Class value = entry.getValue(); this.getObjectMapper().getSerializationConfig().addMixInAnnotations(key, value); } */ }
From source file:stubs.AbstractTestComponent.java
/** * Return the slug of the component, identified by the tag @TypeALias. * @return Component's slug, or null if @TypeAlias was not defined. *//*from w w w. jav a 2 s. c o m*/ public String slug() { String res; Class<? extends AbstractTestComponent> c = this.getClass(); TypeAlias a = c.getAnnotation(TypeAlias.class); res = (a != null) ? a.value() : null; return res; }
From source file:com.consol.citrus.admin.service.spring.filter.GetSpringBeanFilter.java
/** * Constructor using bean definition id as field. *///from ww w . j ava 2 s .com public GetSpringBeanFilter(String id, Class<?> type) { this.elementName = type.getAnnotation(XmlRootElement.class).name(); this.elementNamespace = type.getPackage().getAnnotation(XmlSchema.class).namespace(); this.id = id; }