ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1718067 - in /webservices/axiom/branches/datatypes: aspects/core-aspects/src/main/java/org/apache/axiom/core/ datatypes/src/main/java/org/apache/axiom/datatype/ datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/ datatypes/src/ma...
Date Sat, 05 Dec 2015 10:30:33 GMT
Author: veithen
Date: Sat Dec  5 10:30:33 2015
New Revision: 1718067

URL: http://svn.apache.org/viewvc?rev=1718067&view=rev
Log:
Finalize the implementation of XSQNameType.

Modified:
    webservices/axiom/branches/datatypes/aspects/core-aspects/src/main/java/org/apache/axiom/core/ContextAccessorImpl.java
    webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/ContextAccessor.java
    webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/DOMContextAccessor.java
    webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
    webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java

Modified: webservices/axiom/branches/datatypes/aspects/core-aspects/src/main/java/org/apache/axiom/core/ContextAccessorImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/aspects/core-aspects/src/main/java/org/apache/axiom/core/ContextAccessorImpl.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/aspects/core-aspects/src/main/java/org/apache/axiom/core/ContextAccessorImpl.java
(original)
+++ webservices/axiom/branches/datatypes/aspects/core-aspects/src/main/java/org/apache/axiom/core/ContextAccessorImpl.java
Sat Dec  5 10:30:33 2015
@@ -32,4 +32,9 @@ final class ContextAccessorImpl implemen
     public String lookupPrefix(CoreElement element, Semantics semantics, String namespaceURI)
{
         return element.coreLookupPrefix(namespaceURI, semantics);
     }
+
+    public void declareNamespace(CoreElement element, Semantics semantics, String prefix,
String namespaceURI) {
+        // TODO
+        throw new UnsupportedOperationException();
+    }
 }

Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/ContextAccessor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/ContextAccessor.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/ContextAccessor.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/ContextAccessor.java
Sat Dec  5 10:30:33 2015
@@ -39,4 +39,6 @@ public interface ContextAccessor<T,O> {
     String lookupNamespaceURI(T contextObject, O options, String prefix);
     
     String lookupPrefix(T contextObject, O options, String namespaceURI);
+    
+    void declareNamespace(T contextObject, O options, String prefix, String namespaceURI);
 }

Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/DOMContextAccessor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/DOMContextAccessor.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/DOMContextAccessor.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/helper/dom/DOMContextAccessor.java
Sat Dec  5 10:30:33 2015
@@ -36,4 +36,9 @@ final class DOMContextAccessor implement
     public String lookupPrefix(Element element, Void options, String namespaceURI) {
         return element.lookupPrefix(namespaceURI.length() == 0 ? null : namespaceURI);
     }
+
+    public void declareNamespace(Element element, Void options, String prefix, String namespaceURI)
{
+        // TODO
+        throw new UnsupportedOperationException();
+    }
 }

Modified: webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSQNameTypeImpl.java
Sat Dec  5 10:30:33 2015
@@ -26,6 +26,7 @@ import javax.xml.namespace.QName;
 import org.apache.axiom.datatype.ContextAccessor;
 import org.apache.axiom.datatype.TypeHelper;
 import org.apache.axiom.datatype.UnexpectedCharacterException;
