/** * @param object a persistent object * @return the value in the id property for the supplied object */ protected Object getIdValue(Object object) { Class<?> entityClass = object.getClass(); Object id = null; String idProp = getIdProperty(entityClass); if (idProp != null) { id = ReflectUtils.getInstance().getFieldValue(object, idProp); } return id; }
/** * Get the value of a field or getter method from an object allowing an annotation to override<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public Object getFieldValue(Object object, String fieldName, Class<? extends Annotation> annotationClass) { Object value; Class<?> elementClass = object.getClass(); if (annotationClass != null) { // try to find annotation first String annotatedField = getFieldNameWithAnnotation(elementClass, annotationClass); if (annotatedField != null) { fieldName = annotatedField; } } value = getFieldValue(object, fieldName); return value; }
/** * Get the value of a field or getter method from an object allowing an annotation to override<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public Object getFieldValue(Object object, String fieldName, Class<? extends Annotation> annotationClass) { Object value; Class<?> elementClass = object.getClass(); if (annotationClass != null) { // try to find annotation first String annotatedField = getFieldNameWithAnnotation(elementClass, annotationClass); if (annotatedField != null) { fieldName = annotatedField; } } value = getFieldValue(object, fieldName); return value; }
/** * Override this if desired */ protected Serializable baseGetIdValue(Object object) { Class<?> type = object.getClass(); String idProp = getIdProperty(type); Object idValue = null; if (idProp == null) { throw new IllegalArgumentException("Could not find id property for this class type: " + type); } else { idValue = ReflectUtils.getInstance().getFieldValue(object, idProp); } Serializable serialId = null; if (idValue != null) { if (idValue instanceof Serializable) { serialId = (Serializable) idValue; } else { serialId = idValue.toString(); } } return serialId; }
/** * Get the string value of a field or getter method from an object allowing an annotation to override<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the string value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public String getFieldValueAsString(Object object, String fieldName, Class<? extends Annotation> annotationClass) { String sValue = null; Object value = getFieldValue(object, fieldName, annotationClass); if (value != null) { sValue = getConversionUtils().convert(value, String.class); //value.toString(); } return sValue; }
/** * Get the id value from a persistent object, * this expects that the object is persistent so it should already be checked<br/> * Override this if desired * @param entity any persistent object * @return the id value or null if it is unset */ protected Serializable baseGetIdValue(Object entity) { Class<?> type = findClass(entity); String idProp = getIdProperty(type); Object idValue = null; if (idProp == null) { throw new IllegalArgumentException("Could not find id property for this class type: " + type); } else { idValue = ReflectUtils.getInstance().getFieldValue(entity, idProp); } Serializable serialId = null; if (idValue != null) { if (! (idValue instanceof Serializable)) { serialId = idValue.toString(); } } return serialId; }
/** * Get the string value of a field or getter method from an object allowing an annotation to override<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the string value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public String getFieldValueAsString(Object object, String fieldName, Class<? extends Annotation> annotationClass) { String sValue = null; Object value = getFieldValue(object, fieldName, annotationClass); if (value != null) { sValue = getConversionUtils().convert(value, String.class); //value.toString(); } return sValue; }
lm = ReflectUtils.getInstance().getFieldValue(ed.getData(), "lastModified", EntityLastModified.class); Long l = makeLastModified(lm); if (l != null) {
lm = ReflectUtils.getInstance().getFieldValue(ed.getData(), "lastModified", EntityLastModified.class); Long l = makeLastModified(lm); if (l != null) {
value = ReflectUtils.getInstance().getFieldValue(value, pId);
List<Object> existingObjects = new ArrayList<Object>(); for (Object object : entities) { Object id = ReflectUtils.getInstance().getFieldValue(object, idProp); if (id == null) { newObjects.add(object);
if (value != null && value.getClass().isAssignableFrom(pType)) { pValue = ReflectUtils.getInstance().getFieldValue(value, pId);