cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1421694 - in /cxf/branches/2.6.x-fixes: ./ 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 Fri, 14 Dec 2012 06:59:49 GMT
Author: ema
Date: Fri Dec 14 06:59:48 2012
New Revision: 1421694

URL: http://svn.apache.org/viewvc?rev=1421694&view=rev
Log:
Merged revisions 1419325,1419370 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1419325 | ema | 2012-12-10 18:20:27 +0800 (Mon, 10 Dec 2012) | 1 line
  
  [CXF-4680]:Add @XmlType(propOrder={...}) support for Exception class
........
  r1419370 | ay | 2012-12-10 20:27:19 +0800 (Mon, 10 Dec 2012) | 1 line
  
  checkstyle fix
........

Added:
    cxf/branches/2.6.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/
      - copied from r1419325, cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
    cxf/branches/2.6.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1419325,1419370

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=1421694&r1=1421693&r2=1421694&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Fri Dec 14 06:59:48 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,14 @@ 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 +637,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;
+            }
+        
+        });
+    }
 }

Modified: cxf/branches/2.6.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.6.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=1421694&r1=1421693&r2=1421694&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++ cxf/branches/2.6.x-fixes/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Fri Dec 14 06:59:48 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