From c1b8b3abd0aee06fd2e575a03be290bbfc44ffd3 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 9 Aug 2010 13:47:15 +0000 Subject: TUSCANY-3641 - process an @WebService(wsdlLocation="") annotation by reading the wsdl, identified by the location, from the current contribution. The WSDL is associated with the Java component type service by attaching it to the JavaInterface normalized interface slot. This is not ideal but does allow us to pull things out of the WSDL, such a as policy. The spec state that the component type should have interface.wsdl but this messes up our databinding code which expects the component service to exhibit an interface suitable for the actual implementation. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@983647 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/introspect/impl/JAXWSProcessor.java | 90 +++++++++++++--------- .../java/xml/JavaImplementationProcessor.java | 89 ++++++++++++++++++++- .../introspect/impl/JAXWSProcessorTestCase.java | 36 ++++++++- 3 files changed, 174 insertions(+), 41 deletions(-) (limited to 'sca-java-2.x/trunk/modules/implementation-java/src') 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 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)staxProcessor; + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); } /** @@ -190,7 +205,10 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor