You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/02/10 19:28:01 UTC
svn commit: r505734 - in
/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws:
client/ marshaller/impl/alt/ message/databinding/impl/
runtime/description/marshal/impl/ utility/
Author: scheu
Date: Sat Feb 10 10:28:00 2007
New Revision: 505734
URL: http://svn.apache.org/viewvc?view=rev&rev=505734
Log:
AXIS2-1800 More marshalling refactoring
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/Element.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/AnnotationDescImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/XMLRootElementUtil.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/JAXBDispatch.java Sat Feb 10 10:28:00 2007
@@ -74,7 +74,7 @@
context = new JAXBBlockContext(clazz.getPackage().getName());
}
// Create a block from the value
- QName qName = XMLRootElementUtil.getXmlRootElementQName(value);
+ QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(value);
Block block = factory.createFrom(value, context, qName);
MessageFactory mf = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java Sat Feb 10 10:28:00 2007
@@ -342,11 +342,7 @@
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
- object = XMLRootElementUtil.getElementEnabledObject(
- wrapperQName.getNamespaceURI(),
- wrapperQName.getLocalPart(),
- cls,
- object);
+ object = new JAXBElement(wrapperQName, cls, object);
}
@@ -432,11 +428,7 @@
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
- object = XMLRootElementUtil.getElementEnabledObject(
- wrapperQName.getNamespaceURI(),
- wrapperQName.getLocalPart(),
- cls,
- object);
+ object = new JAXBElement(wrapperQName, cls, object);
}
// Put the object into the message
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java Sat Feb 10 10:28:00 2007
@@ -471,11 +471,7 @@
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
- object = XMLRootElementUtil.getElementEnabledObject(
- wrapperQName.getNamespaceURI(),
- wrapperQName.getLocalPart(),
- cls,
- object);
+ object = new JAXBElement(wrapperQName, cls, object);
}
@@ -579,11 +575,7 @@
// Make sure object can be rendered as an element
if (!marshalDesc.getAnnotationDesc(cls).hasXmlRootElement()) {
- object = XMLRootElementUtil.getElementEnabledObject(
- wrapperQName.getNamespaceURI(),
- wrapperQName.getLocalPart(),
- cls,
- object);
+ object = new JAXBElement(wrapperQName, cls, object);
}
// Put the object into the message
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/Element.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/Element.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/Element.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/Element.java Sat Feb 10 10:28:00 2007
@@ -32,6 +32,34 @@
* * It is the type value associated with the element value. (Thus it is either
* the element value or it is value of the JAXBElement
* * The type value is usually the object needed for the method signature (i.e. String)
+ *
+ * Here is an example for illustration:
+ * <element name='e1'>
+ * <complexType>...</complexType>
+ * </element>
+ *
+ * <element name='e2' type='t2' />
+ * <complexType name= 't2'>..
+ *
+ * <element name='e3' type='e3' /> <!-- note element and type have same name -->
+ * <complexType name= 'e3'>..
+ *
+ * JAXB will generate the following objects: E1, T2, E3
+ * E1 will have an @XMLRootElement annotation. It is "element" and "type" enabled.
+ * e2 does not have a generated object. So it will be represented as a JAXBElement
+ * that contains an object T2. The JAXBElement is "element" enabled.
+ * T2 represents a complexType. It is only "type" enabled.
+ * E3 represents the e3 complexType (it does not represent the e3 element). Thus E3
+ * is "type enabled".
+ *
+ * When JAXB unmarshals an object, it will return an "element" enabled object (either
+ * a generatated object with @XMLRootElement or a JAXBElement).
+ * Conversely, you must always marshal "element" enabled objects.
+ * @see org.apache.axis2.jaxws.marshaller.impl.alt.PDElement
+ *
+ * At the signature level, the values passed as arguments in an SEI operation represent
+ * type enabled objects. Each of the object must be converted to an element enabled object
+ * to marshal (or conversely converted to a type enabled object when unmarshalling)
*/
public class Element {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/MethodMarshallerUtils.java Sat Feb 10 10:28:00 2007
@@ -539,10 +539,11 @@
if (log.isErrorEnabled()) {
log.debug("The faultBean type is" + faultBeanObject.getClass().getName());
}
+
+ QName faultBeanQName = new QName(fd.getTargetNamespace(), fd.getName());
// Make sure the faultBeanObject can be marshalled as an element
if (!marshalDesc.getAnnotationDesc(faultBeanObject.getClass()).hasXmlRootElement()) {
- faultBeanObject = XMLRootElementUtil.getElementEnabledObject(fd.getTargetNamespace(), fd.getName(),
- faultBeanObject.getClass(), faultBeanObject);
+ faultBeanObject = new JAXBElement(faultBeanQName, faultBeanObject.getClass(), faultBeanObject);
}
@@ -553,7 +554,7 @@
context.setRPCType(faultBeanObject.getClass());
}
- QName faultBeanQName = new QName(fd.getTargetNamespace(), fd.getName());
+
// Create a detailblock representing the faultBeanObject
Block[] detailBlocks = new Block[1];
detailBlocks[0] = factory.createFrom(faultBeanObject,context,faultBeanQName);
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockFactoryImpl.java Sat Feb 10 10:28:00 2007
@@ -85,7 +85,7 @@
// (Checking this is expensive, so it is assumed)
// The input QName must be set otherwise we have to look it up, which kills performance.
if (qName == null) {
- qName = XMLRootElementUtil.getXmlRootElementQName(businessObject);
+ qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(businessObject);
}
try {
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/impl/JAXBBlockImpl.java Sat Feb 10 10:28:00 2007
@@ -313,9 +313,9 @@
// String instead. Then we get the correct wire format:
// <foo>1 2 3</foo>
if (isXSDList(type)) {
- QName qName = XMLRootElementUtil.getXmlRootElementQName(b);
+ QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(b);
String text = XSDListUtils.toXSDListString(getTypeEnabledObject(b));
- b = XMLRootElementUtil.getElementEnabledObject(qName.getNamespaceURI(), qName.getLocalPart(), String.class, text);
+ b = new JAXBElement(qName, String.class, text);
}
m.marshal(b, writer);
} catch (Exception e) {
@@ -350,9 +350,9 @@
// Second convert the String into a list or array
if (getTypeEnabledObject(jaxb) instanceof String) {
- QName qName = XMLRootElementUtil.getXmlRootElementQName(jaxb);
+ QName qName = XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
Object obj = XSDListUtils.fromXSDListString((String) getTypeEnabledObject(jaxb), type);
- jaxb = XMLRootElementUtil.getElementEnabledObject(qName.getNamespaceURI(), qName.getLocalPart(), type, obj);
+ jaxb = new JAXBElement(qName, type, obj);
}
}
return jaxb;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/AnnotationDescImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/AnnotationDescImpl.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/AnnotationDescImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/AnnotationDescImpl.java Sat Feb 10 10:28:00 2007
@@ -20,8 +20,10 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.namespace.QName;
import org.apache.axis2.jaxws.runtime.description.marshal.AnnotationDesc;
+import org.apache.axis2.jaxws.utility.XMLRootElementUtil;
/**
*
@@ -51,53 +53,16 @@
static AnnotationDesc create(Class cls) {
AnnotationDescImpl aDesc = new AnnotationDescImpl();
- XmlRootElement root = (XmlRootElement) cls.getAnnotation(XmlRootElement.class);
- if (root == null) {
+ QName qName = XMLRootElementUtil.getXmlRootElementQName(cls);
+ if (qName == null) {
return aDesc;
}
aDesc._hasXmlRootElement = true;
- String name = root.name();
- String namespace = root.namespace();
-
- // The name may need to be defaulted
- if (name == null || name.length() == 0 || namespace.equals("##default")) {
- name = getSimpleName(cls.getCanonicalName());
- }
-
- // The namespace may need to be defaulted
- if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) {
- Package pkg = cls.getPackage();
- XmlSchema schema = (XmlSchema) pkg.getAnnotation(XmlSchema.class);
- if (schema != null) {
- namespace = schema.namespace();
- } else {
- namespace = "";
- }
- }
-
- aDesc._XmlRootElementName = name;
- aDesc._XmlRootElementNamespace = namespace;
+ String name = qName.getLocalPart();
+ String namespace = qName.getNamespaceURI();
return aDesc;
}
- /**
- * utility method to get the last token in a "."-delimited package+classname string
- * @return
- */
- private static String getSimpleName(String in) {
- if (in == null || in.length() == 0) {
- return in;
- }
- String out = null;
- StringTokenizer tokenizer = new StringTokenizer(in, ".");
- if (tokenizer.countTokens() == 0)
- out = in;
- else {
- while (tokenizer.hasMoreTokens()) {
- out = tokenizer.nextToken();
- }
- }
- return out;
- }
+
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/marshal/impl/PackageSetBuilder.java Sat Feb 10 10:28:00 2007
@@ -319,7 +319,7 @@
* @return Class or null
*/
private static Class getElement(Class cls) {
- if (!XMLRootElementUtil.isElementEnabled(cls)) {
+ if (XMLRootElementUtil.getXmlRootElementQName(cls) == null) {
return null;
}
return cls;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/XMLRootElementUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/XMLRootElementUtil.java?view=diff&rev=505734&r1=505733&r2=505734
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/XMLRootElementUtil.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/XMLRootElementUtil.java Sat Feb 10 10:28:00 2007
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.HashMap;
+import java.util.StringTokenizer;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElement;
@@ -39,46 +40,6 @@
import org.apache.commons.logging.LogFactory;
/**
- * This utility contains code to determine if an Object is
- * "element enabled" or "type enabled".
- *
- * Here is an example for illustration:
- * <element name='e1'>
- * <complexType>...</complexType>
- * </element>
- *
- * <element name='e2' type='t2' />
- * <complexType name= 't2'>..
- *
- * <element name='e3' type='e3' /> <!-- note element and type have same name -->
- * <complexType name= 'e3'>..
- *
- * JAXB will generate the following objects: E1, T2, E3
- * E1 will have an @XMLRootElement annotation. It is "element" and "type" enabled.
- * e2 does not have a generated object. So it will be represented as a JAXBElement
- * that contains an object T2. The JAXBElement is "element" enabled.
- * T2 represents a complexType. It is only "type" enabled.
- * E3 represents the e3 complexType (it does not represent the e3 element). Thus E3
- * is "type enabled".
- *
- * When JAXB unmarshals an object, it will return an "element" enabled object (either
- * a generatated object with @XMLRootElement or a JAXBElement).
- * Conversely, you must always marshal "element" enabled objects.
- * @see org.apache.axis2.jaxws.marshaller.impl.alt.PDElement
- *
- * At the signature level, the values passed as arguments in an SEI operation represent
- * type enabled objects. Each of the object must be converted to an element enabled object
- * to marshal (or conversely converted to a type enabled object when unmarshalling)
- *
- * -----------------------------------------
- * There are other simular utility methods in this class. Including utilities to get
- * a xml name -> bean property map.
- *
- * -----------------------------------------
- *
- * @TODO A secondary reason usage of XMLRootElementUtil is to isolate all of the
- * @XMLRootElement and related annotation queries. Annotation queries are expensive.
- * A follow-on version of this class will cache the results so that we can improve performance.
*
*/
public class XMLRootElementUtil {
@@ -91,53 +52,12 @@
private XMLRootElementUtil() {
}
-
- /**
- * Return true if this class is element enabled
- * @param clazz
- * @return true if this class has a corresponding xml root element
- */
- public static boolean isElementEnabled(Class clazz){
- if (clazz.equals(JAXBElement.class)) {
- return true;
- }
- // If the clazz is a primitive, then it does not have a corresponding root element.
- if (clazz.isPrimitive() || ClassUtils.getWrapperClass(clazz) != null) {
- return false;
- }
-
- // Presence of an annotation means that it can be rendered as a root element
- XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
- return root !=null;
- }
-
-
- /**
- * Return an object that can be marshalled/unmarshalled as an element
- * If the specified object is already element enabled, it is returned.
- * @param namespace
- * @param localPart
- * @param cls either the class or super class of obj
- * @param type element or type enabled object
- * @return
- */
- public static Object getElementEnabledObject(String namespace, String localPart, Class cls, Object obj) {
- if (obj != null && isElementEnabled(obj.getClass())) {
- return obj;
- }
-
- QName qName = new QName(namespace, localPart);
- JAXBElement element = new JAXBElement(qName, cls, obj);
- return element;
- }
-
-
/**
* @param clazz
* @return namespace of root element qname or null if this is not object does not represent a root element
*/
- public static QName getXmlRootElementQName(Object obj){
+ public static QName getXmlRootElementQNameFromObject(Object obj){
// A JAXBElement stores its name
if (obj instanceof JAXBElement) {
@@ -145,11 +65,14 @@
}
Class clazz = (obj instanceof java.lang.Class) ? (Class) obj : obj.getClass();
- // If the clazz is a primitive, then it does not have a corresponding root element.
- if (clazz.isPrimitive() ||
- ClassUtils.getWrapperClass(clazz) != null) {
- return null;
- }
+ return getXmlRootElementQName(clazz);
+ }
+
+ /**
+ * @param clazz
+ * @return namespace of root element qname or null if this is not object does not represent a root element
+ */
+ public static QName getXmlRootElementQName(Class clazz){
// See if the object represents a root element
XmlRootElement root = (XmlRootElement) clazz.getAnnotation(XmlRootElement.class);
@@ -157,8 +80,13 @@
return null;
}
+ String name = root.name();
String namespace = root.namespace();
- String localPart = root.name();
+
+ // The name may need to be defaulted
+ if (name == null || name.length() == 0 || name.equals("##default")) {
+ name = getSimpleName(clazz.getCanonicalName());
+ }
// The namespace may need to be defaulted
if (namespace == null || namespace.length() == 0 || namespace.equals("##default")) {
@@ -167,12 +95,32 @@
if (schema != null) {
namespace = schema.namespace();
} else {
- return null;
+ namespace = "";
}
}
- return new QName(namespace, localPart);
+
+ return new QName(namespace, name);
}
+ /**
+ * utility method to get the last token in a "."-delimited package+classname string
+ * @return
+ */
+ private static String getSimpleName(String in) {
+ if (in == null || in.length() == 0) {
+ return in;
+ }
+ String out = null;
+ StringTokenizer tokenizer = new StringTokenizer(in, ".");
+ if (tokenizer.countTokens() == 0)
+ out = in;
+ else {
+ while (tokenizer.hasMoreTokens()) {
+ out = tokenizer.nextToken();
+ }
+ }
+ return out;
+ }
/**
* The JAXBClass has a set of bean properties each represented by a PropertyDescriptor
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org