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 di...@apache.org on 2008/03/31 05:58:27 UTC
svn commit: r642870 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/utility/ test/org/apache/axis2/jaxws/utility/
Author: dims
Date: Sun Mar 30 20:58:25 2008
New Revision: 642870
URL: http://svn.apache.org/viewvc?rev=642870&view=rev
Log:
Support @XmlElementRef on wrapper bean. Many thanks to Martin Adams for his Test Case. Code Design approach suggested by Rich Scheuerle. Bugs are all my fault :)
Added:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/InvokeAction.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/PropertyDescriptorPlusTests.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/PropertyDescriptorPlus.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/utility/PropertyDescriptorPlus.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/PropertyDescriptorPlus.java?rev=642870&r1=642869&r2=642870&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/PropertyDescriptorPlus.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/PropertyDescriptorPlus.java Sun Mar 30 20:58:25 2008
@@ -25,6 +25,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.xml.namespace.QName;
+import javax.xml.bind.JAXBElement;
import java.beans.IndexedPropertyDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
@@ -48,7 +50,7 @@
*/
public class PropertyDescriptorPlus {
PropertyDescriptor descriptor;
- String xmlName = null;
+ QName xmlName = null;
private static Log log = LogFactory.getLog(PropertyDescriptorPlus.class);
private static final boolean DEBUG_ENABLED = log.isDebugEnabled();
@@ -60,17 +62,34 @@
* @param descriptor
* @see XMLRootElementUtil.createPropertyDescriptorMap
*/
- PropertyDescriptorPlus(PropertyDescriptor descriptor, String xmlName) {
+ PropertyDescriptorPlus(PropertyDescriptor descriptor, QName xmlName) {
super();
this.descriptor = descriptor;
this.xmlName = xmlName;
}
+ /**
+ * Package protected constructor. Only created by XMLRootElementUtil.createPropertyDescriptorMap
+ *
+ * @param propertyName
+ * @param descriptor
+ * @see XMLRootElementUtil.createPropertyDescriptorMap
+ */
+ PropertyDescriptorPlus(PropertyDescriptor descriptor, String xmlName) {
+ super();
+ this.descriptor = descriptor;
+ this.xmlName = new QName("", xmlName);
+ }
+
/** @return xmlname */
public String getXmlName() {
- return xmlName;
+ return xmlName.getLocalPart();
}
+ public QName getXmlQName() {
+ return xmlName;
+ }
+
/** @return property type */
public Class getPropertyType() {
return descriptor.getPropertyType();
@@ -115,7 +134,11 @@
if(method == null){
throw new RuntimeException(Messages.getMessage("pDescrErr2",targetBean.getClass().getName()));
}
- return method.invoke(targetBean, null);
+ Object ret = method.invoke(targetBean, null);
+ if (method.getReturnType() == JAXBElement.class) {
+ ret = ((JAXBElement) ret).getValue();
+ }
+ return ret;
}
/**
@@ -149,6 +172,12 @@
} else if (writeMethod == null) {
// Set for List<T>
setList(targetBean, propValue);
+ } else if (descriptor.getPropertyType() == JAXBElement.class) {
+ if (propValue != null) {
+ Class clazz = propValue.getClass();
+ JAXBElement element = new JAXBElement(xmlName, clazz, propValue);
+ setAtomic(targetBean, element, writeMethod);
+ }
} else {
// Normal case
setAtomic(targetBean, propValue, writeMethod);
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?rev=642870&r1=642869&r2=642870&view=diff
==============================================================================
--- 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 Sun Mar 30 20:58:25 2008
@@ -28,6 +28,7 @@
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.namespace.QName;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -199,7 +200,7 @@
if (fieldName.equalsIgnoreCase(pd.getDisplayName()) ||
fieldName.equalsIgnoreCase(pd.getName())) {
// Get the xmlElement name for this field
- String xmlName = getXmlElementName(field.getDeclaringClass(), field);
+ QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field);
found = true;
if (log.isDebugEnabled()) {
log.debug(" Found field " + field.getName() + " which has xmlname=" +
@@ -211,7 +212,7 @@
" already has this same xmlName..this may cause problems.");
}
}
- map.put(xmlName, new PropertyDescriptorPlus(pd, xmlName));
+ map.put(xmlName.getLocalPart(), new PropertyDescriptorPlus(pd, xmlName));
break;
}
@@ -221,7 +222,7 @@
if (fieldName.equalsIgnoreCase(pd.getDisplayName()) ||
fieldName.equalsIgnoreCase(pd.getName())) {
// Get the xmlElement name for this field
- String xmlName = getXmlElementName(field.getDeclaringClass(), field);
+ QName xmlName = getXmlElementRefOrElementQName(field.getDeclaringClass(), field);
found = true;
if (log.isDebugEnabled()) {
log.debug(" Found field " + field.getName() + " which has xmlname=" +
@@ -234,7 +235,7 @@
" already has this same xmlName..this may cause problems.");
}
}
- map.put(xmlName, new PropertyDescriptorPlus(pd, xmlName));
+ map.put(xmlName.getLocalPart(), new PropertyDescriptorPlus(pd, xmlName));
break;
}
}
@@ -299,18 +300,24 @@
* @return
* @throws NoSuchFieldException
*/
- private static String getXmlElementName(Class jaxbClass, Field field)
+ private static QName getXmlElementRefOrElementQName(Class jaxbClass, Field field)
throws NoSuchFieldException {
+ XmlElementRef xmlElementRef = (XmlElementRef)
+ getAnnotation(field, XmlElementRef.class);
+ if (xmlElementRef != null) {
+ return new QName(xmlElementRef.namespace(),
+ xmlElementRef.name());
+ }
XmlElement xmlElement = (XmlElement)
- getAnnotation(field,XmlElement.class);
+ getAnnotation(field, XmlElement.class);
// If XmlElement does not exist, default to using the field name
if (xmlElement == null ||
xmlElement.name().equals("##default")) {
- return field.getName();
+ return new QName("", field.getName());
}
- return xmlElement.name();
-
+ return new QName(xmlElement.namespace(),
+ xmlElement.name());
}
/**
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/InvokeAction.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/InvokeAction.java?rev=642870&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/InvokeAction.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/InvokeAction.java Sun Mar 30 20:58:25 2008
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.utility;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for invokeAction complex type.
+ * <p/>
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * <p/>
+ * <pre>
+ * <complexType name="invokeAction">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="arg0" type="{http://www.w3.org/2001/XMLSchema}base64Binary" minOccurs="0"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "invokeAction", namespace = "http://utility.jaxws.axis2.apache.org/", propOrder = {
+ "arg0"
+ })
+public class InvokeAction {
+
+ @XmlElementRef(name = "arg0", type = JAXBElement.class)
+ protected JAXBElement<byte[]> arg0;
+
+ /**
+ * Gets the value of the arg0 property.
+ *
+ * @return possible object is
+ * {@link JAXBElement }{@code <}{@link byte[]}{@code >}
+ */
+ public JAXBElement<byte[]> getArg0() {
+ return arg0;
+ }
+
+ /**
+ * Sets the value of the arg0 property.
+ *
+ * @param value allowed object is
+ * {@link JAXBElement }{@code <}{@link byte[]}{@code >}
+ */
+ public void setArg0(JAXBElement<byte[]> value) {
+ this.arg0 = ((JAXBElement<byte[]>) value);
+ }
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/PropertyDescriptorPlusTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/PropertyDescriptorPlusTests.java?rev=642870&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/PropertyDescriptorPlusTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/utility/PropertyDescriptorPlusTests.java Sun Mar 30 20:58:25 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.jaxws.utility;
+
+import junit.framework.TestCase;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.Arrays;
+
+public class PropertyDescriptorPlusTests extends TestCase {
+ public void testJAXBElement() throws Exception {
+ InvokeAction object = new InvokeAction();
+
+ BeanInfo structBeanInfo = Introspector.getBeanInfo(InvokeAction.class);
+ PropertyDescriptor[] descriptors = structBeanInfo.getPropertyDescriptors();
+ assertNotNull(descriptors);
+ assertEquals(descriptors.length, 2);
+
+ QName qName = new QName("", "args0");
+ PropertyDescriptorPlus plus = new PropertyDescriptorPlus(descriptors[0], qName);
+ byte[] testValue = {0xd, 0xe, 0xa, 0xd, 0xb, 0xe, 0xe, 0xf};
+ plus.set(object, testValue);
+
+ JAXBElement<byte[]> arg0 = object.getArg0();
+ assertEquals(arg0.getDeclaredType(), byte[].class);
+ assertEquals(arg0.getName(), qName);
+ assertTrue(Arrays.equals(testValue, arg0.getValue()));
+
+ Object value = plus.get(object);
+ assertEquals(value.getClass(), byte[].class);
+ assertTrue(Arrays.equals(testValue, (byte[]) value));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org