Example usage for java.lang.reflect Modifier isTransient

List of usage examples for java.lang.reflect Modifier isTransient

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isTransient.

Prototype

public static boolean isTransient(int mod) 

Source Link

Document

Return true if the integer argument includes the transient modifier, false otherwise.

Usage

From source file:org.apache.flink.api.java.typeutils.TypeExtractor.java

/**
 * Recursively determine all declared fields
 * This is required because class.getFields() is not returning fields defined
 * in parent classes./*from   w ww .  j a  v a 2 s . c om*/
 *
 * @param clazz class to be analyzed
 * @param ignoreDuplicates if true, in case of duplicate field names only the lowest one
 *                            in a hierarchy will be returned; throws an exception otherwise
 * @return list of fields
 */
@PublicEvolving
public static List<Field> getAllDeclaredFields(Class<?> clazz, boolean ignoreDuplicates) {
    List<Field> result = new ArrayList<Field>();
    while (clazz != null) {
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
                continue; // we have no use for transient or static fields
            }
            if (hasFieldWithSameName(field.getName(), result)) {
                if (ignoreDuplicates) {
                    continue;
                } else {
                    throw new InvalidTypesException(
                            "The field " + field + " is already contained in the hierarchy of the " + clazz
                                    + "." + "Please use unique field names through your classes hierarchy");
                }
            }
            result.add(field);
        }
        clazz = clazz.getSuperclass();
    }
    return result;
}

From source file:org.vulpe.controller.AbstractVulpeBaseController.java

/**
 * Method to repair cached classes used by entity.
 *
 * @param entity// w ww .j ava  2 s .c  o m
 * @return Entity with cached values reloaded
 */
protected ENTITY repairCachedClasses(final ENTITY entity) {
    final List<Field> fields = VulpeReflectUtil.getFields(entity.getClass());
    for (final Field field : fields) {
        if (VulpeEntity.class.isAssignableFrom(field.getType())) {
            try {
                final VulpeEntity<ID> value = (VulpeEntity<ID>) PropertyUtils.getProperty(entity,
                        field.getName());
                if (VulpeValidationUtil.isNotEmpty(value) && !Modifier.isTransient(field.getModifiers())
                        && value.getClass().isAnnotationPresent(CachedClass.class)) {
                    final List<ENTITY> cachedList = vulpe.cache().classes()
                            .getAuto(value.getClass().getSimpleName());
                    if (VulpeValidationUtil.isNotEmpty(cachedList)) {
                        for (final ENTITY cached : cachedList) {
                            if (cached.getId().equals(value.getId())) {
                                PropertyUtils.setProperty(entity, field.getName(), cached);
                                break;
                            }
                        }
                    }
                }
            } catch (IllegalAccessException e) {
                LOG.error(e.getMessage());
            } catch (InvocationTargetException e) {
                LOG.error(e.getMessage());
            } catch (NoSuchMethodException e) {
                LOG.error(e.getMessage());
            }
        }
    }
    return entity;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.UploadTable.java

private Vector<Method> getGetters() {
    Method[] methods = tblClass.getMethods();
    Vector<Method> result = new Vector<Method>();
    for (Method m : methods) {
        if (m.getName().startsWith("get") && m.getParameterTypes().length == 0
                && m.getReturnType() != void.class && Modifier.isPublic(m.getModifiers())
                && !Modifier.isTransient(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())
                && !Modifier.isAbstract(m.getModifiers())) {
            Annotation jc = m.getAnnotation(javax.persistence.Column.class);
            Annotation c = m.getAnnotation(javax.persistence.JoinColumn.class);
            Annotation otm = m.getAnnotation(javax.persistence.OneToMany.class);
            if (otm == null && (jc != null || c != null || m.getName().equalsIgnoreCase("getId"))) {
                result.add(m);/*www  .j  a v  a 2 s.c o m*/
            }

        }
    }
    return result;
}