+import org.apache.axiom.util.xml.NSUtils;
 
 final class XSQNameTypeImpl implements XSQNameType {
     public <S,O> QName parse(String literal, ContextAccessor<S,O> contextAccessor,
S contextObject, O options)
@@ -69,12 +70,18 @@ final class XSQNameTypeImpl implements X
         String prefix = value.getPrefix();
         String namespaceURI = value.getNamespaceURI();
         if (!namespaceURI.equals(contextAccessor.lookupNamespaceURI(contextObject, options,
prefix))) {
-            String existingPrefix = contextAccessor.lookupPrefix(contextObject, options,
namespaceURI);
-            if (existingPrefix != null) {
-                prefix = existingPrefix;
+            if (namespaceURI.length() == 0) {
+                contextAccessor.declareNamespace(contextObject, options, "", "");
             } else {
-                // TODO
-                throw new RuntimeException();
+                if (prefix.length() == 0) {
+                    prefix = contextAccessor.lookupPrefix(contextObject, options, namespaceURI);
+                    if (prefix == null) {
+                        prefix = NSUtils.generatePrefix(namespaceURI);
+                        contextAccessor.declareNamespace(contextObject, options, prefix,
namespaceURI);;
+                    }
+                } else {
+                    contextAccessor.declareNamespace(contextObject, options, prefix, namespaceURI);;
+                }
             }
         }
         if (prefix.length() == 0) {

Modified: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/MapContextAccessor.java
Sat Dec  5 10:30:33 2015
@@ -36,7 +36,15 @@ public final class MapContextAccessor im
     }
 
     public String lookupPrefix(Map<String,String> context, Void options, String namespaceURI)
{
-        // TODO
-        throw new UnsupportedOperationException();
+        for (Map.Entry<String,String> entry : context.entrySet()) {
+            if (entry.getValue().equals(namespaceURI)) {
+                return entry.getKey();
+            }
+        }
+        return null;
+    }
+
+    public void declareNamespace(Map<String,String> context, Void options, String prefix,
String namespaceURI) {
+        context.put(prefix, namespaceURI);
     }
 }

Modified: webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java?rev=1718067&r1=1718066&r2=1718067&view=diff
==============================================================================
--- webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
(original)
+++ webservices/axiom/branches/datatypes/datatypes/src/test/java/org/apache/axiom/datatype/xsd/XSQNameTypeTest.java
Sat Dec  5 10:30:33 2015
@@ -22,6 +22,8 @@ import static com.google.common.truth.Tr
 
 import java.text.ParseException;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
@@ -30,7 +32,7 @@ import org.junit.Test;
 
 public class XSQNameTypeTest {
     @Test
-    public void testBoundPrefix() throws ParseException {
+    public void testParseWithBoundPrefix() throws ParseException {
         QName qname = XSQNameType.INSTANCE.parse("p:test", MapContextAccessor.INSTANCE,
                 Collections.singletonMap("p", "urn:test"), null);
         assertThat(qname.getNamespaceURI()).isEqualTo("urn:test");
@@ -39,13 +41,13 @@ public class XSQNameTypeTest {
     }
     
     @Test(expected=ParseException.class)
-    public void testUnboundPrefix() throws ParseException {
+    public void testParseWithUnboundPrefix() throws ParseException {
         XSQNameType.INSTANCE.parse("ns:test", MapContextAccessor.INSTANCE,
                 Collections.<String,String>emptyMap(), null);
     }
     
     @Test
-    public void testXmlPrefix() throws ParseException {
+    public void testParseWithXmlPrefix() throws ParseException {
         QName qname = XSQNameType.INSTANCE.parse("xml:value", MapContextAccessor.INSTANCE,
                 Collections.<String,String>emptyMap(), null);
         assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XML_NS_URI);
@@ -54,11 +56,46 @@ public class XSQNameTypeTest {
     }
     
     @Test
-    public void testXmlnsPrefix() throws ParseException {
+    public void testParseWithXmlnsPrefix() throws ParseException {
         QName qname = XSQNameType.INSTANCE.parse("xmlns:value", MapContextAccessor.INSTANCE,
                 Collections.<String,String>emptyMap(), null);
         assertThat(qname.getNamespaceURI()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
         assertThat(qname.getLocalPart()).isEqualTo("value");
         assertThat(qname.getPrefix()).isEqualTo(XMLConstants.XMLNS_ATTRIBUTE);
     }
+    
+    @Test
+    public void testFormatWithUnboundPrefix() {
+        Map<String,String> context = new HashMap<String,String>();
+        assertThat(XSQNameType.INSTANCE.format(new QName("urn:test", "test", "p"),
+                MapContextAccessor.INSTANCE, context, null)).isEqualTo("p:test");
+        assertThat(context).hasSize(1);
+        assertThat(context).containsEntry("p", "urn:test");
+    }
+    
+    @Test
+    public void testFormatWithExistingNamespace() {
+        assertThat(XSQNameType.INSTANCE.format(new QName("urn:test", "test"),
+                MapContextAccessor.INSTANCE, Collections.singletonMap("p", "urn:test"),
+                null)).isEqualTo("p:test");
+    }
+    
+    @Test
+    public void testFormatWithGeneratedPrefix() {
+        Map<String,String> context = new HashMap<String,String>();
+        String literal = XSQNameType.INSTANCE.format(new QName("urn:test", "test"),
+                MapContextAccessor.INSTANCE, context, null);
+        assertThat(context).hasSize(1);
+        Map.Entry<String,String> entry = context.entrySet().iterator().next();
+        assertThat(entry.getValue()).isEqualTo("urn:test");
+        assertThat(entry.getKey()).isNotEmpty();
+        assertThat(literal).isEqualTo(entry.getKey() + ":test");
+    }
+    
+    @Test
+    public void testFormatWithNoNamespace() {
+        assertThat(XSQNameType.INSTANCE.format(new QName("test"),
+                MapContextAccessor.INSTANCE, Collections.<String,String>emptyMap(),
+                null)).isEqualTo("test");
+    }
 }



Mime
View raw message