You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2009/03/09 03:48:03 UTC

svn commit: r751576 - in /cxf/trunk/rt: databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/

Author: ningjiang
Date: Mon Mar  9 02:48:02 2009
New Revision: 751576

URL: http://svn.apache.org/viewvc?rev=751576&view=rev
Log:
CXF-2076 get CXF work with the XMLBeans wrapper objects

Modified:
    cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
    cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java

Modified: cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java?rev=751576&r1=751575&r2=751576&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java (original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataReaderImpl.java Mon Mar  9 02:48:02 2009
@@ -70,7 +70,7 @@
                 try {
                     SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
                     XmlOptions options = new XmlOptions();
-                    if (!st.isDocumentType() && !isOutClass) {
+                    if (st != null && !st.isDocumentType() && !isOutClass) {
                         options.setLoadReplaceDocumentElement(null);
                     }
                     Method meth = c.getMethod("parse", XMLStreamReader.class, XmlOptions.class);
@@ -124,7 +124,7 @@
         return obj;
     }
 
-    public Object read(QName name, XMLStreamReader input, Class type) {
+    public Object read(QName name, XMLStreamReader input, Class type) {        
         return null;
     }
 

Modified: cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=751576&r1=751575&r2=751576&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java (original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java Mon Mar  9 02:48:02 2009
@@ -94,7 +94,7 @@
                 }
                 SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
 
-                if (!st.isDocumentType()) {
+                if (st != null && !st.isDocumentType()) {
                     if (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
                         output.writeStartElement(part.getConcreteName().getLocalPart());
                         

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java?rev=751576&r1=751575&r2=751576&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperHelper.java Mon Mar  9 02:48:02 2009
@@ -45,10 +45,48 @@
 
     public abstract String getSignature();
     
+    private static Class<?> getXMLBeansValueType(Class<?> wrapperType)  {
+        Class<?> result = wrapperType;
+        for (Method method : wrapperType.getMethods()) {
+            if (method.getName().startsWith("addNew")) {                
+                result = method.getReturnType();
+                break;
+            }
+        }
+        return result;
+    }
+    
+    private static Object createXMLBeansValueObject(Class<?> wrapperType) 
+        throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+            IllegalAccessException, InvocationTargetException {
+        
+        Class<?> cls[] = wrapperType.getDeclaredClasses();
+        Method newType = null;
+        for (Method method : wrapperType.getMethods()) {
+            if (method.getName().startsWith("addNew")) {
+                newType = method;                            
+            }
+        }                     
+        Object obj = null;
+        for (Class<?> c : cls) {                        
+            if ("Factory".equals(c.getSimpleName())) {                            
+                Method method = c.getMethod("newInstance", NO_PARAMS); 
+                // create the instance of document type
+                obj = method.invoke(null, NO_PARAMS);
+                // create the value object
+                obj = newType.invoke(obj, NO_PARAMS);
+                break;
+            }
+        }
+        
+        return obj;
+    }
+       
     public static WrapperHelper createWrapperHelper(Class<?> wrapperType,
                                                     List<String> partNames,
                                                     List<String> elTypeNames,
                                                     List<Class<?>> partClasses) {
+       
         List<Method> getMethods = new ArrayList<Method>(partNames.size());
         List<Method> setMethods = new ArrayList<Method>(partNames.size());
         List<Method> jaxbMethods = new ArrayList<Method>(partNames.size());
@@ -78,7 +116,7 @@
         }
         
         for (int x = 0; x < partNames.size(); x++) {
-            String partName = partNames.get(x);
+            String partName = partNames.get(x);            
             if (partName == null) {
                 getMethods.add(null);
                 setMethods.add(null);
@@ -93,13 +131,18 @@
             String setAccessor = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.SETTER);
             Method getMethod = null;
             Method setMethod = null;
-            try {
-                getMethod = wrapperType.getMethod(getAccessor, NO_PARAMS); 
+            Class<?> valueClass = wrapperType;
+            try {               
+                if (wrapperType.isInterface()) {
+                    valueClass = getXMLBeansValueType(wrapperType);
+                    allMethods = valueClass.getMethods();
+                }
+                getMethod = valueClass.getMethod(getAccessor, NO_PARAMS); 
             } catch (NoSuchMethodException ex) {
                 //ignore for now
             }
 
-            Field elField = getElField(partName, wrapperType);
+            Field elField = getElField(partName, valueClass);
             if (getMethod == null
                 && elementType != null
                 && "boolean".equals(elementType.toLowerCase())
@@ -118,10 +161,10 @@
                 && "return".equals(partName)) {
                 //RI generated code uses this
                 try {
-                    getMethod = wrapperType.getMethod("get_return", NO_PARAMS);
+                    getMethod = valueClass.getMethod("get_return", NO_PARAMS);
                 } catch (NoSuchMethodException ex) {
                     try {
-                        getMethod = wrapperType.getMethod("is_return",
+                        getMethod = valueClass.getMethod("is_return",
                                                           new Class[0]);
                     } catch (NoSuchMethodException ex2) {
                         //ignore for now
@@ -204,7 +247,7 @@
         if ("javax.xml.bind.JAXBElement".equals(method.getReturnType().getCanonicalName())) {
             JAXBElement je = (JAXBElement)method.invoke(in);
             return je == null ? je : je.getValue();
-        } else {
+        } else {            
             return method.invoke(in);
         }
     }
@@ -272,10 +315,13 @@
         }
         public Object createWrapperObject(List<?> lst) 
             throws Fault {
-            
             try {
-                Object ret = wrapperType.newInstance();
-
+                Object value = null;
+                if (wrapperType.isInterface()) {
+                    value = createXMLBeansValueObject(wrapperType);
+                } else {
+                    value = wrapperType.newInstance();
+                }
                 for (int x = 0; x < setMethods.length; x++) {
                     if (getMethods[x] == null
                         && setMethods[x] == null 
@@ -289,38 +335,46 @@
                         o = jaxbObjectMethods[x].invoke(objectFactory, o);
                     }
                     if (o instanceof List) {
-                        List<Object> col = CastUtils.cast((List)getMethods[x].invoke(ret));
+                        List<Object> col = CastUtils.cast((List)getMethods[x].invoke(value));
                         if (col == null) {
                             //broken generated java wrappers
                             if (setMethods[x] != null) {
-                                setMethods[x].invoke(ret, o);
+                                setMethods[x].invoke(value, o);
                             } else {
-                                fields[x].set(ret, lst.get(x));
+                                fields[x].set(value, lst.get(x));
                             }
                         } else {
                             List<Object> olst = CastUtils.cast((List)o);
                             col.addAll(olst);
                         }
-                    } else if (setMethods[x] != null) {
-                        setMethods[x].invoke(ret, o);
+                    } else if (setMethods[x] != null) {                        
+                        setMethods[x].invoke(value, o);
                     } else if (fields[x] != null) {
-                        fields[x].set(ret, lst.get(x));
+                        fields[x].set(value, lst.get(x));
                     }
                 }
-                return ret;
+                return value;
             } catch (Exception ex) {
                 throw new Fault(ex);
             }
         }
         
         public List<Object> getWrapperParts(Object o) throws Fault {
+            Object valueObject = o;
             try {
+                if (wrapperType.isInterface()) {                    
+                    Class<?> valueClass = getXMLBeansValueType(wrapperType);
+                    // we need get the real Object first
+                    Method method = wrapperType.getMethod("get" + valueClass.getSimpleName(), NO_PARAMS);
+                    valueObject = method.invoke(o, NO_PARAMS);
+                }
+            
                 List<Object> ret = new ArrayList<Object>(getMethods.length);
                 for (int x = 0; x < getMethods.length; x++) {
                     if (getMethods[x] != null) {
-                        ret.add(getValue(getMethods[x], o));
+                        ret.add(getValue(getMethods[x], valueObject));                        
                     } else if (fields[x] != null) {
-                        ret.add(fields[x].get(o));
+                        ret.add(fields[x].get(valueObject));
                     } else {
                         //placeholder
                         ret.add(null);



Re: svn commit: r751576 - in /cxf/trunk/rt: databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/

Posted by Willem Jiang <wi...@gmail.com>.
Hi Dan,

I test the code with Systest and my xmlbeans sample with the ASM jar.
All tests passed.
Anyway, I will add the below part in the WrapperHelper, it make sense to
skip the ASM class enhancement part for the XMLBeans.

Thanks,

Willem

Daniel Kulp wrote:
> Willem,
> 
> I noticed that this updates the ReflectWrapperHelper, but didn't touch the ASM 
> compiled version?   Did you test this with ASM available on the classpath?
> 
> Updating the ASM compiled version will probably suck.  My suggestion would be 
> to update the createWrapperHelper method to do:
> if (!wrapperType.isInterface()) {
>     compile.....
> } 
> and allow the interface code to just fall down into the Reflection form.
> 
> Dan
> 
> 
> 
> On Sun March 8 2009 10:48:03 pm ningjiang@apache.org wrote:
>> Author: ningjiang
>> Date: Mon Mar  9 02:48:02 2009
>> New Revision: 751576
>>
>> URL: http://svn.apache.org/viewvc?rev=751576&view=rev
>> Log:
>> CXF-2076 get CXF work with the XMLBeans wrapper objects
>>
>> Modified:
>>    
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aReaderImpl.java
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aWriterImpl.java
>> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>> /WrapperHelper.java
>>
>> Modified:
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aReaderImpl.java URL:
>> http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/jav
>> a/org/apache/cxf/xmlbeans/DataReaderImpl.java?rev=751576&r1=751575&r2=751576
>> &view=diff
>> ===========================================================================
>> === ---
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aReaderImpl.java (original) +++
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aReaderImpl.java Mon Mar  9 02:48:02 2009 @@ -70,7 +70,7 @@
>>                  try {
>>                      SchemaType st =
>> (SchemaType)part.getProperty(SchemaType.class.getName()); XmlOptions
>> options = new XmlOptions();
>> -                    if (!st.isDocumentType() && !isOutClass) {
>> +                    if (st != null && !st.isDocumentType() && !isOutClass)
>> { options.setLoadReplaceDocumentElement(null); }
>>                      Method meth = c.getMethod("parse",
>> XMLStreamReader.class, XmlOptions.class); @@ -124,7 +124,7 @@
>>          return obj;
>>      }
>>
>> -    public Object read(QName name, XMLStreamReader input, Class type) {
>> +    public Object read(QName name, XMLStreamReader input, Class type) {
>>          return null;
>>      }
>>
>>
>> Modified:
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aWriterImpl.java URL:
>> http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/jav
>> a/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=751576&r1=751575&r2=751576
>> &view=diff
>> ===========================================================================
>> === ---
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aWriterImpl.java (original) +++
>> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>> aWriterImpl.java Mon Mar  9 02:48:02 2009 @@ -94,7 +94,7 @@
>>                  }
>>                  SchemaType st =
>> (SchemaType)part.getProperty(SchemaType.class.getName());
>>
>> -                if (!st.isDocumentType()) {
>> +                if (st != null && !st.isDocumentType()) {
>>                      if
>> (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
>> output.writeStartElement(part.getConcreteName().getLocalPart());
>>
>>
>> Modified:
>> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>> /WrapperHelper.java URL:
>> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/
>> apache/cxf/jaxws/interceptors/WrapperHelper.java?rev=751576&r1=751575&r2=751
>> 576&view=diff
>> ===========================================================================
>> === ---
>> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>> /WrapperHelper.java (original) +++
>> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>> /WrapperHelper.java Mon Mar  9 02:48:02 2009 @@ -45,10 +45,48 @@
>>
>>      public abstract String getSignature();
>>
>> +    private static Class<?> getXMLBeansValueType(Class<?> wrapperType)  {
>> +        Class<?> result = wrapperType;
>> +        for (Method method : wrapperType.getMethods()) {
>> +            if (method.getName().startsWith("addNew")) {
>> +                result = method.getReturnType();
>> +                break;
>> +            }
>> +        }
>> +        return result;
>> +    }
>> +
>> +    private static Object createXMLBeansValueObject(Class<?> wrapperType)
>> +        throws SecurityException, NoSuchMethodException,
>> IllegalArgumentException, +            IllegalAccessException,
>> InvocationTargetException {
>> +
>> +        Class<?> cls[] = wrapperType.getDeclaredClasses();
>> +        Method newType = null;
>> +        for (Method method : wrapperType.getMethods()) {
>> +            if (method.getName().startsWith("addNew")) {
>> +                newType = method;
>> +            }
>> +        }
>> +        Object obj = null;
>> +        for (Class<?> c : cls) {
>> +            if ("Factory".equals(c.getSimpleName())) {
>> +                Method method = c.getMethod("newInstance", NO_PARAMS);
>> +                // create the instance of document type
>> +                obj = method.invoke(null, NO_PARAMS);
>> +                // create the value object
>> +                obj = newType.invoke(obj, NO_PARAMS);
>> +                break;
>> +            }
>> +        }
>> +
>> +        return obj;
>> +    }
>> +
>>      public static WrapperHelper createWrapperHelper(Class<?> wrapperType,
>>                                                      List<String>
>> partNames, List<String> elTypeNames, List<Class<?>> partClasses) { +
>>          List<Method> getMethods = new ArrayList<Method>(partNames.size());
>>          List<Method> setMethods = new ArrayList<Method>(partNames.size());
>>          List<Method> jaxbMethods = new
>> ArrayList<Method>(partNames.size()); @@ -78,7 +116,7 @@
>>          }
>>
>>          for (int x = 0; x < partNames.size(); x++) {
>> -            String partName = partNames.get(x);
>> +            String partName = partNames.get(x);
>>              if (partName == null) {
>>                  getMethods.add(null);
>>                  setMethods.add(null);
>> @@ -93,13 +131,18 @@
>>              String setAccessor = JAXBUtils.nameToIdentifier(partName,
>> JAXBUtils.IdentifierType.SETTER); Method getMethod = null;
>>              Method setMethod = null;
>> -            try {
>> -                getMethod = wrapperType.getMethod(getAccessor, NO_PARAMS);
>> +            Class<?> valueClass = wrapperType;
>> +            try {
>> +                if (wrapperType.isInterface()) {
>> +                    valueClass = getXMLBeansValueType(wrapperType);
>> +                    allMethods = valueClass.getMethods();
>> +                }
>> +                getMethod = valueClass.getMethod(getAccessor, NO_PARAMS);
>>              } catch (NoSuchMethodException ex) {
>>                  //ignore for now
>>              }
>>
>> -            Field elField = getElField(partName, wrapperType);
>> +            Field elField = getElField(partName, valueClass);
>>              if (getMethod == null
>>                  && elementType != null
>>                  && "boolean".equals(elementType.toLowerCase())
>> @@ -118,10 +161,10 @@
>>                  && "return".equals(partName)) {
>>                  //RI generated code uses this
>>                  try {
>> -                    getMethod = wrapperType.getMethod("get_return",
>> NO_PARAMS); +                    getMethod =
>> valueClass.getMethod("get_return", NO_PARAMS); } catch
>> (NoSuchMethodException ex) {
>>                      try {
>> -                        getMethod = wrapperType.getMethod("is_return",
>> +                        getMethod = valueClass.getMethod("is_return",
>>                                                            new Class[0]);
>>                      } catch (NoSuchMethodException ex2) {
>>                          //ignore for now
>> @@ -204,7 +247,7 @@
>>          if
>> ("javax.xml.bind.JAXBElement".equals(method.getReturnType().getCanonicalNam
>> e())) { JAXBElement je = (JAXBElement)method.invoke(in);
>>              return je == null ? je : je.getValue();
>> -        } else {
>> +        } else {
>>              return method.invoke(in);
>>          }
>>      }
>> @@ -272,10 +315,13 @@
>>          }
>>          public Object createWrapperObject(List<?> lst)
>>              throws Fault {
>> -
>>              try {
>> -                Object ret = wrapperType.newInstance();
>> -
>> +                Object value = null;
>> +                if (wrapperType.isInterface()) {
>> +                    value = createXMLBeansValueObject(wrapperType);
>> +                } else {
>> +                    value = wrapperType.newInstance();
>> +                }
>>                  for (int x = 0; x < setMethods.length; x++) {
>>                      if (getMethods[x] == null
>>                          && setMethods[x] == null
>> @@ -289,38 +335,46 @@
>>                          o = jaxbObjectMethods[x].invoke(objectFactory, o);
>>                      }
>>                      if (o instanceof List) {
>> -                        List<Object> col =
>> CastUtils.cast((List)getMethods[x].invoke(ret)); +                       
>> List<Object> col = CastUtils.cast((List)getMethods[x].invoke(value)); if
>> (col == null) {
>>                              //broken generated java wrappers
>>                              if (setMethods[x] != null) {
>> -                                setMethods[x].invoke(ret, o);
>> +                                setMethods[x].invoke(value, o);
>>                              } else {
>> -                                fields[x].set(ret, lst.get(x));
>> +                                fields[x].set(value, lst.get(x));
>>                              }
>>                          } else {
>>                              List<Object> olst = CastUtils.cast((List)o);
>>                              col.addAll(olst);
>>                          }
>> -                    } else if (setMethods[x] != null) {
>> -                        setMethods[x].invoke(ret, o);
>> +                    } else if (setMethods[x] != null) {
>> +                        setMethods[x].invoke(value, o);
>>                      } else if (fields[x] != null) {
>> -                        fields[x].set(ret, lst.get(x));
>> +                        fields[x].set(value, lst.get(x));
>>                      }
>>                  }
>> -                return ret;
>> +                return value;
>>              } catch (Exception ex) {
>>                  throw new Fault(ex);
>>              }
>>          }
>>
>>          public List<Object> getWrapperParts(Object o) throws Fault {
>> +            Object valueObject = o;
>>              try {
>> +                if (wrapperType.isInterface()) {
>> +                    Class<?> valueClass =
>> getXMLBeansValueType(wrapperType); +                    // we need get the
>> real Object first
>> +                    Method method = wrapperType.getMethod("get" +
>> valueClass.getSimpleName(), NO_PARAMS); +                    valueObject =
>> method.invoke(o, NO_PARAMS);
>> +                }
>> +
>>                  List<Object> ret = new
>> ArrayList<Object>(getMethods.length); for (int x = 0; x <
>> getMethods.length; x++) {
>>                      if (getMethods[x] != null) {
>> -                        ret.add(getValue(getMethods[x], o));
>> +                        ret.add(getValue(getMethods[x], valueObject));
>>                      } else if (fields[x] != null) {
>> -                        ret.add(fields[x].get(o));
>> +                        ret.add(fields[x].get(valueObject));
>>                      } else {
>>                          //placeholder
>>                          ret.add(null);
> 


Re: svn commit: r751576 - in /cxf/trunk/rt: databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/

Posted by Daniel Kulp <dk...@apache.org>.
Willem,

I noticed that this updates the ReflectWrapperHelper, but didn't touch the ASM 
compiled version?   Did you test this with ASM available on the classpath?

Updating the ASM compiled version will probably suck.  My suggestion would be 
to update the createWrapperHelper method to do:
if (!wrapperType.isInterface()) {
    compile.....
} 
and allow the interface code to just fall down into the Reflection form.

Dan



On Sun March 8 2009 10:48:03 pm ningjiang@apache.org wrote:
> Author: ningjiang
> Date: Mon Mar  9 02:48:02 2009
> New Revision: 751576
>
> URL: http://svn.apache.org/viewvc?rev=751576&view=rev
> Log:
> CXF-2076 get CXF work with the XMLBeans wrapper objects
>
> Modified:
>    
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aReaderImpl.java
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aWriterImpl.java
> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>/WrapperHelper.java
>
> Modified:
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aReaderImpl.java URL:
> http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/jav
>a/org/apache/cxf/xmlbeans/DataReaderImpl.java?rev=751576&r1=751575&r2=751576
>&view=diff
> ===========================================================================
>=== ---
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aReaderImpl.java (original) +++
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aReaderImpl.java Mon Mar  9 02:48:02 2009 @@ -70,7 +70,7 @@
>                  try {
>                      SchemaType st =
> (SchemaType)part.getProperty(SchemaType.class.getName()); XmlOptions
> options = new XmlOptions();
> -                    if (!st.isDocumentType() && !isOutClass) {
> +                    if (st != null && !st.isDocumentType() && !isOutClass)
> { options.setLoadReplaceDocumentElement(null); }
>                      Method meth = c.getMethod("parse",
> XMLStreamReader.class, XmlOptions.class); @@ -124,7 +124,7 @@
>          return obj;
>      }
>
> -    public Object read(QName name, XMLStreamReader input, Class type) {
> +    public Object read(QName name, XMLStreamReader input, Class type) {
>          return null;
>      }
>
>
> Modified:
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aWriterImpl.java URL:
> http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/jav
>a/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=751576&r1=751575&r2=751576
>&view=diff
> ===========================================================================
>=== ---
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aWriterImpl.java (original) +++
> cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/Dat
>aWriterImpl.java Mon Mar  9 02:48:02 2009 @@ -94,7 +94,7 @@
>                  }
>                  SchemaType st =
> (SchemaType)part.getProperty(SchemaType.class.getName());
>
> -                if (!st.isDocumentType()) {
> +                if (st != null && !st.isDocumentType()) {
>                      if
> (StringUtils.isEmpty(part.getConcreteName().getNamespaceURI())) {
> output.writeStartElement(part.getConcreteName().getLocalPart());
>
>
> Modified:
> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>/WrapperHelper.java URL:
> http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/
>apache/cxf/jaxws/interceptors/WrapperHelper.java?rev=751576&r1=751575&r2=751
>576&view=diff
> ===========================================================================
>=== ---
> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>/WrapperHelper.java (original) +++
> cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors
>/WrapperHelper.java Mon Mar  9 02:48:02 2009 @@ -45,10 +45,48 @@
>
>      public abstract String getSignature();
>
> +    private static Class<?> getXMLBeansValueType(Class<?> wrapperType)  {
> +        Class<?> result = wrapperType;
> +        for (Method method : wrapperType.getMethods()) {
> +            if (method.getName().startsWith("addNew")) {
> +                result = method.getReturnType();
> +                break;
> +            }
> +        }
> +        return result;
> +    }
> +
> +    private static Object createXMLBeansValueObject(Class<?> wrapperType)
> +        throws SecurityException, NoSuchMethodException,
> IllegalArgumentException, +            IllegalAccessException,
> InvocationTargetException {
> +
> +        Class<?> cls[] = wrapperType.getDeclaredClasses();
> +        Method newType = null;
> +        for (Method method : wrapperType.getMethods()) {
> +            if (method.getName().startsWith("addNew")) {
> +                newType = method;
> +            }
> +        }
> +        Object obj = null;
> +        for (Class<?> c : cls) {
> +            if ("Factory".equals(c.getSimpleName())) {
> +                Method method = c.getMethod("newInstance", NO_PARAMS);
> +                // create the instance of document type
> +                obj = method.invoke(null, NO_PARAMS);
> +                // create the value object
> +                obj = newType.invoke(obj, NO_PARAMS);
> +                break;
> +            }
> +        }
> +
> +        return obj;
> +    }
> +
>      public static WrapperHelper createWrapperHelper(Class<?> wrapperType,
>                                                      List<String>
> partNames, List<String> elTypeNames, List<Class<?>> partClasses) { +
>          List<Method> getMethods = new ArrayList<Method>(partNames.size());
>          List<Method> setMethods = new ArrayList<Method>(partNames.size());
>          List<Method> jaxbMethods = new
> ArrayList<Method>(partNames.size()); @@ -78,7 +116,7 @@
>          }
>
>          for (int x = 0; x < partNames.size(); x++) {
> -            String partName = partNames.get(x);
> +            String partName = partNames.get(x);
>              if (partName == null) {
>                  getMethods.add(null);
>                  setMethods.add(null);
> @@ -93,13 +131,18 @@
>              String setAccessor = JAXBUtils.nameToIdentifier(partName,
> JAXBUtils.IdentifierType.SETTER); Method getMethod = null;
>              Method setMethod = null;
> -            try {
> -                getMethod = wrapperType.getMethod(getAccessor, NO_PARAMS);
> +            Class<?> valueClass = wrapperType;
> +            try {
> +                if (wrapperType.isInterface()) {
> +                    valueClass = getXMLBeansValueType(wrapperType);
> +                    allMethods = valueClass.getMethods();
> +                }
> +                getMethod = valueClass.getMethod(getAccessor, NO_PARAMS);
>              } catch (NoSuchMethodException ex) {
>                  //ignore for now
>              }
>
> -            Field elField = getElField(partName, wrapperType);
> +            Field elField = getElField(partName, valueClass);
>              if (getMethod == null
>                  && elementType != null
>                  && "boolean".equals(elementType.toLowerCase())
> @@ -118,10 +161,10 @@
>                  && "return".equals(partName)) {
>                  //RI generated code uses this
>                  try {
> -                    getMethod = wrapperType.getMethod("get_return",
> NO_PARAMS); +                    getMethod =
> valueClass.getMethod("get_return", NO_PARAMS); } catch
> (NoSuchMethodException ex) {
>                      try {
> -                        getMethod = wrapperType.getMethod("is_return",
> +                        getMethod = valueClass.getMethod("is_return",
>                                                            new Class[0]);
>                      } catch (NoSuchMethodException ex2) {
>                          //ignore for now
> @@ -204,7 +247,7 @@
>          if
> ("javax.xml.bind.JAXBElement".equals(method.getReturnType().getCanonicalNam
>e())) { JAXBElement je = (JAXBElement)method.invoke(in);
>              return je == null ? je : je.getValue();
> -        } else {
> +        } else {
>              return method.invoke(in);
>          }
>      }
> @@ -272,10 +315,13 @@
>          }
>          public Object createWrapperObject(List<?> lst)
>              throws Fault {
> -
>              try {
> -                Object ret = wrapperType.newInstance();
> -
> +                Object value = null;
> +                if (wrapperType.isInterface()) {
> +                    value = createXMLBeansValueObject(wrapperType);
> +                } else {
> +                    value = wrapperType.newInstance();
> +                }
>                  for (int x = 0; x < setMethods.length; x++) {
>                      if (getMethods[x] == null
>                          && setMethods[x] == null
> @@ -289,38 +335,46 @@
>                          o = jaxbObjectMethods[x].invoke(objectFactory, o);
>                      }
>                      if (o instanceof List) {
> -                        List<Object> col =
> CastUtils.cast((List)getMethods[x].invoke(ret)); +                       
> List<Object> col = CastUtils.cast((List)getMethods[x].invoke(value)); if
> (col == null) {
>                              //broken generated java wrappers
>                              if (setMethods[x] != null) {
> -                                setMethods[x].invoke(ret, o);
> +                                setMethods[x].invoke(value, o);
>                              } else {
> -                                fields[x].set(ret, lst.get(x));
> +                                fields[x].set(value, lst.get(x));
>                              }
>                          } else {
>                              List<Object> olst = CastUtils.cast((List)o);
>                              col.addAll(olst);
>                          }
> -                    } else if (setMethods[x] != null) {
> -                        setMethods[x].invoke(ret, o);
> +                    } else if (setMethods[x] != null) {
> +                        setMethods[x].invoke(value, o);
>                      } else if (fields[x] != null) {
> -                        fields[x].set(ret, lst.get(x));
> +                        fields[x].set(value, lst.get(x));
>                      }
>                  }
> -                return ret;
> +                return value;
>              } catch (Exception ex) {
>                  throw new Fault(ex);
>              }
>          }
>
>          public List<Object> getWrapperParts(Object o) throws Fault {
> +            Object valueObject = o;
>              try {
> +                if (wrapperType.isInterface()) {
> +                    Class<?> valueClass =
> getXMLBeansValueType(wrapperType); +                    // we need get the
> real Object first
> +                    Method method = wrapperType.getMethod("get" +
> valueClass.getSimpleName(), NO_PARAMS); +                    valueObject =
> method.invoke(o, NO_PARAMS);
> +                }
> +
>                  List<Object> ret = new
> ArrayList<Object>(getMethods.length); for (int x = 0; x <
> getMethods.length; x++) {
>                      if (getMethods[x] != null) {
> -                        ret.add(getValue(getMethods[x], o));
> +                        ret.add(getValue(getMethods[x], valueObject));
>                      } else if (fields[x] != null) {
> -                        ret.add(fields[x].get(o));
> +                        ret.add(fields[x].get(valueObject));
>                      } else {
>                          //placeholder
>                          ret.add(null);

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog