cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r494310 - in /incubator/cxf/trunk: ./ api/ api/src/main/java/org/apache/cxf/wsdl/ api/src/test/java/org/apache/cxf/wsdl/ api/src/test/resources/schemas/wsdl/ api/src/test/resources/wsdl/
Date Tue, 09 Jan 2007 03:45:00 GMT
Author: ningjiang
Date: Mon Jan  8 19:44:59 2007
New Revision: 494310

URL: http://svn.apache.org/viewvc?view=rev&rev=494310
Log:
[CXF-354] Applied the Balaji's Printing Extension Elements patch 
Update wstx-asl to 3.0.3

Modified:
    incubator/cxf/trunk/api/pom.xml
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/PrettyPrintXMLStreamWriter.java
    incubator/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
    incubator/cxf/trunk/api/src/test/resources/schemas/wsdl/test-conf.xsd
    incubator/cxf/trunk/api/src/test/resources/wsdl/test_ext.wsdl
    incubator/cxf/trunk/pom.xml

Modified: incubator/cxf/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/pom.xml?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/pom.xml (original)
+++ incubator/cxf/trunk/api/pom.xml Mon Jan  8 19:44:59 2007
@@ -80,6 +80,10 @@
             <groupId>javax.annotation</groupId>
             <artifactId>jsr250-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>woodstox</groupId> 
+            <artifactId>wstx-asl</artifactId> 
+        </dependency>
     </dependencies>
 
     <build>

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java Mon
Jan  8 19:44:59 2007
@@ -130,7 +130,7 @@
 
             javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
             XMLStreamWriter writer =
