Example usage for java.lang.reflect Field isAnnotationPresent

List of usage examples for java.lang.reflect Field isAnnotationPresent

Introduction

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

Prototype

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

Source Link

Usage

From source file:main.okapi.cf.annotations.AnnotationsInfo.java

public JSONObject getInfo() throws ClassNotFoundException, IOException, JSONException {
    JSONObject obj = new JSONObject();
    ArrayList<JSONObject> cl = new ArrayList<JSONObject>();
    Iterable<Class> classes = getClasses(this.topPackage);
    for (Class c : classes) {
        JSONObject forClass = new JSONObject();
        if (c.getAnnotations().length > 0) {

            ArrayList<JSONObject> parameters = new ArrayList<JSONObject>();
            for (Field field : c.getDeclaredFields()) {
                if (field.isAnnotationPresent(HyperParameter.class)) {
                    HyperParameter hp = field.getAnnotation(HyperParameter.class);
                    JSONObject parJSON = new JSONObject();
                    parJSON.put("parameterName", hp.parameterName());
                    parJSON.put("defaultValue", hp.defaultValue());
                    parJSON.put("minimumValue", hp.minimumValue());
                    parJSON.put("maximumValue", hp.maximumValue());
                    parameters.add(parJSON);
                }//from   w w w  .j a v a  2  s. c om
            }
            JSONObject method = new JSONObject();
            method.put("hyperParameters", parameters);
            method.put("class", c.getCanonicalName());
            cl.add(method);
        }
    }
    obj.put("methods", cl);
    return obj;
}

From source file:org.broadinstitute.sting.commandline.ArgumentTypeDescriptor.java

/**
 * Returns true if an argument annotation is present
 * @param field The field to check for an annotation.
 * @return True if an argument annotation is present on the field.
 *///from  ww  w. j  av  a  2 s .  c o  m
@SuppressWarnings("unchecked")
public static boolean isArgumentAnnotationPresent(Field field) {
    for (Class annotation : ARGUMENT_ANNOTATIONS)
        if (field.isAnnotationPresent(annotation))
            return true;
    return false;
}

From source file:org.appverse.web.framework.backend.api.helpers.log.AutowiredLoggerBeanPostProcessor.java

@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {
    ReflectionUtils.doWithFields(bean.getClass(), new ReflectionUtils.FieldCallback() {

        @Override//from  w  ww  .jav a2s.c  o m
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            if (field.isAnnotationPresent(AutowiredLogger.class)) {
                field.setAccessible(true);
                field.set(bean, LoggerFactory.getLogger(bean.getClass()));
            }

        }
    });
    return bean;
}

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

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

    metadata.setIndexName(clazz.getSimpleName());

    Index idx = clazz.getAnnotation(Index.class);
    if (null != idx) {
        boolean isIndexable = idx.index();
        metadata.setIndexable(isIndexable);

        if (!isIndexable) {
            log.debug("@Entity " + clazz.getName() + " will not be indexed.");
            return;
        }//from  w  ww  .  j  a v a 2  s  .c  om
    }

    log.debug("Processing @Entity " + clazz.getName() + " for Indexes.");

    // scan for fields
    for (Field f : clazz.getDeclaredFields()) {
        if (f.isAnnotationPresent(Column.class)) {
            Column c = f.getAnnotation(Column.class);
            String alias = c.name().trim();
            if (alias.isEmpty()) {
                alias = f.getName();
            }

            metadata.addIndexProperty(metadata.new PropertyIndex(f, alias));

        } else if (f.isAnnotationPresent(Id.class)) {
            metadata.addIndexProperty(metadata.new PropertyIndex(f, f.getName()));
        }
    }
}

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

public List<Object> fullTextSearch(String text) {
    List aRetornar = new ArrayList();

    for (Class entidade : getAllIndexedEntities()) {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
        QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(entidade)
                .get();/*ww w.  java  2 s.c om*/
        String atributos = "";
        List<Field> todosAtributos = getTodosAtributos(entidade);
        for (Field f : todosAtributos) {
            if (f.isAnnotationPresent(org.hibernate.search.annotations.Field.class)) {
                atributos += f.getName() + ",";
            }
        }
        if (!atributos.isEmpty()) {
            atributos = atributos.substring(0, atributos.length() - 1);
            Query query = qb.keyword().onFields(atributos.split(",")).matching(text).createQuery();
            aRetornar.addAll(fullTextEntityManager.createFullTextQuery(query, entidade).getResultList());
        }
    }
    return aRetornar;
}

