cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r791948 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
Date Tue, 07 Jul 2009 19:30:14 GMT
Author: dkulp
Date: Tue Jul  7 19:30:14 2009
New Revision: 791948

URL: http://svn.apache.org/viewvc?rev=791948&view=rev
Log:
Merged revisions 791354 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r791354 | bimargulies | 2009-07-05 20:59:50 -0400 (Sun, 05 Jul 2009) | 1 line
  
  CXF-2331: try harder to avoid modifying read-only trees.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul  7 19:30:14 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java?rev=791948&r1=791947&r2=791948&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
(original)
+++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
Tue Jul  7 19:30:14 2009
@@ -45,31 +45,31 @@
 import org.apache.ws.commons.schema.XmlSchema;
 
 /**
- * Supply default implementations, as appropriate, for DataBinding. 
+ * Supply default implementations, as appropriate, for DataBinding.
  */
 public abstract class AbstractDataBinding implements DataBinding {
     private static final Map<String, String> BUILTIN_SCHEMA_LOCS = new HashMap<String,
String>();
     {
         BUILTIN_SCHEMA_LOCS.put("http://www.w3.org/2005/08/addressing",
-                     "http://www.w3.org/2006/03/addressing/ws-addr.xsd");
+                                "http://www.w3.org/2006/03/addressing/ws-addr.xsd");
     }
-    
-    
+
     protected int mtomThreshold;
     private Bus bus;
     private Collection<DOMSource> schemas;
     private Map<String, String> namespaceMap;
     private boolean hackAroundEmptyNamespaceIssue;
-    
+
     protected Bus getBus() {
         if (bus == null) {
             return BusFactory.getDefaultBus();
         }
         return bus;
     }
-    
+
     /**
      * This call is used to set the bus. It should only be called once.
+     * 
      * @param bus
      */
     @Resource(name = "cxf")
@@ -87,47 +87,71 @@
     }
 
     public XmlSchema addSchemaDocument(ServiceInfo serviceInfo, SchemaCollection col, Document
d,
-                                          String systemId) {
+                                       String systemId) {
         String ns = d.getDocumentElement().getAttribute("targetNamespace");
-        
+        boolean copied = false;
+
         if (StringUtils.isEmpty(ns)) {
             if (DOMUtils.getFirstElement(d.getDocumentElement()) == null) {
                 hackAroundEmptyNamespaceIssue = true;
                 return null;
             }
-            //create a copy of the dom so we 
-            //can modify it.
+            // create a copy of the dom so we
+            // can modify it.
             d = copy(d);
+            copied = true;
             ns = serviceInfo.getInterface().getName().getNamespaceURI();
             d.getDocumentElement().setAttribute("targetNamespace", ns);
         }
-        
+
         SchemaInfo schemaInfo = serviceInfo.getSchema(ns);
-        if (schemaInfo != null && (systemId == null && schemaInfo.getSystemId()
== null 
-            || systemId != null && systemId.equalsIgnoreCase(schemaInfo.getSystemId())))
{
+        if (schemaInfo != null
+            && (systemId == null && schemaInfo.getSystemId() == null || systemId
!= null
+                                                                        && systemId
+                                                                            .equalsIgnoreCase(schemaInfo
+                                                                                .getSystemId())))
{
             return schemaInfo.getSchema();
         }
-        
-        
+
         if (hackAroundEmptyNamespaceIssue) {
-            d = doEmptyNamespaceHack(d);            
+            d = doEmptyNamespaceHack(d, copied);
         }
 
         Node n = d.getDocumentElement().getFirstChild();
-        while (n != null) { 
+        boolean patchRequired = false;
+        while (n != null) {
             if (n instanceof Element) {
                 Element e = (Element)n;
                 if (e.getLocalName().equals("import")) {
-                    e.removeAttribute("schemaLocation");
-                    updateSchemaLocation(e);
-                    if (StringUtils.isEmpty(e.getAttribute("namespace"))) {
-                        e.setAttribute("namespace", serviceInfo.getInterface().getName().getNamespaceURI());
-                    }
+                    patchRequired = true;
+                    break;
                 }
             }
             n = n.getNextSibling();
         }
         
+        if (patchRequired) {
+            if (!copied) {
+                d = copy(d);
+            }
+            n = d.getDocumentElement().getFirstChild();
+            while (n != null) {
+                if (n instanceof Element) {
+                    Element e = (Element)n;
+                    if (e.getLocalName().equals("import")) {
+                        e = (Element)n;
+                        e.removeAttribute("schemaLocation");
+                        updateSchemaLocation(e);
+                        if (StringUtils.isEmpty(e.getAttribute("namespace"))) {
+                            e.setAttribute("namespace", serviceInfo.getInterface().getName()
+                                .getNamespaceURI());
+                        }
+                    }
+                }
+                n = n.getNextSibling();
+            }
+        }
+
         SchemaInfo schema = new SchemaInfo(ns);
         schema.setSystemId(systemId);
         XmlSchema xmlSchema;
@@ -139,11 +163,12 @@
         serviceInfo.addSchema(schema);
         return xmlSchema;
     }
-    private Document doEmptyNamespaceHack(Document d) {
+
+    private Document doEmptyNamespaceHack(Document d, boolean alreadyWritable) {
         boolean hasStuffToRemove = false;
         Element el = DOMUtils.getFirstElement(d.getDocumentElement());
         while (el != null) {
-            if ("import".equals(el.getLocalName())
+            if ("import".equals(el.getLocalName()) 
                 && StringUtils.isEmpty(el.getAttribute("targetNamespace"))) {
                 hasStuffToRemove = true;
                 break;
@@ -151,9 +176,11 @@
             el = DOMUtils.getNextElement(el);
         }
         if (hasStuffToRemove) {
-            //create a copy of the dom so we 
-            //can modify it.
-            d = copy(d);
+            // create a copy of the dom so we
+            // can modify it.
+            if (!alreadyWritable) {
+                d = copy(d);
+            }
             el = DOMUtils.getFirstElement(d.getDocumentElement());
             while (el != null) {
                 if ("import".equals(el.getLocalName())
@@ -165,7 +192,7 @@
                 }
             }
         }
-            
+
         return d;
     }
 
@@ -173,9 +200,9 @@
         try {
             return StaxUtils.copy(doc);
         } catch (XMLStreamException e) {
-            //ignore
+            // ignore
         } catch (ParserConfigurationException e) {
-            //ignore
+            // ignore
         }
         return doc;
     }
@@ -189,7 +216,7 @@
     }
 
     /**
-      * @return Returns the namespaceMap.
+     * @return Returns the namespaceMap.
      */
     public Map<String, String> getNamespaceMap() {
         return namespaceMap;
@@ -211,10 +238,9 @@
         this.namespaceMap = namespaceMap;
     }
 
-    /** 
-     * Provide explicit mappings to ReflectionServiceFactory.
-     * {@inheritDoc}
-     * */
+    /**
+     * Provide explicit mappings to ReflectionServiceFactory. {@inheritDoc}
+     */
     public Map<String, String> getDeclaredNamespaceMappings() {
         return this.namespaceMap;
     }



Mime
View raw message