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.impetus.kundera.metadata.processor.DocumentProcessor.java

@Override
public void process(Class<?> clazz, EntityMetadata metadata) {
    if (!clazz.isAnnotationPresent(Document.class)) {
        return;//  w w  w .  j ava 2 s  .  co  m
    }

    LOG.debug("Processing @Entity(" + clazz.getName() + ") for Document.");

    metadata.setType(EntityMetadata.Type.DOCUMENT);

    Document coll = clazz.getAnnotation(Document.class);

    // set columnFamily
    //Name of collection for document based datastore
    metadata.setColumnFamilyName(coll.name());

    // set keyspace
    //DB name for document based datastore
    String keyspace = coll.db().length() != 0 ? coll.db() : em.getKeyspace();
    metadata.setKeyspaceName(keyspace);

    // scan for fields
    for (Field f : clazz.getDeclaredFields()) {

        // if @Id
        if (f.isAnnotationPresent(Id.class)) {
            LOG.debug(f.getName() + " => Id");
            metadata.setIdProperty(f);
            populateIdAccessorMethods(metadata, clazz, f);
            populateIdColumn(metadata, clazz, f);
        }

        // if any valid JPA annotation?
        else {
            String name = getValidJPAColumnName(clazz, f);
            if (null != name) {
                metadata.addColumn(name, metadata.new Column(name, f));
            }
        }
    }
}

From source file:com.google.code.rees.scope.spring.SpringConversationArbitrator.java

@Override
protected Set<Class<?>> getConversationControllers(Class<?> clazz) {
    Set<Class<?>> annotatedClasses = new HashSet<Class<?>>();
    for (Class<?> clazzClass : clazz.getInterfaces()) {
        if (clazzClass.isAnnotationPresent(ConversationController.class) || clazzClass
                .isAnnotationPresent(com.google.code.rees.scope.spring.ConversationController.class)) {
            annotatedClasses.add(clazzClass);
        }/* ww w  .j  a v  a2s.  com*/
    }
    if (clazz.isAnnotationPresent(ConversationController.class)
            || clazz.isAnnotationPresent(com.google.code.rees.scope.spring.ConversationController.class)) {
        annotatedClasses.add(clazz);
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        annotatedClasses.addAll(getConversationControllers(superClass));
    }
    return annotatedClasses;
}

From source file:com.impetus.kundera.metadata.processor.ColumnFamilyProcessor.java

@Override
public final void process(Class<?> clazz, EntityMetadata metadata) {

    if (!clazz.isAnnotationPresent(ColumnFamily.class)) {
        return;/*from   w  ww.  j  a v a2 s .c  o  m*/
    }

    LOG.debug("Processing @Entity(" + clazz.getName() + ") for ColumnFamily.");

    metadata.setType(EntityMetadata.Type.COLUMN_FAMILY);

    ColumnFamily cf = clazz.getAnnotation(ColumnFamily.class);

    // set columnFamily
    metadata.setColumnFamilyName(cf.family());

    // set keyspace
    String keyspace = cf.keyspace().length() != 0 ? cf.keyspace() : em.getKeyspace();
    metadata.setKeyspaceName(keyspace);

    // scan for fields
    for (Field f : clazz.getDeclaredFields()) {

        // if @Id
        if (f.isAnnotationPresent(Id.class)) {
            LOG.debug(f.getName() + " => Id");
            metadata.setIdProperty(f);
            populateIdAccessorMethods(metadata, clazz, f);
        }

        // if any valid JPA annotation?
        else {
            String name = getValidJPAColumnName(clazz, f);
            if (null != name) {
                metadata.addColumn(name, metadata.new Column(name, f));
            }
        }
    }
}

From source file:io.gumga.application.GumgaUntypedRepository.java

/**
 * Pegar as entidades que esto anotadas com {@link Indexed}
 * @return dados da pesquisa/*from w  w  w .jav  a  2  s  .  c  om*/
 */
private List<Class> getAllIndexedEntities() {
    List<Class> aRetornar = new ArrayList<>();
    Session session = em.unwrap(Session.class);
    SessionFactory sessionFactory = session.getSessionFactory();
    Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata();
    for (String k : map.keySet()) {
        Class mappedClass = map.get(k).getMappedClass();
        if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) {
            aRetornar.add(mappedClass);
        }
    }
    return aRetornar;
}

