Example usage for java.lang Class isAnnotationPresent

List of usage examples for java.lang Class isAnnotationPresent

Introduction

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

Prototype

@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) 

Source Link

Usage

From source file:com.cloudera.nav.sdk.client.writer.registry.MClassRegistry.java

/**
 * Get the @MProperty annotation information from a given class
 * @param aClass//from w  w  w  .  j  a  v a2 s  .  c  o m
 * @return
 */
public Collection<MPropertyEntry> getProperties(Class<?> aClass) {
    Preconditions
            .checkArgument(Relation.class.isAssignableFrom(aClass) || aClass.isAnnotationPresent(MClass.class));
    try {
        return propertyRegistry.get(aClass);
    } catch (ExecutionException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.gradle.model.internal.manage.schema.extraction.ModelSchemaExtractor.java

public boolean isManaged(Class<?> type) {
    return type.isAnnotationPresent(Managed.class);
}

From source file:org.springframework.data.repository.cdi.CdiRepositoryExtensionSupport.java

/**
 * Determines the qualifiers of the given type.
 *///w  w  w.  j  av a 2s .  co m
@SuppressWarnings("serial")
private Set<Annotation> getQualifiers(final Class<?> type) {

    Set<Annotation> qualifiers = new HashSet<Annotation>();
    Annotation[] annotations = type.getAnnotations();
    for (Annotation annotation : annotations) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        if (annotationType.isAnnotationPresent(Qualifier.class)) {
            qualifiers.add(annotation);
        }
    }
    // Add @Default qualifier if no qualifier is specified.
    if (qualifiers.isEmpty()) {
        qualifiers.add(new AnnotationLiteral<Default>() {
        });
    }
    // Add @Any qualifier.
    qualifiers.add(new AnnotationLiteral<Any>() {
    });
    return qualifiers;
}

From source file:org.jasig.portlet.courses.dao.xml.Jaxb2CourseSummaryHttpMessageConverter.java

@Override
public boolean canRead(Class<?> clazz, MediaType mediaType) {
    return (clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class)
            || clazz.getPackage().equals(CourseSummaryWrapper.class.getPackage())) && isSupported(mediaType);
}

From source file:net.kamhon.ieagle.orm.hibernate.HAnnotationSessionFactoryBean.java

public void setAnnotatationOrHbmXmlPackagePattern(String[] patterns) {

    List<Class<?>> annotationClasses = new ArrayList<Class<?>>();
    List<String> hbmXmlFiles = new ArrayList<String>();

    try {/*from w  w w.  j av  a  2s .  co m*/
        for (String pattern : patterns) {
            Set<String> filePaths = ReflectionUtil.findFileNames(pattern.substring(0, pattern.indexOf("\\")),
                    true, pattern, ".class", ".hbm.xml");

            for (String filePath : filePaths) {

                if (filePath.endsWith(".class")) {
                    try {

                        Class<?> clazz = Class.forName(filePath.substring(0, filePath.indexOf(".class")));
                        if (clazz.isAnnotationPresent(Entity.class)) {

                            annotationClasses.add(clazz);
                            log.info("<mapping class=\"" + clazz.toString() + "\" />");

                        }

                    } catch (Exception e) {
                        log.debug("Class can't be loaded for hibernate mapping = " + filePath);
                    }

                } else if (filePath.endsWith(".hbm.xml")) {

                    filePath = filePath.replaceAll("\\.", "\\\\");
                    filePath = filePath.replaceAll("\\\\hbm\\\\xml", ".hbm.xml");
                    hbmXmlFiles.add(filePath);
                    log.info("Hibernate hbm.xml mapping file: " + filePath);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    log.info((annotationClasses.size() + hbmXmlFiles.size()) + " hibernate mapping file.");
    setAnnotatedClasses(annotationClasses.toArray(new Class[] {}));
    setMappingResources(hbmXmlFiles.toArray(new String[0]));
}

From source file:org.openmrs.web.dwr.DeprecationCheckTest.java

/**
 * For the given class, checks if it contains any {@literal @}Deprecated annotation (at method/class level).
 * @param metadataReader/*  w  w w .  j a v a 2 s  .c  om*/
 * @return true if it finds {@literal @}Deprecated annotation in the class or any of its methods.
 * @throws ClassNotFoundException
 */
private boolean doesClassContainDeprecatedAnnotation(MetadataReader metadataReader)
        throws ClassNotFoundException {
    try {
        Class dwrClass = Class.forName(metadataReader.getClassMetadata().getClassName());

        if (dwrClass.isAnnotationPresent(Deprecated.class)) {
            return true;
        }

        Method[] methods = dwrClass.getDeclaredMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(Deprecated.class))
                return true;
        }
    } catch (Throwable e) {
    }
    return false;
}

From source file:com.terremark.handlers.BasicAuthenticationHandler.java

/**
 * Method invoked in the chain. If the request entity class is not annotated with
 * {@link com.terremark.annotations.AuthenticationNotRequired AuthenticationNotRequired} this method will add the
 * {@code Authorization} header.// www.j ava 2  s .  c om
 *
 * @param request Client request.
 * @param context Request context.
 * @return Client response.
 * @throws Exception If there is a problem invoking the chain.
 */
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public final ClientResponse handle(final ClientRequest request, final HandlerContext context) throws Exception {
    final Class<?> responseEntityClass = (Class<?>) request.getAttributes()
            .get(ClientRequestImpl.RESPONSE_ENTITY_CLASS_TYPE);
    if (!responseEntityClass.isAnnotationPresent(AuthenticationNotRequired.class)) {
        request.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, authHeader);
    }

    return context.doChain(request);
}

From source file:com.github.tddts.jet.view.fx.spring.DialogProvider.java

private <T extends Dialog<?>> T createDialog(Class<T> type) {

    if (!type.isAnnotationPresent(FxDialog.class)) {
        throw new DialogException("Dialog class should have a @FxDialog annotation!");
    }/*from  w ww.  j av a2  s . com*/

    FxDialog dialogAnnotation = type.getDeclaredAnnotation(FxDialog.class);
    T dialog = getDialog(type, dialogAnnotation);

    fxBeanWirer.initBean(dialog);
    dialogCache.put(type, dialog);

    return dialog;
}

From source file:com.github.lightdocs.ModelBuilder.java

/**
 * @param cls//from  w w w .  j a va  2  s  .com
 *            required
 * @return true if there is any Path or GET/POST/etc annotation.
 */
private boolean hasPathAnnotation(Class<?> cls) {
    if (cls.isAnnotationPresent(Path.class)) {
        return true;
    } else {
        for (Method m : cls.getMethods()) {
            if (m.isAnnotationPresent(Path.class)) {
                return true;
            }
        }
        return false;
    }
}

From source file:org.openspotlight.graph.internal.NodeAndLinkSupport.java

public static boolean isMetanode(final Class<? extends Node> clazz) {
    return clazz.isAnnotationPresent(IsMetaType.class);
}