From source file:org.excalibur.service.deployment.server.context.handler.CreateNodeManagerHandler.java

private void configure(NodeManager manager, ApplicationContext context) {
    Mirror mirror = new Mirror();

    for (Field field : manager.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(Autowired.class)) {
            mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
        } else if (field.isAnnotationPresent(Resource.class)) {
            Resource resource = field.getAnnotation(Resource.class);
            if (!isNullOrEmpty(resource.name())) {
                mirror.on(manager).set().field(field).withValue(context.getBean(resource.name()));
            } else {
                mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
            }/*from w  w w .  j a  v  a2s  . c om*/
        }
    }
}

From source file:com.github.tddts.jet.config.spring.postprocessor.LoadContentAnnotationBeanPostProcessor.java

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    Pair<Class<?>, Object> typeObjectPair = SpringUtil.checkForDinamicProxy(bean);
    Class<?> type = typeObjectPair.getLeft();
    Object target = typeObjectPair.getRight();

    try {//from   w  ww .jav  a2 s .  c  o m

        for (Field field : type.getDeclaredFields()) {
            if (field.isAnnotationPresent(LoadContent.class) && String.class.equals(field.getType())) {

                field.setAccessible(true);
                String fileName = getFileName(target, field);

                if (!StringUtils.isEmpty(fileName)) {
                    field.set(target, Util.loadContent(fileName));
                }
            }
        }
    } catch (Exception e) {
        throw new BeanInitializationException(e.getMessage(), e);
    }

    return bean;
}

From source file:org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext.java

@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {

    boolean hasHashKey = false;
    boolean hasRangeKey = false;
    for (Method method : type.getType().getMethods()) {
        if (method.isAnnotationPresent(DynamoDBHashKey.class))
            hasHashKey = true;/* w  ww .j  a v a 2 s. c o m*/
        if (method.isAnnotationPresent(DynamoDBRangeKey.class))
            hasRangeKey = true;

    }
    for (Field field : type.getType().getFields()) {
        if (field.isAnnotationPresent(DynamoDBHashKey.class))
            hasHashKey = true;
        if (field.isAnnotationPresent(DynamoDBRangeKey.class))
            hasRangeKey = true;

    }
    return type.getType().isAnnotationPresent(DynamoDBTable.class) || (hasHashKey && hasRangeKey);
}

From source file:net.kamhon.ieagle.vo.ORWrapper.java

private String getDbColumn(Field field) {
    if (field.isAnnotationPresent(Column.class)) {
        Column column = field.getAnnotation(Column.class);
        return column.name();
    } else {/*from ww  w.j ava  2s .  co m*/
        return null;
    }
}

From source file:com.googlesource.gerrit.plugins.rabbitmq.config.AMQProperties.java

public AMQProperties(PluginProperties properties) {
    this.message = properties.getSection(Message.class);
    this.headers = new HashMap<>();
    for (Section section : properties.getSections()) {
        for (Field f : section.getClass().getFields()) {
            if (f.isAnnotationPresent(MessageHeader.class)) {
                MessageHeader mh = f.getAnnotation(MessageHeader.class);
                try {
                    Object value = f.get(section);
                    if (value == null) {
                        continue;
                    }//from   w  ww . j a  va2 s . co m
                    switch (f.getType().getSimpleName()) {
                    case "String":
                        headers.put(mh.value(), value.toString());
                        break;
                    case "Integer":
                        headers.put(mh.value(), Integer.valueOf(value.toString()));
                        break;
                    case "Long":
                        headers.put(mh.value(), Long.valueOf(value.toString()));
                        break;
                    case "Boolean":
                        headers.put(mh.value(), Boolean.valueOf(value.toString()));
                        break;
                    default:
                        break;
                    }
                } catch (IllegalAccessException | IllegalArgumentException ex) {
                    LOGGER.warn("Cannot access field {}. Cause: {}", f.getName(), ex.getMessage());
                }
            }
        }
    }
}