Author: rfeng
Date: Wed Oct 10 09:00:43 2007
New Revision: 583524
URL: http://svn.apache.org/viewvc?rev=583524&view=rev
Log:
Add default element info to java interface
Modified:
incubator/tuscany/java/sca/itest/exceptions-simple-ws/src/main/resources/example.composite
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
incubator/tuscany/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
Modified:
incubator/tuscany/java/sca/itest/exceptions-simple-ws/src/main/resources/example.composite
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/exceptions-simple-ws/src/main/resources/example.composite?rev=583524&r1=583523&r2=583524&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/exceptions-simple-ws/src/main/resources/example.composite
(original)
+++
incubator/tuscany/java/sca/itest/exceptions-simple-ws/src/main/resources/example.composite
Wed Oct 10 09:00:43 2007
@@ -23,18 +23,18 @@
name="example">
<component name="ExampleClientComponent">
+ <implementation.java class="com.example.ExampleClientImpl" />
<reference name="myService">
<interface.wsdl
interface="http://example.com#wsdl.interface(ExampleServicePortType)" />
<binding.ws
wsdlElement="http://example.com#wsdl.port(ExampleService/ExampleServiceSOAP11port_http)"
/>
</reference>
- <implementation.java class="com.example.ExampleClientImpl" />
</component>
<component name="ExampleComponent">
+ <implementation.java class="com.example.ExampleServiceImpl"/>
<service name="ExampleService">
<interface.wsdl
interface="http://example.com#wsdl.interface(ExampleServicePortType)" />
<binding.ws
wsdlElement="http://example.com#wsdl.port(ExampleService/ExampleServiceSOAP11port_http)"
/>
</service>
- <implementation.java class="com.example.ExampleServiceImpl"/>
</component>
</composite>
Modified:
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java?rev=583524&r1=583523&r2=583524&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
(original)
+++
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
Wed Oct 10 09:00:43 2007
@@ -20,11 +20,11 @@
package org.apache.tuscany.sca.core.databinding.wire;
import java.lang.reflect.InvocationTargetException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
+import javax.xml.namespace.QName;
+
import org.apache.tuscany.sca.databinding.DataBinding;
import org.apache.tuscany.sca.databinding.ExceptionHandler;
import org.apache.tuscany.sca.databinding.Mediator;
@@ -54,9 +54,9 @@
private Mediator mediator;
public DataTransformationInterceptor(RuntimeWire wire,
- Operation sourceOperation,
- Operation targetOperation,
- Mediator mediator) {
+ Operation sourceOperation,
+ Operation targetOperation,
+ Mediator mediator) {
super();
this.sourceOperation = sourceOperation;
this.targetOperation = targetOperation;
@@ -123,7 +123,7 @@
DataType targetFaultType = getFaultType(targetDataType);
if (targetFaultType == null) {
- throw new TransformationException("Target fault type
cannot be resolved");
+ throw new TransformationException("Target fault type
cannot be resolved: " + targetDataType);
}
// FIXME: How to match a source fault type to a target fault
@@ -133,7 +133,7 @@
for (DataType exType : sourceOperation.getFaultTypes()) {
DataType faultType = getFaultType(exType);
// Match by the QName (XSD element) of the fault type
- if (faultType != null &&
typesMatch(targetFaultType.getLogical(),faultType.getLogical())) {
+ if (faultType != null &&
typesMatch(targetFaultType.getLogical(), faultType.getLogical())) {
sourceDataType = exType;
sourceFaultType = faultType;
break;
@@ -141,7 +141,7 @@
}
if (sourceFaultType == null) {
- throw new TransformationException("No matching source
fault type is found");
+ throw new TransformationException("No matching source
fault type is found: " + targetFaultType);
}
Object newResult =
@@ -168,15 +168,14 @@
return source;
}
Map<String, Object> metadata = new HashMap<String, Object>();
- metadata.put("source.operation", isResponse? targetOperation:
sourceOperation);
- metadata.put("target.operation", isResponse? sourceOperation:
targetOperation);
+ metadata.put("source.operation", isResponse ? targetOperation :
sourceOperation);
+ metadata.put("target.operation", isResponse ? sourceOperation :
targetOperation);
return mediator.mediate(source, sourceType, targetType, metadata);
}
private DataType getFaultType(DataType exceptionType) {
// FIXME: We cannot assume the exception will have a databinding set
- DataBinding targetDataBinding =
-
mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding());
+ DataBinding targetDataBinding =
mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding());
if (targetDataBinding == null) {
return null;
}
@@ -191,39 +190,34 @@
if (first.equals(second)) {
return true;
}
- if (first instanceof XMLType && second instanceof Class) {
- if
(toJavaClassName((XMLType)first).equals(((Class)second).getName())) {
- return true;
- }
- }
- if (first instanceof Class && second instanceof XMLType) {
- if
(((Class)first).getName().equals(toJavaClassName((XMLType)second))) {
- return true;
- }
+ if (first instanceof XMLType && second instanceof XMLType) {
+ XMLType t1 = (XMLType)first;
+ XMLType t2 = (XMLType)second;
+ return matches(t1.getElementName(), t2.getElementName()) &&
matches(t1.getTypeName(), t2.getTypeName());
}
return false;
}
- private String toJavaClassName(XMLType type) {
- String result = type.getElementName().getLocalPart();
- String authority = "";
- try {
- URI uri = new URI(type.getElementName().getNamespaceURI());
- authority = uri.getAuthority();
- } catch (URISyntaxException e) {
- }
- for (int i = 0; i < authority.length(); ) {
- int j = authority.indexOf(".", i);
- if (j == -1) {
- j = authority.length();
- }
- result = authority.substring(i, j) + "." + result;
- if (j < authority.length()) {
- j += 1;
- }
- i = j;
+ /**
+ * @param qn1
+ * @param qn2
+ */
+ private boolean matches(QName qn1, QName qn2) {
+ if (qn1 == qn2) {
+ return true;
+ }
+ if (qn1 == null || qn2 == null) {
+ return false;
}
- return result;
+ String ns1 = qn1.getNamespaceURI();
+ String ns2 = qn2.getNamespaceURI();
+ String e1 = qn1.getLocalPart();
+ String e2 = qn2.getLocalPart();
+ if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") ||
ns2.equals(ns1 + "/"))) {
+ // Tolerating the trailing / which is required by JAX-WS java
package --> xml ns mapping
+ return true;
+ }
+ return false;
}
/**
Modified:
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java?rev=583524&r1=583523&r2=583524&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
Wed Oct 10 09:00:43 2007
@@ -24,6 +24,8 @@
import java.util.List;
import java.util.Set;
+import javax.xml.namespace.QName;
+
import org.apache.tuscany.sca.interfacedef.ConversationSequence;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.InvalidCallbackException;
@@ -36,6 +38,7 @@
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import
org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.osoa.sca.annotations.Conversational;
import org.osoa.sca.annotations.EndsConversation;
import org.osoa.sca.annotations.OneWay;
@@ -62,10 +65,10 @@
boolean remotable = type.isAnnotationPresent(Remotable.class);
javaInterface.setRemotable(remotable);
-
+
boolean conversational =
type.isAnnotationPresent(Conversational.class);
javaInterface.setConversational(conversational);
-
+
Class<?> callbackClass = null;
org.osoa.sca.annotations.Callback callback =
type.getAnnotation(org.osoa.sca.annotations.Callback.class);
if (callback != null && !Void.class.equals(callback.value())) {
@@ -74,19 +77,20 @@
throw new InvalidCallbackException("No callback interface
specified on annotation");
}
javaInterface.setCallbackClass(callbackClass);
-
- javaInterface.getOperations().addAll(getOperations(type, remotable,
conversational));
+
+ String ns = JavaInterfaceUtil.getNamespace(type);
+ javaInterface.getOperations().addAll(getOperations(type, remotable,
conversational, ns));
for (JavaInterfaceVisitor extension : visitors) {
extension.visitInterface(javaInterface);
}
}
- private <T> List<Operation> getOperations(Class<T> type, boolean
remotable, boolean conversational)
+ private <T> List<Operation> getOperations(Class<T> type, boolean
remotable, boolean conversational, String ns)
throws InvalidInterfaceException {
Method[] methods = type.getMethods();
List<Operation> operations = new ArrayList<Operation>(methods.length);
- Set<String> names = remotable? new HashSet<String>() : null;
+ Set<String> names = remotable ? new HashSet<String>() : null;
for (Method method : methods) {
if (method.getDeclaringClass() == Object.class) {
// Skip the methods on the Object.class
@@ -96,7 +100,7 @@
if (remotable && names.contains(name)) {
throw new OverloadedOperationException(method);
}
- if(remotable) {
+ if (remotable) {
names.add(name);
}
@@ -117,23 +121,27 @@
}
// Set outputType to null for void
- DataType<Class> returnDataType = returnType == void.class ? null
- : new
DataTypeImpl<Class>(UNKNOWN_DATABINDING,
-
returnType, returnType);
+ XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null);
+ DataType<XMLType> returnDataType =
+ returnType == void.class ? null : new
DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, returnType,
+
xmlReturnType);
List<DataType> paramDataTypes = new
ArrayList<DataType>(paramTypes.length);
- for (Class paramType : paramTypes) {
- paramDataTypes.add(new
DataTypeImpl<Class>(UNKNOWN_DATABINDING, paramType, paramType));
+ for (int i = 0; i < paramTypes.length; i++) {
+ Class paramType = paramTypes[i];
+ XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i),
null);
+ paramDataTypes.add(new
DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, paramType, xmlParamType));
}
List<DataType> faultDataTypes = new
ArrayList<DataType>(faultTypes.length);
for (Class faultType : faultTypes) {
// Only add checked exceptions
if (Exception.class.isAssignableFrom(faultType) &&
(!RuntimeException.class.isAssignableFrom(faultType))) {
- faultDataTypes.add(new
DataTypeImpl<Class>(UNKNOWN_DATABINDING, faultType, faultType));
+ XMLType xmlFaultType = new XMLType(new QName(ns,
faultType.getSimpleName()), null);
+ faultDataTypes.add(new
DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, faultType, xmlFaultType));
}
}
- DataType<List<DataType>> inputType = new
DataTypeImpl<List<DataType>>(IDL_INPUT, Object[].class,
-
paramDataTypes);
+ DataType<List<DataType>> inputType =
+ new DataTypeImpl<List<DataType>>(IDL_INPUT, Object[].class,
paramDataTypes);
Operation operation = new OperationImpl(name);
operation.setInputType(inputType);
operation.setOutputType(returnDataType);
Modified:
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java?rev=583524&r1=583523&r2=583524&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
(original)
+++
incubator/tuscany/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
Wed Oct 10 09:00:43 2007
@@ -126,5 +126,22 @@
return found;
}
+
+ public static String getNamespace(Class<?> cls) {
+ Package pkg = cls.getPackage();
+ if (pkg == null) {
+ return "";
+ }
+ StringBuffer ns = new StringBuffer("http://");
+ String[] names = pkg.getName().split("\\.");
+ for (int i = names.length - 1; i >= 0; i--) {
+ ns.append(names[i]);
+ if (i != 0) {
+ ns.append('.');
+ }
+ }
+ ns.append('/');
+ return ns.toString();
+ }
}
Modified:
incubator/tuscany/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java?rev=583524&r1=583523&r2=583524&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
(original)
+++
incubator/tuscany/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
Wed Oct 10 09:00:43 2007
@@ -24,9 +24,10 @@
import static org.easymock.EasyMock.verify;
import java.io.IOException;
-import java.lang.reflect.Type;
import java.util.List;
+import javax.xml.namespace.QName;
+
import junit.framework.TestCase;
import org.apache.tuscany.sca.interfacedef.DataType;
@@ -36,6 +37,7 @@
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import
org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.easymock.EasyMock;
/**
@@ -54,21 +56,26 @@
Operation baseInt = operations.get(0);
assertEquals("baseInt", baseInt.getName());
- DataType<Type> returnType = baseInt.getOutputType();
+ QName element = new
QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/",
"return");
+
+ DataType<XMLType> returnType = baseInt.getOutputType();
assertEquals(Integer.TYPE, returnType.getPhysical());
- assertEquals(Integer.TYPE, returnType.getLogical());
+ assertEquals(element, returnType.getLogical().getElementName());
List<DataType> parameterTypes = baseInt.getInputType().getLogical();
assertEquals(1, parameterTypes.size());
- DataType<Type> arg0 = parameterTypes.get(0);
+ DataType<XMLType> arg0 = parameterTypes.get(0);
assertEquals(Integer.TYPE, arg0.getPhysical());
- assertEquals(Integer.TYPE, arg0.getLogical());
+
+ element = new
QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/",
"arg0");
+ assertEquals(element, arg0.getLogical().getElementName());
List<DataType> faultTypes = baseInt.getFaultTypes();
assertEquals(1, faultTypes.size());
- DataType<Type> fault0 = faultTypes.get(0);
+ DataType<XMLType> fault0 = faultTypes.get(0);
assertEquals(IOException.class, fault0.getPhysical());
- assertEquals(IOException.class, fault0.getLogical());
+ element = new
QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/",
"IOException");
+ assertEquals(element, fault0.getLogical().getElementName());
}
public void testUnregister() throws Exception {
@@ -82,7 +89,7 @@
factory.createJavaInterface(Base.class);
verify(extension);
}
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]