cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1409656 - in /cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb: JAXBContextInitializer.java JAXBEncoderDecoder.java Utils.java
Date Thu, 15 Nov 2012 06:06:33 GMT
Author: ffang
Date: Thu Nov 15 06:06:32 2012
New Revision: 1409656

URL: http://svn.apache.org/viewvc?rev=1409656&view=rev
Log:
[CXF-4594]when use code first, If no setter method in Exception class, the property can't
get marshalled nor available in generated wsdl

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java?rev=1409656&r1=1409655&r2=1409656&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Thu Nov 15 06:06:32 2012
@@ -379,8 +379,9 @@ class JAXBContextInitializer extends Ser
     static boolean isMethodAccepted(Method method, XmlAccessType accessType) {
         // We only accept non static property getters which are not marked @XmlTransient
         if (Modifier.isStatic(method.getModifiers()) 
-            || method.isAnnotationPresent(XmlTransient.class)
-            || !Modifier.isPublic(method.getModifiers())) {
+                || method.isAnnotationPresent(XmlTransient.class)
+                || !Modifier.isPublic(method.getModifiers())
+                || "getClass".equals(method.getName())) {
             return false;
         }
 
@@ -390,11 +391,17 @@ class JAXBContextInitializer extends Ser
             || method.getDeclaringClass().equals(Throwable.class)) {
             return false;
         }
-
+        if (method.getName().startsWith("get")
+                || method.getName().startsWith("is")) { 
+                //continue with below check.
+        } else {
+            return false;
+        }
         int beginIndex = 3;
         if (method.getName().startsWith("is")) {
             beginIndex = 2;
         }
+        
         Method setter = null;
         try {
             setter = method.getDeclaringClass()
@@ -403,10 +410,11 @@ class JAXBContextInitializer extends Ser
         } catch (Exception e) {
             //getter, but no setter
         }
-        if (setter == null 
-            || setter.isAnnotationPresent(XmlTransient.class)
-            || !Modifier.isPublic(setter.getModifiers())) {
+        if ((setter != null) 
+                && ((setter.isAnnotationPresent(XmlTransient.class)
+                 || !Modifier.isPublic(setter.getModifiers())))) {
             return false;
+             
         }
 
         if (accessType == XmlAccessType.NONE

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=1409656&r1=1409655&r2=1409656&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Thu Nov 15 06:06:32 2012
@@ -488,7 +488,7 @@ public final class JAXBEncoderDecoder {
                         m = Utils.getMethod(cls, accessType, "is" + s);
                     }
                     Type type = m.getGenericReturnType();
-                    Method m2 = Utils.getMethod(cls, accessType, "set" + s, m.getReturnType());
+                    Object o = null;
                     if (JAXBSchemaInitializer.isArray(type)) {
                         Class<?> compType = JAXBSchemaInitializer
                             .getArrayComponentType(type);
@@ -496,7 +496,7 @@ public final class JAXBEncoderDecoder {
                                                            q,
                                                            compType,
                                                            createList(type));
-                        Object o = ret;
+                        o = ret;
                         if (!isList(type)) {
                             if (compType.isPrimitive()) {
                                 o = java.lang.reflect.Array.newInstance(compType, ret.size());
@@ -507,12 +507,23 @@ public final class JAXBEncoderDecoder {
                                 o = ret.toArray((Object[])Array.newInstance(compType, ret.size()));
                             }
                         }
-
-                        m2.invoke(obj, o);
                     } else {
-                        Object o = getElementValue(u.unmarshal(reader, Utils.getMethodReturnType(m)));
-                        Utils.setMethodValue(m, m2, obj, o);
+                        o = getElementValue(u.unmarshal(reader, Utils.getMethodReturnType(m)));
                     }
+                    Method m2 = Utils.getMethod(cls, accessType, "set" + s, m.getReturnType());
+                    if (m2 != null) {
+                        if (JAXBSchemaInitializer.isArray(type)) {
+                            m2.invoke(obj, o);
+                        } else {
+                            Utils.setMethodValue(m, m2, obj, o);
+                        }
+                    } else {
+                        Field fn = ReflectionUtil.getDeclaredField(cls, q.getLocalPart());
+                        if (fn != null) {
+                            ReflectionUtil.setAccessible(fn);
+                            fn.set(obj, o);
+                        }
+                    }                
                 }
             }
             return (Exception)obj;

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java?rev=1409656&r1=1409655&r2=1409656&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java Thu Nov 15
06:06:32 2012
@@ -136,7 +136,8 @@ final class Utils {
         if (method.isBridge()
                 || Modifier.isStatic(method.getModifiers())
                 || method.isAnnotationPresent(XmlTransient.class)
-                || method.getDeclaringClass().equals(Throwable.class)) {
+                || method.getDeclaringClass().equals(Throwable.class)
+                || "getClass".equals(method.getName())) {
             return false;
         }
         // Allow only public methods if PUBLIC_MEMBER access is requested
@@ -169,6 +170,9 @@ final class Utils {
                 String setterName = "set" + m.getName().substring(index);
                 Class<?> paramTypes = m.getReturnType();
                 Method setter = getDeclaredMethod(declaringClass, setterName, paramTypes);
+                if (setter == null) {
+                    return true;
+                }
                 if (setter != null && !setter.isAnnotationPresent(XmlTransient.class))
{
                     return true;
                 }



Mime
View raw message