From source file:fr.exanpe.t5.lib.internal.authorize.AuthorizePageFilter.java

/**
 * Return the {@link Authorize} annotation if found
 * /*from  w  w  w.  j  a  v a  2 s. c om*/
 * @param clazz the class to look for
 * @return the annotation, or null
 */
private Authorize process(Class<?> clazz) {
    if (!clazz.isAnnotationPresent(Authorize.class)) {
        return null;
    }

    return clazz.getAnnotation(Authorize.class);
}

From source file:gov.nih.nci.indexgen.IndexGenerator.java

/**
 * Returns the set of classes (EntityPersisters) with the Indexed annotation.
 *//*from w  w w . jav  a2s .  c om*/
public Set<EntityPersister> getIndexedClasses() throws Exception {

    Map metadata = sessionFactory.getAllClassMetadata();
    Set<EntityPersister> classSet = new HashSet<EntityPersister>();
    for (Iterator i = metadata.values().iterator(); i.hasNext();) {
        EntityPersister persister = (EntityPersister) i.next();
        Class clazz = Class.forName(persister.getEntityName());
        if (clazz.isAnnotationPresent(Indexed.class)) {
            classSet.add(persister);
        }
    }
    return classSet;
}

From source file:net.ymate.platform.mvc.support.impl.ControllerBeanFactory.java

public IBeanMeta add(Class<?> clazz) {
    if (clazz.isAnnotationPresent(Controller.class)) {
        IBeanMetaLoader _loader = this.getBeanMetaLoader(clazz);
        for (IBeanMeta _meta : _loader.loadBeanMetas()) {
            if (!this.beanMap.containsKey(_meta.getClassName())) {
                _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.add_controller",
                        _meta.getClassName()));
                this.beanMetaList.add(_meta);
                this.addBeanMeta(_meta);
                return _meta;
            }//from w  w  w  . ja  v  a  2s.c  om
        }
    } else if (ClassUtils.isInterfaceOf(clazz, IFilter.class)) {
        IBeanMetaLoader _loader = new AnnotationBeanMetaLoader<Bean>(Bean.class, clazz);
        for (IBeanMeta _meta : _loader.loadBeanMetas()) {
            if (!this.beanMap.containsKey(_meta.getClassName())) {
                _LOG.info(I18N.formatMessage(YMP.__LSTRING_FILE, null, null, "ymp.mvc.add_filter",
                        _meta.getClassName()));
                this.beanMetaList.add(_meta);
                this.addBeanMeta(_meta);
                return _meta;
            }
        }
    }
    return null;
}

From source file:com.jroossien.boxx.nms.NMS.java

public <T> Object loadFromNMS(Class<T> dep, Object... objects) {
    if (!dep.isAnnotationPresent(NMSDependant.class))
        return null;
    NMSDependant nmsDependant = dep.getAnnotation(NMSDependant.class);
    Class<?> impl = null;//from w w w  . j a  v a2 s  .co m
    try {
        impl = Class.forName(nmsDependant.implementationPath() + "." + dep.getSimpleName() + "_" + version);
        return ConstructorUtils.invokeConstructor(impl, objects);
    } catch (ClassNotFoundException e) {
        Boxx.get().error("The current version is not supported: " + version + ".\n" + e.getMessage());
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
            | InvocationTargetException e) {
        e.printStackTrace();
    }
    return impl;
}

From source file:de.hybris.platform.webservices.util.objectgraphtransformer.impl.DefaultNodeConfig.java

public DefaultNodeConfig(final Class<?> type) {
    super();/*from   w w  w.jav a2s .co m*/
    this.type = type;

    if (type.isAnnotationPresent(GraphNode.class)) {
        final GraphNode cfg = type.getAnnotation(GraphNode.class);
        if (cfg.uidProperties().trim().length() > 0) {
            setUidPropertyNames(cfg.uidProperties());
        }
    }
}

From source file:org.sakaiproject.resteasy.DefaultJsonProvider.java

/**
 * {@inheritDoc}/*from w  ww.j a va2  s  .  c o  m*/
 *
 * @see javax.ws.rs.ext.MessageBodyWriter#isWriteable(java.lang.Class,
 *      java.lang.reflect.Type, java.lang.annotation.Annotation[],
 *      javax.ws.rs.core.MediaType)
 */
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return !type.isAnnotationPresent(XmlRootElement.class);
}