From e0db762e3cdaf5878c79620b0525f3a613db9c57 Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 20 Jul 2009 19:07:59 +0000 Subject: Fix for TUSCANY-3167 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@795959 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/databinding/jaxb/XMLRootElementUtil.java | 25 ++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'java') diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java index b26c6e7e36..d177d53eda 100644 --- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java +++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; +import java.util.WeakHashMap; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElement; @@ -44,7 +45,14 @@ import javax.xml.namespace.QName; /** * */ -public final class XMLRootElementUtil { +public class XMLRootElementUtil { + + /** + * TUSCANY-3167 + * Cache for property descriptors + */ + private static Map, Map> PROPERTY_MAP = + new WeakHashMap, Map>(); /** Constructor is intentionally private. This class only provides static utility methods */ private XMLRootElementUtil() { @@ -158,11 +166,16 @@ public final class XMLRootElementUtil { * @param jaxbClass * @return map */ - public static Map createPropertyDescriptorMap(Class jaxbClass) + public synchronized static Map createPropertyDescriptorMap(Class jaxbClass) throws NoSuchFieldException, IntrospectionException { + Map map = PROPERTY_MAP.get(jaxbClass); + if (map != null) { + return map; + } + + map = new HashMap(); PropertyDescriptor[] pds = Introspector.getBeanInfo(jaxbClass).getPropertyDescriptors(); - Map map = new HashMap(); // Unfortunately the element names are stored on the fields. // Get all of the fields in the class and super classes @@ -217,8 +230,8 @@ public final class XMLRootElementUtil { map.put(xmlName, new JAXBPropertyDescriptor(pd, xmlName, index)); index++; } - } + PROPERTY_MAP.put(jaxbClass, map); return map; } @@ -228,7 +241,7 @@ public final class XMLRootElementUtil { * @param beanClass * @return */ - private static List getFields(final Class beanClass) { + static private List getFields(final Class beanClass) { // This class must remain private due to Java 2 Security concerns List fields = AccessController.doPrivileged(new PrivilegedAction>() { public List run() { @@ -273,7 +286,7 @@ public final class XMLRootElementUtil { /** * Get an annotation. This is wrappered to avoid a Java2Security violation. * @param cls Class that contains annotation - * @param annotation Class of requested Annotation + * @param annotation Class of requrested Annotation * @return annotation or null */ private static T getAnnotation(final AnnotatedElement element, final Class annotation) { -- cgit v1.2.3