summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-java/src
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-java/src')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java90
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java89
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java36
3 files changed, 174 insertions, 41 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
index f8b087662b..dfa3ac0a56 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessor.java
@@ -35,6 +35,9 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
import org.apache.tuscany.sca.policy.Intent;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.oasisopen.sca.annotation.Remotable;
@@ -46,16 +49,15 @@ import org.oasisopen.sca.annotation.Remotable;
public class JAXWSProcessor extends BaseJavaClassVisitor {
private PolicyFactory policyFactory;
-
- public JAXWSProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory, PolicyFactory policyFactory) {
- super(assemblyFactory);
- this.javaInterfaceFactory = javaFactory;
- this.policyFactory = policyFactory;
- }
+ private WSDLFactory wsdlFactory;
public JAXWSProcessor(ExtensionPointRegistry registry) {
super(registry);
- this.policyFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(PolicyFactory.class);
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.wsdlFactory = factories.getFactory(WSDLFactory.class);
+ this.assemblyFactory = factories.getFactory(AssemblyFactory.class);
+ this.policyFactory = factories.getFactory(PolicyFactory.class);
+ this.javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
}
@Override
@@ -72,22 +74,22 @@ public class JAXWSProcessor extends BaseJavaClassVisitor {
// JCA 11015
}
- WebService webService = clazz.getAnnotation(WebService.class);
+ WebService webServiceAnnotation = clazz.getAnnotation(WebService.class);
+ org.oasisopen.sca.annotation.Service serviceAnnotation = clazz.getAnnotation(org.oasisopen.sca.annotation.Service.class);
String tns = JavaXMLMapper.getNamespace(clazz);
String localName = clazz.getSimpleName();
Class<?> interfaze = clazz;
- if (webService != null) {
- tns = getValue(webService.targetNamespace(), tns);
- localName = getValue(webService.name(), localName);
+ if (webServiceAnnotation != null &&
+ serviceAnnotation == null) {
+ tns = getValue(webServiceAnnotation.targetNamespace(), tns);
+ localName = getValue(webServiceAnnotation.name(), localName);
- String serviceInterfaceName = webService.endpointInterface();
- // TODO - how to resolve this interface name
- // needs to be done higher up where we have
- // access to the resolver.
+ String serviceInterfaceName = webServiceAnnotation.endpointInterface();
+ String wsdlLocation = webServiceAnnotation.wsdlLocation();
Service service;
try {
- service = createService(clazz, interfaze, localName);
+ service = createService(clazz, localName, serviceInterfaceName, wsdlLocation);
} catch (InvalidInterfaceException e) {
throw new IntrospectionException(e);
}
@@ -106,32 +108,48 @@ public class JAXWSProcessor extends BaseJavaClassVisitor {
return "".equals(value) ? defaultValue : value;
}
- public Service createService(Class<?> clazz, Class<?> interfaze, String name) throws InvalidInterfaceException {
+ public Service createService(Class<?> clazz, String serviceName, String javaInterfaceName, String wsdlFileName) throws InvalidInterfaceException, IntrospectionException {
Service service = assemblyFactory.createService();
- JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
- service.setInterfaceContract(interfaceContract);
- if (name == null) {
- service.setName(interfaze.getSimpleName());
+ if (serviceName != null) {
+ service.setName(serviceName);
+ } else if (javaInterfaceName != null){
+ service.setName(javaInterfaceName.substring(javaInterfaceName.lastIndexOf('.')));
+ }
+
+ // create the physical Java interface contract
+ JavaInterfaceContract javaInterfaceContract = javaInterfaceFactory.createJavaInterfaceContract();;
+ service.setInterfaceContract(javaInterfaceContract);
+
+ if (javaInterfaceName != null &&
+ javaInterfaceName.length() > 0){
+ JavaInterface callInterface = javaInterfaceFactory.createJavaInterface();
+ callInterface.setName(javaInterfaceName);
+ callInterface.setRemotable(true);
+ callInterface.setUnresolved(true);
+ javaInterfaceContract.setInterface(callInterface);
} else {
- service.setName(name);
- }
-
- JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(interfaze);
- boolean remotable = clazz.getAnnotation(Remotable.class) != null;
- if (remotable){
+ // we use the bean class as the service interface
+ JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(clazz);
callInterface.setRemotable(true);
+ callInterface.setUnresolved(false); // this will already be false but this makes it easy to follow the logic
+ javaInterfaceContract.setInterface(callInterface);
}
- service.getInterfaceContract().setInterface(callInterface);
- if (callInterface.getCallbackClass() != null) {
- JavaInterface callbackInterface = javaInterfaceFactory.createJavaInterface(callInterface.getCallbackClass());
- if (remotable){
- callbackInterface.setRemotable(true);
- }
- service.getInterfaceContract().setCallbackInterface(callbackInterface);
- }
- return service;
+ // create the logical WSDL interface if it's specified in
+ // the @WebService annotation
+ if (wsdlFileName != null &&
+ wsdlFileName.length() > 0){
+ WSDLInterface callInterface = wsdlFactory.createWSDLInterface();
+ callInterface.setUnresolved(true);
+ callInterface.setRemotable(true);
+
+ WSDLInterfaceContract wsdlInterfaceContract = wsdlFactory.createWSDLInterfaceContract();
+ wsdlInterfaceContract.setInterface(callInterface);
+ wsdlInterfaceContract.setLocation(wsdlFileName);
+ javaInterfaceContract.setNormailizedWSDLContract(wsdlInterfaceContract);
+ }
+ return service;
}
}
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
index efb4a37143..3fdbc19e0e 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
@@ -50,14 +50,24 @@ import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ClassReference;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.implementation.java.IntrospectionException;
import org.apache.tuscany.sca.implementation.java.JavaElementImpl;
import org.apache.tuscany.sca.implementation.java.JavaImplementation;
import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.Compatibility;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
+import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract;
import org.apache.tuscany.sca.monitor.Monitor;
import org.apache.tuscany.sca.monitor.Problem;
import org.apache.tuscany.sca.monitor.Problem.Severity;
@@ -74,13 +84,18 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
private AssemblyFactory assemblyFactory;
private PolicyFactory policyFactory;
private PolicySubjectProcessor policyProcessor;
-
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private transient InterfaceContractMapper interfaceContractMapper;
- public JavaImplementationProcessor(FactoryExtensionPoint modelFactories) {
+ public JavaImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor<?> staxProcessor) {
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class);
this.policyProcessor = new PolicySubjectProcessor(policyFactory);
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
}
/**
@@ -190,7 +205,10 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
checkNoStaticAnnotations(monitor, javaImplementation);
+ postJAXWSProcessorResolve(resolver, javaImplementation, context);
+
javaImplementation.setUnresolved(false);
+
mergeComponentType(resolver, javaImplementation, context);
// FIXME the introspector should always create at least one service
@@ -309,6 +327,73 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm
}
}
+
+// private void postJAXWSProcessorResolve(ModelResolver resolver, JavaImplementation impl, ProcessorContext context)
+// throws ContributionResolveException {
+// for(Service service : impl.getServices()){
+// InterfaceContract interfaceContract = service.getInterfaceContract();
+//
+// // InterfaceContract not marked as resolved so have to look
+// // at each type and work it out
+// if (interfaceContract instanceof JavaInterfaceContract){
+// JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)interfaceContract;
+// JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+// if (javaInterface.isUnresolved()){
+// extensionProcessor.resolve(javaInterfaceContract, resolver, context);
+// }
+// } else {
+// WSDLInterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)interfaceContract;
+// WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+// if (wsdlInterface.isUnresolved()){
+// //WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlInterface.getWsdlDefinition(), context);
+// extensionProcessor.resolve(wsdlInterfaceContract, resolver, context);
+// }
+// }
+// }
+// }
+
+ private void postJAXWSProcessorResolve(ModelResolver resolver, JavaImplementation impl, ProcessorContext context)
+ throws ContributionResolveException, IncompatibleInterfaceContractException {
+ for(Service service : impl.getServices()){
+ JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)service.getInterfaceContract();
+
+ JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+ if (javaInterface.isUnresolved()){
+ extensionProcessor.resolve(javaInterfaceContract, resolver, context);
+ }
+
+ WSDLInterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)javaInterfaceContract.getNormalizedWSDLContract();
+ if(wsdlInterfaceContract != null){
+ // The user has explicitly associated a WSDL with the Java implementation
+ // using a @WebService(wsdlLocation="...") annotation
+ WSDLInterface wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+ if (wsdlInterface.isUnresolved()){
+ //WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlInterface.getWsdlDefinition(), context);
+ extensionProcessor.resolve(wsdlInterfaceContract, resolver, context);
+
+ // check that the Java and WSDL contracts are compatible
+ interfaceContractMapper.checkCompatibility(javaInterfaceContract,
+ wsdlInterfaceContract,
+ Compatibility.MUTUAL,
+ false,
+ false);
+
+ // retrieve the resolved WSDL interface
+ wsdlInterface = (WSDLInterface)wsdlInterfaceContract.getInterface();
+
+ // copy policy from the WSDL interface to the Java interface
+ javaInterface.getPolicySets().addAll(wsdlInterface.getPolicySets());
+ javaInterface.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
+
+ // copy policy from the WSDL interface to the component type service
+ service.getPolicySets().addAll(wsdlInterface.getPolicySets());
+ service.getRequiredIntents().addAll(wsdlInterface.getRequiredIntents());
+
+ // TODO - is there anything else to be copied from the user specified WSDL?
+ }
+ }
+ }
+ }
private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) {
String className = impl.getJavaClass().getName();
diff --git a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
index 7fb07713c6..2e6ef50996 100644
--- a/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
+++ b/sca-java-2.x/trunk/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JAXWSProcessorTestCase.java
@@ -55,11 +55,19 @@ public class JAXWSProcessorTestCase {
@Before
public void setUp() throws Exception {
ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
- processor = new JAXWSProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory(registry), new DefaultPolicyFactory());
+ processor = new JAXWSProcessor(registry);
javaImplementationFactory = new DefaultJavaImplementationFactory();
}
@Test
+ public void testWebServiceNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Foo0Impl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, "Foo0Impl");
+ assertNotNull(service);
+ }
+
+ @Test
public void testWebServiceName() throws Exception {
JavaImplementation type = javaImplementationFactory.createJavaImplementation();
processor.visitClass(Foo1Impl.class, type);
@@ -75,6 +83,21 @@ public class JAXWSProcessorTestCase {
assertNotNull(service);
}
+ @Test
+ public void testWebServiceWSDL() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Foo3Impl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, "Foo3");
+ assertNotNull(service);
+ }
+
+ @WebService()
+ private static class Foo0Impl{
+ public String doSomething(String aParam){
+ return null;
+ }
+ }
+
@WebService(name="Foo1")
private static class Foo1Impl{
public String doSomething(String aParam){
@@ -86,12 +109,19 @@ public class JAXWSProcessorTestCase {
public String doSomething(String aParam);
}
- @WebService(name="Foo2", endpointInterface="Foo2")
+ @WebService(name="Foo2", endpointInterface="org.apache.tuscany.sca.implementation.java.introspect.impl.JAXWSProcessorTestCase.Foo2")
private static class Foo2Impl{
public String doSomething(String aParam){
return null;
}
- }
+ }
+
+ @WebService(name="Foo3", wsdlLocation="foo3.wsdl")
+ private static class Foo3Impl{
+ public String doSomething(String aParam){
+ return null;
+ }
+ }
}