cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1419325 - in /cxf/trunk: rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/ tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/
Date Mon, 10 Dec 2012 10:20:28 GMT
Author: ema
Date: Mon Dec 10 10:20:27 2012
New Revision: 1419325

URL: http://svn.apache.org/viewvc?rev=1419325&view=rev
Log:
[CXF-4680]:Add @XmlType(propOrder={...}) support for Exception class

Added:
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo.java
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/EchoImpl.java
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException.java
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/SuperException.java
Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=1419325&r1=1419324&r2=1419325&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Mon Dec 10 10:20:27 2012
@@ -26,8 +26,13 @@ import java.lang.reflect.GenericArrayTyp
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
@@ -58,6 +63,7 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
+import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
 import org.apache.ws.commons.schema.XmlSchemaType;
@@ -464,6 +470,7 @@ class JAXBSchemaInitializer extends Serv
             }
         }
         XmlType xmlTypeAnno = cls.getAnnotation(XmlType.class);
+        String[] propertyOrder = null;
         boolean respectXmlTypeNS = false;
         XmlSchema faultBeanSchema = null;
         if (xmlTypeAnno != null && !StringUtils.isEmpty(xmlTypeAnno.namespace())

@@ -474,9 +481,14 @@ class JAXBSchemaInitializer extends Serv
             nsMap.add(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
             
             SchemaInfo faultBeanSchemaInfo = createSchemaIfNeeded(xmlTypeAnno.namespace(),
nsMap);
-            faultBeanSchema = faultBeanSchemaInfo.getSchema();            
+            faultBeanSchema = faultBeanSchemaInfo.getSchema(); 
         }
         
+        if (xmlTypeAnno != null &&  xmlTypeAnno.propOrder().length > 0) {
+            propertyOrder = xmlTypeAnno.propOrder();
+            //TODO: handle @XmlAccessOrder
+        }
+                        
         XmlSchema schema = null;
         if (schemaInfo == null) {
             NamespaceMap nsMap = new NamespaceMap();
@@ -516,7 +528,7 @@ class JAXBSchemaInitializer extends Serv
         ct.setParticle(seq);
         String namespace = part.getElementQName().getNamespaceURI();
         XmlAccessType accessType = Utils.getXmlAccessType(cls);
-
+//
         for (Field f : Utils.getFields(cls, accessType)) {
             //map field
             Type type = Utils.getFieldType(f);
@@ -546,6 +558,13 @@ class JAXBSchemaInitializer extends Serv
             seq.getItems().add(exEle);
 
         }
+        
+        if (propertyOrder != null && propertyOrder.length == seq.getItems().size())
{
+            sortItems(seq, propertyOrder);
+        } else if (propertyOrder != null && propertyOrder.length != seq.getItems().size())
{
+            LOG.log(Level.WARNING, "propOrder in @XmlType doesn't define all schema elements
:" + Arrays.toString(propertyOrder));
+        }
+       
         schemas.addCrossImports();
         part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
     }
@@ -617,4 +636,18 @@ class JAXBSchemaInitializer extends Serv
     private boolean isExistSchemaElement(XmlSchema schema, QName qn) {
         return schema.getElementByName(qn) != null;
     }
+    
+    private void sortItems(final XmlSchemaSequence seq, final String[] propertyOrder) {
+        final List<String> propList = Arrays.asList(propertyOrder);
+        Collections.sort(seq.getItems(), new Comparator<XmlSchemaSequenceMember>()
{
+            public int compare(XmlSchemaSequenceMember o1, XmlSchemaSequenceMember o2) {
+                XmlSchemaElement element1 = (XmlSchemaElement)o1;
+                XmlSchemaElement element2 = (XmlSchemaElement)o2;
+                int index1 = propList.indexOf(element1.getName());
+                int index2 = propList.indexOf(element2.getName());
+                return index1 - index2;
+            }
+        
+        });
+    }
 }

Added: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo.java?rev=1419325&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo.java
(added)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo.java
Mon Dec 10 10:20:27 2012
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tools.fortest.exception;
+
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://cxf.apache.org/test/HelloService", name = "HelloService")
+public interface Echo {
+    String echo(String request) throws MyException;
+}

Added: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/EchoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/EchoImpl.java?rev=1419325&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/EchoImpl.java
(added)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/EchoImpl.java
Mon Dec 10 10:20:27 2012
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tools.fortest.exception;
+
+import javax.jws.WebService;
+
+@WebService(serviceName = "HelloService", 
+            portName = "HelloPort", 
+            endpointInterface = "org.apache.cxf.tools.fortest.exception.Echo", 
+            targetNamespace = "http://cxf.apache.org/test/HelloService")
+public class EchoImpl {
+    public String echo(String request) throws MyException {
+        return "Response";
+
+    }
+
+}

Added: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException.java?rev=1419325&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException.java
(added)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException.java
Mon Dec 10 10:20:27 2012
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tools.fortest.exception;
+
+import javax.xml.bind.annotation.XmlType;
+
+@javax.xml.ws.WebFault
+@XmlType(namespace = "http://cxf.apache.org/test/HelloService",
+         name = "MyException", 
+         propOrder = { "summary", "from", "id" })
+public class MyException extends SuperException {
+    private static final long serialVersionUID = 8575109064272599936L;
+    private String summary;
+    private String from;
+
+    public MyException(String message) {
+        super(message);
+    }
+
+    public void setSummary(String summary) {
+        this.summary = summary;
+    }
+
+    public void setFrom(String from) {
+        this.from = from;
+    }
+
+    public String getSummary() {
+        return summary;
+    }
+
+    public String getFrom() {
+        return from;
+    }
+
+}

Added: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/SuperException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/SuperException.java?rev=1419325&view=auto
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/SuperException.java
(added)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/SuperException.java
Mon Dec 10 10:20:27 2012
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.tools.fortest.exception;
+
+public class SuperException extends Exception {
+    private static final long serialVersionUID = 1L;
+    private int id;
+
+    public SuperException(String message) {
+        super(message);
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+}

Modified: cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=1419325&r1=1419324&r2=1419325&view=diff
==============================================================================
--- cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Mon Dec 10 10:20:27 2012
@@ -699,4 +699,33 @@ public class JavaToProcessorTest extends
                    != -1);
         assertTrue(wsdlContent.indexOf("wsdl:part name=\"add1\" element=\"tns:add1\"") !=
-1);
     }
+    
+    
+    
+    @Test
+    public void testPropOrderInException() throws Exception {
+        env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception_prop_order.wsdl");
+        env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.EchoImpl");
+        env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+        try {
+            processor.setEnvironment(env);
+            processor.process();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        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);
+        
+    }
+    
+    
 }



Mime
View raw message