cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r992605 - /cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
Date Sat, 04 Sep 2010 14:05:21 GMT
Author: bimargulies
Date: Sat Sep  4 14:05:21 2010
New Revision: 992605

URL: http://svn.apache.org/viewvc?rev=992605&view=rev
Log:
Add some sanity checks to AbstractDataBinding.addSchemaDocument. Something is rotten, and
this will help find out what.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java?rev=992605&r1=992604&r2=992605&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/databinding/AbstractDataBinding.java Sat Sep
 4 14:05:21 2010
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.Resource;
+import javax.xml.XMLConstants;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.dom.DOMSource;
@@ -69,7 +70,7 @@ public abstract class AbstractDataBindin
 
     /**
      * This call is used to set the bus. It should only be called once.
-     * 
+     *
      * @param bus
      */
     @Resource(name = "cxf")
@@ -88,6 +89,23 @@ public abstract class AbstractDataBindin
 
     public XmlSchema addSchemaDocument(ServiceInfo serviceInfo, SchemaCollection col, Document
d,
                                        String systemId) {
+
+
+        /*
+         * Sanity check. The document has to remotely resemble a schema.
+         */
+        if (!XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(d.getDocumentElement().getNamespaceURI()))
{
+            throw new RuntimeException("Invalid schema document passed to "
+                                       + "AbstractDataBinding.addSchemaDocument, "
+                                       + "not in W3C schema namespace");
+        }
+
+        if (!"schema".equals(d.getDocumentElement().getLocalName())) {
+            throw new RuntimeException("Invalid schema document passed to "
+                                       + "AbstractDataBinding.addSchemaDocument, "
+                                       + "document element isn't 'schema'");
+        }
+
         String ns = d.getDocumentElement().getAttribute("targetNamespace");
         boolean copied = false;
 
@@ -129,7 +147,7 @@ public abstract class AbstractDataBindin
             }
             n = n.getNextSibling();
         }
-        
+
         if (patchRequired) {
             if (!copied) {
                 d = copy(d);
@@ -168,7 +186,7 @@ public abstract class AbstractDataBindin
         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;
@@ -216,7 +234,7 @@ public abstract class AbstractDataBindin
     }
 
     /**
-     * @return the namespaceMap (URI to prefix). This will be null 
+     * @return the namespaceMap (URI to prefix). This will be null
      * if no particular namespace map has been set.
      */
     public Map<String, String> getNamespaceMap() {
@@ -224,9 +242,9 @@ public abstract class AbstractDataBindin
     }
 
     /**
-     * Set a map of from URI to prefix. If possible, the data binding will use these 
+     * Set a map of from URI to prefix. If possible, the data binding will use these
      * prefixes on the wire.
-     * 
+     *
      * @param namespaceMap The namespaceMap to set.
      */
     public void setNamespaceMap(Map<String, String> namespaceMap) {



Mime
View raw message