Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 83853 invoked from network); 7 Jul 2009 19:30:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Jul 2009 19:30:29 -0000 Received: (qmail 98896 invoked by uid 500); 7 Jul 2009 19:30:39 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 98841 invoked by uid 500); 7 Jul 2009 19:30:39 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 98832 invoked by uid 99); 7 Jul 2009 19:30:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jul 2009 19:30:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jul 2009 19:30:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AAEF723888A4; Tue, 7 Jul 2009 19:30:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090707193014.AAEF723888A4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 BUILTIN_SCHEMA_LOCS = new HashMap(); { 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 schemas; private Map 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 getNamespaceMap() { return namespaceMap; @@ -211,10 +238,9 @@ this.namespaceMap = namespaceMap; } - /** - * Provide explicit mappings to ReflectionServiceFactory. - * {@inheritDoc} - * */ + /** + * Provide explicit mappings to ReflectionServiceFactory. {@inheritDoc} + */ public Map getDeclaredNamespaceMappings() { return this.namespaceMap; }