cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1509148 - in /cxf/branches/2.5.x-fixes: ./ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/
Date Thu, 01 Aug 2013 09:30:12 GMT
Author: ema
Date: Thu Aug  1 09:30:12 2013
New Revision: 1509148

URL: http://svn.apache.org/r1509148
Log:
Merged revisions 1509145 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1509145 | ema | 2013-08-01 17:27:57 +0800 (Thu, 01 Aug 2013) | 20 lines
  
  Merged revisions 1509144 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
  
  ................
    r1509144 | ema | 2013-08-01 17:25:54 +0800 (Thu, 01 Aug 2013) | 13 lines
    
    Merged revisions 1509138,1509142 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1509138 | ema | 2013-08-01 17:16:39 +0800 (Thu, 01 Aug 2013) | 1 line
      
      [CXF-5163]:Support marshall exception calss with @XmlAccessorOrder in JAXBEncoderDecoder(patch
by Kyle)
    ........
      r1509142 | ema | 2013-08-01 17:20:55 +0800 (Thu, 01 Aug 2013) | 1 line
      
      [CXF-5163]:Add missing test class
    ........
  ................
................

Added:
    cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java
      - copied unchanged from r1509145, cxf/branches/2.6.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/OrderException.java
Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1509144
  Merged /cxf/trunk:r1509138-1509142
  Merged /cxf/branches/2.6.x-fixes:r1509145

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

Modified: cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=1509148&r1=1509147&r2=1509148&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Thu Aug  1 09:30:12 2013
@@ -26,6 +26,7 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Member;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
@@ -37,6 +38,8 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
@@ -49,7 +52,9 @@ import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessOrder;
 import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorOrder;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
 import javax.xml.bind.attachment.AttachmentMarshaller;
@@ -358,9 +363,31 @@ public final class JAXBEncoderDecoder {
             } else {
                 LOG.warning("Schema associated with " + namespace + " is null");
             }
+            List<Member> combinedMembers = new ArrayList<Member>();
+
+
             for (Field f : Utils.getFields(cls, accessType)) {
                 XmlAttribute at = f.getAnnotation(XmlAttribute.class);
                 if (at == null) {
+                    combinedMembers.add(f);
+                }
+            }
+            for (Method m : Utils.getGetters(cls, accessType)) {
+                combinedMembers.add(m);
+            }
+
+            XmlAccessorOrder xmlAccessorOrder = cls.getAnnotation(XmlAccessorOrder.class);
+            if (xmlAccessorOrder != null && xmlAccessorOrder.value().equals(XmlAccessOrder.ALPHABETICAL))
{
+                Collections.sort(combinedMembers, new Comparator<Member>() {
+                    public int compare(Member m1, Member m2) {
+                        return m1.getName().compareTo(m2.getName());
+                    }
+                });
+            }
+
+            for (Member member : combinedMembers) {
+                if (member instanceof Field) {
+                    Field f = (Field)member;
                     QName fname = new QName(namespace, f.getName());
                     ReflectionUtil.setAccessible(f);
                     if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
@@ -369,18 +396,18 @@ public final class JAXBEncoderDecoder {
                         Object o = Utils.getFieldValue(f, elValue); 
                         writeObject(marshaller, writer, newJAXBElement(fname, String.class,
o));
                     }
-                }
-            }
-            for (Method m : Utils.getGetters(cls, accessType)) {
-                int idx = m.getName().startsWith("get") ? 3 : 2;
-                String name = m.getName().substring(idx);
-                name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
-                QName mname = new QName(namespace, name);
-                if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
-                    writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
-                } else {
-                    Object o = Utils.getMethodValue(m, elValue); 
-                    writeObject(marshaller, writer, newJAXBElement(mname, String.class, o));
+                } else { // it's a Method
+                    Method m = (Method)member;
+                    int idx = m.getName().startsWith("get") ? 3 : 2;
+                    String name = m.getName().substring(idx);
+                    name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
+                    QName mname = new QName(namespace, name);
+                    if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
+                        writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
+                    } else {
+                        Object o = Utils.getMethodValue(m, elValue); 
+                        writeObject(marshaller, writer, new JAXBElement(mname, String.class,
o));
+                    }
                 }
             }
 

Modified: cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java?rev=1509148&r1=1509147&r2=1509148&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
Thu Aug  1 09:30:12 2013
@@ -55,8 +55,13 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement;
 import org.apache.cxf.jaxb_misc.Base64WithDefaultValueType;
 import org.apache.cxf.jaxb_misc.ObjectFactory;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.StaxStreamFilter;
+import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.hello_world_soap_http.types.GreetMe;
 import org.apache.hello_world_soap_http.types.GreetMeResponse;
 import org.apache.hello_world_soap_http.types.StringStruct;
@@ -429,6 +434,46 @@ public class JAXBEncoderDecoderTest exte
     }
 
     @Test
+    public void testMarshallExceptionWithOrder() throws Exception {
+        Document doc = DOMUtils.createDocument();
+        Element elNode = doc.createElementNS("http://cxf.apache.org",  "ExceptionRoot");
+        
+        OrderException exception = new OrderException("Mymessage");
+        exception.setAValue("avalue");
+        exception.setDetail("detail");
+        exception.setInfo1("info1");
+        exception.setInfo2("info2");
+        exception.setIntVal(10000);
+       
+        QName elName = new QName("http://cxf.apache.org", "OrderException");       
+        ServiceInfo serviceInfo = new ServiceInfo();
+        InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
+        OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org",
"operation"));     
+        MessageInfo message = new MessageInfo(op, null, null);
+        MessagePartInfo part = new MessagePartInfo(elName, message);
+        part.setElement(true);
+        part.setElementQName(elName);
+        part.setTypeClass(OrderException.class);
+            
+        JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] {
+            OrderException.class,
+        });
+        JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception,
part, elNode);
+        
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        StaxUtils.writeTo(elNode, bout);
+        int a = bout.toString().lastIndexOf("aValue");
+        int b = bout.toString().lastIndexOf("detail");
+        int c = bout.toString().lastIndexOf("info1");
+        int d = bout.toString().lastIndexOf("info2");
+        int e = bout.toString().lastIndexOf("intVal");
+        assertTrue(a < b);
+        assertTrue(b < c);
+        assertTrue(c < d);
+        assertTrue(d < e);
+    }
+    
+    @Test
     public void testMarshallWithoutQNameInfo() throws Exception {
         GreetMe obj = new GreetMe();
         obj.setRequestType("Hello");



Mime
View raw message