cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1543152 - in /cxf/branches/2.7.x-fixes: api/src/main/java/org/apache/cxf/common/jaxb/ api/src/main/java/org/apache/cxf/common/util/ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/ tools/javato/ws/src/test/java/org/apache/cxf/tool...
Date Mon, 18 Nov 2013 21:04:41 GMT
Author: dkulp
Date: Mon Nov 18 21:04:40 2013
New Revision: 1543152

URL: http://svn.apache.org/r1543152
Log:
Merged revisions 1540857 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1540857 | dkulp | 2013-11-11 16:54:17 -0500 (Mon, 11 Nov 2013) | 2 lines

  Get a bit furthur with MOXy by fixing some tests to not use hard coded strings

........

Modified:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
    cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
    cxf/branches/2.7.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java?rev=1543152&r1=1543151&r2=1543152&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java Mon
Nov 18 21:04:40 2013
@@ -995,17 +995,16 @@ public final class JAXBUtils {
     }
     
     private static synchronized Object createNamespaceWrapper(Class<?> mcls, Map<String,
String> map) {
-        ASMHelper helper = new ASMHelper();
-        String className = "org.apache.cxf.jaxb.NamespaceMapper";
         String postFix = ""; 
         if (mcls.getName().contains("eclipse")) {
-            //can use the map directly
-            return map;
+            return createEclipseNamespaceMapper(mcls, map);
         } else if (mcls.getName().contains(".internal")) {
             postFix = "Internal";
         } else if (mcls.getName().contains("com.sun")) {
             postFix = "RI";
         }
+        ASMHelper helper = new ASMHelper();
+        String className = "org.apache.cxf.jaxb.NamespaceMapper";
         className += postFix;
         Class<?> cls = helper.findClass(className, JAXBUtils.class);
         if (cls == null) {
@@ -1021,6 +1020,217 @@ public final class JAXBUtils {
             return null;
         }
     }
+    /*
+    // This is the "prototype" for the ASM generated class below
+    public static class MapNamespacePrefixMapper2 
+        extends org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper
{
+        
+        String nsctxt[];
+        
+        public MapNamespacePrefixMapper2(Map<String, String> foo) {
+            super(foo);
+        }
+        public String[] getPreDeclaredNamespaceUris() {
+            String sup[] = super.getPreDeclaredNamespaceUris();
+            if (nsctxt == null) {
+                return sup;
+            }
+            List<String> s = new ArrayList<String>(Arrays.asList(sup));
+            for (int x = 1; x < nsctxt.length; x = x + 2) {
+                s.remove(nsctxt[x]);
+            }
+            return s.toArray(new String[s.size()]);
+        }
+        public void setContextualNamespaceDecls(String f[]) {
+            nsctxt = f;
+        }
+        public String[] getContextualNamespaceDecls() {
+            return nsctxt;
+        }
+    }
+    */
+    //CHECKSTYLE:OFF
+    //bunch of really long ASM based methods that cannot be shortened easily
+    private static Object createEclipseNamespaceMapper(Class<?> mcls, Map<String,
String> map) {
+        ASMHelper helper = new ASMHelper();
+        String className = "org.apache.cxf.jaxb.EclipseNamespaceMapper";
+        String slashedName = "org/apache/cxf/jaxb/EclipseNamespaceMapper";
+        Class<?> cls = helper.findClass(className, JAXBUtils.class);
+        
+        if (cls == null) {
+            ClassWriter cw = helper.createClassWriter();
+            if (cw == null) {
+                return null;
+            }
+            String superName = "org/eclipse/persistence/internal/oxm/record/namespaces/MapNamespacePrefixMapper";
+            FieldVisitor fv;
+            MethodVisitor mv;
+            cw.visit(Opcodes.V1_6,
+                     Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
+                     slashedName, null,
+                     superName, null);
+
+            cw.visitSource("EclipseNamespaceMapper.java", null);
+            
+            fv = cw.visitField(Opcodes.ACC_PRIVATE, "nsctxt", "[Ljava/lang/String;", null,
null);
+            fv.visitEnd();
+            
+           
+            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Ljava/util/Map;)V",

+                                "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V",
null);
+            mv.visitCode();
+            Label l0 = helper.createLabel();
+            mv.visitLabel(l0);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitVarInsn(Opcodes.ALOAD, 1);
+            mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
+                               superName, "<init>", "(Ljava/util/Map;)V");
+            Label l1 = helper.createLabel();
+            mv.visitLabel(l1);
+            mv.visitInsn(Opcodes.RETURN);
+            Label l2 = helper.createLabel();
+            mv.visitLabel(l2);
+            mv.visitMaxs(2, 2);
+            mv.visitEnd();            
+            
+            
+            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setContextualNamespaceDecls", "([Ljava/lang/String;)V",
+                                null, null);
+            mv.visitCode();
+            l0 = helper.createLabel();
+            mv.visitLabel(l0);
+            mv.visitLineNumber(47, l0);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitVarInsn(Opcodes.ALOAD, 1);
+            mv.visitFieldInsn(Opcodes.PUTFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
+            l1 = helper.createLabel();
+            mv.visitLabel(l1);
+            mv.visitLineNumber(48, l1);
+            mv.visitInsn(Opcodes.RETURN);
+            l2 = helper.createLabel();
+            mv.visitLabel(l2);
+            mv.visitLocalVariable("this", "L" + slashedName + ";", null, l0, l2, 0);
+            mv.visitLocalVariable("contextualNamespaceDecls", "[Ljava/lang/String;", null,
l0, l2, 1);
+            mv.visitMaxs(2, 2);
+            mv.visitEnd();
+
+            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getContextualNamespaceDecls", "()[Ljava/lang/String;",
null, null);
+            mv.visitCode();
+            l0 = helper.createLabel();
+            mv.visitLabel(l0);
+            mv.visitLineNumber(51, l0);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
+            mv.visitInsn(Opcodes.ARETURN);
+            l1 = helper.createLabel();
+
+            mv.visitLabel(l1);
+            mv.visitLocalVariable("this", "L" + slashedName + ";", null, l0, l1, 0);
+            
+            mv.visitMaxs(1, 1);
+            mv.visitEnd();
+            
+            
+            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreDeclaredNamespaceUris", "()[Ljava/lang/String;",
null, null);
+            mv.visitCode();
+            l0 = helper.createLabel();
+            mv.visitLabel(l0);
+            mv.visitLineNumber(1036, l0);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, 
+                               superName,
+                               "getPreDeclaredNamespaceUris", "()[Ljava/lang/String;");
+            mv.visitVarInsn(Opcodes.ASTORE, 1);
+            l1 = helper.createLabel();
+            mv.visitLabel(l1);
+            mv.visitLineNumber(1037, l1);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
+            l2 = helper.createLabel();
+            mv.visitJumpInsn(Opcodes.IFNONNULL, l2);
+            Label l3 = helper.createLabel();
+            mv.visitLabel(l3);
+            mv.visitLineNumber(1038, l3);
+            mv.visitVarInsn(Opcodes.ALOAD, 1);
+            mv.visitInsn(Opcodes.ARETURN);
+            mv.visitLabel(l2);
+            mv.visitLineNumber(1040, l2);
+            mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] {"[Ljava/lang/String;"}, 0, null);
+            mv.visitTypeInsn(Opcodes.NEW, "java/util/ArrayList");
+            mv.visitInsn(Opcodes.DUP);
+            mv.visitVarInsn(Opcodes.ALOAD, 1);
+            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "asList", 
+                               "([Ljava/lang/Object;)Ljava/util/List;");
+            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>",
"(Ljava/util/Collection;)V");
+            mv.visitVarInsn(Opcodes.ASTORE, 2);
+            Label l4 = helper.createLabel();
+            mv.visitLabel(l4);
+            mv.visitLineNumber(1041, l4);
+            mv.visitInsn(Opcodes.ICONST_1);
+            mv.visitVarInsn(Opcodes.ISTORE, 3);
+            Label l5 = helper.createLabel();
+            mv.visitLabel(l5);
+            Label l6 = helper.createLabel();
+            mv.visitJumpInsn(Opcodes.GOTO, l6);
+            Label l7 = helper.createLabel();
+            mv.visitLabel(l7);
+            mv.visitLineNumber(1042, l7);
+            mv.visitFrame(Opcodes.F_APPEND, 2, new Object[] {"java/util/List", Opcodes.INTEGER},
0, null);
+            mv.visitVarInsn(Opcodes.ALOAD, 2);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD, slashedName, "nsctxt", "[Ljava/lang/String;");
+            mv.visitVarInsn(Opcodes.ILOAD, 3);
+            mv.visitInsn(Opcodes.AALOAD);
+            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "remove", "(Ljava/lang/Object;)Z");
+            mv.visitInsn(Opcodes.POP);
+            Label l8 = helper.createLabel();
+            mv.visitLabel(l8);
+            mv.visitLineNumber(1041, l8);
+            mv.visitIincInsn(3, 2);
+            mv.visitLabel(l6);
+            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
+            mv.visitVarInsn(Opcodes.ILOAD, 3);
+            mv.visitVarInsn(Opcodes.ALOAD, 0);
+            mv.visitFieldInsn(Opcodes.GETFIELD,
+                              slashedName, 
+                              "nsctxt", "[Ljava/lang/String;");
+            mv.visitInsn(Opcodes.ARRAYLENGTH);
+            mv.visitJumpInsn(Opcodes.IF_ICMPLT, l7);
+            Label l9 = helper.createLabel();
+            mv.visitLabel(l9);
+            mv.visitLineNumber(1044, l9);
+            mv.visitVarInsn(Opcodes.ALOAD, 2);
+            mv.visitVarInsn(Opcodes.ALOAD, 2);
+            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "size", "()I");
+            mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
+            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", 
+                               "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
+            mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/String;");
+            mv.visitInsn(Opcodes.ARETURN);
+            Label l10 = helper.createLabel();
+            mv.visitLabel(l10);
+            mv.visitLocalVariable("this", "L" + slashedName + ";",
+                                  null, l0, l10, 0);
+            mv.visitLocalVariable("sup", "[Ljava/lang/String;", null, l1, l10, 1);
+            mv.visitLocalVariable("s", "Ljava/util/List;", "Ljava/util/List<Ljava/lang/String;>;",
l4, l10, 2);
+            mv.visitLocalVariable("x", "I", null, l5, l9, 3);
+            mv.visitMaxs(3, 4);
+            mv.visitEnd();
+
+            cw.visitEnd();
+
+            byte bts[] = cw.toByteArray();
+            cls = helper.loadClass(className,
+                                   mcls, bts);
+        }
+        try {
+            return cls.getConstructor(Map.class).newInstance(map);
+        } catch (Throwable e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
     private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter
cw, 
                                                            String postFix, Class<?>
ref) {
         String className = "org.apache.cxf.jaxb.NamespaceMapper" + postFix;

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=1543152&r1=1543151&r2=1543152&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java Mon
Nov 18 21:04:40 2013
@@ -105,20 +105,32 @@ public class ASMHelper {
         public static int CHECKCAST = 0;
         public static int INVOKEINTERFACE = 0;
         public static int GETFIELD = 0;
+        public static int GETSTATIC = 0;
         public static int ASTORE = 0;
         public static int PUTFIELD = 0;
+        public static int PUTSTATIC = 0;
         public static int RETURN = 0;
+        public static int F_APPEND = 0;
+        public static int F_SAME = 0;
+        public static int F_SAME1 = 0;
         public static int INVOKESPECIAL = 0;
         public static int ACC_PUBLIC = 0;
         public static int ACC_FINAL = 0;
         public static int ACC_SUPER = 0;
         public static int ACC_PRIVATE = 0;
+        public static int ACC_STATIC = 0;
         public static int V1_5 = 0;
+        public static int V1_6 = 0;
         public static int ACC_ABSTRACT = 0;
         public static int ACC_INTERFACE = 0;
+        public static int ACC_SYNTHETIC = 0;
         public static int ILOAD = 0;
+        public static int ISTORE = 0;
+        public static int AALOAD = 0;
+        public static int ARRAYLENGTH = 0;
         public static int IRETURN = 0;
         public static int NEW = 0;
+        public static int ANEWARRAY = 0;
         public static int DUP = 0;
         public static int ATHROW = 0;
         public static int INVOKEVIRTUAL = 0;
@@ -129,9 +141,12 @@ public class ASMHelper {
         public static int SIPUSH = 0;
         public static int INVOKESTATIC = 0;
         public static int ICONST_0;
+        public static int ICONST_1;
         public static int LCONST_0;
         public static int FCONST_0;
         public static int DCONST_0;
+        public static int IF_ICMPLT = 0;
+        public static java.lang.Integer INTEGER;
         
         //CHECKSTYLE:ON
         static {
@@ -168,7 +183,7 @@ public class ASMHelper {
         return buf.toString();
     }
     
-    protected static String periodToSlashes(String s) {
+    public static String periodToSlashes(String s) {
         char ch[] = s.toCharArray();
         for (int x = 0; x < ch.length; x++) {
             if (ch[x] == '.') {
@@ -445,9 +460,14 @@ public class ASMHelper {
         void visitMethodInsn(int invokevirtual, String periodToSlashes,
                              String name, String methodSignature);
         void visitIntInsn(int sipush, int x);
+        void visitIincInsn(int i, int j);
         void visitFieldInsn(int getfield, String periodToSlashes,
                             String string, String string2);
         void visitJumpInsn(int ifnonnull, @UnwrapParam(typeMethodName = "realType") Label
nonNullLabel);
+        void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack);
+        
+        @WrapReturn(AnnotationVisitor.class)
+        AnnotationVisitor visitAnnotation(String cls, boolean b);
     }
     public interface AnnotationVisitor {
         void visit(String arg0, @UnwrapParam(typeMethodName = "realType") ASMType arg1);

Modified: cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java?rev=1543152&r1=1543151&r2=1543152&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
Mon Nov 18 21:04:40 2013
@@ -224,6 +224,71 @@ public class XMLStreamDataWriterTest ext
         assertEquals("TESTOUTPUTMESSAGE", reader.getText());
     }
 
+    @Test
+    public void testWriteWithNamespacePrefixMapping() throws Exception {
+        JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
+        Map<String, String> nspref = new HashMap<String, String>();
+        nspref.put("http://apache.org/hello_world_soap_http/types", "x");
+        db.setNamespaceMap(nspref);
+        
+        // use the output stream instead of XMLStreamWriter to test
+        DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
+        assertNotNull(dw);
+
+        GreetMe val = new GreetMe();
+        val.setRequestType("Hello");
+        dw.write(val, baos);
+        
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
+        DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
+        StaxUtils.toNextElement(reader);
+        QName qname = reader.getName(); 
+        assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMe"),
qname);
+        assertEquals("x", qname.getPrefix());
+        
+        assertEquals(1, reader.getNamespaceCount());
+        assertEquals("http://apache.org/hello_world_soap_http/types", reader.getNamespaceURI(0));
+        assertEquals("x", reader.getNamespacePrefix(0));
+        
+        StaxUtils.nextEvent(reader);
+        StaxUtils.toNextElement(reader);
+        qname = reader.getName();
+        assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"),
qname);
+        assertEquals("x", qname.getPrefix());
+        
+        StaxUtils.nextEvent(reader);
+        StaxUtils.toNextText(reader);
+        assertEquals("Hello", reader.getText());
+    }
+
+    @Test
+    public void testWriteWithContextualNamespaceDecls() throws Exception {
+        JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
+        Map<String, String> nspref = new HashMap<String, String>();
+        nspref.put("http://apache.org/hello_world_soap_http/types", "x");
+        db.setNamespaceMap(nspref);
+        db.setContextualNamespaceMap(nspref);
+        
+        // use the output stream instead of XMLStreamWriter to test
+        DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
+        assertNotNull(dw);
+
+        GreetMe val = new GreetMe();
+        val.setRequestType("Hello");
+        dw.write(val, baos);
+        
+        String xstr = new String(baos.toByteArray());
+        
+        // there should be no namespace decls
+        if (!db.getContext().getClass().getName().contains("eclipse")) {
+            //bug in eclipse moxy
+            //https://bugs.eclipse.org/bugs/show_bug.cgi?id=421463
+            
+            assertEquals("<x:greetMe><x:requestType>Hello</x:requestType></x:greetMe>",
xstr);
+        }
+    }
+
     private JAXBDataBinding getTestWriterFactory(Class<?>... clz) throws Exception
{
         JAXBContext ctx = JAXBContext.newInstance(clz);
         return new JAXBDataBinding(ctx);

Modified: cxf/branches/2.7.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=1543152&r1=1543151&r2=1543152&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ cxf/branches/2.7.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Mon Nov 18 21:04:40 2013
@@ -22,7 +22,9 @@ package org.apache.cxf.tools.java2wsdl.p
 import java.io.File;
 import java.io.FileInputStream;
 import java.net.URI;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
@@ -31,12 +33,14 @@ import javax.xml.namespace.QName;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 
 import org.apache.cxf.common.WSDLConstants;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.WSDLHelper;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.helpers.XPathUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolConstants;
@@ -644,17 +648,36 @@ public class JavaToProcessorTest extends
         File wsdlFile = new File(output, "exception.wsdl");
         assertTrue(wsdlFile.exists());
         // schema element
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        assertTrue(wsdlContent.indexOf("<xs:complexType name=\"Exception\">") != -1);
-        assertTrue(wsdlContent.indexOf("<xs:element name=\"Exception\" type=\"tns:Exception\"/>")
!= -1);
-        assertTrue(wsdlContent.indexOf("<xs:element minOccurs=\"0\" name=\"message\" type=\"xs:string\"/>")

-                   != -1);
-        assertTrue(wsdlContent.indexOf("<xs:element minOccurs=\"0\" name=\"message\" type=\"xs:string\"/>")

-                   != -1);
-        assertTrue(wsdlContent.indexOf("<wsdl:part name=\"Exception\" element=\"tns:Exception\">")
!= -1);
-        assertTrue(wsdlContent.indexOf("<wsdl:fault name=\"Exception\" message=\"tns:Exception\">")
!= -1);
-        assertTrue(wsdlContent.indexOf("<soap:fault name=\"Exception\" use=\"literal\"/>")
!= -1);
-
+        
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        XPathUtils util = new XPathUtils(map);
+        
+        assertNotNull(util.getValueNode("//xsd:complexType[@name='Exception']", doc));
+
+        Element nd = (Element)util.getValueNode("//xsd:element[@name='Exception']", doc);
+        assertNotNull(nd);
+        assertTrue(nd.getAttribute("type").contains("Exception"));
+        
+        nd = (Element)util.getValueNode("//xsd:element[@name='message']", doc);
+        assertNotNull(nd);
+        assertTrue(nd.getAttribute("type").contains("string"));
+        assertTrue(nd.getAttribute("minOccurs").contains("0"));
+        
+        nd = (Element)util.getValueNode("//wsdl:part[@name='Exception']", doc);
+        assertNotNull(nd);
+        assertTrue(nd.getAttribute("element").contains(":Exception"));
+
+        nd = (Element)util.getValueNode("//wsdl:fault[@name='Exception']", doc);
+        assertNotNull(nd);
+        assertTrue(nd.getAttribute("message").contains(":Exception"));
+
+        nd = (Element)util.getValueNode("//soap:fault[@name='Exception']", doc);
+        assertNotNull(nd);
+        assertTrue(nd.getAttribute("use").contains("literal"));
     }
     
     //CXF-1509
@@ -718,15 +741,35 @@ public class JavaToProcessorTest extends
         }
         File wsdlFile = new File(output, "exception_prop_order.wsdl");
         assertTrue(wsdlFile.exists());
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int summaryIndex = wsdlContent.indexOf("<xs:element name=\"summary\"");
-        int fromIndex = wsdlContent.indexOf("<xs:element name=\"from\"");
-        int idIndex = wsdlContent.indexOf("<xs:element name=\"id\"");
-        
-        assertTrue(summaryIndex > -1);
-        assertTrue(fromIndex > -1);
-        assertTrue(idIndex > -1);
-        assertTrue(fromIndex > summaryIndex && idIndex > fromIndex);      
 
+        
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        XPathUtils util = new XPathUtils(map);
+
+        Element summary = (Element)util.getValueNode("//xsd:element[@name='summary']", doc);
+        Element from = (Element)util.getValueNode("//xsd:element[@name='from']", doc);
+        Element id = (Element)util.getValueNode("//xsd:element[@name='id']", doc);
+        assertNotNull(summary);
+        assertNotNull(from);
+        assertNotNull(id);
+        
+        Node nd = summary.getNextSibling();
+        while (nd != null) {
+            if (nd == from) {
+                from = null;
+            } else if (nd == id) {
+                if (from != null) {
+                    fail("id before from");
+                }
+                id = null;
+            }
+            nd = nd.getNextSibling();
+        }
+        assertNull(id);
+        assertNull(from);
     }
     
     @Test
@@ -742,17 +785,35 @@ public class JavaToProcessorTest extends
         }
         File wsdlFile = new File(output, "exception_order.wsdl");
         assertTrue(wsdlFile.exists());
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-
-        int fromIndex = wsdlContent.indexOf("<xs:element name=\"from\"");
-        int idIndex = wsdlContent.indexOf("<xs:element name=\"id\"");
-        int summaryIndex = wsdlContent.indexOf("<xs:element name=\"summary\"");
         
-        
-        assertTrue(fromIndex > -1);
-        assertTrue(idIndex > -1);
-        assertTrue(summaryIndex > -1);
-        assertTrue(summaryIndex > idIndex && idIndex > fromIndex);        
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        XPathUtils util = new XPathUtils(map);
+
+        Element summary = (Element)util.getValueNode("//xsd:element[@name='summary']", doc);
+        Element from = (Element)util.getValueNode("//xsd:element[@name='from']", doc);
+        Element id = (Element)util.getValueNode("//xsd:element[@name='id']", doc);
+        assertNotNull(summary);
+        assertNotNull(from);
+        assertNotNull(id);
+        
+        Node nd = from.getNextSibling();
+        while (nd != null) {
+            if (nd == id) {
+                from = null;
+            } else if (nd == summary) {
+                if (from != null) {
+                    fail("from before summary");
+                }
+                id = null;
+            }
+            nd = nd.getNextSibling();
+        }
+        assertNull(id);
+        assertNull(from);
     }
     
     @Test
@@ -769,13 +830,26 @@ public class JavaToProcessorTest extends
         
         File wsdlFile = new File(output, "exception_list.wsdl");
         assertTrue(wsdlFile.exists());
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int unboundIndex = wsdlContent
-            .indexOf("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"names\"
type=\"tns:myData\"/>");
-        assertTrue(unboundIndex > -1);
-        unboundIndex = wsdlContent
-            .indexOf("<xs:element maxOccurs=\"unbounded\" minOccurs=\"0\" name=\"address\"
type=\"tns:myData\"/>");
-        assertTrue(unboundIndex > -1);
+        
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        XPathUtils util = new XPathUtils(map);
+
+        Element nd = (Element)util.getValueNode("//xsd:element[@name='names']", doc);
+        assertNotNull(nd);
+        assertEquals("0", nd.getAttribute("minOccurs"));
+        assertEquals("unbounded", nd.getAttribute("maxOccurs"));
+        assertTrue(nd.getAttribute("type").endsWith(":myData"));
+        
+        
+        nd = (Element)util.getValueNode("//xsd:element[@name='address']", doc);
+        StaxUtils.print(nd);
+        assertNotNull(nd);
+        assertEquals("0", nd.getAttribute("minOccurs"));
+        assertTrue(nd.getAttribute("type").endsWith(":myData"));
     }
     
     @Test
