You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/04/02 05:24:15 UTC
svn commit: r643696 - in /incubator/tuscany/java/sca/modules:
databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/
interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/
interface-java-jaxws/src/test/java/org/a...
Author: rfeng
Date: Tue Apr 1 20:24:11 2008
New Revision: 643696
URL: http://svn.apache.org/viewvc?rev=643696&view=rev
Log:
Create wrapper for java interfaces if it's not BARE style
Modified:
incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java
incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java
incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java
incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java
incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/TestJavaInterface.java
Modified: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java (original)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java Tue Apr 1 20:24:11 2008
@@ -18,9 +18,6 @@
*/
package org.apache.tuscany.sca.databinding.impl;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -34,7 +31,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* Helper for DOM
@@ -132,32 +128,30 @@
QName name = new QName(element.getNamespaceURI(), element.getLocalName());
if (xmlType.isElement() && !xmlType.getElementName().equals(name)) {
QName newName = xmlType.getElementName();
- String prefix = element.getPrefix();
+ String prefix = newName.getPrefix();
String qname = newName.getLocalPart();
if (prefix != null && !prefix.equals("")) {
qname = prefix + ":" + qname;
}
- Element newElement = element.getOwnerDocument().createElementNS(newName.getNamespaceURI(), qname);
- // newElement.setPrefix(prefix);
- NodeList nodeList = element.getChildNodes();
- // Need to copy the nodes from the list first as the appendChild() will change the list
- int length = nodeList.getLength();
- List<Node> nodes = new ArrayList<Node>();
- for (int i = 0; i < length; i++) {
- nodes.add(nodeList.item(i));
- }
+ Document doc = element.getOwnerDocument();
+ Element newElement = doc.createElementNS(newName.getNamespaceURI(), qname);
+ // Copy the attributes to the new element
NamedNodeMap attrs = element.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
- nodes.add(attrs.item(i));
+ Attr attr = (Attr)doc.importNode(attrs.item(i), true);
+ newElement.getAttributes().setNamedItem(attr);
}
- for (int i = 0; i < nodes.size(); i++) {
- Node node = nodes.get(i);
- if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
- newElement.setAttributeNodeNS((Attr)node.cloneNode(true));
- } else {
- newElement.appendChild(nodes.get(i));
- }
+
+ // Move all the children
+ while (element.hasChildNodes()) {
+ newElement.appendChild(element.getFirstChild());
}
+
+ // Replace the old node with the new node
+ if (element.getParentNode() != null) {
+ element.getParentNode().replaceChild(newElement, element);
+ }
+
return newElement;
}
}
Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java Tue Apr 1 20:24:11 2008
@@ -22,6 +22,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import javax.jws.Oneway;
@@ -41,6 +42,7 @@
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
@@ -68,9 +70,9 @@
Class<?> clazz = contract.getJavaClass();
WebService webService = clazz.getAnnotation(WebService.class);
- String tns = "";
+ String tns = JavaInterfaceUtil.getNamespace(clazz);
if (webService != null) {
- tns = webService.targetNamespace();
+ tns = getValue(webService.targetNamespace(), tns);
// Mark SEI as Remotable
contract.setRemotable(true);
}
@@ -81,8 +83,8 @@
// SOAP binding (doc/lit/wrapped|bare or rpc/lit)
SOAPBinding soapBinding = clazz.getAnnotation(SOAPBinding.class);
- for (Operation op : contract.getOperations()) {
- JavaOperation operation = (JavaOperation)op;
+ for (Iterator<Operation> it = contract.getOperations().iterator(); it.hasNext();) {
+ JavaOperation operation = (JavaOperation)it.next();
Method method = operation.getJavaMethod();
introspectFaultTypes(operation);
@@ -93,18 +95,26 @@
}
boolean documentStyle = true;
+ boolean bare = false;
if (methodSOAPBinding != null) {
- operation.setWrapperStyle(methodSOAPBinding.parameterStyle() == SOAPBinding.ParameterStyle.WRAPPED);
+ bare = methodSOAPBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE;
+ // For BARE parameter style, the data is in the wrapped format already
+ operation.setWrapperStyle(bare);
documentStyle = methodSOAPBinding.style() == Style.DOCUMENT;
}
+ String operationName = operation.getName();
// WebMethod
WebMethod webMethod = method.getAnnotation(WebMethod.class);
- if (webMethod == null) {
- continue;
+ if (webMethod != null) {
+ if (webMethod.exclude()) {
+ // Exclude the method
+ it.remove();
+ continue;
+ }
+ operationName = getValue(webMethod.operationName(), operationName);
+ operation.setName(operationName);
}
- String operationName = getValue(webMethod.operationName(), operation.getName());
- operation.setName(operationName);
// Is one way?
Oneway oneway = method.getAnnotation(Oneway.class);
@@ -115,7 +125,7 @@
}
// Handle BARE mapping
- if (!operation.isWrapperStyle()) {
+ if (bare) {
for (int i = 0; i < method.getParameterTypes().length; i++) {
WebParam param = getAnnotation(method, i, WebParam.class);
if (param != null) {
@@ -140,49 +150,61 @@
((XMLType)logical).setElementName(element);
}
}
- }
+ // FIXME: [rfeng] For the BARE mapping, do we need to create a Wrapper?
+ // it's null at this point
+ } else {
+
+ RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class);
+ String ns = requestWrapper == null ? tns : getValue(requestWrapper.targetNamespace(), tns);
+ String name =
+ requestWrapper == null ? operationName : getValue(requestWrapper.localName(), operationName);
+ QName inputWrapper = new QName(ns, name);
+
+ ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class);
+ ns = responseWrapper == null ? tns : getValue(responseWrapper.targetNamespace(), tns);
+ name =
+ responseWrapper == null ? operationName + "Response" : getValue(responseWrapper.localName(),
+ operationName + "Response");
+ QName outputWrapper = new QName(ns, name);
- RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class);
- ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class);
- if (requestWrapper == null) {
- continue;
- }
+ List<ElementInfo> inputElements = new ArrayList<ElementInfo>();
+ for (int i = 0; i < method.getParameterTypes().length; i++) {
+ WebParam param = getAnnotation(method, i, WebParam.class);
+ ns = param != null ? param.targetNamespace() : "";
+ // Default to "" for doc-lit-wrapped && non-header
+ ns = getValue(ns, documentStyle && (param == null || !param.header()) ? "" : tns);
+ name = param != null ? param.name() : "";
+ name = getValue(name, "arg" + i);
+ QName element = new QName(ns, name);
+ Object logical = operation.getInputType().getLogical().get(i).getLogical();
+ if (logical instanceof XMLType) {
+ ((XMLType)logical).setElementName(element);
+ }
+ inputElements.add(new ElementInfo(element, null));
+ }
- String ns = getValue(requestWrapper.targetNamespace(), tns);
- String name = getValue(requestWrapper.localName(), operationName);
- QName inputWrapper = new QName(ns, name);
-
- ns = getValue(responseWrapper.targetNamespace(), tns);
- name = getValue(responseWrapper.localName(), operationName + "Response");
-
- QName outputWrapper = new QName(ns, name);
-
- List<ElementInfo> inputElements = new ArrayList<ElementInfo>();
- for (int i = 0; i < method.getParameterTypes().length; i++) {
- WebParam param = getAnnotation(method, i, WebParam.class);
- assert param != null;
+ List<ElementInfo> outputElements = new ArrayList<ElementInfo>();
+ WebResult result = method.getAnnotation(WebResult.class);
// Default to "" for doc-lit-wrapped && non-header
- ns = getValue(param.targetNamespace(), documentStyle && !param.header() ? "" : tns);
- name = getValue(param.name(), "arg" + i);
+ ns = result != null ? result.targetNamespace() : "";
+ ns = getValue(ns, documentStyle && (result == null || !result.header()) ? "" : tns);
+ name = result != null ? result.name() : "";
+ name = getValue(name, "return");
QName element = new QName(ns, name);
- inputElements.add(new ElementInfo(element, null));
- }
- List<ElementInfo> outputElements = new ArrayList<ElementInfo>();
- WebResult result = method.getAnnotation(WebResult.class);
- // Default to "" for doc-lit-wrapped && non-header
- ns = getValue(result.targetNamespace(), documentStyle && !result.header() ? "" : tns);
- name = getValue(result.name(), "return");
- QName element = new QName(ns, name);
- outputElements.add(new ElementInfo(element, null));
-
- WrapperInfo wrapperInfo =
- new WrapperInfo(JAXB_DATABINDING, new ElementInfo(inputWrapper, null), new ElementInfo(outputWrapper,
- null),
- inputElements, outputElements);
- operation.setWrapper(wrapperInfo);
- // operation.setDataBinding(JAXB_DATABINDING); // could be JAXB or SDO
+ if (operation.getOutputType() != null) {
+ Object logical = operation.getOutputType().getLogical();
+ if (logical instanceof XMLType) {
+ ((XMLType)logical).setElementName(element);
+ }
+ }
+ outputElements.add(new ElementInfo(element, null));
+ WrapperInfo wrapperInfo =
+ new WrapperInfo(JAXB_DATABINDING, new ElementInfo(inputWrapper, null),
+ new ElementInfo(outputWrapper, null), inputElements, outputElements);
+ operation.setWrapper(wrapperInfo);
+ }
}
}
Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java Tue Apr 1 20:24:11 2008
@@ -19,13 +19,15 @@
package org.apache.tuscany.sca.interfacedef.java.jaxws;
+import javax.jws.WebMethod;
import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
import junit.framework.TestCase;
-import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
-import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor;
/**
*
@@ -47,56 +49,50 @@
* {@link org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor#visitInterface(JavaInterface)}.
*/
public final void testProcessor() throws Exception {
- JavaInterface contract = new MockJavaInterfaceImpl();
- contract.setJavaClass(WebServiceInterfaceWithoutAnnotation.class);
-
+ DefaultJavaInterfaceFactory iFactory = new DefaultJavaInterfaceFactory();
+ JavaInterface contract = iFactory.createJavaInterface(WebServiceInterfaceWithoutAnnotation.class);
+
interfaceProcessor.visitInterface(contract);
assertFalse(contract.isRemotable());
-
- contract.setJavaClass(WebServiceInterfaceWithAnnotation.class);
+
+ contract = iFactory.createJavaInterface(WebServiceInterfaceWithAnnotation.class);
interfaceProcessor.visitInterface(contract);
assertTrue(contract.isRemotable());
- }
- @WebService
- private static interface WebServiceInterfaceWithAnnotation {
-
- }
-
- private static interface WebServiceInterfaceWithoutAnnotation {
-
- }
-
- private class MockJavaInterfaceImpl extends InterfaceImpl implements JavaInterface {
- private Class<?> javaClass;
-
- public Class<?> getCallbackClass() {
- // TODO Auto-generated method stub
- return null;
- }
+ Operation op1 = contract.getOperations().get(0);
+ Operation op2 = contract.getOperations().get(1);
- public Class<?> getJavaClass() {
- // TODO Auto-generated method stub
- return javaClass;
+ Operation op = null;
+ if ("m1".equals(op1.getName())) {
+ op = op1;
+ } else {
+ op = op2;
}
- public String getName() {
- // TODO Auto-generated method stub
- return null;
- }
+ assertTrue(op.isWrapperStyle());
- public void setCallbackClass(Class<?> callbackClass) {
- // TODO Auto-generated method stub
-
+ if ("M2".equals(op2.getName())) {
+ op = op2;
+ } else {
+ op = op1;
}
+ assertTrue(!op2.isWrapperStyle() && op2.getWrapper() != null);
- public void setJavaClass(Class<?> javaClass) {
- this.javaClass = javaClass;
- }
+ }
+
+ @WebService
+ private static interface WebServiceInterfaceWithAnnotation {
+
+ @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
+ @WebMethod(operationName = "m1")
+ String m1(String str);
+
+ @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
+ @WebMethod(operationName = "M2")
+ String m2(String str, int i);
+ }
+
+ private static interface WebServiceInterfaceWithoutAnnotation {
- public void setName(String className) {
- // TODO Auto-generated method stub
-
- }
}
}
Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Interface2WSDLGenerator.java Tue Apr 1 20:24:11 2008
@@ -125,7 +125,7 @@
definition.addMessage(inputMsg);
// FIXME: By default, java interface is mapped to doc-lit-wrapper style WSDL
- if (!op.isWrapperStyle()) {
+ if (op.getWrapper() != null) {
// Generate doc-lit-wrapper style
inputMsg.addPart(generateWrapperPart(definition, op, true));
} else {
@@ -148,7 +148,7 @@
outputMsg.setUndefined(false);
definition.addMessage(outputMsg);
- if (!op.isWrapperStyle()) {
+ if (op.getWrapper() != null) {
inputMsg.addPart(generateWrapperPart(definition, op, false));
} else {
inputMsg.addPart(generatePart(definition, op.getOutputType(), "return"));
Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/Java2WSDLGeneratorTestCase.java Tue Apr 1 20:24:11 2008
@@ -25,6 +25,7 @@
import javax.wsdl.xml.WSDLWriter;
import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor;
import org.junit.Test;
@@ -36,8 +37,8 @@
@Test
public void testGenerate() throws Exception {
DefaultJavaInterfaceFactory iFactory = new DefaultJavaInterfaceFactory();
- iFactory.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor());
- org.apache.tuscany.sca.interfacedef.Interface iface = iFactory.createJavaInterface(TestJavaInterface.class);
+ JavaInterface iface = iFactory.createJavaInterface(TestJavaInterface.class);
+ new JAXWSJavaInterfaceProcessor().visitInterface(iface);
Interface2WSDLGenerator generator = new Interface2WSDLGenerator();
Definition definition = generator.generate(iface);
// System.out.println(definition);
Modified: incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/TestJavaInterface.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/TestJavaInterface.java?rev=643696&r1=643695&r2=643696&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/TestJavaInterface.java (original)
+++ incubator/tuscany/java/sca/modules/interface-wsdl-java2wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/interface2wsdl/TestJavaInterface.java Tue Apr 1 20:24:11 2008
@@ -19,19 +19,29 @@
package org.apache.tuscany.sca.interfacedef.wsdl.interface2wsdl;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
import org.osoa.sca.annotations.OneWay;
import org.osoa.sca.annotations.Remotable;
@Remotable
+@WebService
public interface TestJavaInterface {
String m1(String str);
@OneWay
+ @WebMethod
void m2(int i);
-
+
+ @WebMethod
String m3();
-
+
void m4();
-
+
+ @WebMethod
String m5(String str, int i);
+
+ @WebMethod(exclude = true)
+ void dummy();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org