Author: dkulp
Date: Mon Jul 2 07:27:48 2007
New Revision: 552502
URL: http://svn.apache.org/viewvc?view=rev&rev=552502
Log:
WrapperType handling optimizations phase one - collect the Method/Field objects
up front and use those each time instead of re-quearying for each property.
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassOutInterceptor.java
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java?view=diff&rev=552502&r1=552501&r2=552502
==============================================================================
---
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
(original)
+++
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/WrapperHelper.java
Mon Jul 2 07:27:48 2007
@@ -22,261 +22,222 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElement;
-public final class WrapperHelper {
+import org.apache.cxf.helpers.CastUtils;
- private WrapperHelper() {
- // complete
+public class WrapperHelper {
+ private static final Class NO_PARAMS[] = new Class[0];
+
+ final Class<?> wrapperType;
+ final Method setMethods[];
+ final Method getMethods[];
+ final Method jaxbObjectMethods[];
+ final Field fields[];
+ final Object objectFactory;
+
+ WrapperHelper(Class<?> wt,
+ Method sets[],
+ Method gets[],
+ Method jaxbs[],
+ Field f[],
+ Object of) {
+ setMethods = sets;
+ getMethods = gets;
+ fields = f;
+ jaxbObjectMethods = jaxbs;
+ wrapperType = wt;
+ objectFactory = of;
}
-
- public static void setWrappedPart(String partName, Object wrapperType,
Object part)
- throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
-
- if (part instanceof List) {
- setWrappedListProperty(partName, wrapperType, part);
- } else {
- String fieldName = partName;
- if (JAXBUtils.isJavaKeyword(partName)) {
- fieldName = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.VARIABLE);
- }
-
-
- if (part == null) {
- XmlElement el = null;
- Field elField = null;
- for (Field field : wrapperType.getClass().getDeclaredFields())
{
- if (field.getName().equals(fieldName)) {
- elField = field;
- el = elField.getAnnotation(XmlElement.class);
- break;
- }
- }
- if (el != null
- && !el.nillable()
- && elField.getType().isPrimitive()) {
- throw new IllegalArgumentException("null value for field
not permitted.");
- }
- return;
- }
-
- String modifier = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.SETTER);
- String modifier2 = modifier;
- if ("return".equals(partName)) {
- //some versions of jaxb map "return" to "set_return" instead
of "setReturn"
- modifier2 = "set_return";
- }
-
- boolean setInvoked = false;
- for (Method method : wrapperType.getClass().getMethods()) {
- if (method.getParameterTypes() != null &&
method.getParameterTypes().length == 1
- && (modifier.equals(method.getName())
- || modifier2.equals(method.getName()))) {
- if
("javax.xml.bind.JAXBElement".equals(method.getParameterTypes()[0].getName())) {
- if (!setJAXBElementValueIntoWrapType(method,
wrapperType, part)) {
- throw new RuntimeException("Failed to set the part
value (" + part
- + ") to wrapper type (" +
wrapperType.getClass() + ")");
- }
- } else {
- method.invoke(wrapperType, part);
- }
- setInvoked = true;
- break;
- }
- }
- if (!setInvoked) {
- Field elField = getField(wrapperType, partName, fieldName);
- // JAXB Type get XmlElement Annotation
- if (elField != null) {
- elField.setAccessible(true);
- elField.set(wrapperType, part);
- setInvoked = true;
- }
- }
- if (!setInvoked) {
- throw new IllegalArgumentException("Could not find a modifier
method on Wrapper Type for "
- + partName);
+
+ public Object createWrapperObject(List<?> lst)
+ throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException {
+
+ Object ret = wrapperType.newInstance();
+
+ for (int x = 0; x < setMethods.length; x++) {
+ Object o = lst.get(x);
+ if (jaxbObjectMethods[x] != null) {
+ o = jaxbObjectMethods[x].invoke(objectFactory, o);
+ }
+ if (o instanceof List) {
+ List<Object> col =
CastUtils.cast((List)getMethods[x].invoke(ret));
+ List<Object> olst = CastUtils.cast((List)o);
+ col.addAll(olst);
+ } else if (setMethods[x] != null) {
+ setMethods[x].invoke(ret, o);
+ } else {
+ fields[x].set(ret, lst.get(x));
}
}
+
+ return ret;
}
-
- private static Field getField(Object wrapperType, String partName, String
fieldName) {
- // match fieldName and partName first
- for (Field field : wrapperType.getClass().getDeclaredFields()) {
- if (field.getName().equals(fieldName)) {
- XmlElement el = field.getAnnotation(XmlElement.class);
- if (el != null && el.name().equals(partName)) {
- return field;
- }
- }
- }
- // if above fails, check partName only
- for (Field field : wrapperType.getClass().getDeclaredFields()) {
- XmlElement el = field.getAnnotation(XmlElement.class);
- if (el != null && el.name().equals(partName)) {
- return field;
+
+ public List<Object> getWrapperParts(Object o)
+ throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
+
+ 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));
+ } else if (fields[x] != null) {
+ ret.add(fields[x].get(o));
+ } else {
+ //placeholder
+ ret.add(null);
}
}
- return null;
+
+ return ret;
}
-
- private static boolean setJAXBElementValueIntoWrapType(Method method,
Object wrapType, Object value) {
- String typeClassName = wrapType.getClass().getCanonicalName();
- String objectFactoryClassName = typeClassName.substring(0,
typeClassName.lastIndexOf('.'))
+
+ 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());
+ List<Field> fields = new ArrayList<Field>(partNames.size());
+
+ Method allMethods[] = wrapperType.getMethods();
+
+ String objectFactoryClassName = wrapperType.getPackage().getName()
+ ".ObjectFactory";
+
+ Object objectFactory = null;
try {
- Object objectFactory =
wrapType.getClass().getClassLoader().loadClass(objectFactoryClassName)
- .newInstance();
- String methodName = "create" + wrapType.getClass().getSimpleName()
- + method.getName().substring(3);
- Method objectFactoryMethod =
objectFactory.getClass().getMethod(methodName, value.getClass());
- if (objectFactoryMethod != null) {
- JAXBElement je =
(JAXBElement)objectFactoryMethod.invoke(objectFactory, value);
- method.invoke(wrapType, je);
- } else {
- return false;
- }
- return true;
+ objectFactory =
wrapperType.getClassLoader().loadClass(objectFactoryClassName).newInstance();
} catch (Exception e) {
- return false;
- }
-
- }
-
- private static void setWrappedListProperty(String partName, Object
wrapperType, Object part)
- throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
-
- String accessorName = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.GETTER);
- for (Method method : wrapperType.getClass().getMethods()) {
- if (accessorName.equals(method.getName())
- && List.class.isAssignableFrom(method.getReturnType())) {
- Object ret = method.invoke(wrapperType);
- Method addAll = ret.getClass().getMethod("addAll",
Collection.class);
- addAll.invoke(ret, part);
- break;
- }
+ //ignore, probably won't need it
}
- }
-
- public static Object getWrappedPart(String partName, Object wrapperType,
Class<?> partClazz)
- throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
-
- String accessor = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.GETTER);
-
- if (partClazz.equals(boolean.class) ||
partClazz.equals(Boolean.class)) {
- // JAXB Exception to get the Boolean property
- accessor = accessor.replaceFirst("get", "is");
+ Method allOFMethods[];
+ if (objectFactory != null) {
+ allOFMethods = objectFactory.getClass().getMethods();
+ } else {
+ allOFMethods = new Method[0];
}
-
- for (Method method : wrapperType.getClass().getMethods()) {
- if (method.getParameterTypes().length == 0 &&
accessor.equals(method.getName())) {
-
- return getValue(method, wrapperType);
+
+ for (int x = 0; x < partNames.size(); x++) {
+ String partName = partNames.get(x);
+ if (partName == null) {
+ getMethods.add(null);
+ setMethods.add(null);
+ fields.add(null);
+ jaxbMethods.add(null);
+ continue;
}
- }
- return null;
- }
-
- public static Object getWrappedPart(String partName, Object wrapperType,
String elementType)
- throws IllegalAccessException, NoSuchMethodException,
InvocationTargetException {
-
- String accessor = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.GETTER);
- Method method = null;
- NoSuchMethodException nsex = null;
- try {
- method = wrapperType.getClass().getMethod(accessor, new Class[0]);
- } catch (NoSuchMethodException ex) {
- //ignore for now
- nsex = (NoSuchMethodException)ex.fillInStackTrace();
- }
-
- Field elField = null;
- if (method == null
- && elementType != null
- && "boolean".equals(elementType.toLowerCase())) {
- elField = getElField(partName, wrapperType);
-
- if (elField == null
- || (!Collection.class.isAssignableFrom(elField.getType())
- && !elField.getType().isArray())) {
-
+ String elementType = elTypeNames.get(x);
+
+ String getAccessor = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.GETTER);
+ String setAccessor = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.SETTER);
+ Method getMethod = null;
+ Method setMethod = null;
+ try {
+ getMethod = wrapperType.getMethod(getAccessor, NO_PARAMS);
+ } catch (NoSuchMethodException ex) {
+ //ignore for now
+ }
+
+ Field elField = getElField(partName, wrapperType);
+ if (getMethod == null
+ && elementType != null
+ && "boolean".equals(elementType.toLowerCase())
+ && (elField == null
+ || (!Collection.class.isAssignableFrom(elField.getType())
+ && !elField.getType().isArray()))) {
+
try {
- method =
wrapperType.getClass().getMethod(accessor.replaceFirst("get", "is"),
- new Class[0]);
+ String newAcc = getAccessor.replaceFirst("get", "is");
+ getMethod = wrapperType.getMethod(newAcc, NO_PARAMS);
} catch (NoSuchMethodException ex) {
//ignore for now
}
- }
- }
- if (method == null
- && "return".equals(partName)) {
- //RI generated code uses this
- try {
- method = wrapperType.getClass().getMethod("get_return", new
Class[0]);
- } catch (NoSuchMethodException ex) {
+ }
+ if (getMethod == null
+ && "return".equals(partName)) {
+ //RI generated code uses this
try {
- method = wrapperType.getClass().getMethod("is_return",
- new Class[0]);
- } catch (NoSuchMethodException ex2) {
- //ignore for now
+ getMethod = wrapperType.getClass().getMethod("get_return",
NO_PARAMS);
+ } catch (NoSuchMethodException ex) {
+ try {
+ getMethod =
wrapperType.getClass().getMethod("is_return",
+ new
Class[0]);
+ } catch (NoSuchMethodException ex2) {
+ //ignore for now
+ }
+ }
+ }
+ String setAccessor2 = setAccessor;
+ if ("return".equals(partName)) {
+ //some versions of jaxb map "return" to "set_return" instead
of "setReturn"
+ setAccessor2 = "set_return";
+ }
+
+ for (Method method : allMethods) {
+ if (method.getParameterTypes() != null &&
method.getParameterTypes().length == 1
+ && (setAccessor.equals(method.getName())
+ || setAccessor2.equals(method.getName()))) {
+ setMethod = method;
+ break;
+ }
+ }
+
+ getMethods.add(getMethod);
+ setMethods.add(setMethod);
+ if (setMethod != null
+ &&
JAXBElement.class.isAssignableFrom(setMethod.getParameterTypes()[0])) {
+
+ String methodName = "create" + wrapperType.getSimpleName()
+ + setMethod.getName().substring(3);
+
+ for (Method m : allOFMethods) {
+ if (m.getName().equals(methodName)) {
+ jaxbMethods.add(m);
+ }
+ }
+ } else {
+ jaxbMethods.add(null);
+ }
+
+ if (elField != null) {
+ // JAXB Type get XmlElement Annotation
+ XmlElement el = elField.getAnnotation(XmlElement.class);
+ if (el != null
+ && partName.equals(el.name())) {
+ elField.setAccessible(true);
+ fields.add(elField);
+ } else {
+ fields.add(null);
}
- }
- }
-
- if (method != null) {
- return getValue(method, wrapperType);
- }
- if (elField == null) {
- elField = getElField(partName, wrapperType);
- }
- if (elField != null) {
- // JAXB Type get XmlElement Annotation
- XmlElement el = elField.getAnnotation(XmlElement.class);
- if (el != null
- && partName.equals(el.name())) {
- elField.setAccessible(true);
- return elField.get(wrapperType);
+ } else {
+ fields.add(null);
}
- } else if (nsex != null) {
- throw nsex;
+
}
-
- return null;
+ return new WrapperHelper(wrapperType,
+ setMethods.toArray(new
Method[setMethods.size()]),
+ getMethods.toArray(new
Method[getMethods.size()]),
+ jaxbMethods.toArray(new
Method[jaxbMethods.size()]),
+ fields.toArray(new Field[fields.size()]),
+ objectFactory);
}
- private static Field getElField(String partName, Object wrapperType) {
+ private static Field getElField(String partName, Class<?> wrapperType) {
String fieldName = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.VARIABLE);
- Field elField = null;
- for (Field field : wrapperType.getClass().getDeclaredFields()) {
+ for (Field field : wrapperType.getDeclaredFields()) {
if (field.getName().equals(fieldName)) {
- elField = field;
- break;
+ return field;
}
}
- return elField;
- }
-
- public static Object getWrappedPart(String partName, Object wrapperType)
throws IllegalAccessException,
- NoSuchMethodException, InvocationTargetException {
- String accessor = JAXBUtils.nameToIdentifier(partName,
JAXBUtils.IdentifierType.GETTER);
-
- // TODO: There must be a way to determine the class by inspecting
- // wrapperType
- // if (partClazz.equals(boolean.class) ||
- // partClazz.equals(Boolean.class)) {
- // //JAXB Exception to get the Boolean property
- // accessor = accessor.replaceFirst("get", "is");
- // }
- for (Method method : wrapperType.getClass().getMethods()) {
- if (method.getParameterTypes().length == 0 &&
accessor.equals(method.getName())) {
- return getValue(method, wrapperType);
- }
- }
return null;
}
Modified:
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java?view=diff&rev=552502&r1=552501&r2=552502
==============================================================================
---
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
(original)
+++
incubator/cxf/trunk/common/common/src/test/java/org/apache/cxf/jaxb/WrapperHelperTest.java
Mon Jul 2 07:27:48 2007
@@ -18,6 +18,9 @@
*/
package org.apache.cxf.jaxb;
+import java.util.Arrays;
+import java.util.List;
+
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -34,25 +37,52 @@
public void getBooleanTypeWrappedPart() throws Exception {
SetIsOK ok = new SetIsOK();
ok.setParameter3(new boolean[] {true, false});
- Object object = WrapperHelper.getWrappedPart("Parameter1", ok,
"boolean");
- assertTrue(object instanceof Boolean);
- object = WrapperHelper.getWrappedPart("Parameter3", ok, "boolean");
- assertTrue(object instanceof boolean[]);
- assertTrue(((boolean[])object)[0]);
- assertFalse(((boolean[])object)[1]);
- WrapperHelper.setWrappedPart("Parameter1", ok, true);
+ List<String> partNames = Arrays.asList(new String[] {
+ "Parameter1",
+ "Parameter2",
+ "Parameter3"
+ });
+ List<String> elTypeNames = Arrays.asList(new String[] {
+ "boolean",
+ "int",
+ "boolean"
+ });
+ List<Class<?>> partClasses = Arrays.asList(new Class<?>[] {
+ Boolean.TYPE,
+ Integer.TYPE,
+ boolean[].class
+ });
+
+ WrapperHelper wh = WrapperHelper.createWrapperHelper(SetIsOK.class,
+ partNames,
+ elTypeNames,
+ partClasses);
+
+ List<Object> lst = wh.getWrapperParts(ok);
+ assertEquals(3, lst.size());
+ assertTrue(lst.get(0) instanceof Boolean);
+ assertTrue(lst.get(1) instanceof Integer);
+
+
+ assertTrue(lst.get(2) instanceof boolean[]);
+ assertTrue(((boolean[])lst.get(2))[0]);
+ assertFalse(((boolean[])lst.get(2))[1]);
+
+ lst.set(0, Boolean.TRUE);
+ Object o = wh.createWrapperObject(lst);
+ assertNotNull(0);
+ ok = (SetIsOK)o;
assertTrue(ok.isParameter1());
- WrapperHelper.setWrappedPart("Parameter3", ok, new boolean[] {false,
true});
- assertTrue(ok.getParameter3()[1]);
- assertFalse(ok.getParameter3()[0]);
+ assertTrue(ok.getParameter3()[0]);
+ assertFalse(ok.getParameter3()[1]);
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "parameter1", "parameter2", "parameter3"
})
@XmlRootElement(name = "setIsOK")
- class SetIsOK {
+ public static class SetIsOK {
@XmlElement(name = "Parameter1")
protected boolean parameter1;
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java?view=diff&rev=552502&r1=552501&r2=552502
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
Mon Jul 2 07:27:48 2007
@@ -86,6 +86,7 @@
}
Class<?> wrapperClass = null;
Object wrappedObject = null;
+ MessagePartInfo wrapperPart = null;
if (wrappedMessageInfo != null) {
for (MessagePartInfo part :
wrappedMessageInfo.getMessageParts()) {
//headers should appear in both, find the part that doesn't
@@ -94,6 +95,7 @@
for (Object o : lst) {
if (wrapperClass.isInstance(o)) {
wrappedObject = o;
+ wrapperPart = part;
break;
}
}
@@ -116,36 +118,63 @@
return;
}
- List<Object> newParams = new ArrayList<Object>();
- for (MessagePartInfo part : messageInfo.getMessageParts()) {
- if (wrappedMessageInfo.getMessagePart(part.getName()) != null)
{
- newParams.add(lst.get(part.getIndex()));
- } else {
- try {
- String elementType = null;
- if (part.isElement()) {
- elementType =
part.getElementQName().getLocalPart();
- } else {
- if (part.getTypeQName() == null) {
- // handling anonymous complex type
- elementType = null;
- } else {
- elementType =
part.getTypeQName().getLocalPart();
- }
- }
- Object obj =
WrapperHelper.getWrappedPart(part.getName().getLocalPart(),
-
wrappedObject,
- elementType);
-
- newParams.add(obj);
- } catch (Exception e) {
- // TODO - fault
- throw new Fault(e);
+ WrapperHelper helper = wrapperPart.getProperty("WRAPPER_CLASS",
WrapperHelper.class);
+ if (helper == null) {
+ helper = createWrapperHelper(messageInfo, wrappedMessageInfo,
wrapperClass);
+ wrapperPart.setProperty("WRAPPER_CLASS", helper);
+ }
+ List<Object> newParams;
+ try {
+ newParams = helper.getWrapperParts(wrappedObject);
+
+ int idx = 0;
+ for (MessagePartInfo part : messageInfo.getMessageParts()) {
+ if (wrappedMessageInfo.getMessagePart(part.getName()) !=
null) {
+ newParams.set(idx, lst.get(part.getIndex()));
}
+ ++idx;
}
+ } catch (Exception e) {
+ throw new Fault(e);
}
+
message.setContent(List.class, newParams);
}
}
-
+
+ private WrapperHelper createWrapperHelper(MessageInfo messageInfo,
+ MessageInfo wrappedMessageInfo,
+ Class<?> wrapperClass) {
+ List<String> partNames = new ArrayList<String>();
+ List<String> elTypeNames = new ArrayList<String>();
+ List<Class<?>> partClasses = new ArrayList<Class<?>>();
+
+ for (MessagePartInfo p : messageInfo.getMessageParts()) {
+ if (wrappedMessageInfo.getMessagePart(p.getName()) != null) {
+ elTypeNames.add(null);
+ partClasses.add(null);
+ partNames.add(null);
+ } else {
+ String elementType = null;
+ if (p.isElement()) {
+ elementType = p.getElementQName().getLocalPart();
+ } else {
+ if (p.getTypeQName() == null) {
+ // handling anonymous complex type
+ elementType = null;
+ } else {
+ elementType = p.getTypeQName().getLocalPart();
+ }
+ }
+
+ elTypeNames.add(elementType);
+ partClasses.add(p.getClass());
+ partNames.add(p.getName().getLocalPart());
+ }
+ }
+ return WrapperHelper.createWrapperHelper(wrapperClass,
+ partNames,
+ elTypeNames,
+ partClasses);
+ }
}
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassOutInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassOutInterceptor.java?view=diff&rev=552502&r1=552501&r2=552502
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassOutInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassOutInterceptor.java
Mon Jul 2 07:27:48 2007
@@ -65,23 +65,45 @@
if (wrapped != null) {
List<Object> objs = CastUtils.cast(message.getContent(List.class));
-
- try {
- Object wrapperType = wrapped.newInstance();
- int i = 0;
- for (MessagePartInfo p : messageInfo.getMessageParts()) {
- Object part = objs.get(i);
- WrapperHelper.setWrappedPart(p.getName().getLocalPart(),
wrapperType, part);
-
- i++;
- }
+ WrapperHelper helper = parts.get(0).getProperty("WRAPPER_CLASS",
WrapperHelper.class);
+ if (helper == null) {
+ List<String> partNames = new ArrayList<String>();
+ List<String> elTypeNames = new ArrayList<String>();
+ List<Class<?>> partClasses = new ArrayList<Class<?>>();
+ for (MessagePartInfo p : messageInfo.getMessageParts()) {
+ partNames.add(p.getName().getLocalPart());
+
+ String elementType = null;
+ if (p.isElement()) {
+ elementType = p.getElementQName().getLocalPart();
+ } else {
+ if (p.getTypeQName() == null) {
+ // handling anonymous complex type
+ elementType = null;
+ } else {
+ elementType = p.getTypeQName().getLocalPart();
+ }
+ }
+
+ elTypeNames.add(elementType);
+ partClasses.add(p.getClass());
+ }
+ helper = WrapperHelper.createWrapperHelper(wrapped,
+ partNames,
+ elTypeNames,
+ partClasses);
+
+ parts.get(0).setProperty("WRAPPER_CLASS", helper);
+ }
+ try {
+ Object o2 = helper.createWrapperObject(objs);
objs = new ArrayList<Object>(1);
- objs.add(wrapperType);
+ objs.add(o2);
message.setContent(List.class, objs);
- } catch (Exception exc) {
- throw new Fault(exc);
+ } catch (Exception e) {
+ throw new Fault(e);
}
// we've now wrapped the object, so use the wrapped binding op