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:com.sonatype.security.ldap.api.DeepEqualsBuilder.java

private static void reflectionAppend(Object lhs, Object rhs, Class clazz, EqualsBuilder builder,
        boolean useTransients, String[] excludeFields) {
    while (clazz.getSuperclass() != null) {

        Field[] fields = clazz.getDeclaredFields();
        List excludedFieldList = excludeFields != null ? Arrays.asList(excludeFields) : Collections.EMPTY_LIST;
        AccessibleObject.setAccessible(fields, true);
        for (int i = 0; i < fields.length && builder.isEquals(); i++) {
            Field f = fields[i];/*from w w  w  .j a  v  a  2s  . c  o  m*/
            if (!excludedFieldList.contains(f.getName()) && (f.getName().indexOf('$') == -1)
                    && (useTransients || !Modifier.isTransient(f.getModifiers()))
                    && (!Modifier.isStatic(f.getModifiers()))) {
                try {
                    Object lhsChild = f.get(lhs);
                    Object rhsChild = f.get(rhs);
                    Class testClass = getTestClass(lhsChild, rhsChild);
                    boolean hasEqualsMethod = classHasEqualsMethod(testClass);

                    if (testClass != null && !hasEqualsMethod) {
                        reflectionAppend(lhsChild, rhsChild, testClass, builder, useTransients, excludeFields);
                    } else {
                        builder.append(lhsChild, rhsChild);
                    }
                } catch (IllegalAccessException e) {
                    // this can't happen. Would get a Security exception instead
                    // throw a runtime exception in case the impossible happens.
                    throw new InternalError("Unexpected IllegalAccessException");
                }
            }
        }

        // now for the parent
        clazz = clazz.getSuperclass();
        reflectionAppend(lhs, rhs, clazz, builder, useTransients, excludeFields);
    }
}

From source file:edu.brown.utils.ClassUtil.java

/**
 * @param clazz//w  w  w . j a v a 2s.c  o  m
 * @return
 */
public static <T> Field[] getFieldsByType(Class<?> clazz, Class<? extends T> fieldType) {
    List<Field> fields = new ArrayList<Field>();
    for (Field f : clazz.getDeclaredFields()) {
        int modifiers = f.getModifiers();
        if (Modifier.isTransient(modifiers) == false && Modifier.isPublic(modifiers) == true
                && Modifier.isStatic(modifiers) == false
                && ClassUtil.getSuperClasses(f.getType()).contains(fieldType)) {

            fields.add(f);
        }
    } // FOR
    return (fields.toArray(new Field[fields.size()]));
}

From source file:org.datalorax.populace.core.walk.field.StdRawField.java

/**
 * {@inheritDoc}
 */
@Override
public boolean isTransient() {
    return Modifier.isTransient(field.getModifiers());
}

From source file:com.ls.http.base.handler.MultipartRequestHandler.java

