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:io.gumga.application.GumgaUntypedRepository.java

/**
 * Fazer a pesquisa com os atributos que esto anotados com {@link org.hibernate.search.annotations.Field}
 * @param text//  ww w . j a v  a 2  s .c om
 * @return dados da pesquisa
 */
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();
        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:me.ronghai.sa.model.ModelMeta.java

public ModelMeta(Class<T> clazz) {
    this.clazz = clazz;
    this.columnFields = new HashMap<>();
    this.field2Setter = new HashMap<>();
    this.field2Getter = new HashMap<>();
    Map<String, PropertyDescriptor> fieldName2PropertyDescriptor = ReflectUtils
            .findFieldName2PropertyDescriptor(clazz);

    List<Field> cf = ReflectUtils.getDeclaredFields((List<Field>) null, clazz, false);
    for (Field field : cf) {
        if (field.isAnnotationPresent(Column.class)) {
            Column annotation = (Column) field.getAnnotation(Column.class);
            String cname;/*w  w  w.  j  a  v  a2  s  .  co m*/
            if (annotation != null && org.apache.commons.lang.StringUtils.isNotEmpty(annotation.name())) {
                cname = annotation.name();
                cname = cname.replaceAll("[\\[\\]]", "`");
            } else {
                cname = field.getName();
            }
            this.columnFields.put(cname, field);
            this.field2Getter.put(field.getName(),
                    ReflectUtils.findGetter(this.clazz, field, fieldName2PropertyDescriptor, null));

            this.field2Setter.put(field.getName(),
                    ReflectUtils.findSetter(this.clazz, field, fieldName2PropertyDescriptor, null));
        }
    }
}

From source file:net.larry1123.elec.util.config.ConfigFile.java

/**
 * Will search Class and super Classes to find fields for use and add them to our known field list.
 *
 * @param config    The Object to use to search
 * @param lastClass Mostly an internal PlaceHolder
 *//*from w  ww  .  ja v  a  2s  . c  om*/
protected void collectFields(ConfigBase config, Class lastClass) {
    Class currentClass = lastClass == null ? config.getClass() : lastClass.getSuperclass();
    for (Field field : currentClass.getDeclaredFields()) {
        if (field.isAnnotationPresent(ConfigField.class)) {
            configFields = ArrayUtils.add(configFields, field);
        }
    }
    if (currentClass.getSuperclass() != null) {
        collectFields(config, currentClass);
    }
}

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

private boolean checkField(Field field, Class<?> type) {
    if (!field.isAnnotationPresent(Message.class)) {
        return false;
    }/*from   ww w . j a  va 2 s  . c om*/
    if (field.getType().equals(String.class)) {
        return true;
    }
    logger.warn("Field [" + type + "." + field.getName()
            + "] is not populated with message. Should be a String field.");
    return false;
}

From source file:py.una.pol.karaku.dao.entity.interceptors.CaseSensitiveInterceptor.java

@Override
public boolean interceptable(Operation op, Field f, Object bean) {

    if (op == Operation.DELETE || f.isAnnotationPresent(CaseSensitive.class)) {
        return false;
    }//from  w  w  w .  ja  va 2s .  c o m
    boolean interceptable = true;
    for (Annotation a : f.getAnnotations()) {
        if (a.annotationType().isAnnotationPresent(CaseSensitive.class)) {
            interceptable = false;
            break;
        }
    }

    return interceptable;
}

From source file:py.una.pol.karaku.util.KarakuConverter.java

private Object getIdValue(Object obj) {

    try {/*from w  w  w  . j av  a 2 s  .c o m*/
        for (Field field : obj.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(Id.class)) {
                field.setAccessible(true);
                Object data = field.get(obj);
                field.setAccessible(false);
                return data;
            }
        }
        return null;
    } catch (Exception ex) {
        log.error("Error al obtener el Id", ex);
        return null;
    }
}

From source file:com.cognifide.slice.persistence.impl.serializer.RecursiveSerializer.java

private void serializeObject(Resource parent, String childName, Object object, SerializerContext ctx)
        throws PersistenceException {
    Resource child = parent.getChild(childName);
    if (child == null) {
        child = parent.getResourceResolver().create(parent, childName, ctx.getInitialProperties());
    }/*w  ww.j  av  a2 s .  c  om*/
    for (final Field field : object.getClass().getDeclaredFields()) {
        if (!field.isAnnotationPresent(JcrProperty.class)) {
            continue;
        }

        final String propertyName = retrievePropertyName(field);
        field.setAccessible(true);
        Object fieldValue;
        try {
            fieldValue = field.get(object);
        } catch (IllegalAccessException e) {
            throw new PersistenceException("Can't get field", e);
        }

        ctx.getFacade().serializeField(field, propertyName, fieldValue, child, ctx);
    }
}

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

/**
 * Gets the valid jpa column.//w w w  . j  av a 2 s  . co  m
 * 
 * @param entity
 *            the entity
 * @param f
 *            the f
 * 
 * @return the valid jpa column
 */
protected final String getValidJPAColumnName(Class<?> entity, Field f) {

    String name = null;

    if (f.isAnnotationPresent(Column.class)) {
        Column c = f.getAnnotation(Column.class);
        if (!c.name().isEmpty()) {
            name = c.name();
        } else {
            name = f.getName();
        }
    } else if (f.isAnnotationPresent(Basic.class)) {
        name = f.getName();
    }

    if (f.isAnnotationPresent(Temporal.class)) {
        if (!f.getType().equals(Date.class)) {
            log.error("@Temporal must map to java.util.Date for @Entity(" + entity.getName() + "." + f.getName()
                    + ")");
            return name;
        }
        if (null == name) {
            name = f.getName();
        }
    }
    return name;
}

From source file:com.pamarin.income.lazyload.LazyLoad.java

private Object getIdOfInstance(Object instance) {
    Object instanceId = null;// w  ww.j a  va  2 s. c o m
    try {
        Class instanceClass = instance.getClass();
        Field[] fields = instanceClass.getDeclaredFields();
        Field idField = null;
        for (Field field : fields) {
            if (field.isAnnotationPresent(Id.class)) {
                idField = field;
                break;
            }
        }

        if (idField != null) {
            String idName = idField.getName();
            idName = idName.substring(0, 1).toUpperCase() + idName.substring(1);
            Method method = instanceClass.getDeclaredMethod("get" + idName);
            instanceId = method.invoke(instance);
        }
    } catch (Exception ex) {
        LOG.warn(null, ex);
    }

    return instanceId;
}

From source file:ro.pippo.spring.AnnotationFieldValueProvider.java

@Override
public boolean supportsField(Field field) {
    return field.isAnnotationPresent(Inject.class);
}