@@ -792,10 +866,18 @@ public class JavaToProcessorTest extends
         
         File wsdlFile = new File(output, "exception-ref-nillable.wsdl");
         assertTrue(wsdlFile.exists());
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int refElement = wsdlContent.indexOf("<xs:element ref=\"tns:item\"/>");
-        assertTrue(refElement > -1);
-
+        
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+        map.put("tns", "http://cxf.apache.org/test/HelloService");
+        XPathUtils util = new XPathUtils(map);
+        
+        Element el = (Element)util.getValueNode("//xsd:element[@ref]", doc);
+        assertNotNull(el);
+        assertTrue(el.getAttribute("ref").contains("item"));
     }
     
     @Test
@@ -812,12 +894,19 @@ public class JavaToProcessorTest extends
         
         File wsdlFile = new File(output, "exception-type-adapter.wsdl");
         assertTrue(wsdlFile.exists());
-        String wsdlContent = getStringFromFile(wsdlFile).replaceAll("  ", " ");
-        int class2Element = wsdlContent.indexOf("<xs:complexType name=\"myClass2\">");
-        assertTrue(class2Element > -1);
-        int refElement = wsdlContent.indexOf("<xs:element name=\"adapted\" nillable=\"true\"
type=\"tns:myClass2\"/>");
-        assertTrue(refElement > -1);
-
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema");
+        XPathUtils util = new XPathUtils(map);
+        Node nd = util.getValueNode("//xsd:complexType[@name='myClass2']", doc);
+        assertNotNull(nd);
+        
+        nd = util.getValueNode("//xsd:element[@name='adapted']", doc);
+        assertNotNull(nd); 
+        
+        String at = ((Element)nd).getAttribute("type");
+        assertTrue(at.contains("myClass2"));
+        assertEquals("true", ((Element)nd).getAttribute("nillable"));
     }
     
     



Mime
View raw message