cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1292763 - in /cxf/trunk/rt: core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java
Date Thu, 23 Feb 2012 12:22:19 GMT
Author: ay
Date: Thu Feb 23 12:22:19 2012
New Revision: 1292763

URL: http://svn.apache.org/viewvc?rev=1292763&view=rev
Log:
[CXF-3993] WS-RM's blueprint configuration fails to parse RMAssertion entries (fix)

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java?rev=1292763&r1=1292762&r2=1292763&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
Thu Feb 23 12:22:19 2012
@@ -18,7 +18,14 @@
  */
 package org.apache.cxf.configuration.blueprint;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
@@ -33,6 +40,10 @@ import org.apache.aries.blueprint.mutabl
 import org.apache.aries.blueprint.mutable.MutableRefMetadata;
 import org.apache.aries.blueprint.mutable.MutableValueMetadata;
 import org.apache.cxf.bus.blueprint.BlueprintBus;
+import org.apache.cxf.common.jaxb.JAXBContextCache;
+import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.osgi.framework.Bundle;
@@ -49,6 +60,11 @@ public abstract class AbstractBPBeanDefi
     private static final String XMLNS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
     private static final String COMPONENT_ID = "component-id";
 
+    private static final Logger LOG = LogUtils.getL7dLogger(AbstractBPBeanDefinitionParser.class);
+
+    private JAXBContext jaxbContext;
+    private Set<Class<?>> jaxbClasses;
+
     protected boolean hasBusProperty() {
         return false;
     }
@@ -285,4 +301,60 @@ public abstract class AbstractBPBeanDefi
             el = DOMUtils.getNextElement(el);
         }
     }
+
+    protected void mapElementToJaxbProperty(ParserContext ctx,
+                                            MutableBeanMetadata bean, Element parent, 
+                                            QName name,
+                                            String propertyName, 
+                                            Class<?> c) {
+
+        Element data = DOMUtils.getFirstChildWithName(parent, name);
+        if (data == null) {
+            return;
+        }
+        
+        try {
+            Unmarshaller unmarshaller = getContext(c).createUnmarshaller();
+            MutablePassThroughMetadata value = ctx.createMetadata(MutablePassThroughMetadata.class);
+            value.setObject(unmarshaller.unmarshal(data, c).getValue());
+            bean.addProperty(propertyName, value);
+        } catch (JAXBException e) {
+            LOG.warning("Unable to parse property " + propertyName + " due to " + e);
+        }
+    }
+
+    private synchronized JAXBContext getContext(Class<?> cls) {
+        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
+            try {
+                Set<Class<?>> tmp = new HashSet<Class<?>>();
+                if (jaxbClasses != null) {
+                    tmp.addAll(jaxbClasses);
+                }
+                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
+                                            cls == null 
+                                            ? getClass().getClassLoader() 
+                                                : cls.getClassLoader());
+                if (cls != null) {
+                    boolean hasOf = false;
+                    for (Class<?> c : tmp) {
+                        if (c.getPackage() == cls.getPackage()
+                            && "ObjectFactory".equals(c.getSimpleName())) {
+                            hasOf = true;
+                        }
+                    }
+                    if (!hasOf) {
+                        tmp.add(cls);
+                    }
+                }
+                JAXBContextCache.scanPackages(tmp);
+                CachedContextAndSchemas ccs 
+                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
+                jaxbClasses = ccs.getClasses();
+                jaxbContext = ccs.getContext();
+            } catch (JAXBException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return jaxbContext;
+    }
 }

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java?rev=1292763&r1=1292762&r2=1292763&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/blueprint/RMBPBeanDefinitionParser.java
Thu Feb 23 12:22:19 2012
@@ -19,25 +19,14 @@
 
 package org.apache.cxf.ws.rm.blueprint;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
 
 import org.apache.aries.blueprint.ParserContext;
 import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
-import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
-import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.ws.rm.RMManager;
 import org.apache.cxf.ws.rm.manager.DeliveryAssuranceType;
 import org.apache.cxf.ws.rm.manager.DestinationPolicyType;
@@ -52,10 +41,6 @@ import org.osgi.service.blueprint.reflec
 public class RMBPBeanDefinitionParser extends AbstractBPBeanDefinitionParser {
     protected static final String RM_NS = "http://cxf.apache.org/ws/rm/manager";
 
-    private static final Logger LOG = LogUtils.getL7dLogger(RMBPBeanDefinitionParser.class);
-
-    private Map<Class<?>, JAXBContext> jaxbContexts = new HashMap<Class<?>,
JAXBContext>();
-
     private Class<?> beanClass;
     
     public RMBPBeanDefinitionParser(Class<?> beanClass) {
@@ -100,8 +85,6 @@ public class RMBPBeanDefinitionParser ex
         return bean;
     }
 
-
-
     @Override
     protected void mapElement(ParserContext ctx, MutableBeanMetadata bean, Element el, String
name) {
         if ("store".equals(name)) {
@@ -110,32 +93,4 @@ public class RMBPBeanDefinitionParser ex
             bean.addProperty("addressingNamespace", createValue(ctx, el.getTextContent()));
         }
     }
-
-    protected void mapElementToJaxbProperty(ParserContext ctx,
-                                            MutableBeanMetadata bean, Element parent, 
-                                            QName name,
-                                            String propertyName, 
-                                            Class<?> c) {
-
-        Element data = DOMUtils.getFirstElement(parent);
-        
-        try {
-            Unmarshaller unmarshaller = getJAXBContext(c).createUnmarshaller();
-            MutablePassThroughMetadata value = ctx.createMetadata(MutablePassThroughMetadata.class);
-            value.setObject(unmarshaller.unmarshal(data, c).getValue());
-            bean.addProperty(propertyName, value);
-        } catch (JAXBException e) {
-            LOG.warning("Unable to parse property " + propertyName + " due to " + e);
-        }
-    }
-
-    private synchronized JAXBContext getJAXBContext(Class<?> c) throws JAXBException
{
-        JAXBContext jaxbContext = jaxbContexts.get(c);
-        if (jaxbContext == null) {
-            jaxbContext = JAXBContext.newInstance(PackageUtils.getPackageName(c), 
-                                                  c.getClassLoader());
-            jaxbContexts.put(c, jaxbContext);
-        }
-        return jaxbContext;
-    }
 }



Mime
View raw message