private void formMultipartEntityObject(Object source) {
    Class<?> currentClass = source.getClass();
    while (!Object.class.equals(currentClass)) {
        Field[] fields = currentClass.getDeclaredFields();
        for (int counter = 0; counter < fields.length; counter++) {
            Field field = fields[counter];
            Expose expose = field.getAnnotation(Expose.class);
            if (expose != null && !expose.deserialize() || Modifier.isTransient(field.getModifiers())) {
                continue;// We don't have to copy ignored fields.
            }/*from   w ww.  j a va  2  s . com*/
            field.setAccessible(true);
            Object value;

            String name;
            SerializedName serializableName = field.getAnnotation(SerializedName.class);
            if (serializableName != null) {
                name = serializableName.value();
            } else {
                name = field.getName();
            }
            try {
                value = field.get(source);
                addEntity(name, value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        currentClass = currentClass.getSuperclass();
    }
    httpentity = entity.build();
}

From source file:org.eclipse.skalli.core.persistence.EntityHelper.java

private static void doNormalize(EntityBase entity) {
    if (entity == null) {
        return;/*w w w .  j  av a 2s  .  c  om*/
    }
    Class<?> currentClass = entity.getClass();
    while (currentClass != null) {
        for (Field field : currentClass.getDeclaredFields()) {
            try {
                // do not try to change constants or transient fields
                int modifiers = field.getModifiers();
                if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)
                        || Modifier.isTransient(modifiers)) {
                    continue;
                }
                field.setAccessible(true);

                // ensure, thet the value is non null
                Object value = field.get(entity);
                if (value == null) {
                    instantiateField(entity, field);
                } else {
                    // for non-null collections or maps, ensure that there
                    // are no null entries or empty strings
                    Class<?> type = field.getType();
                    if (Collection.class.isAssignableFrom(type)) {
                        Collection<?> collection = (Collection<?>) value;
                        ArrayList<Object> remove = new ArrayList<Object>();
                        for (Object entry : collection) {
                            if (entry instanceof String && StringUtils.isBlank((String) entry)) {
                                remove.add(entry);
                            }
                        }
                        collection.removeAll(remove);
                        field.set(entity, collection);
                    } else if (Map.class.isAssignableFrom(type)) {
                        Map<?, ?> map = (Map<?, ?>) value;
                        ArrayList<Object> remove = new ArrayList<Object>();
                        for (Entry<?, ?> entry : map.entrySet()) {
                            if (entry.getValue() instanceof String
                                    && StringUtils.isBlank((String) entry.getValue())) {
                                remove.add(entry.getKey());
                            }
                        }
                        for (Object key : remove) {
                            map.remove(key);
                        }
                        field.set(entity, map);
                    }
                }
            } catch (UnsupportedOperationException e) {
                //  TODO exception handling/logging
                // some collections/map may not support remove
                throw new RuntimeException(e);
            } catch (IllegalArgumentException e) {
                //TODO exception handling/logging
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                //TODO exception handling/logging
                throw new RuntimeException(e);
            }
        }
        currentClass = currentClass.getSuperclass();
    }
}

From source file:org.objectpocket.references.ReferenceSupport.java

private List<Field> filterTransientFields(List<Field> fields) {
    List<Field> returnFields = new ArrayList<Field>(fields.size());
    for (Field field : fields) {
        if (!Modifier.isTransient(field.getModifiers())) {
            returnFields.add(field);/*w  w  w  .j  a va2s. c o  m*/
        }
    }
    return returnFields;
}

From source file:pl.bristleback.server.bristle.utils.PropertyUtils.java

private static boolean isPrivateField(Field field) {
    return !Modifier.isTransient(field.getModifiers()) && !Modifier.isStatic(field.getModifiers());
}

From source file:org.soyatec.windowsazure.internal.util.xml.AtomUtil.java

private static String convertToXml(String tableName, ITableServiceEntity entity) {
    StringBuilder sb = new StringBuilder();
    sb.append(MessageFormat.format("<content type=\"{0}\">", TableStorageConstants.ApplicationXml));
    sb.append("<m:properties>");
    sb.append(//from w ww  .  j  av a 2s  . c o  m
            MessageFormat.format("<d:PartitionKey>{0}</d:PartitionKey>", escapeXml(entity.getPartitionKey())));
    sb.append(MessageFormat.format("<d:RowKey>{0}</d:RowKey>", escapeXml(entity.getRowKey())));

    List<?> ignoreFields = Arrays.asList(new String[] { "rowKey", "partitionKey", "timestamp" });
    Class<?> clazz = entity.getClass();
    Field[] fields = clazz.getDeclaredFields();

    for (Field f : fields) {
        String name = f.getName();
        if (ignoreFields.contains(name)) {
            continue;
        }
        if (Modifier.isTransient(f.getModifiers()) || f.isSynthetic()) {
            continue;
        }
        sb.append(convertToXml(f, entity));
    }
    List<ICloudTableColumn> properties = entity.getValues();
    if (properties != null) {
        for (ICloudTableColumn key : properties) {
            sb.append(MessageFormat.format("<d:{0}>{1}</d:{0}>", key.getName(), escapeXml(key.getValue())));
        }
    }

    sb.append("<d:Timestamp m:type=\"Edm.DateTime\">" + Utilities.formatTimeStamp(entity.getTimestamp())
            + "</d:Timestamp>");
    sb.append("</m:properties></content>");
    return sb.toString();
}

From source file:com.happyblueduck.lembas.datastore.LembasEntity.java

/**
 * copies values from  lembasEntity to this entity. skip objectKey from that.
 * @param that/*from  w  ww .  j  a  v  a  2s . co m*/
 */
public void copy(LembasEntity that) {

    ArrayList<Field> fields = Lists.newArrayList(that.getClass().getFields());
    for (Field f : fields) {
        try {

            int modifiers = f.getModifiers();
            if (Modifier.isPrivate(modifiers))
                continue;
            if (Modifier.isStatic(modifiers))
                continue;
            if (Modifier.isTransient(modifiers))
                continue;
            if (Modifier.isFinal(modifiers))
                continue;
            if (Modifier.isVolatile(modifiers))
                continue;

            if (f.getName().equalsIgnoreCase(LembasUtil.objectKey))
                continue;

            Object value = f.get(that);
            if (value != null)
                this.setField(f, value);

        } catch (IllegalAccessException exception) {
            exception.printStackTrace();
        }
    }
}

From source file:org.jiemamy.utils.reflect.ModifierUtil.java

/**
 * {@code transient}????{@code true}?????????{@code false}??
 * /*from w w  w  . j av a 2s.c  o  m*/
 * @param field 
 * @return {@code transient}????{@code true}?????????{@code false}
 * @throws IllegalArgumentException ?{@code null}???
 */
public static boolean isTransient(Field field) {
    Validate.notNull(field);
    return Modifier.isTransient(field.getModifiers());
}