cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r833963 - in /cxf/trunk/api/src: main/java/org/apache/cxf/databinding/AbstractDataBinding.java test/java/org/apache/cxf/databinding/ test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java
Date Mon, 09 Nov 2009 01:46:43 GMT
Author: bimargulies
Date: Mon Nov  9 01:46:43 2009
New Revision: 833963

URL: http://svn.apache.org/viewvc?rev=833963&view=rev
Log:
CXF-2520. Fix checks for impossible namespace maps in AbstractDataBinding.

Added:
    cxf/trunk/api/src/test/java/org/apache/cxf/databinding/
    cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java  
(with props)
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=833963&r1=833962&r2=833963&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 Mon Nov
 9 01:46:43 2009
@@ -216,25 +216,21 @@
     }
 
     /**
-     * @return Returns the namespaceMap.
+     * @return the namespaceMap (URI to prefix). This will be null 
+     * if no particular namespace map has been set.
      */
     public Map<String, String> getNamespaceMap() {
         return namespaceMap;
     }
 
     /**
+     * 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) {
-        // make some checks. This is a map from namespace to prefix, but we want unique prefixes.
-        if (namespaceMap != null) {
-            Set<String> prefixesSoFar = new HashSet<String>();
-            for (Map.Entry<String, String> mapping : namespaceMap.entrySet()) {
-                if (prefixesSoFar.contains(mapping.getValue())) {
-                    throw new IllegalArgumentException("Duplicate prefix " + mapping.getValue());
-                }
-            }
-        }
+        checkNamespaceMap(namespaceMap);
         this.namespaceMap = namespaceMap;
     }
 
@@ -253,6 +249,7 @@
                 if (prefixesSoFar.contains(mapping.getValue())) {
                     throw new IllegalArgumentException("Duplicate prefix " + mapping.getValue());
                 }
+                prefixesSoFar.add(mapping.getValue());
             }
         }
     }

Added: cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java?rev=833963&view=auto
==============================================================================
--- cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java (added)
+++ cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java Mon
Nov  9 01:46:43 2009
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.databinding;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class AbstractDataBindingTest extends Assert {
+    @Test(expected = IllegalArgumentException.class)
+    public void testNamespaceMapCheckDuplicates() {
+        Map<String, String> testMap = new HashMap<String, String>();
+        testMap.put("urn:hello.there", "ht");
+        testMap.put("urn:high.temperature", "ht");
+        AbstractDataBinding.checkNamespaceMap(testMap);
+    }
+    
+    @Test
+    public void testNamespaceMapOK() {
+        Map<String, String> testMap = new HashMap<String, String>();
+        testMap.put("urn:hello.there", "ht");
+        testMap.put("urn:high.temperature", "warm");
+        AbstractDataBinding.checkNamespaceMap(testMap);
+    }
+
+}

Propchange: cxf/trunk/api/src/test/java/org/apache/cxf/databinding/AbstractDataBindingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message