cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r732020 - in /cxf/trunk: ./ common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/core/src/main/java/org/apache/cxf/test/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/en...
Date Tue, 06 Jan 2009 17:43:37 GMT
Author: bimargulies
Date: Tue Jan  6 09:43:36 2009
New Revision: 732020

URL: http://svn.apache.org/viewvc?rev=732020&view=rev
Log:
Disentangle unit tests, and especially the soap-encoding support code, from JDOM. Sadly, there's
more work where this came from.

Modified:
    cxf/trunk/   (props changed)
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/MapNamespaceContext.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DepthXMLStreamReader.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java

Propchange: cxf/trunk/
            ('svnmerge-blocked' removed)

Propchange: cxf/trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jan  6 09:43:36 2009
@@ -1 +1 @@
-/cxf/sandbox/benson/aegis_xmlschema:1-730867 /cxf/sandbox/benson/lessjdom:1-731648
+/cxf/sandbox/benson/lessjdom:1-731648

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Tue Jan  6
09:43:36 2009
@@ -531,13 +531,20 @@
     }
 
     /**
-     * Searches the given element including it's parent elements
-     * for a matching namspace decleration.
-     * @param el element to search for namespace definitions
+     * Starting from a node, find the namespace declaration for a prefix.
+     * for a matching namespace declaration.
+     * @param node search up from here to search for namespace definitions
      * @param searchPrefix the prefix we are searching for
      * @return the namespace if found.
      */
