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.projectforge.common.BeanHelper.java

/**
 * Gets all declared fields which are neither transient, static nor final.
 * @param clazz//from   w  ww .ja v a  2 s  . c om
 * @return
 */
public static Field[] getDeclaredPropertyFields(final Class<?> clazz) {
    final Field[] fields = getAllDeclaredFields(clazz);
    final List<Field> list = new ArrayList<Field>();
    for (final Field field : fields) {
        if (Modifier.isTransient(field.getModifiers()) == false
                && Modifier.isStatic(field.getModifiers()) == false
                && Modifier.isFinal(field.getModifiers()) == false) {
            list.add(field);
        }
    }
    final Field[] result = new Field[list.size()];
    list.toArray(result);
    return result;
}

From source file:com.fluidops.iwb.api.ProviderServiceImpl.java

protected void collectUserObjects(Object config, List<User> users) throws IOException {
    if (config == null)
        return;//from w ww .  j a v  a2  s. com

    if (config instanceof User)
        users.add((User) config);

    for (Field f : config.getClass().getFields()) {
        if (Modifier.isTransient(f.getModifiers()))
            continue;
        if (Modifier.isStatic(f.getModifiers()))
            continue;

        try {
            Object kid = f.get(config);
            if (kid instanceof Object[])
                for (Object item : (Object[]) kid)
                    collectUserObjects(item, users);
            else if (kid instanceof Collection)
                for (Object item : (Collection) kid)
                    collectUserObjects(item, users);
            else
                collectUserObjects(kid, users);
        } catch (Exception e) {
            throw new IOException(
                    "Error saving config object. Could not check for User data. Make sure config objects are simple pojos with public fields",
                    e);
        }
    }
}

From source file:com.pwn9.pwnchat.config.ConfigObject.java

protected boolean doSkip(Field field) {
    return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())
            || Modifier.isFinal(field.getModifiers()) || Modifier.isPrivate(field.getModifiers());
}

From source file:name.yumaa.ChromeLogger4J.java

/**
 * Returns a nicely formatted key of the field or method name
 * @param mod    .getModifiers()//from   www  .j  a v  a 2 s .  c  om
 * @param end    key ending
 * @return class member keys, converted to string
 */
private String getKey(int mod, String end) {
    StringBuilder key = new StringBuilder("");
    if (Modifier.isPublic(mod))
        key.append("public ");
    if (Modifier.isPrivate(mod))
        key.append("private ");
    if (Modifier.isProtected(mod))
        key.append("protected ");
    if (Modifier.isStatic(mod))
        key.append("static ");
    if (Modifier.isTransient(mod))
        key.append("transient ");
    if (Modifier.isVolatile(mod))
        key.append("volatile ");
    if (Modifier.isFinal(mod))
        key.append("final ");
    if (Modifier.isSynchronized(mod))
        key.append("synchronized ");
    return key.append(end).toString();
}

From source file:org.vulpe.model.dao.impl.jpa.VulpeBaseDAOJPA.java