-                new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), pw, parent);
+                new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), parent);
             writer.setNamespaceContext(new javax.xml.namespace.NamespaceContext() {
                 
                 public String getNamespaceURI(String arg) {

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/PrettyPrintXMLStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/PrettyPrintXMLStreamWriter.java?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/PrettyPrintXMLStreamWriter.java
(original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/PrettyPrintXMLStreamWriter.java
Mon Jan  8 19:44:59 2007
@@ -19,7 +19,6 @@
 
 package org.apache.cxf.wsdl;
 
-import java.io.PrintWriter;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Stack;
@@ -46,7 +45,6 @@
     static final int DEFAULT_INDENT_LEVEL = 2;
 
     XMLStreamWriter baseWriter;
-    PrintWriter pw;
 
     int indent;
     Stack<CurrentElement> elems = new Stack<CurrentElement>();
@@ -54,17 +52,23 @@
     boolean nestedStartElement;   
 
     public PrettyPrintXMLStreamWriter(XMLStreamWriter writer,
-                                      PrintWriter printWriter,
                                       Class<?> parent) {
         baseWriter = writer;
-        pw = printWriter;
         indent = getIndentLevel(parent);
     }
 
-    public void indent() {
+    public void writeSpaces() throws XMLStreamException {
         for (int i = 0; i < indent; i++) {
-            pw.print(' ');
+            baseWriter.writeCharacters(" ");
         }
+    }
+
+    public void indentWithSpaces() throws XMLStreamException {
+        writeSpaces();
+        indent();
+    }
+
+    public void indent() {
         indent += DEFAULT_INDENT_LEVEL;
     }
     
@@ -168,15 +172,15 @@
     }
 
     public void writeEndElement() throws XMLStreamException {
-        unindent();
         CurrentElement elem = (CurrentElement) elems.pop();
+        unindent();
         if (elem.hasChildElements()) {
-            pw.println();
-            indent();
+            baseWriter.writeCharacters("\n");
+            writeSpaces();
         }
         baseWriter.writeEndElement();
         if (elems.empty()) {
-            pw.println();
+            baseWriter.writeCharacters("\n");
         }
     }
 
@@ -226,11 +230,11 @@
                            java.lang.String namespaceURI) throws XMLStreamException {
         QName currElemName = new QName(namespaceURI, localName);
         if (elems.empty()) {
-            indent();
+            indentWithSpaces();
         } else {
             baseWriter.writeCharacters("");
-            pw.println();
-            indent();
+            baseWriter.writeCharacters("\n");
+            indentWithSpaces();
             CurrentElement elem = (CurrentElement) elems.peek();
             elem.setChildElements(true);
         }

Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
(original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/wsdl/JAXBExtensionHelperTest.java
Mon Jan  8 19:44:59 2007
@@ -19,6 +19,11 @@
 
 package org.apache.cxf.wsdl;
 
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+
 import java.util.List;
 
 import javax.wsdl.Definition;
@@ -27,13 +32,17 @@
 import javax.wsdl.extensions.ExtensionRegistry;
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
+import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
 
 import junit.framework.TestCase;
 
 import org.apache.cxf.abc.test.AnotherPolicyType;
+import org.apache.cxf.abc.test.NewServiceType;
 import org.apache.cxf.abc.test.TestPolicyType;
 
+import org.apache.cxf.common.util.PackageUtils;
+
 public class JAXBExtensionHelperTest extends TestCase {
 
     private WSDLFactory wsdlFactory;
@@ -69,6 +78,10 @@
                         "org.apache.cxf.abc.test.AnotherPolicyType", Thread.currentThread()
                                         .getContextClassLoader());
 
+        JAXBExtensionHelper.addExtensions(registry, "javax.wsdl.Definition",
+                        "org.apache.cxf.abc.test.NewServiceType", Thread.currentThread()
+                                        .getContextClassLoader());
+
         String file = this.getClass().getResource("/wsdl/test_ext.wsdl").getFile();
 
         wsdlReader.setExtensionRegistry(registry);
@@ -96,6 +109,64 @@
         assertEquals("Unexpected value for TestPolicyType stringAttr", "hello", tp.getStringAttr());
         assertTrue("Unexpected value for AnotherPolicyType floatAttr",
             Math.abs(0.1F - ap.getFloatAttr()) < 0.5E-5);
+    }
+
+    public void testPrettyPrintXMLStreamWriter() throws Exception {
+        JAXBExtensionHelper.addExtensions(registry, "javax.wsdl.Definition",
+                        "org.apache.cxf.abc.test.NewServiceType", Thread.currentThread()
+                                        .getContextClassLoader());
+
+        String file = this.getClass().getResource("/wsdl/test_ext.wsdl").getFile();
+
+        wsdlReader.setExtensionRegistry(registry);
+
+        wsdlDefinition = wsdlReader.readWSDL(file);
+
+        List extList = wsdlDefinition.getExtensibilityElements();
+        NewServiceType newService = null;
+        for (Object ext : extList) {
+            if (ext instanceof NewServiceType) {
+                newService = (NewServiceType) ext;
+                break;
+            }
+        }
+
+        assertNotNull("Could not find extension element NewServiceType", newService);
+
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
+
+        JAXBContext context = JAXBContext.newInstance(PackageUtils.getPackageName(NewServiceType.class),
+                                                      NewServiceType.class.getClassLoader());
+        JAXBExtensionHelper helper = new JAXBExtensionHelper(context, NewServiceType.class);
+        helper.marshall(javax.wsdl.Definition.class,
+                        new QName("http://cxf.apache.org/test/hello_world", "newService"),
+                        newService,
+                        new PrintWriter(stream),
+                        wsdlDefinition,
+                        registry);
+        BufferedReader reader = new BufferedReader(new StringReader(new String(stream.toByteArray())));
+        String actual = reader.readLine();
+        int spaces = 0;
+        while (actual != null) {
+            if (!actual.endsWith("/>")) {
+                if (!actual.contains("</")) {
+                    spaces += 2;
+                } else {
+                    spaces -= 2;
+                }
+            }
+            checkSpaces(actual, spaces);
+            actual = reader.readLine();
+        }
+    }
+
+    private void checkSpaces(String actual, int spaces) {
+        String space = "";
+        for (int i = 0; i < spaces; i++) {
+            space += " ";
+        }
+        assertTrue("Indentation level not proper when marshalling a extension element;" +
actual,
+                   actual.startsWith(space));
     }
 
 }

Modified: incubator/cxf/trunk/api/src/test/resources/schemas/wsdl/test-conf.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/resources/schemas/wsdl/test-conf.xsd?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/src/test/resources/schemas/wsdl/test-conf.xsd (original)
+++ incubator/cxf/trunk/api/src/test/resources/schemas/wsdl/test-conf.xsd Mon Jan  8 19:44:59
2007
@@ -50,6 +50,29 @@
         </xs:complexContent>
     </xs:complexType>
     <xs:element name="anotherPolicy" type="tns:AnotherPolicyType"/>
-
     
+    <xs:complexType name="struct">
+        <xs:sequence>
+            <xs:element name="member" type="tns:memberType" minOccurs="0" maxOccurs="unbounded"/>
+            <xs:element name="struct" type="tns:struct" minOccurs="0" maxOccurs="unbounded"/>
+        </xs:sequence>
+        <xs:attribute name="name" type="xs:string" use="required"/>
+    </xs:complexType>
+
+    <xs:complexType name="memberType">
+        <xs:attribute name="name" type="xs:string" use="required"/>
+    </xs:complexType>
+
+    <xs:element name="newService" type="tns:newServiceType"/>
+
+    <xs:complexType name="newServiceType">
+        <xs:complexContent>
+            <xs:extension base="wsdl:tExtensibilityElement">
+                <xs:sequence>
+                    <xs:element name="struct" type="tns:struct" maxOccurs="unbounded"/>
+                </xs:sequence>
+            </xs:extension>
+        </xs:complexContent>
+    </xs:complexType>
+
 </xs:schema>

Modified: incubator/cxf/trunk/api/src/test/resources/wsdl/test_ext.wsdl
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/resources/wsdl/test_ext.wsdl?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/api/src/test/resources/wsdl/test_ext.wsdl (original)
+++ incubator/cxf/trunk/api/src/test/resources/wsdl/test_ext.wsdl Mon Jan  8 19:44:59 2007
@@ -25,6 +25,24 @@
     xmlns:tns="http://cxf.apache.org/test/hello_world" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 
+    <test:newService name="testDefinitionExtensibility">
+        <test:struct name="testString1">
+            <test:member name="x" />
+            <test:member name="y" />
+            <test:member name="z" />
+        </test:struct>
+        <test:struct name="testString2">
+            <test:member name="x" />
+            <test:member name="y" />
+            <test:member name="z" />
+            <test:struct name="innerTestString1">
+                <test:member name="x" />
+                <test:member name="y" />
+                <test:member name="z" />
+            </test:struct>
+        </test:struct>
+    </test:newService>
+
     <message name="greetMe">
         <part name="stringParam0" type="xsd:string"/>
     </message>

Modified: incubator/cxf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/pom.xml?view=diff&rev=494310&r1=494309&r2=494310
==============================================================================
--- incubator/cxf/trunk/pom.xml (original)
+++ incubator/cxf/trunk/pom.xml Mon Jan  8 19:44:59 2007
@@ -433,7 +433,7 @@
             <dependency>
                 <groupId>woodstox</groupId>
                 <artifactId>wstx-asl</artifactId>
-                <version>3.0.2</version>
+                <version>3.0.3</version>
             </dependency>
             <dependency>
                 <groupId>javax.mail</groupId>



Mime
View raw message