public Class<?> genericType() { Type type = field.getGenericType(); return ReflectionUtils.determineGenericsType(type); } }
@Override protected Method getReadMethod() throws NoSuchMethodException { if (readMethod == null || readMethod.get() == null) { if (customGetMethod != null) { Method method = ReflectionUtils.findAMethod(clazz, customGetMethod); readMethod = new SoftReference<Method>(method); } else { return super.getReadMethod(); } } return readMethod.get(); }
public static Method findAMethod(Class<?> clazz, String methodName) throws NoSuchMethodException { StringTokenizer tokenizer = new StringTokenizer(methodName, "("); String m = tokenizer.nextToken(); Method result; // If tokenizer has more elements, it mean that parameters may have been // specified if (tokenizer.hasMoreElements()) { StringTokenizer tokens = new StringTokenizer(tokenizer.nextToken(), ")"); String params = (tokens.hasMoreTokens() ? tokens.nextToken() : null); result = findMethodWithParam(clazz, m, params); } else { result = findMethod(clazz, methodName); } if (result == null) { throw new NoSuchMethodException(clazz.getName() + "." + methodName); } return result; }
/** * Invokes given method with specified arguments. * * NOTE: implementation of current class has to process proxy method * parameters to get values of real method. * * @param instance target object * @param method method reference * @param params proxy method arguments * @return result of method invocation */ public Object invoke(Object instance, Method method, Object[] params) { Object[] args = getParameterValues(params); return ReflectionUtils.invoke(method, instance, args); } }
Object factory = ReflectionUtils.newInstance(objectFactory); Method method = null; try { method = ReflectionUtils.getMethod(objectFactory, "create" + beanId.substring(beanId.lastIndexOf(".") + 1), new Class[] {}); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); Object returnObject = ReflectionUtils.invoke(method, factory, new Object[] {}); log.debug("createBean(Object, Class, String) - end [{}]", returnObject.getClass().getName()); result = returnObject;
DeepHierarchyElement hierarchyElement = hierarchy[i]; PropertyDescriptor pd = hierarchyElement.getPropDescriptor(); Object value = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); Class<?> clazz; Class<?> collectionEntryType; } else if (Collection.class.isAssignableFrom(clazz)) { Class<?> genericType = ReflectionUtils.determineGenericsType(parentObj.getClass(), pd); if (genericType != null) { collectionEntryType = genericType; ReflectionUtils.invoke(pd.getWriteMethod(), parentObj, new Object[]{o}); value = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); collectionEntryType = ReflectionUtils.determineGenericsType(parentObj.getClass(), pd); ReflectionUtils.invoke(pd.getWriteMethod(), parentObj, new Object[]{value}); } else { try { method = ReflectionUtils.findAMethod(parentObj.getClass(), getSetMethodName()); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); ReflectionUtils.invoke(method, parentObj, new Object[]{destFieldValue}); } else { writeIndexedValue(parentObj, destFieldValue);
DeepHierarchyElement hierarchyElement = hierarchy[i]; PropertyDescriptor pd = hierarchyElement.getPropDescriptor(); Object value = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); Class<?> clazz; Class<?> collectionEntryType; collectionEntryType = ReflectionUtils.getComponentType(clazz, pd, hintType); ReflectionUtils.invoke(pd.getWriteMethod(), parentObj, new Object[] { o }); value = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); Class<?> componentType = ReflectionUtils.getComponentType(pd.getPropertyType(), pd, hintType); ReflectionUtils.invoke(pd.getWriteMethod(), parentObj, new Object[] { value }); value = ReflectionUtils.invoke(pd.getReadMethod(), parentObj, null); } else { try { method = ReflectionUtils.findAMethod(parentObj.getClass(), getSetMethodName()); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); ReflectionUtils.invoke(method, parentObj, new Object[] { destFieldValue }); } else { writeIndexedValue(parentObj, destFieldValue);
PropertyDescriptor propDescriptor = findPropertyDescriptor(latestClass, theFieldName, deepIndexHintContainer); DeepHierarchyElement r = new DeepHierarchyElement(propDescriptor, collectionIndex); latestClass = latestClass.getComponentType(); } else if (Collection.class.isAssignableFrom(latestClass)) { Class<?> genericType = determineGenericsType(parentClass.getClass(), propDescriptor);
ChainedPropertyDescriptor(Class<?> clazz, String fieldName, boolean indexed, String index) { this.indexed = indexed; this.index = index; field = ReflectionUtils.getFieldFromBean(clazz, fieldName); }
for (Class<?> superInterfaceClass : interfaces) { List<PropertyDescriptor> superInterfacePropertyDescriptors = Arrays .asList(getInterfacePropertyDescriptors(superInterfaceClass)); PropertyDescriptor existingPropDescriptor = findPropDescriptorByName(propDescriptors, superPropDescriptor.getName()); if (existingPropDescriptor == null) { propDescriptors.add(superPropDescriptor);
PropertyDescriptor result = null; if (MappingUtils.isDeepMapping(fieldName)) { DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(objectClass, fieldName, deepIndexHintContainer); result = hierarchy[hierarchy.length - 1].getPropDescriptor(); } else { PropertyDescriptor[] descriptors = getPropertyDescriptors(objectClass); Method readMethod = descriptors[i].getReadMethod(); if (fieldName.equals(propertyName)) { return fixGenericDescriptor(objectClass, descriptors[i]);
DeepHierarchyElement[] hierarchy = getDeepFieldHierarchy(objectClass, fieldName, deepIndexHintContainer); result = hierarchy[hierarchy.length - 1].getPropDescriptor(); } else { PropertyDescriptor[] descriptors = getPropertyDescriptors(objectClass);
public boolean apply(ClassMap classMap, Configuration configuration) { Class<?> srcClass = classMap.getSrcClassToMap(); Class<?> destClass = classMap.getDestClassToMap(); PropertyDescriptor[] destProperties = ReflectionUtils.getPropertyDescriptors(destClass); for (PropertyDescriptor destPropertyDescriptor : destProperties) { String fieldName = destPropertyDescriptor.getName(); if (shouldIgnoreField(fieldName, srcClass, destClass)) { continue; } // If field has already been accounted for, then skip if (classMap.getFieldMapUsingDest(fieldName) != null || classMap .getFieldMapUsingSrc(fieldName) != null) { continue; } // If destination field does not have a write method, then skip if (destPropertyDescriptor.getWriteMethod() == null) { continue; } PropertyDescriptor srcProperty = ReflectionUtils.findPropertyDescriptor(srcClass, fieldName, null); // If the sourceProperty is null we know that there is not a // corresponding property to map to. // If source property does not have a read method, then skip if (srcProperty == null || srcProperty.getReadMethod() == null) { continue; } addGenericMapping(classMap, configuration, fieldName, fieldName); } return false; }
private PropertyDescriptor getPropertyDescriptor(HintContainer deepIndexHintContainer) { if (pd == null) { pd = ReflectionUtils.findPropertyDescriptor(clazz, fieldName, deepIndexHintContainer); if (pd == null) { MappingUtils.throwMappingException("Property: '" + fieldName + "' not found in Class: " + clazz); } } return pd; }
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> objectClass) { // If the class is an interface, use custom method to get all prop descriptors in the inheritance hierarchy. // PropertyUtils.getPropertyDescriptors() does not work correctly for interface inheritance. It finds props in the // actual interface ok, but does not find props in the inheritance hierarchy. if (objectClass.isInterface()) { return getInterfacePropertyDescriptors(objectClass); } else { return PropertyUtils.getPropertyDescriptors(objectClass); } }
public static Method getMethod(Class<?> clazz, String methodName) { Method result = findMethod(clazz, methodName); if (result == null) { MappingUtils.throwMappingException("No method found for class:" + clazz + " and method name:" + methodName); } return result; }
private DeepHierarchyElement[] getDeepFieldHierarchy(Object obj, HintContainer deepIndexHintContainer) { return ReflectionUtils.getDeepFieldHierarchy(obj.getClass(), fieldName, deepIndexHintContainer); }
protected Object invokeReadMethod(Object target) { Object result = null; try { result = ReflectionUtils.invoke(getReadMethod(), target, null); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return result; }
Object factory = ReflectionUtils.newInstance(objectFactory); Method method = null; try { method = ReflectionUtils.getMethod(objectFactory, "create" + beanId.substring(beanId.lastIndexOf(".") + 1), new Class[] {}); MappingUtils.throwMappingException(e); Object returnObject = ReflectionUtils.invoke(method, factory, new Object[] {}); log.debug("createBean(Object, Class, String) - end [{}]", returnObject.getClass().getName()); result = returnObject;