private void mountParameters(final ENTITY entity, final Map<String, Object> params, final String parent) {
    final List<Field> fields = VulpeReflectUtil.getFields(entity.getClass());
    if (StringUtils.isNotEmpty(entity.getAutocomplete())) {
        try {// w  w  w.  java 2  s .  c  o  m
            if (entity.getId() != null) {
                params.put("id", entity.getId());
            } else {
                final String[] autocompleteParts = entity.getAutocomplete().split(",");
                if (autocompleteParts.length > 1) {
                    for (final String autocomplete : autocompleteParts) {
                        final String value = "[like]%" + entity.getAutocompleteTerm() + "%";
                        params.put(autocomplete, value);
                    }
                } else {
                    final String value = "[like]%" + entity.getAutocompleteTerm() + "%";
                    params.put(entity.getAutocomplete(), value);
                }
            }
        } catch (Exception e) {
            throw new VulpeSystemException(e);
        }
    } else {
        for (final Field field : fields) {
            if ((field.isAnnotationPresent(SkipAutoFilter.class) || field.isAnnotationPresent(Transient.class)
                    || Modifier.isTransient(field.getModifiers()))
                    && !field.isAnnotationPresent(QueryParameter.class)) {
                continue;
            }
            try {
                Object value = PropertyUtils.getProperty(entity, field.getName());
                Class<?> valueClass = PropertyUtils.getPropertyType(entity, field.getName());
                if (VulpeEntity.class.isAssignableFrom(valueClass)) {
                    final ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);
                    final QueryParameter queryParameter = field.getAnnotation(QueryParameter.class);
                    final String paramName = (StringUtils.isNotEmpty(parent) ? parent + "." : "")
                            + (queryParameter != null && StringUtils.isNotEmpty(queryParameter.value())
                                    ? "_" + queryParameter.value()
                                    : field.getName());
                    if (value != null) {
                        if (manyToOne != null
                                || (queryParameter != null && StringUtils.isNotEmpty(queryParameter.value()))) {
                            if (!value.getClass().getSimpleName().contains(CGLIB_ENHANCER)) {
                                mountParameters((ENTITY) value, params, paramName);
                            }
                        } else if (isNotEmpty(value)) {
                            params.put(paramName, value);
                        }
                    }
                } else if (value instanceof Collection) {
                    final OneToMany oneToMany = field.getAnnotation(OneToMany.class);
                    final String paramName = (StringUtils.isNotEmpty(parent) ? parent + "." : "")
                            + field.getName();
                    if (oneToMany != null) {
                        for (final ENTITY item : (Collection<ENTITY>) value) {
                            mountParameters(item, params, paramName);
                        }
                    }
                } else if (isNotEmpty(value)) {
                    final QueryParameter queryParameter = field.getAnnotation(QueryParameter.class);
                    String alias = StringUtils.isNotEmpty(parent) ? parent + "." : "";
                    StringBuilder paramName = new StringBuilder(alias);
                    String fieldName = field.getName();
                    if (queryParameter != null) {
                        if (queryParameter.fake() && StringUtils.isNotEmpty(queryParameter.value())) {
                            fieldName = "!" + fieldName;
                        } else if (StringUtils.isNotEmpty(queryParameter.value())
                                && queryParameter.type().equals(TypeParameter.DATE)) {
                            value = new String(queryParameter.value().replaceAll(" ", "").replace(":value",
                                    new SimpleDateFormat(queryParameter.pattern()).format(value)));
                        }
                    }
                    paramName.append(fieldName);
                    final Like like = field.getAnnotation(Like.class);
                    if (like != null) {
                        if (like.type().equals(LikeType.BEGIN)) {
                            value = value + "%";
                        } else if (like.type().equals(LikeType.END)) {
                            value = "%" + value;
                        } else {
                            value = "%" + value + "%";
                        }
                        value = "[like]" + value;
                    }
                    params.put(paramName.toString(), value);
                }
            } catch (Exception e) {
                throw new VulpeSystemException(e);
            }
        }
    }
}

From source file:com.mstiles92.plugins.stileslib.config.ConfigObject.java

protected boolean doSkip(Field field) {
    return Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())
            || Modifier.isFinal(field.getModifiers()) || Modifier.isProtected(field.getModifiers())
            || Modifier.isPrivate(field.getModifiers());
}

From source file:de.javakaffee.web.msm.serializer.javolution.AaltoTranscoderTest.java

private void assertEqualDeclaredFields(final Class<? extends Object> clazz, final Object one,
        final Object another) throws Exception, IllegalAccessException {
    for (final Field field : clazz.getDeclaredFields()) {
        field.setAccessible(true);// w  ww.j av a  2s.com
        if (!Modifier.isTransient(field.getModifiers())) {
            assertDeepEquals(field.get(one), field.get(another));
        }
    }
}

From source file:org.gvnix.occ.roo.addon.addon.OCCChecksumMetadata.java

/**
 * Get string of code required to generate the string representation of a
 * Roo Bean//from www  . ja  v a 2 s  .c o  m
 * 
 * @param members of the Roo Bean
 * @param prefix for every property (use null for this bean itself)
 * @return
 */
private String getToStringCodeForRooBean(MemberDetails members, String prefix) {
    StringBuilder strb = new StringBuilder();
    for (MemberHoldingTypeDetails memberHoldingTypeDetails : members.getDetails()) {
        for (MethodMetadata method : memberHoldingTypeDetails.getDeclaredMethods()) {
            if (BeanInfoUtils.isAccessorMethod(method)) {

                JavaSymbolName propertyName = BeanInfoUtils.getPropertyNameForJavaBeanMethod(method);

                FieldMetadata field = BeanInfoUtils.getFieldForPropertyName(members, propertyName);
                if (field != null) {
                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.Version")) != null) {
                        continue;
                    }

                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.Transient")) != null) {
                        continue;
                    }

                    if (Modifier.isTransient(field.getModifier())) {
                        continue;
                    }

                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.ManyToMany")) != null) {
                        continue;
                    }

                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.OneToMany")) != null) {
                        continue;
                    }

                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.ManyToOne")) != null) {
                        strb.append(getToStringManyToOneProperty(method, field, prefix));
                        continue;
                    }

                    if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                            new JavaType("javax.persistence.EmbeddedId")) != null) {
                        continue;
                    }

                    strb.append(getToStringCodeForBaseField(prefix, method.getMethodName(), field));

                }
            }
        }
    }
    return strb.toString();
}

