private Class determinePropertyType() { Method readMethod = getBridgedReadMethod(); Method writeMethod = getBridgedWriteMethod(); Class returnType = null; try { returnType = TypeResolver.resolvePropertyType(clazz, readMethod, writeMethod); } catch (Exception ignore) { } if (returnType != null) { return returnType; } if (readMethod == null && writeMethod == null) { throw new MappingException( "No read or write method found for field (" + fieldName + ") in class (" + clazz + ")"); } if (readMethod == null) { return determineByWriteMethod(writeMethod); } else { try { return readMethod.getReturnType(); } catch (Exception e) { // let us try the set method - the field might have inacessible // 'get' method return determineByWriteMethod(writeMethod); } } }
public Class<?> getPropertyType() { if (propertyType == null) { propertyType = determinePropertyType(); } return propertyType; }
public Object getPropertyValue(Object bean) { Object result; if (MappingUtils.isDeepMapping(fieldName)) { result = getDeepSrcFieldValue(bean); } else { result = invokeReadMethod(bean); if (isIndexed) { result = MappingUtils.getIndexedValue(result, index); } } return result; }
private void writeIndexedValue(Object destObj, Object destFieldValue) { Object existingValue = invokeReadMethod(destObj); Object indexedValue = MappingUtils.prepareIndexedCollection(getPropertyType(), existingValue, destFieldValue, index); invokeWriteMethod(destObj, indexedValue); }
private void writeIndexedValue(Object destObj, int collectionIndex, Object existingValue, Object destFieldValue) { Object indexedValue = MappingUtils.prepareIndexedCollection(getPropertyType(), existingValue, destFieldValue, collectionIndex); invokeWriteMethod(destObj, indexedValue); }
public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { //First check if value is indexed. If it's null, then the new array will be created if (isIndexed) { writeIndexedValue(bean, value); } else { // Check if dest value is already set and is equal to src value. If true, no need to rewrite the dest value try { if (getPropertyValue(bean) == value && !isIndexed) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, and continue... } invokeWriteMethod(bean, value); } } } }
protected void writeDeepDestinationValue(Object destObj, Object destFieldValue, FieldMap fieldMap) { DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(destObj, fieldMap.getDestDeepIndexHintContainer()); if (!isIndexed) { Method method = null; if (!isCustomSetMethod()) { method = pd.getWriteMethod(); } else { try { method = ReflectionUtils.findAMethod(parentObj.getClass(), getSetMethodName()); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); writeIndexedValue(parentObj, destFieldValue);
private Method getBridgedReadMethod() { try { return BridgedMethodFinder.findMethod(getReadMethod(), clazz); } catch (Exception ignore) { } return null; }
private Object getDeepSrcFieldValue(Object srcObj) { // follow deep field hierarchy. If any values are null along the way, then return null Object parentObj = srcObj; Object hierarchyValue = parentObj; DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(srcObj, srcDeepIndexHintContainer); int size = hierarchy.length; for (int i = 0; i < size; i++) { DeepHierarchyElement hierarchyElement = hierarchy[i]; PropertyDescriptor pd = hierarchyElement.getPropDescriptor(); // If any fields in the deep hierarchy are indexed, get actual value within the collection at the specified index if (hierarchyElement.getIndex() > -1) { hierarchyValue = MappingUtils.getIndexedValue(ReflectionUtils.invoke(pd.getReadMethod(), hierarchyValue, null), hierarchyElement.getIndex()); } else { hierarchyValue = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); } parentObj = hierarchyValue; if (hierarchyValue == null) { break; } } // If dest field is indexed, get actual value within the collection at the specified index if (isIndexed) { hierarchyValue = MappingUtils.getIndexedValue(hierarchyValue, index); } return hierarchyValue; }
public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { // First check if value is indexed. If it's null, then the new // array will be created if (isIndexed) { // write value using index information // writeIndexedValue(bean, value); } else { // Check if dest value is already set and is equal to src // value. If true, no need to rewrite the dest value try { if (getPropertyValue(bean) == value && !isIndexed) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, // and continue... } invokeWriteMethod(bean, value); } } } }
protected void writeDeepDestinationValue(Object destObj, Object destFieldValue, FieldMap fieldMap) { DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(destObj, fieldMap.getDestDeepIndexHintContainer()); if (!isIndexed) { Method method = null; if (!isCustomSetMethod()) { method = pd.getWriteMethod(); } else { try { method = ReflectionUtils.findAMethod(parentObj.getClass(), getSetMethodName()); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); writeIndexedValue(parentObj, destFieldValue);
private void writeIndexedValue(Object destObj, int collectionIndex, Object existingValue, Object destFieldValue) { Object indexedValue = MappingUtils.prepareIndexedCollection(getPropertyType(), existingValue, destFieldValue, collectionIndex); invokeWriteMethod(destObj, indexedValue); }
private Method getBridgedReadMethod() { try { return BridgedMethodFinder.findMethod(getReadMethod(), clazz); } catch (Exception ignore) { } return null; }
DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(srcObj, deepIndexHintContainer); int hierarchyLength = hierarchy.length;
public void setPropertyValue(Object bean, Object value, FieldMap fieldMap) { if (MappingUtils.isDeepMapping(fieldName)) { writeDeepDestinationValue(bean, value, fieldMap); } else { if (!getPropertyType().isPrimitive() || value != null) { // First check if value is indexed. If it's null, then the new // array will be created if (isIndexed) { // write value using index information // writeIndexedValue(bean, value); } else { // Check if dest value is already set and is equal to src // value. If true, no need to rewrite the dest value try { if (getPropertyValue(bean) == value && !isIndexed) { return; } } catch (Exception e) { // if we failed to read the value, assume we must write, // and continue... } invokeWriteMethod(bean, value); } } } }
protected void writeDeepDestinationValue(Object destObj, Object destFieldValue, FieldMap fieldMap) { DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(destObj, fieldMap.getDestDeepIndexHintContainer()); if (!isIndexed) { Method method = null; if (!isCustomSetMethod()) { method = pd.getWriteMethod(); } else { try { method = ReflectionUtils.findAMethod(parentObj.getClass(), getSetMethodName()); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); writeIndexedValue(parentObj, destFieldValue);
private Class determinePropertyType() { Method readMethod = getBridgedReadMethod(); Method writeMethod = getBridgedWriteMethod(); Class returnType = null; try { returnType = TypeResolver.resolvePropertyType(clazz, readMethod, writeMethod); } catch (Exception ignore) { } if (returnType != null) { return returnType; } if (readMethod == null && writeMethod == null) { throw new MappingException("No read or write method found for field (" + fieldName + ") in class (" + clazz + ")"); } if (readMethod == null) { return determineByWriteMethod(writeMethod); } else { try { return readMethod.getReturnType(); } catch (Exception e) { // let us try the set method - the field might have inacessible 'get' method return determineByWriteMethod(writeMethod); } } }
public Object getPropertyValue(Object bean) { Object result; if (MappingUtils.isDeepMapping(fieldName)) { result = getDeepSrcFieldValue(bean); } else { result = invokeReadMethod(bean); if (isIndexed) { if (MappingUtils.isSimpleCollectionIndex(index)) { int collectionIndex = MappingUtils.getCollectionIndex(index); result = MappingUtils.getCollectionIndexedValue(result, collectionIndex); } else { String expression = String.format("%s[%s]", fieldName, index); result = MappingUtils.getXPathIndexedValue(bean, expression); } } } return result; }
private Method getBridgedReadMethod() { try { return BridgedMethodFinder.findMethod(getReadMethod(), clazz); } catch (Exception ignore) { } return null; }
public Class<?> getPropertyType() { if (propertyType == null) { propertyType = determinePropertyType(); } return propertyType; }