You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2009/09/11 18:08:03 UTC
svn commit: r813899 - in /cxf/branches/2.2.x-fixes: ./
common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
Author: dkulp
Date: Fri Sep 11 16:08:03 2009
New Revision: 813899
URL: http://svn.apache.org/viewvc?rev=813899&view=rev
Log:
Merged revisions 812615 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r812615 | bimargulies | 2009-09-08 14:36:56 -0400 (Tue, 08 Sep 2009) | 2 lines
CXF-2417. Borrow help from Spring to avoid leaks and other problems with property descriptors.
Non-spring users are stuck with Sun's bugs for now.
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=813899&r1=813898&r2=813899&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java (original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java Fri Sep 11 16:08:03 2009
@@ -19,12 +19,22 @@
package org.apache.cxf.common.util;
+import java.beans.BeanInfo;
+import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+
public final class ReflectionUtil {
+
+ private static Method springBeanUtilsDescriptorFetcher;
+ private static boolean springChecked;
+
private ReflectionUtil() {
// intentionally empty
}
@@ -79,4 +89,62 @@
String packageName = clzName.substring(0, clzName.lastIndexOf("/"));
return packageName.replace("/", ".");
}
+
+ /**
+ * create own array of property descriptors to:
+ * <pre>
+ * - prevent memory leaks by Introspector's cache
+ * - get correct type for generic properties from superclass
+ * that are limited to a specific type in beanClass
+ * see http://bugs.sun.com/view_bug.do?bug_id=6528714
+ * we cannot use BeanUtils.getPropertyDescriptors because of issue SPR-6063
+ * </pre>
+ * @param refClass calling class for class loading.
+ * @param beanInfo Bean in question
+ * @param beanClass class for bean in question
+ * @param propertyDescriptors raw descriptors
+ * @return
+ */
+ public static PropertyDescriptor[] getPropertyDescriptorsAvoidSunBug(Class<?> refClass,
+ BeanInfo beanInfo,
+ Class<?> beanClass,
+ PropertyDescriptor[] propertyDescriptors) {
+ if (!springChecked) {
+ try {
+ springChecked = true;
+ Class<?> cls = ClassLoaderUtils
+ .loadClass("org.springframework.beans.BeanUtils", refClass);
+ springBeanUtilsDescriptorFetcher
+ = cls.getMethod("getPropertyDescriptor", new Class[] {Class.class, String.class});
+ } catch (Exception e) {
+ //ignore - just assume it's an unsupported/unknown annotation
+ }
+ }
+
+ if (springBeanUtilsDescriptorFetcher != null) {
+ PropertyDescriptor[] descriptors = null;
+ if (propertyDescriptors != null) {
+ descriptors = new PropertyDescriptor[propertyDescriptors.length];
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ try {
+ descriptors[i] =
+ (PropertyDescriptor)
+ springBeanUtilsDescriptorFetcher.invoke(null,
+ beanClass,
+ propertyDescriptor.getName());
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return descriptors;
+ } else {
+ return beanInfo.getPropertyDescriptors();
+ }
+ }
}
Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java?rev=813899&r1=813898&r2=813899&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java (original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java Fri Sep 11 16:08:03 2009
@@ -36,6 +36,7 @@
import org.apache.cxf.aegis.type.Type;
import org.apache.cxf.aegis.type.TypeCreator;
import org.apache.cxf.aegis.type.TypeMapping;
+import org.apache.cxf.common.util.ReflectionUtil;
public class BeanTypeInfo {
private Map<QName, QName> mappedName2typeName = new HashMap<QName, QName>();
@@ -286,7 +287,14 @@
}
if (beanInfo != null) {
- descriptors = beanInfo.getPropertyDescriptors();
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ if (propertyDescriptors != null) {
+ // see comments on this function.
+ descriptors = ReflectionUtil.getPropertyDescriptorsAvoidSunBug(getClass(),
+ beanInfo,
+ beanClass,
+ propertyDescriptors);
+ }
}
if (descriptors == null) {