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:org.apache.aries.blueprint.plugin.model.Bean.java

public static String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    Named named = clazz.getAnnotation(Named.class);
    if (component != null && !"".equals(component.value())) {
        return component.value();
    } else if (named != null && !"".equals(named.value())) {
        return named.value();
    } else {//from  w  w w.  j  a  va  2s.com
        String name = clazz.getSimpleName();
        return getBeanNameFromSimpleName(name);
    }
}

From source file:com.intel.podm.client.typeidresolver.ResourceResolver.java

private static List<String> extractOdataTypes(Class clazz) {
    OdataTypes odataTypes = (OdataTypes) clazz.getAnnotation(OdataTypes.class);
    if (odataTypes == null) {
        throw new IllegalArgumentException(
                format("Provided class: %s should use %s annotation.", clazz, OdataTypes.class));
    }//from   w  ww  .  j  av  a 2 s . c o m

    return stream(odataTypes.value()).collect(toList());
}

From source file:com.nineteendrops.tracdrops.client.core.Utils.java

public static String findTracClassName(Class clazz) {

    TracClass annotationsForTracClass = (TracClass) clazz.getAnnotation(TracClass.class);

    return annotationsForTracClass == null ? null : annotationsForTracClass.tracClass();

}

From source file:com.nortal.petit.beanmapper.BeanMappingReflectionUtils.java

private static Column getAttributeOverride(Class<?> type, String name) {
    AttributeOverride ao = type.getAnnotation(AttributeOverride.class);
    if (ao != null) {
        if (ao.name().equals(name)) {
            return ao.column();
        }/*from   w  w w. j  ava 2  s .  c  om*/
    }

    AttributeOverrides aos = type.getAnnotation(AttributeOverrides.class);
    if (aos != null) {
        for (AttributeOverride a : aos.value()) {
            if (a.name().equals(name)) {
                return a.column();
            }
        }
    }

    return null;
}

From source file:com.khs.sherpa.util.Util.java

public static String getObjectName(Class<?> type) {
    String name = null;/*from   w  w  w  . jav a  2s . co m*/
    if (type.isAnnotationPresent(Endpoint.class)) {
        name = type.getAnnotation(Endpoint.class).value();
    }

    if (StringUtils.isEmpty(name)) {
        name = type.getSimpleName();
    }
    return name;
}

From source file:controllers.modules.opinionMiners.base.OpinionMiner.java

public static <T extends OpinionMiner> Class<? extends T> findSubMiner(String code, Class<T> minerBase) {
    for (Class<? extends T> subMiner : getSubMiners(minerBase)) {
        Coded coded = subMiner.getAnnotation(Coded.class);
        if (coded != null && StringUtils.equals(code, coded.value())) {
            return subMiner;
        }//from  w w  w .jav  a  2 s  .com
    }

    return null;
}

From source file:ch.ethz.inf.vs.hypermedia.client.Utils.java

public static <V> MediaType getMediaTypeAnnotation(Class<V> type) {
    return type.getAnnotation(MediaType.class);
}

From source file:com.haulmont.cuba.core.global.PersistenceHelper.java

/**
 * @param entityClass entity class//  ww w .  j  a v a2  s.  c  o m
 * @return entity name as defined in {@link javax.persistence.Entity} annotation
 */
public static String getEntityName(Class<?> entityClass) {
    Annotation annotation = entityClass.getAnnotation(javax.persistence.Entity.class);
    if (annotation == null)
        throw new IllegalArgumentException("Class " + entityClass + " is not a persistent entity");
    String name = ((javax.persistence.Entity) annotation).name();
    if (!StringUtils.isEmpty(name))
        return name;
    else
        return entityClass.getSimpleName();
}

From source file:net.sourceforge.jaulp.io.annotations.ImportResourcesUtils.java

/**
 * Gets a map with ImportResource objects and the corresponding to the found class from the
 * given package Name. The search is made recursive. The key from an entry of the map is the
 * class where the ImportResource objects found and the value is an Array of the ImportResource
 * objects that contains in the class./* w ww.ja  v  a 2s. co m*/
 * 
 * @param packageName
 *            the package name
 * @return the import resources
 * @throws ClassNotFoundException
 *             the class not found exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public static Map<Class<?>, ImportResource[]> getImportResources(String packageName)
        throws ClassNotFoundException, IOException {
    final Map<Class<?>, ImportResource[]> resourcesMap = new LinkedHashMap<>();

    final Class<ImportResources> importResourcesClass = ImportResources.class;
    final Class<ImportResource> importResourceClass = ImportResource.class;
    final Set<Class<?>> importResourcesClasses = AnnotationUtils.getAllAnnotatedClasses(packageName,
            importResourcesClass);
    final Set<Class<?>> importResourceClasses = AnnotationUtils.getAllAnnotatedClasses(packageName,
            importResourceClass);
    importResourcesClasses.addAll(importResourceClasses);
    for (Class<?> annotatedClass : importResourcesClasses) {
        final ImportResources importResources = annotatedClass.getAnnotation(ImportResources.class);
        ImportResource[] importResourcesArray = null;
        ImportResource[] importResourceArray = null;
        if (importResources != null) {
            importResourcesArray = importResources.resources();
        }

        final ImportResource importResource = annotatedClass.getAnnotation(ImportResource.class);
        if (importResource != null) {
            importResourceArray = new ImportResource[1];
            importResourceArray[0] = importResource;
        }
        ImportResource[] array = (ImportResource[]) ArrayUtils.addAll(importResourceArray,
                importResourcesArray);
        Arrays.sort(array, new ImportResourceComparator());
        resourcesMap.put(annotatedClass, array);

    }
    return resourcesMap;
}

From source file:com.adeptj.runtime.common.Servlets.java

private static WebServlet checkWebServletAnnotation(Class<? extends HttpServlet> cls) {
    return Optional.ofNullable(cls.getAnnotation(WebServlet.class)).orElseThrow(
            () -> new IllegalArgumentException("Can't register a servlet without @WebServlet annotation!!"));
}