Example usage for java.lang Class getAnnotation

List of usage examples for java.lang Class getAnnotation

Introduction

In this page you can find the example usage for java.lang Class getAnnotation.

Prototype

@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) 

Source Link

Usage

From source file:net.eledge.android.toolkit.db.internal.SQLBuilder.java

public static String getTableName(Class<?> clazz) {
    Entity entity = clazz.getAnnotation(Entity.class);
    return StringUtils.defaultIfBlank(entity.name(), clazz.getName().toLowerCase(Locale.ENGLISH));
}

From source file:generators.ExpressionDeprecationValidator.java

private static boolean isDeprecated(final ExpressionMetaData expression) {

    final Class type = expression.getExpressionType();
    final Annotation annotation = type.getAnnotation(Deprecated.class);
    if (annotation != null) {
        return true;
    }//from   w  ww  . j a v a  2 s.  c om
    return false;
}

From source file:Main.java

public static <A extends Annotation> A getClassAnnotation(Class<?> clientInterface, Class<A> annotationClass) {
    A annotation = clientInterface.getAnnotation(annotationClass);
    if (annotation == null) {
        for (Class<?> parentClass : clientInterface.getInterfaces()) {
            annotation = getClassAnnotation(parentClass, annotationClass);
            if (annotation != null) {
                System.out.println(parentClass);
                return annotation;
            }/*from ww  w  .  j  a v  a  2s .c o  m*/
        }
    }
    return annotation;
}

From source file:org.openmrs.module.jmx.util.MBeanProxifier.java

/**
 * Finds the MBean interface of the given object by searching for the MXBean annotation
 * @param mbean the object//w ww  . jav a2  s . c o m
 * @return the interface
 */
public static Class<?> getMBeanInterface(Object mbean) {
    Class<?>[] interfaces = mbean.getClass().getInterfaces();
    for (Class<?> intf : interfaces) {
        MXBean annotation = intf.getAnnotation(MXBean.class);
        if (annotation != null && annotation.value())
            return intf;
    }
    return null;
}

From source file:Main.java

public static <A extends Annotation> A getAnnotationFromHierarchy(final Class<?> clazz,
        final Class<A> annotation) {
    Class<?> currentClass = clazz;
    A annotationInstance;//from  w  w w .  j a  va2s.c om
    do {
        annotationInstance = currentClass.getAnnotation(annotation);
        currentClass = currentClass.getSuperclass();
    } while (annotationInstance == null && currentClass != Object.class);
    return annotationInstance;
}

From source file:Main.java

static private String getElementName(Class<?> clazz) {

    while (clazz != null) {
        XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);

        if (rootElement != null) {
            return rootElement.name();
        }/*from   ww  w .ja va2s. c  o m*/

        clazz = clazz.getSuperclass();
    }

    throw new RuntimeException();
}

From source file:Main.java

public static <A extends Annotation> A getAnnotation(Class<?> cla, Class<A> clazz) {
    A result = null;//from   www.  j  av a2s.c  o m
    if (cla != null && clazz != null) {
        result = cla.getAnnotation(clazz);
    }
    return result;
}

From source file:com.xemantic.tadedon.guice.matcher.Annotations.java

/**
 * Check if given {@code annotationType} has {@link Retention} set to {@link RetentionPolicy#RUNTIME}.
 *
 * @param annotationType the annotation type to check.
 *//*w  ww .j  a  va2  s .  c o  m*/
public static void checkForRuntimeRetention(Class<? extends Annotation> annotationType) {
    Retention retention = annotationType.getAnnotation(Retention.class);
    checkArgument(((retention != null) && (retention.value() == RetentionPolicy.RUNTIME)),
            "Annotation %s is missing RUNTIME retention", annotationType.getSimpleName());
}

From source file:blue.lapis.pore.converter.type.TypeConverterTest.java

@BeforeClass
public static void initializeCatalogs() throws Exception {
    for (ClassPath.ClassInfo info : PoreTests.getClassPath().getTopLevelClassesRecursive(API_PACKAGE)) {
        Class<?> loaded = info.load();
        CatalogedBy catalogedBy = loaded.getAnnotation(CatalogedBy.class);
        if (catalogedBy != null) {
            PoreTests.setConstants(catalogedBy.value());
        }/*from w  w w  . ja  v  a 2  s.c o  m*/
    }
}

From source file:org.fingerprintsoft.vitunit.test.VitUnitTestCase.java

protected static DataSource loadDatasource(final Class<? extends VitUnitTestCase> clazz) {

    DataSourceConfiguration annotation = clazz.getAnnotation(DataSourceConfiguration.class);

    String jdbcPropertiesFile = annotation.jdbcPropertiesFile();
    InputStream resourceAsStream = clazz.getClassLoader().getResourceAsStream(jdbcPropertiesFile);
    Properties properties = new Properties();
    try {//from  w ww .ja  v  a  2s .c  o m
        properties.load(resourceAsStream);
    } catch (IOException e) {
        throw new SetupException("Could not load properties.", e);
    }

    try {
        return BasicDataSourceFactory.createDataSource(properties);
    } catch (Exception e) {
        throw new SetupException("Could not create datasource.", e);
    }
}