List of usage examples for java.lang.reflect Modifier isTransient
public static boolean isTransient(int mod)
From source file:objenome.util.bytecode.SgUtils.java
private static void checkModifiers(int type, int modifiers) { for (int modifier = ABSTRACT; modifier <= STRICTFP; modifier++) { if (Modifier.isPrivate(modifiers) && !MODIFIERS_MATRIX[PRIVATE][type]) { throwIllegalArgument(type, PRIVATE); }//from w w w .j av a2 s. c o m if (Modifier.isProtected(modifiers) && !MODIFIERS_MATRIX[PROTECTED][type]) { throwIllegalArgument(type, PROTECTED); } if (Modifier.isPublic(modifiers) && !MODIFIERS_MATRIX[PUBLIC][type]) { throwIllegalArgument(type, PUBLIC); } if (Modifier.isStatic(modifiers) && !MODIFIERS_MATRIX[STATIC][type]) { throwIllegalArgument(type, STATIC); } if (Modifier.isAbstract(modifiers) && !MODIFIERS_MATRIX[ABSTRACT][type]) { throwIllegalArgument(type, ABSTRACT); } if (Modifier.isFinal(modifiers) && !MODIFIERS_MATRIX[FINAL][type]) { throwIllegalArgument(type, FINAL); } if (Modifier.isNative(modifiers) && !MODIFIERS_MATRIX[NATIVE][type]) { throwIllegalArgument(type, NATIVE); } if (Modifier.isSynchronized(modifiers) && !MODIFIERS_MATRIX[SYNCHRONIZED][type]) { throwIllegalArgument(type, SYNCHRONIZED); } if (Modifier.isTransient(modifiers) && !MODIFIERS_MATRIX[TRANSIENT][type]) { throwIllegalArgument(type, TRANSIENT); } if (Modifier.isVolatile(modifiers) && !MODIFIERS_MATRIX[VOLATILE][type]) { throwIllegalArgument(type, VOLATILE); } if (Modifier.isStrict(modifiers) && !MODIFIERS_MATRIX[STRICTFP][type]) { throwIllegalArgument(type, STRICTFP); } } }
From source file:org.sjmvc.binding.AbstractBinder.java
/** * Sets the given value to the given field. * // w w w . j a v a 2s.c o m * @param currentObject The current object being processed. * @param name The name of the field. * @param values The values to set. * @throws BindingError If the value of the property cannot be set. */ protected void setValue(Object currentObject, String name, String values[]) throws BindingError { try { Field field = currentObject.getClass().getDeclaredField(name); int modifiers = field.getModifiers(); if (!Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers)) { // If property is a collection, iterate over the values if (Collection.class.isAssignableFrom(field.getType())) { setCollectionValues(field, currentObject, name, values); } else if (field.getType().isArray()) { setArrayValues(field, currentObject, name, values); } else { setSimpleValue(field, currentObject, name, values[0]); } } else { LOGGER.debug("Property {} is static or transient " + "and binding will ignore it", name); } } catch (Exception ex) { throw new BindingError( "Could not bind property [" + name + "] of [" + currentObject.getClass().getName() + "]", ex); } }
From source file:org.guzz.builder.JPA2AnnotationsBuilder.java
protected static void parseClassForAttributes(GuzzContextImpl gf, POJOBasedObjectMapping map, Business business, DBGroup dbGroup, SimpleTable st, Class domainClass) { //???/*from w w w .j a v a2s . co m*/ Class parentCls = domainClass.getSuperclass(); if (parentCls != null && parentCls.isAnnotationPresent(MappedSuperclass.class)) { parseClassForAttributes(gf, map, business, dbGroup, st, parentCls); } javax.persistence.Access access = (javax.persistence.Access) domainClass .getAnnotation(javax.persistence.Access.class); AccessType accessType = null; if (access == null) { //@Id@Idfieldproperty boolean hasColumnAOnField = false; boolean hasColumnAOnProperty = false; //detect from @Id, field first. Field[] fs = domainClass.getDeclaredFields(); for (Field f : fs) { if (f.isAnnotationPresent(Transient.class)) continue; if (f.isAnnotationPresent(javax.persistence.Id.class)) { accessType = AccessType.FIELD; break; } else if (f.isAnnotationPresent(javax.persistence.Column.class)) { hasColumnAOnField = true; } else if (f.isAnnotationPresent(org.guzz.annotations.Column.class)) { hasColumnAOnField = true; } } if (accessType == null) { Method[] ms = domainClass.getDeclaredMethods(); for (Method m : ms) { if (m.isAnnotationPresent(Transient.class)) continue; if (m.isAnnotationPresent(javax.persistence.Id.class)) { accessType = AccessType.PROPERTY; break; } else if (m.isAnnotationPresent(javax.persistence.Column.class)) { hasColumnAOnProperty = true; } else if (m.isAnnotationPresent(org.guzz.annotations.Column.class)) { hasColumnAOnProperty = true; } } } //@Id@Column@Columnfield? if (accessType == null) { if (hasColumnAOnField) { accessType = AccessType.FIELD; } else if (hasColumnAOnProperty) { accessType = AccessType.PROPERTY; } else { accessType = AccessType.FIELD; } } } else { accessType = access.value(); } //orm by field if (accessType == AccessType.FIELD) { Field[] fs = domainClass.getDeclaredFields(); for (Field f : fs) { if (f.isAnnotationPresent(Transient.class)) continue; if (Modifier.isTransient(f.getModifiers())) continue; if (Modifier.isStatic(f.getModifiers())) continue; if (f.isAnnotationPresent(javax.persistence.Id.class)) { addIdMapping(gf, map, st, dbGroup, f.getName(), domainClass, f); } else { addPropertyMapping(gf, map, st, f.getName(), f, f.getType()); } } } else { Method[] ms = domainClass.getDeclaredMethods(); for (Method m : ms) { if (m.isAnnotationPresent(Transient.class)) continue; if (Modifier.isTransient(m.getModifiers())) continue; if (Modifier.isStatic(m.getModifiers())) continue; if (Modifier.isPrivate(m.getModifiers())) continue; String methodName = m.getName(); String fieldName = null; if (m.getParameterTypes().length != 0) { continue; } else if (Void.TYPE.equals(m.getReturnType())) { continue; } if (methodName.startsWith("get")) { fieldName = methodName.substring(3); } else if (methodName.startsWith("is")) {//is boolean? Class retType = m.getReturnType(); if (boolean.class.isAssignableFrom(retType)) { fieldName = methodName.substring(2); } else if (Boolean.class.isAssignableFrom(retType)) { fieldName = methodName.substring(2); } } //not a javabean read method if (fieldName == null) { continue; } fieldName = java.beans.Introspector.decapitalize(fieldName); if (m.isAnnotationPresent(javax.persistence.Id.class)) { addIdMapping(gf, map, st, dbGroup, fieldName, domainClass, m); } else { addPropertyMapping(gf, map, st, fieldName, m, m.getReturnType()); } } } //?attribute override AttributeOverride gao = (AttributeOverride) domainClass.getAnnotation(AttributeOverride.class); AttributeOverrides gaos = (AttributeOverrides) domainClass.getAnnotation(AttributeOverrides.class); AttributeOverride[] aos = gao == null ? new AttributeOverride[0] : new AttributeOverride[] { gao }; if (gaos != null) { ArrayUtil.addToArray(aos, gaos.value()); } for (AttributeOverride ao : aos) { String name = ao.name(); Column col = ao.column(); TableColumn tc = st.getColumnByPropName(name); Assert.assertNotNull(tc, "@AttributeOverride cann't override a attribute that doesn't exist. The attribute is:" + name); //update is remove and add st.removeColumn(tc); //change the column name in the database. tc.setColName(col.name()); st.addColumn(tc); } }
From source file:org.forgerock.openam.cts.utils.blob.strategies.AttributeCompressionStrategy.java
/** * Examines the class using reflection for all declared fields which are suitable * for serialisation./*from w w w . ja va 2s .co m*/ * * @param c Non null class to examine. * * @return A non null but possibly empty collection of Fields. */ public static Collection<Field> getAllValidFields(Class c) { List<Field> r = new ArrayList<Field>(); for (Field f : c.getDeclaredFields()) { int modifiers = f.getModifiers(); if (Modifier.isStatic(modifiers)) continue; if (Modifier.isVolatile(modifiers)) continue; if (Modifier.isTransient(modifiers)) continue; r.add(f); } return r; }
From source file:org.kuali.kfs.sys.context.DocumentSerializabilityTest.java
/** * Determines if a given field is serializable * @param field the field to check/*from ww w .ja va 2s .c om*/ * @return true if the field is serializable, false otherwise */ protected boolean isSerializable(Field field) { return java.io.Serializable.class.isAssignableFrom(field.getType()) || java.util.Collection.class.isAssignableFrom(field.getType()) || java.util.Map.class.isAssignableFrom(field.getType()) || field.getName().equals("dataObject") || Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || isPrimitive(field.getType()); }
From source file:org.vulpe.commons.util.VulpeReflectUtil.java
/** * Copy attributes from <code>origin</code> to <code>destination</code>. * * @param destination/* w w w.ja v a2s. c o m*/ * @param origin * @param ignoreTransient */ public static void copy(final Object destination, final Object origin, boolean ignoreTransient) { final List<Field> fields = getFields(origin.getClass()); for (final Field field : fields) { if (ignoreTransient && Modifier.isTransient(field.getModifiers())) { continue; } try { final Object value = PropertyUtils.getProperty(origin, field.getName()); if (Collection.class.isAssignableFrom(field.getType())) { final Collection valueDes = (Collection) PropertyUtils.getProperty(destination, field.getName()); if (value == null) { if (valueDes != null) { valueDes.clear(); } } else { if (valueDes == null) { PropertyUtils.setProperty(destination, field.getName(), value); } else { valueDes.clear(); valueDes.addAll((Collection) value); } } } else { PropertyUtils.setProperty(destination, field.getName(), value); } } catch (NoSuchMethodException e) { LOG.debug("Method not found.", e); } catch (Exception e) { throw new VulpeSystemException(e); } } }
From source file:com.yahoo.elide.core.EntityBinding.java
/** * Bind fields of an entity including the Id field, attributes, and relationships. * * @param cls Class type to bind fields// w w w. ja v a2 s. c o m * @param type JSON API type identifier * @param fieldOrMethodList List of fields and methods on entity */ private void bindEntityFields(Class<?> cls, String type, Collection<AccessibleObject> fieldOrMethodList) { for (AccessibleObject fieldOrMethod : fieldOrMethodList) { bindTrigger(OnCreate.class, fieldOrMethod); bindTrigger(OnDelete.class, fieldOrMethod); bindTrigger(OnUpdate.class, fieldOrMethod); bindTrigger(OnCommit.class, fieldOrMethod); if (fieldOrMethod.isAnnotationPresent(Id.class)) { bindEntityId(cls, type, fieldOrMethod); } else if (fieldOrMethod.isAnnotationPresent(Transient.class) && !fieldOrMethod.isAnnotationPresent(ComputedAttribute.class)) { continue; // Transient. Don't serialize } else if (!fieldOrMethod.isAnnotationPresent(Exclude.class)) { if (fieldOrMethod instanceof Field && Modifier.isTransient(((Field) fieldOrMethod).getModifiers())) { continue; // Transient. Don't serialize } if (fieldOrMethod instanceof Method && Modifier.isTransient(((Method) fieldOrMethod).getModifiers())) { continue; // Transient. Don't serialize } if (fieldOrMethod instanceof Field && !fieldOrMethod.isAnnotationPresent(Column.class) && Modifier.isStatic(((Field) fieldOrMethod).getModifiers())) { continue; // Field must have Column annotation? } bindAttrOrRelation(cls, fieldOrMethod); } } }
From source file:org.alex73.skarynka.scan.Book2.java
private void get(Object obj, String prefix, List<String> lines) throws Exception { for (Field f : obj.getClass().getFields()) { if (Modifier.isPublic(f.getModifiers()) && !Modifier.isStatic(f.getModifiers()) && !Modifier.isTransient(f.getModifiers())) { if (f.getType() == int.class) { int v = f.getInt(obj); if (v != -1) { lines.add(prefix + f.getName() + "=" + v); }// w ww .j a v a2 s .c o m } else if (f.getType() == boolean.class) { lines.add(prefix + f.getName() + "=" + f.getBoolean(obj)); } else if (f.getType() == String.class) { String s = (String) f.get(obj); if (s != null) { lines.add(prefix + f.getName() + "=" + s); } } else if (Set.class.isAssignableFrom(f.getType())) { Set<?> set = (Set<?>) f.get(obj); StringBuilder t = new StringBuilder(); for (Object o : set) { t.append(o.toString()).append(';'); } if (t.length() > 0) { t.setLength(t.length() - 1); } lines.add(prefix + f.getName() + "=" + t); } else { throw new RuntimeException("Unknown field class for get '" + f.getName() + "'"); } } } }
From source file:com.zuoxiaolong.niubi.job.persistent.BaseDaoImpl.java
private <T> List<Object> generateValueListAndSetSql(Class<T> clazz, T entity, StringBuffer sqlBuffer, boolean useLike) { List<Object> valueList = new ArrayList<>(); if (entity != null) { Field[] fields = ReflectHelper.getAllFields(entity); for (int i = 0, index = 0; i < fields.length; i++) { Field field = fields[i]; int modifiers = field.getModifiers(); if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isFinal(modifiers) || ObjectHelper.isTransientId(clazz, field)) { continue; }/* w ww. j ava 2 s .co m*/ Object value = ReflectHelper.getFieldValueWithGetterMethod(entity, entity.getClass(), field.getName()); if (ObjectHelper.isEmpty(value)) { continue; } if (field.getType() == String.class && useLike) { sqlBuffer.append("and " + field.getName() + " like ?" + index++ + " "); valueList.add("%" + value + "%"); } else { sqlBuffer.append("and " + field.getName() + "=?" + index++ + " "); valueList.add(value); } } } return valueList; }
From source file:de.javakaffee.web.msm.serializer.xstream.XStreamTranscoderTest.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);/* www .j av a 2 s . co m*/ if (!Modifier.isTransient(field.getModifiers())) { assertEquals(field.get(one), field.get(another)); } } }