-    public static String getNamespace(Element el, String searchPrefix) {
+    public static String getNamespace(Node node, String searchPrefix) {
+        
+        Element el;
+        while (!(node instanceof Element)) {
+            node = node.getParentNode();
+        }
+        el = (Element) node;
+        
         NamedNodeMap atts = el.getAttributes();
         for (int i = 0; i < atts.getLength(); i++) {
             Node currentAttribute = atts.item(i);

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/MapNamespaceContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/MapNamespaceContext.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/MapNamespaceContext.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/MapNamespaceContext.java
Tue Jan  6 09:43:36 2009
@@ -55,11 +55,16 @@
     }
 
     public String getNamespaceURI(String prefix) {
+        if (null == prefix) {
+            throw new IllegalArgumentException("Null prefix to getNamespacePrefix");
+        }
+        // if we have a target node, facts-on-the-ground in its parent tree take precedence.
         if (targetNode != null) {
-            String s = targetNode.lookupNamespaceURI(prefix);
-            if (prefix != null && s != null) {
-                namespaces.put(prefix, s);
+            String uri = DOMUtils.getNamespace(targetNode, prefix);
+            if (uri != null) {
+                return uri;
             }
+            
         }
         return namespaces.get(prefix);
     }

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DepthXMLStreamReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DepthXMLStreamReader.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DepthXMLStreamReader.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DepthXMLStreamReader.java
Tue Jan  6 09:43:36 2009
@@ -75,8 +75,8 @@
         return reader.getAttributeValue(arg0);
     }
 
-    public String getAttributeValue(String arg0, String arg1) {
-        return reader.getAttributeValue(arg0, arg1);
+    public String getAttributeValue(String namespace, String localName) {
+        return reader.getAttributeValue(namespace, localName);
     }
 
     public String getCharacterEncodingScheme() {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/AbstractCXFTest.java Tue Jan  6 09:43:36
2009
@@ -25,6 +25,7 @@
 import java.util.Map;
 
 import javax.wsdl.WSDLException;
+import javax.xml.namespace.NamespaceContext;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -34,6 +35,7 @@
 import org.apache.cxf.BusException;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.helpers.MapNamespaceContext;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -156,6 +158,10 @@
     public void addNamespace(String ns, String uri) {
         testUtilities.addNamespace(ns, uri);
     }
+    
+    public NamespaceContext getNamespaceContext() {
+        return new MapNamespaceContext(testUtilities.getNamespaces());
+    }
 
     public Map<String, String> getNamespaces() {
         return testUtilities.getNamespaces();

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfo.java
Tue Jan  6 09:43:36 2009
@@ -24,6 +24,8 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
+
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.aegis.DatabindingException;
@@ -56,7 +58,8 @@
     }
 
     public ArrayTypeInfo(MessageReader reader, TypeMapping tm) {
-        this(readAttributeValue(reader, SOAP_ARRAY_TYPE), readAttributeValue(reader, SOAP_ARRAY_OFFSET));
+        this(reader.getXMLStreamReader().getNamespaceContext(),
+             readAttributeValue(reader, SOAP_ARRAY_TYPE), readAttributeValue(reader, SOAP_ARRAY_OFFSET));
 
         // if type is xsd:ur-type replace it with xsd:anyType
         String namespace = reader.getNamespaceForPrefix(typeName.getPrefix());
@@ -85,11 +88,11 @@
         }
     }
 
-    public ArrayTypeInfo(String arrayTypeValue) {
-        this(arrayTypeValue, null);
+    public ArrayTypeInfo(NamespaceContext namespaceContext, String arrayTypeValue) {
+        this(namespaceContext, arrayTypeValue, null);
     }
 
-    public ArrayTypeInfo(String arrayTypeValue, String offsetString) {
+    public ArrayTypeInfo(NamespaceContext namespaceContext, String arrayTypeValue, String
offsetString) {
         if (arrayTypeValue == null) {
             throw new NullPointerException("arrayTypeValue is null");
         }
@@ -110,7 +113,8 @@
             throw new DatabindingException("Invalid ArrayType value " + arrayTypeValue);
         }
         if (tokens.get(1).equals(":")) {
-            typeName = new QName("", tokens.get(2), tokens.get(0));
+            typeName = 
+                new QName(namespaceContext.getNamespaceURI(tokens.get(0)), tokens.get(2),
tokens.get(0));
             tokens = tokens.subList(3, tokens.size());
         } else {
             typeName = new QName("", tokens.get(0));
@@ -218,6 +222,11 @@
 
     public String toString() {
         StringBuilder string = new StringBuilder();
+        
+        // no prefix handed to us by someone else ...
+        if ("".equals(typeName.getPrefix()) && !"".equals(typeName.getNamespaceURI()))
{
+            throw new RuntimeException("No prefix provided in QName for " + typeName.getNamespaceURI());
+        }
 
         // typeName: foo:bar
         if (typeName.getPrefix() != null && typeName.getPrefix().length() > 0)
{

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/encoded/SoapArrayType.java
Tue Jan  6 09:43:36 2009
@@ -136,7 +136,7 @@
                 sparse = position != null;
             }
 
-            // nested element names can specifiy a type
+            // nested element names can specify a type
             Type compType = getTypeMapping().getType(creader.getName());
             if (compType == null) {
                 // use the type declared in the arrayType attribute
@@ -291,6 +291,9 @@
         // Root component's schema type
         QName rootType = getRootType();
         String prefix = writer.getPrefixForNamespace(rootType.getNamespaceURI(), rootType.getPrefix());
+        if (prefix == null) {
+            prefix = "";
+        }
         rootType = new QName(rootType.getNamespaceURI(), rootType.getLocalPart(), prefix);
 
 
@@ -298,6 +301,9 @@
         ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(rootType,
                 getDimensions() - 1,
                 Array.getLength(values));
+        // ensure that the writer writes out this prefix...
+        writer.getPrefixForNamespace(arrayTypeInfo.getTypeName().getNamespaceURI(), 
+                                     arrayTypeInfo.getTypeName().getPrefix());
         arrayTypeInfo.writeAttribute(writer);
 
         // write each element

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
Tue Jan  6 09:43:36 2009
@@ -75,7 +75,7 @@
         DOMUtils.getPrefixesRecursive(element, namespaceURI, prefixes);
     }
 
-    private static String getUniquePrefix(Element el) {
+    public static String getUniquePrefix(Element el) {
         int n = 1;
 
         while (true) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/jdom/JDOMWriter.java
Tue Jan  6 09:43:36 2009
@@ -71,7 +71,7 @@
     }
 
     public XMLStreamWriter getXMLStreamWriter() {
-        throw new UnsupportedOperationException("Stream writing not supported from a JDOMWriter.");
+        throw new UnsupportedOperationException("Stream writing not supported from a W3CDOMWriter.");
     }
 
     public String getPrefixForNamespace(String namespace, String hint) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
Tue Jan  6 09:43:36 2009
@@ -162,6 +162,7 @@
     public void close() {
         try {
             writer.writeEndElement();
+            writer.flush();
         } catch (XMLStreamException e) {
             throw new DatabindingException("Error writing document.", e);
         }
@@ -207,13 +208,18 @@
     public String getPrefixForNamespace(String ns, String hint) {
         try {
             String pfx = writer.getPrefix(ns);
+            String contextPfx = writer.getNamespaceContext().getPrefix(ns);
 
             if (pfx == null) {
                 String ns2 = writer.getNamespaceContext().getNamespaceURI(hint);
-                if (ns2 == null) {
+                // if the hint is "" (the default) and the context does 
+                if (ns2 == null && !"".equals(hint)) { 
                     pfx = hint;
-                } else if (ns2.equals(ns)) {
-                    return pfx;
+                } else if (ns.equals(ns2)) {
+                    // just because it's in the context, doesn't mean it has been written.
+                    pfx = hint;
+                } else if (contextPfx != null) {
+                    pfx = contextPfx;
                 } else {
                     pfx = NamespaceHelper.getUniquePrefix(writer);
                 }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/AbstractAegisTest.java
Tue Jan  6 09:43:36 2009
@@ -26,16 +26,22 @@
 import javax.wsdl.WSDLException;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMResult;
 
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.binding.soap.SoapBindingConstants;
 import org.apache.cxf.binding.soap.SoapBindingFactory;
@@ -48,9 +54,12 @@
 import org.apache.cxf.endpoint.ServerRegistry;
 import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
 import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.MapNamespaceContext;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
 import org.apache.cxf.service.Service;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.test.AbstractCXFTest;
 import org.apache.cxf.transport.ConduitInitiatorManager;
 import org.apache.cxf.transport.DestinationFactoryManager;
@@ -61,8 +70,6 @@
 import org.apache.cxf.wsdl11.WSDLManagerImpl;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.utils.NamespaceMap;
-import org.jdom.Element;
-import org.jdom.output.DOMOutputter;
 import org.junit.Before;
 
 public abstract class AbstractAegisTest extends AbstractCXFTest {
@@ -71,7 +78,7 @@
     @Before
     public void setUp() throws Exception {
         super.setUpBus();
-
+        
         SoapBindingFactory bindingFactory = new SoapBindingFactory();
         bindingFactory.setBus(bus);
 
@@ -234,23 +241,6 @@
 
     }
 
-    protected void assertXPathEquals(String xpath, String value, Element element) throws
Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-        assertXPathEquals(xpath, value, doc);
-    }
-
-    protected NodeList assertValid(String xpath, Element element) throws Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-
-        return assertValid(xpath, doc);
-    }
-
-    protected void assertInvalid(String xpath, Element element) throws Exception {
-        org.w3c.dom.Document doc = new DOMOutputter().output(element.getDocument());
-
-        assertInvalid(xpath, doc);
-    }
-
     protected Document getWSDLDocument(String string) throws WSDLException {
         Definition definition = getWSDLDefinition(string);
         if (definition == null) {
@@ -279,4 +269,48 @@
         xmlsNamespaceMap.add("xsd", XmlSchemaConstants.XSD_NAMESPACE_URI);
         return s;
     }
+    
+    protected Element createElement(String namespace, String name) {
+        return createElement(namespace, name, null);
+    }
+
+    protected Element createElement(String namespace, String name, String namespacePrefix)
{
+        Document doc = DOMUtils.createDocument();
+
+        Element element = doc.createElementNS(namespace, name);
+        if (namespacePrefix != null) {
+            element.setPrefix(namespacePrefix);
+            DOMUtils.addNamespacePrefix(element, namespace, namespacePrefix);
+        }
+
+        doc.appendChild(element);
+        return element;
+    }
+    
+    protected ElementWriter getElementWriter(Element element) {
+        return getElementWriter(element, new MapNamespaceContext());
+    }
+
+    protected ElementWriter getElementWriter(Element element, NamespaceContext namespaceContext)
{
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(new DOMResult(element));
+        try {
+            writer.setNamespaceContext(namespaceContext);
+        } catch (XMLStreamException e) {
+            throw new RuntimeException(e);
+        }
+        return new ElementWriter(writer);
+    }
+
+    protected Element writeObjectToElement(Type type, Object bean) {
+        return writeObjectToElement(type, bean, getContext());
+    }
+
+    protected Element writeObjectToElement(Type type, Object bean, Context context) {
+        Element element = createElement("urn:Bean", "root", "b");
+        ElementWriter writer = getElementWriter(element, new MapNamespaceContext());
+        type.writeObject(bean, writer, getContext());
+        writer.close();
+        return element;
+    }
+    
 }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/BeanTest.java
Tue Jan  6 09:43:36 2009
@@ -24,6 +24,10 @@
 import java.util.Date;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import org.apache.cxf.aegis.AbstractAegisTest;
 import org.apache.cxf.aegis.AegisContext;
@@ -32,21 +36,18 @@
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeCreationOptions;
 import org.apache.cxf.aegis.type.TypeMapping;
-import org.apache.cxf.aegis.util.jdom.StaxBuilder;
-import org.apache.cxf.aegis.xml.jdom.JDOMReader;
-import org.apache.cxf.aegis.xml.jdom.JDOMWriter;
 import org.apache.cxf.aegis.xml.stax.ElementReader;
 import org.apache.cxf.aegis.xml.stax.ElementWriter;
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.common.xmlschema.XmlSchemaConstants;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaAttribute;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
-import org.jdom.Document;
-import org.jdom.Element;
 import org.junit.Test;
 
 public class BeanTest extends AbstractAegisTest {
@@ -99,14 +100,12 @@
         bean.setBleh("bleh");
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
 
         assertValid("/b:root/b:bleh[text()='bleh']", element);
         assertValid("/b:root/b:howdy[text()='howdy']", element);
     }
-    
+
     @Test
     public void testBeanWithXsiType() throws Exception {
         BeanType type = new BeanType();
@@ -125,10 +124,7 @@
 
         reader.getXMLStreamReader().close();
 
-        // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
 
         assertValid("/b:root/b:bleh[text()='bleh']", element);
         assertValid("/b:root/b:howdy[text()='howdy']", element);
@@ -158,10 +154,7 @@
 
         reader.getXMLStreamReader().close();
 
-        // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
 
         assertInvalid("/b:root/b:bleh", element);
         assertValid("/b:root/b:howdycustom[text()='howdy']", element);
@@ -188,10 +181,7 @@
         reader.getXMLStreamReader().close();
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
-
+        Element element = writeObjectToElement(type, bean, getContext());
         assertValid("/b:root[@b:bleh='bleh']", element);
         assertValid("/b:root[@b:howdy='howdy']", element);
         
@@ -247,9 +237,8 @@
 
         bos.close();
         
-        StaxBuilder builder = new StaxBuilder();
-        Document doc = builder.build(new ByteArrayInputStream(bos.toByteArray()));
-        Element element = doc.getRootElement();
+        Document doc = DOMUtils.readXml(new ByteArrayInputStream(bos.toByteArray()));
+        Element element = doc.getDocumentElement();
 
         addNamespace("b2", "urn:Bean2");
         assertValid("/b:root[@b2:bleh='bleh']", element);
@@ -271,9 +260,8 @@
         SimpleBean bean = new SimpleBean();
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        
+        Element element = writeObjectToElement(type, bean, getContext());
 
         assertInvalid("/b:root[@b:howdy]", element);
         assertValid("/b:root/b:bleh[@xsi:nil='true']", element);
@@ -449,12 +437,10 @@
         assertTrue(littleByteOk);
         assertTrue(bigByteOk);
         
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
         SimpleBean bean = new SimpleBean();
         bean.setBigByte(new Byte((byte)0xfe));
         bean.setLittleByte((byte)0xfd);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
         Byte bb = new Byte((byte)0xfe);
         String bbs = bb.toString();
         assertValid("/b:root/bz:bigByte[text()='" + bbs + "']", element);
@@ -482,9 +468,7 @@
         DateBean bean = new DateBean();
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
 
         // Make sure the date doesn't have an element. Its non nillable so it
         // just
@@ -508,10 +492,7 @@
         ExtendedBean bean = new ExtendedBean();
         bean.setHowdy("howdy");
 
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
-
+        Element element = writeObjectToElement(type, bean, getContext());
         assertValid("/b:root/b:howdy[text()='howdy']", element);
     }
     @Test
@@ -533,9 +514,7 @@
         ByteBean bean = new ByteBean();
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        type.writeObject(bean, new JDOMWriter(element), getContext());
+        Element element = writeObjectToElement(type, bean, getContext());
 
         // Make sure the date doesn't have an element. Its non nillable so it
         // just
@@ -544,7 +523,8 @@
         addNamespace("xsi", SOAPConstants.XSI_NS);
         assertValid("/b:root/b:data[@xsi:nil='true']", element);
 
-        bean = (ByteBean)type.readObject(new JDOMReader(element), getContext());
+        XMLStreamReader sreader = StaxUtils.createXMLStreamReader(element);
+        bean = (ByteBean)type.readObject(new ElementReader(sreader), getContext());
         assertNotNull(bean);
         assertNull(bean.getData());
     }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/QualificationTest.java
Tue Jan  6 09:43:36 2009
@@ -20,6 +20,8 @@
 
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.aegis.AbstractAegisTest;
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.Context;
@@ -28,10 +30,8 @@
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeCreationOptions;
 import org.apache.cxf.aegis.type.TypeMapping;
-import org.apache.cxf.aegis.xml.jdom.JDOMWriter;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.jdom.Document;
-import org.jdom.Element;
+
 import org.junit.Test;
 
 public class QualificationTest extends AbstractAegisTest {
@@ -55,10 +55,8 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         Context messageContext = new Context(context);
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
         AttributeBean bean = new AttributeBean();
-        type.writeObject(bean, new JDOMWriter(element), messageContext);
+        Element element = writeObjectToElement(type, bean, messageContext);
         assertValid("/b:root[@xyzzy:attrExplicitString]", element);
         assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
         assertValid("/b:root[@attrPlainString]", element);
@@ -79,10 +77,8 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         Context messageContext = new Context(context);
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
         AttributeBean bean = new AttributeBean();
-        type.writeObject(bean, new JDOMWriter(element), messageContext);
+        Element element = writeObjectToElement(type, bean, messageContext);
         assertValid("/b:root[@xyzzy:attrExplicitString]", element);
         assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
         assertValid("/b:root[@pkg:attrPlainString]", element);
@@ -98,10 +94,9 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         Context messageContext = new Context(context);
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
         XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
-        type.writeObject(bean, new JDOMWriter(element), messageContext);
+        
+        Element element = writeObjectToElement(type, bean, messageContext);
         assertValid("/b:root[@attrXmlString]", element);
         assertXPathEquals("/b:root/@attrXmlString", "attrXml", element);
     }
@@ -120,10 +115,9 @@
         type.setSchemaType(new QName("urn:Bean", "bean"));
 
         Context messageContext = new Context(context);
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
         XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
-        type.writeObject(bean, new JDOMWriter(element), messageContext);
+
+        Element element = writeObjectToElement(type, bean, messageContext);
         assertValid("/b:root[@pkg:attrXmlString]", element);
         assertXPathEquals("/b:root/@pkg:attrXmlString", "attrXml", element);
     }

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/AbstractEncodedTest.java
Tue Jan  6 09:43:36 2009
@@ -19,10 +19,13 @@
 package org.apache.cxf.aegis.type.encoded;
 
 import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.List;
 import java.util.Map;
 import javax.xml.stream.XMLStreamException;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.aegis.AbstractAegisTest;
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.Context;
@@ -32,15 +35,13 @@
 import org.apache.cxf.aegis.type.TypeMapping;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
-import org.apache.cxf.aegis.xml.jdom.JDOMWriter;
 import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.common.util.SOAPConstants;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.Namespace;
-import org.jdom.output.Format;
-import org.jdom.output.XMLOutputter;
+import org.apache.cxf.helpers.MapNamespaceContext;
+import org.apache.cxf.helpers.XMLUtils;
+
 import org.junit.Before;
 
 public abstract class AbstractEncodedTest extends AbstractAegisTest {
@@ -100,10 +101,14 @@
     }
 
     public Object readRef(Element element) throws XMLStreamException {
-        XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
-        String xml = xmlOutputter.outputString(element);
-        ElementReader root = new ElementReader(new ByteArrayInputStream(xml.getBytes()));
-        return readRef(root);
+        String xml = XMLUtils.toString(element);
+        ElementReader root;
+        try {
+            root = new ElementReader(new ByteArrayInputStream(xml.getBytes("utf-8")));
+            return readRef(root);
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public Object readRef(ElementReader root) throws XMLStreamException {
@@ -135,12 +140,12 @@
         assertNotNull("no type found for " + instance.getClass().getName());
 
         // create the document
-        Element element = new Element("root", "b", "urn:Bean");
+        Element element = createElement("urn:Bean", "root", "b");
+        MapNamespaceContext namespaces = new MapNamespaceContext();
         for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
-            element.addNamespaceDeclaration(Namespace.getNamespace(entry.getKey(), entry.getValue()));
+            namespaces.addNamespace(entry.getKey(), entry.getValue());
         }
-        new Document(element);
-        JDOMWriter rootWriter = new JDOMWriter(element);
+        ElementWriter rootWriter = getElementWriter(element, namespaces);
         Context context = getContext();
 
         // get Type based on the object instance

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/ArrayTypeInfoTest.java
Tue Jan  6 09:43:36 2009
@@ -88,7 +88,7 @@
     }
 
     public void assertEquals(ArrayTypeInfo expected, String actualString) throws Exception
{
-        ArrayTypeInfo actual = new ArrayTypeInfo(actualString);
+        ArrayTypeInfo actual = new ArrayTypeInfo(getNamespaceContext(), actualString);
 
         // only compare local part because prefix is only resolved when using the MessageReader
constructor
         assertEquals(expected.getRanks(), actual.getRanks());
@@ -128,7 +128,7 @@
 
     public void assertInvalid(String actualString) {
         try {
-            new ArrayTypeInfo(actualString);
+            new ArrayTypeInfo(getNamespaceContext(), actualString);
             fail("Expected a DatabindingException from invalid arrayType " + actualString);
         } catch (Exception expected) {
             // expected

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/SoapArrayTypeTest.java
Tue Jan  6 09:43:36 2009
@@ -125,12 +125,23 @@
         assertArrayEquals(Arrays.asList(objects).toString(),
                           new Object[]{42, new BigDecimal("42.42"), "Forty Two"},
                           objects);
-
+    }
+    
+    @Test
+    public void testUrTypeArrayReadWriteRef1() throws Exception {
+        Object[] objects;
         // round trip tests
         objects = readWriteReadRef("arrayUrType1.xml", Object[].class);
         assertArrayEquals(new Object[]{42, new Float(42.42f), "Forty Two"}, objects);
+    }
+
+    @Test
+    public void testUrTypeArrayReadWriteRef2() throws Exception {
+        Object[] objects;
+        // round trip tests
         objects = readWriteReadRef("arrayUrType2.xml", Object[].class);
         assertArrayEquals(new Object[]{42, new BigDecimal("42.42"), "Forty Two"}, objects);
+        
     }
 
     @Test

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java?rev=732020&r1=732019&r2=732020&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/encoded/StructTypeTest.java
Tue Jan  6 09:43:36 2009
@@ -22,17 +22,16 @@
 import java.util.TreeMap;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
 import org.apache.cxf.aegis.AegisContext;
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
-import org.apache.cxf.aegis.xml.jdom.JDOMWriter;
 import org.apache.cxf.aegis.xml.stax.ElementReader;
-import org.apache.cxf.helpers.CastUtils;
-import org.jdom.Attribute;
-import org.jdom.Content;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.output.XMLOutputter;
+import org.apache.cxf.helpers.DOMUtils;
+
 import org.junit.Test;
 
 public class StructTypeTest extends AbstractEncodedTest {
@@ -82,9 +81,7 @@
         reader.getXMLStreamReader().close();
 
         // Test writing
-        Element element = new Element("root", "b", "urn:Bean");
-        new Document(element);
-        addressType.writeObject(address, new JDOMWriter(element), getLocalContext());
+        Element element = writeObjectToElement(addressType, address, getLocalContext());

         validateShippingAddress(element);
     }
 
@@ -162,9 +159,9 @@
     private void validatePurchaseOrder(Element element) throws Exception {
         Element poRefElement = null;
         Map<String, Element> blocks = new TreeMap<String, Element>();
-        for (Content content : CastUtils.<Content>cast(element.getContent())) {
-            if (content instanceof Element) {
-                Element child = (Element) content;
+        for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
+            if (n instanceof Element) {
+                Element child = (Element) n;
                 if (poRefElement == null) {
                     poRefElement = child;
                 } else {
@@ -176,11 +173,11 @@
 
         Element po = getReferencedElement("poRef", poRefElement, blocks);
 
-        Element shippingRef = po.getChild("shipping");
+        Element shippingRef = (Element)DOMUtils.getChild(po, "shipping");
         Element shipping = getReferencedElement("shipping", shippingRef, blocks);
         validateShippingAddress(shipping);
 
-        Element billingRef = po.getChild("billing");
+        Element billingRef = (Element)DOMUtils.getChild(po, "billing");
         Element billing = getReferencedElement("billing", billingRef, blocks);
         validateBillingAddress(billing);
     }
@@ -197,26 +194,22 @@
     }
 
     private static void assertChildEquals(String expected, Element element, String childName)
{
-        assertEquals(expected, element.getChild(childName).getText());
+        assertEquals(expected, DOMUtils.getChild(element, childName).getTextContent());
     }
 
     private String getId(String childName, Element child) {
         assertNotNull(childName + " is null", child);
-        Attribute idAttribute = child.getAttribute("id");
-        XMLOutputter xmlOutputter = new XMLOutputter();
-        assertNotNull(childName + " id is null \n" + xmlOutputter.outputString(child), idAttribute);
+        Attr idAttribute = child.getAttributeNode("id");
+        assertNotNull(childName + " id is null \n", idAttribute);
         String id = idAttribute.getValue();
-        assertNotNull(childName + " id is null \n" + xmlOutputter.outputString(child), id);
+        assertNotNull(childName + " id is null \n", id);
         return id;
     }
 
     private String getRef(String childName, Element child) {
         assertNotNull(childName + " is null", child);
-        Attribute hrefAttribute = child.getAttribute("href");
-        XMLOutputter xmlOutputter = new XMLOutputter();
-        assertNotNull(childName + " href is null \n" + xmlOutputter.outputString(child),
hrefAttribute);
-        String href = hrefAttribute.getValue();
-        assertNotNull(childName + " href is null \n" + xmlOutputter.outputString(child),
href);
-        return href;
+        String hrefAttribute = child.getAttribute("href");
+        assertNotSame("", childName + " href is null \n", hrefAttribute);
+        return hrefAttribute;
     }
 }



Mime
View raw message