List of usage examples for java.lang Class getAnnotation
@SuppressWarnings("unchecked") public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
From source file:org.camunda.bpm.elasticsearch.jackson.JacksonMixInFilterModule.java
public static String getJsonFilterAnnotationValue(Class clazz) { JsonFilter jsonFilterAnnotation = (JsonFilter) clazz.getAnnotation(JsonFilter.class); if (jsonFilterAnnotation != null) { return jsonFilterAnnotation.value(); }// w w w .j av a 2 s . c om return null; }
From source file:com.helpinput.spring.Commons.java
public static String getBeanName(Class<?> beanClass) { String beanName = null;/* w ww . j a v a2 s . co m*/ Named nameAnn = beanClass.getAnnotation(Named.class); //todo named?bean; if (nameAnn != null) { if (Utils.hasLength(nameAnn.value())) beanName = nameAnn.value(); } else { Component componentAnn = beanClass.getAnnotation(Component.class); if (componentAnn != null) { if (Utils.hasLength(componentAnn.value())) beanName = componentAnn.value(); } } if (!Utils.hasLength(beanName)) { beanName = Utils.beanName(beanClass.getSimpleName()); } return beanName; }
From source file:com.fantasy.Application.java
private static boolean isCandidate(MetadataReader metadataReader) throws ClassNotFoundException { try {// ww w . j a v a 2s . co m Class c = Class.forName(metadataReader.getClassMetadata().getClassName()); if (c.getAnnotation(TaskRunner.class) != null) { return true; } } catch (Throwable e) { } return false; }
From source file:io.devcon5.pageobjects.tx.TransactionHelper.java
/** * Determines the transaction name for the class. The class must be annoted with {@link Transaction} otherwise an * empty optional is returned. The name of the transaction is either the value of the annotation of the simple name * of the class itself//www.j a va 2 s. co m * * @param type * the type for which a transaction name should be determined * * @return the name of the transaction of the empty optional if the class is not transactional */ public static Optional<String> getClassTxName(final Class<?> type) { return Optional.ofNullable(type.getAnnotation(Transaction.class)) .map(t -> isEmpty(t.value()) ? type.getSimpleName() : t.value()); }
From source file:com.thinkbiganalytics.policy.precondition.AvailablePolicies.java
/** * Find all classes annotated with {@link PreconditionPolicy} and transfrom them into the user interface object * * @return user interface objects of the {@link PreconditionPolicy} on the classpath *///w ww . j a v a 2 s. c om public static List<PreconditionRule> discoverPreconditions() { List<PreconditionRule> rules = new ArrayList<>(); Set<Class<?>> validators = ReflectionPolicyAnnotationDiscoverer .getTypesAnnotatedWith(PreconditionPolicy.class); for (Class c : validators) { PreconditionPolicy policy = (PreconditionPolicy) c.getAnnotation(PreconditionPolicy.class); String desc = policy.description(); String shortDesc = policy.shortDescription(); if (StringUtils.isBlank(desc) && StringUtils.isNotBlank(shortDesc)) { desc = shortDesc; } if (StringUtils.isBlank(shortDesc) && StringUtils.isNotBlank(desc)) { shortDesc = desc; } List<FieldRuleProperty> properties = PreconditionAnnotationTransformer.instance().getUiProperties(c); rules.add(new PreconditionRuleBuilder(policy.name()).description(desc).shortDescription(shortDesc) .addProperties(properties).objectClassType(c).build()); } return rules; }
From source file:com.xemantic.tadedon.guice.persistence.PersistenceUtils.java
/** * Checks {@link Transactional#readOnly()} property for given {@code method}. * <p>/*w w w. jav a2s. com*/ * Algorithm starts with method annotation checking also overridden methods * from supertypes. If no annotation is found on the {@code method}, annotation * of declaring class and it's supertypes will be used. Absence of any * {@code Transactional} annotation will cause {@link IllegalArgumentException}. * * @param method the method starting transaction. * @return {@code true} if method should be run in read-only transaction, {@code false} * otherwise. * @throws IllegalArgumentException if no {@link Transactional} annotation is found * either on the {@code method}}, or on declaring class. */ public static boolean isTransactionReadOnly(Method method) { final Transactional methodTransactional = AnnotationUtils.findAnnotation(method, Transactional.class); final boolean readOnly; if (methodTransactional != null) { readOnly = methodTransactional.readOnly(); } else { final Class<?> klass = method.getDeclaringClass(); final Transactional classTransactional = klass.getAnnotation(Transactional.class); checkNotNull(classTransactional, "Either method or declaring class should be annotated @Transacetional, method: %s", method); readOnly = classTransactional.readOnly(); } return readOnly; }
From source file:com.manydesigns.portofino.pageactions.PageActionLogic.java
public static String getDescriptionKey(Class<?> actionClass) { PageActionName annotation = actionClass.getAnnotation(PageActionName.class); if (annotation != null) { return annotation.value(); } else {//from w w w . jav a2 s.co m return actionClass.getName(); } }
From source file:net.nullschool.grains.jackson.datatype.GrainsAnnotationIntrospector.java
/** * Returns the contents of the {@link PublicInterfaceRef} annotation on the specified class, or null if it does * not exist.//from ww w.j a v a 2s.c om */ private static Class<?> publicInterfaceOf(Class<?> clazz) { return Grain.class.isAssignableFrom(clazz) ? valueOf(clazz.getAnnotation(PublicInterfaceRef.class)) : null; }
From source file:com.epam.jdi.uitests.web.selenium.elements.composite.WebSite.java
public static void init(String driverName, Class<?>... sites) { for (Class<?> site : sites) { if (site.isAnnotationPresent(JSite.class)) { String value = site.getAnnotation(JSite.class).value(); if (isNotBlank(value)) DOMAIN = value;//from w w w .j ava2 s . com } new WebCascadeInit().initStaticPages(site, driverName); } currentSite = sites[sites.length - 1]; }
From source file:io.leishvl.core.data.AnnotationCollectionUtils.java
public static final String getCollectionName(final Class<?> clazz) { String collection = null;// w w w .ja va2s .c o m if (clazz != null) { final Annotation annotation = clazz.getAnnotation(Document.class); if (annotation instanceof Document) { collection = ((Document) annotation).collection(); } if (isBlank(collection)) collection = uncapitalize(clazz.getSimpleName()); } return collection; }