From source file:com.twinsoft.convertigo.beans.CheckBeans.java

private static void analyzeJavaClass(String javaClassName) {
    try {/*from w  w  w . j a  v a 2 s  .  c  om*/
        Class<?> javaClass = Class.forName(javaClassName);
        String javaClassSimpleName = javaClass.getSimpleName();

        if (!DatabaseObject.class.isAssignableFrom(javaClass)) {
            //Error.NON_DATABASE_OBJECT.add(javaClassName);
            return;
        }

        nBeanClass++;

        String dboBeanInfoClassName = javaClassName + "BeanInfo";
        MySimpleBeanInfo dboBeanInfo = null;
        try {
            dboBeanInfo = (MySimpleBeanInfo) (Class.forName(dboBeanInfoClassName)).newInstance();
        } catch (ClassNotFoundException e) {
            if (!Modifier.isAbstract(javaClass.getModifiers())) {
                Error.MISSING_BEAN_INFO
                        .add(javaClassName + " (expected bean info: " + dboBeanInfoClassName + ")");
            }
            return;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        BeanDescriptor beanDescriptor = dboBeanInfo.getBeanDescriptor();

        // Check abstract class
        if (Modifier.isAbstract(javaClass.getModifiers())) {
            // Check icon (16x16)
            String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo,
                    MySimpleBeanInfo.ICON_COLOR_16x16);
            if (declaredIconName != null) {
                Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName);
            }

            // Check icon (32x32)
            declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32);
            if (declaredIconName != null) {
                Error.ABSTRACT_CLASS_WITH_ICON.add(javaClassName);
            }

            // Check display name
            if (!beanDescriptor.getDisplayName().equals("?")) {
                Error.ABSTRACT_CLASS_WITH_DISPLAY_NAME.add(javaClassName);
            }

            // Check description
            if (!beanDescriptor.getShortDescription().equals("?")) {
                Error.ABSTRACT_CLASS_WITH_DESCRIPTION.add(javaClassName);
            }
        } else {
            nBeanClassNotAbstract++;

            // Check bean declaration in database_objects.xml
            if (!dboXmlDeclaredDatabaseObjects.contains(javaClassName)) {
                Error.BEAN_DEFINED_BUT_NOT_USED.add(javaClassName);
            }

            // Check icon name policy (16x16)
            String declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo,
                    MySimpleBeanInfo.ICON_COLOR_16x16);
            String expectedIconName = javaClassName.replace(javaClassSimpleName,
                    "images/" + javaClassSimpleName);
            expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_16x16";
            expectedIconName = expectedIconName.toLowerCase() + ".png";
            if (declaredIconName != null) {
                if (!declaredIconName.equals(expectedIconName)) {
                    Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + "      Declared: "
                            + declaredIconName + "\n" + "      Expected: " + expectedIconName);
                }
            }

            // Check icon file (16x16)
            File iconFile = new File(srcBase + declaredIconName);
            if (!iconFile.exists()) {
                Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName);
            } else {
                icons.remove(declaredIconName);
            }

            // Check icon name policy (32x32)
            declaredIconName = MySimpleBeanInfo.getIconName(dboBeanInfo, MySimpleBeanInfo.ICON_COLOR_32x32);
            expectedIconName = javaClassName.replace(javaClassSimpleName, "images/" + javaClassSimpleName);
            expectedIconName = "/" + expectedIconName.replace('.', '/') + "_color_32x32";
            expectedIconName = expectedIconName.toLowerCase() + ".png";
            if (declaredIconName != null) {
                if (!declaredIconName.equals(expectedIconName)) {
                    Error.BEAN_ICON_NAMING_POLICY.add(javaClassName + "\n" + "      Declared: "
                            + declaredIconName + "\n" + "      Expected: " + expectedIconName);
                }
            }

            // Check icon file (32x32)
            iconFile = new File(srcBase + declaredIconName);
            if (!iconFile.exists()) {
                Error.BEAN_MISSING_ICON.add(javaClassName + " - icon missing: " + declaredIconName);
            } else {
                icons.remove(declaredIconName);
            }

            // Check display name
            if (beanDescriptor.getDisplayName().equals("?")) {
                Error.BEAN_MISSING_DISPLAY_NAME.add(javaClassName);
            }

            // Check description
            if (beanDescriptor.getShortDescription().equals("?")) {
                Error.BEAN_MISSING_DESCRIPTION.add(javaClassName);
            }
        }

        // Check declared bean properties
        PropertyDescriptor[] propertyDescriptors = dboBeanInfo.getLocalPropertyDescriptors();
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            String propertyName = propertyDescriptor.getName();
            try {
                javaClass.getDeclaredField(propertyName);
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                try {
                    // Try to find it in the upper classes
                    javaClass.getField(propertyName);
                } catch (SecurityException e1) {
                    // printStackTrace();
                } catch (NoSuchFieldException e1) {
                    Error.PROPERTY_DECLARED_BUT_NOT_FOUND.add(javaClassName + ": " + propertyName);
                }
            }
        }

        Method[] methods = javaClass.getDeclaredMethods();
        List<Method> listMethods = Arrays.asList(methods);
        List<String> listMethodNames = new ArrayList<String>();
        for (Method method : listMethods) {
            listMethodNames.add(method.getName());
        }

        Field[] fields = javaClass.getDeclaredFields();

        for (Field field : fields) {
            int fieldModifiers = field.getModifiers();

            // Ignore static fields (constants)
            if (Modifier.isStatic(fieldModifiers))
                continue;

            String fieldName = field.getName();

            String errorMessage = javaClassName + ": " + field.getName();

            // Check bean info
            PropertyDescriptor propertyDescriptor = isBeanProperty(fieldName, dboBeanInfo);
            if (propertyDescriptor != null) {
                // Check bean property name policy
                if (!propertyDescriptor.getName().equals(fieldName)) {
                    Error.PROPERTY_NAMING_POLICY.add(errorMessage);
                }

                String declaredGetter = propertyDescriptor.getReadMethod().getName();
                String declaredSetter = propertyDescriptor.getWriteMethod().getName();

                String formattedFieldName = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
                String expectedGetter = "get" + formattedFieldName;
                String expectedSetter = "set" + formattedFieldName;

                // Check getter name policy
                if (!declaredGetter.equals(expectedGetter)) {
                    Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH
                            .add(errorMessage + "\n" + "      Declared getter: " + declaredGetter + "\n"
                                    + "      Expected getter: " + expectedGetter);
                }

                // Check setter name policy
                if (!declaredSetter.equals(expectedSetter)) {
                    Error.GETTER_SETTER_DECLARED_EXPECTED_NAMES_MISMATCH
                            .add(errorMessage + "\n" + "      Declared setter: " + declaredSetter + "\n"
                                    + "      Expected setter: " + expectedSetter);
                }

                // Check required private modifiers for bean property
                if (!Modifier.isPrivate(fieldModifiers)) {
                    Error.PROPERTY_NOT_PRIVATE.add(errorMessage);
                }

                // Check getter
                if (!listMethodNames.contains(declaredGetter)) {
                    Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND
                            .add(errorMessage + " - Declared getter not found: " + declaredGetter);
                }

                // Check setter
                if (!listMethodNames.contains(declaredSetter)) {
                    Error.GETTER_SETTER_DECLARED_BUT_NOT_FOUND
                            .add(errorMessage + " - Declared setter not found: " + declaredGetter);
                }

                // Check non transient modifier
                if (Modifier.isTransient(fieldModifiers)) {
                    Error.PROPERTY_TRANSIENT.add(errorMessage);
                }
            } else if (!Modifier.isTransient(fieldModifiers)) {
                Error.FIELD_NOT_TRANSIENT.add(errorMessage);
            }
        }
    } catch (ClassNotFoundException e) {
        System.out.println("ERROR on " + javaClassName);
        e.printStackTrace();
    }
}

From source file:ch.flashcard.HibernateDetachUtility.java

private static void nullOutFieldsByFieldAccess(Object object, Map<Integer, Object> checkedObjects,
        Map<Integer, List<Object>> checkedObjectCollisionMap, int depth, SerializationType serializationType)
        throws Exception {

    Class tmpClass = object.getClass();
    List<Field> fieldsToClean = new ArrayList<Field>();
    while (tmpClass != null && tmpClass != Object.class) {
        Field[] declaredFields = tmpClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            // do not process static final or transient fields since they won't be serialized anyway
            int modifiers = declaredField.getModifiers();
            if (!((Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers))
                    || Modifier.isTransient(modifiers))) {
                fieldsToClean.add(declaredField);
            }//from w w  w  .  j  av a 2s  . c  o  m
        }
        tmpClass = tmpClass.getSuperclass();
    }

    nullOutFieldsByFieldAccess(object, fieldsToClean, checkedObjects, checkedObjectCollisionMap, depth,
            serializationType);
}