diff options
Diffstat (limited to 'branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding')
2 files changed, 32 insertions, 3 deletions
diff --git a/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java index cf330d67c0..4eaaf3db7f 100644 --- a/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java +++ b/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java @@ -47,6 +47,11 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.bind.annotation.XmlTransient; +import javax.xml.bind.annotation.XmlType; import javax.xml.transform.Source; import org.apache.tuscany.sca.databinding.util.LRUCache; @@ -417,9 +422,20 @@ public class JAXBContextCache { } // Adding classes that are not part of JAXB packages for (Class<?> cls : classes) { + Package pkg = getPackage(cls); if (pkg == null || nonJAXBPackages.contains(pkg)) { classSet.add(cls); + } else { + // TUSCANY-3162: Test if a class is generated by JAXB + // There might be the case that non-JAXB classes are in the same package as the JAXB classes + if (!cls.isAnnotationPresent(XmlType.class) + && !cls.isAnnotationPresent(XmlEnum.class) + && !cls.isAnnotationPresent(XmlSeeAlso.class) + && !cls.isAnnotationPresent(XmlRootElement.class) + && !cls.isAnnotationPresent(XmlTransient.class)) { + classSet.add(cls); + } } } return classSet; diff --git a/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java b/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java index ad4bd04084..d177d53eda 100644 --- a/branches/sca-java-1.5.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLRootElementUtil.java +++ b/branches/sca-java-1.5.1/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; @@ -46,6 +47,13 @@ import javax.xml.namespace.QName; */ public class XMLRootElementUtil { + /** + * TUSCANY-3167 + * Cache for property descriptors + */ + private static Map<Class<?>, Map<String, JAXBPropertyDescriptor>> PROPERTY_MAP = + new WeakHashMap<Class<?>, Map<String, JAXBPropertyDescriptor>>(); + /** Constructor is intentionally private. This class only provides static utility methods */ private XMLRootElementUtil() { @@ -158,11 +166,16 @@ public class XMLRootElementUtil { * @param jaxbClass * @return map */ - public static Map<String, JAXBPropertyDescriptor> createPropertyDescriptorMap(Class<?> jaxbClass) + public synchronized static Map<String, JAXBPropertyDescriptor> createPropertyDescriptorMap(Class<?> jaxbClass) throws NoSuchFieldException, IntrospectionException { + Map<String, JAXBPropertyDescriptor> map = PROPERTY_MAP.get(jaxbClass); + if (map != null) { + return map; + } + + map = new HashMap<String, JAXBPropertyDescriptor>(); PropertyDescriptor[] pds = Introspector.getBeanInfo(jaxbClass).getPropertyDescriptors(); - Map<String, JAXBPropertyDescriptor> map = new HashMap<String, JAXBPropertyDescriptor>(); // 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 class XMLRootElementUtil { map.put(xmlName, new JAXBPropertyDescriptor(pd, xmlName, index)); index++; } - } + PROPERTY_MAP.put(jaxbClass, map); return map; } |