From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/databinding/databinding-jaxb/.ruleset | 172 +++++++ .../databinding/databinding-jaxb/LICENSE.txt | 202 ++++++++ .../databinding/databinding-jaxb/NOTICE.txt | 14 + .../services/databinding/databinding-jaxb/pom.xml | 148 ++++++ .../apache/tuscany/databinding/jaxb/JAXB2Node.java | 72 +++ .../databinding/jaxb/JAXBContextHelper.java | 192 ++++++++ .../tuscany/databinding/jaxb/JAXBDataBinding.java | 114 +++++ .../databinding/jaxb/JAXBExceptionHandler.java | 106 +++++ .../databinding/jaxb/JAXBWrapperHandler.java | 123 +++++ .../jaxb/JAXWSJavaInterfaceProcessor.java | 107 +++++ .../apache/tuscany/databinding/jaxb/Node2JAXB.java | 69 +++ .../tuscany/databinding/jaxb/Reader2JAXB.java | 70 +++ .../databinding/jaxb/XMLStreamReader2JAXB.java | 70 +++ .../resources/META-INF/sca/databinding.jaxb.scdl | 49 ++ .../src/main/resources/META-INF/sca/default.scdl | 49 ++ .../resources/META-INF/sca/extension.composite | 22 + .../databinding/jaxb/JAXBDataBindingTestCase.java | 127 +++++ .../jaxb/JAXBExceptionHandlerTestCase.java | 77 +++ .../tuscany/databinding/jaxb/JAXBTestCase.java | 158 +++++++ .../jaxb/JAXBWrapperHandlerTestCase.java | 72 +++ .../databinding/jaxb/fault/InvalidSymbolFault.java | 59 +++ .../jaxb/fault/InvalidSymbolFault_Exception.java | 44 ++ .../databinding-jaxb/src/test/resources/ipo.xsd | 118 +++++ .../services/databinding/databinding-json/.ruleset | 172 +++++++ .../databinding/databinding-json/LICENSE.txt | 202 ++++++++ .../databinding/databinding-json/NOTICE.txt | 14 + .../services/databinding/databinding-json/pom.xml | 70 +++ .../databinding/json/JSON2XMLStreamReader.java | 62 +++ .../tuscany/databinding/json/JSONDataBinding.java | 52 ++ .../databinding/json/XMLStreamReader2JSON.java | 69 +++ .../databinding/json/XMLStreamSerializer.java | 272 +++++++++++ .../databinding/json/axiom/JSON2OMElement.java | 83 ++++ .../json/axiom/JSONBadgerfishDataSource.java | 56 +++ .../databinding/json/axiom/JSONDataSource.java | 174 +++++++ .../resources/META-INF/sca/databinding.json.scdl | 43 ++ .../resources/META-INF/sca/extension.composite | 22 + .../databinding/json/JSONTransformerTestCase.java | 91 ++++ .../databinding-json/src/test/resources/ipo.xsd | 118 +++++ .../databinding/databinding-sdo-axiom/.checkstyle | 6 + .../databinding/databinding-sdo-axiom/.ruleset | 172 +++++++ .../databinding/databinding-sdo-axiom/LICENSE.txt | 202 ++++++++ .../databinding/databinding-sdo-axiom/NOTICE.txt | 14 + .../databinding/databinding-sdo-axiom/pom.xml | 138 ++++++ .../databinding/sdo2om/DataObject2OMElement.java | 89 ++++ .../databinding/sdo2om/DataObjectSerializer.java | 408 ++++++++++++++++ .../tuscany/databinding/sdo2om/SDODataSource.java | 66 +++ .../databinding/sdo2om/XMLDocument2OMElement.java | 64 +++ .../META-INF/sca/databinding.sdo-axiom.scdl | 39 ++ .../resources/META-INF/sca/extension.composite | 22 + .../sdo2om/DataObject2OMElementTestCase.java | 38 ++ .../sdo2om/MockTransformationContext.java | 83 ++++ .../sdo2om/SDOTransformerTestCaseBase.java | 78 +++ .../sdo2om/XMLDocument2OMElementTestCase.java | 45 ++ .../src/test/resources/ipo.xsd | 118 +++++ .../src/test/resources/stock.xsd | 33 ++ .../databinding/databinding-sdo/.checkstyle | 6 + .../services/databinding/databinding-sdo/.ruleset | 172 +++++++ .../databinding/databinding-sdo/LICENSE.txt | 202 ++++++++ .../databinding/databinding-sdo/NOTICE.txt | 14 + .../services/databinding/databinding-sdo/pom.xml | 119 +++++ .../tuscany/databinding/sdo/DataObject2String.java | 61 +++ .../sdo/DataObject2XMLStreamReader.java | 70 +++ .../tuscany/databinding/sdo/DataObjectLoader.java | 73 +++ .../apache/tuscany/databinding/sdo/ImportSDO.java | 47 ++ .../tuscany/databinding/sdo/ImportSDOBuilder.java | 57 +++ .../tuscany/databinding/sdo/ImportSDOLoader.java | 163 +++++++ .../tuscany/databinding/sdo/ModelDataObject.java | 43 ++ .../tuscany/databinding/sdo/SDOContextHelper.java | 111 +++++ .../tuscany/databinding/sdo/SDODataBinding.java | 122 +++++ .../databinding/sdo/SDOExceptionHandler.java | 123 +++++ .../tuscany/databinding/sdo/SDOHelperContext.java | 48 ++ .../databinding/sdo/SDOSimpleTypeMapper.java | 66 +++ .../tuscany/databinding/sdo/SDOWrapperHandler.java | 99 ++++ .../tuscany/databinding/sdo/String2DataObject.java | 58 +++ .../databinding/sdo/XMLDocument2String.java | 62 +++ .../sdo/XMLDocument2XMLStreamReader.java | 66 +++ .../sdo/XMLStreamReader2DataObject.java | 67 +++ .../sdo/XMLStreamReader2XMLDocument.java | 61 +++ .../resources/META-INF/sca/databinding.sdo.scdl | 72 +++ .../src/main/resources/META-INF/sca/default.scdl | 66 +++ .../resources/META-INF/sca/extension.composite | 22 + .../sdo/fault/InvalidSymbolFault_Exception.java | 67 +++ .../databinding/sdo/DataObject2StringTestCase.java | 64 +++ .../sdo/DataObject2XMLStreamReaderTestCase.java | 57 +++ .../databinding/sdo/DataObjectLoaderTestCase.java | 82 ++++ .../databinding/sdo/ImportSDOLoaderTestCase.java | 87 ++++ .../databinding/sdo/SDODataBindingTestCase.java | 110 +++++ .../sdo/SDOExceptionHandlerTestCase.java | 81 ++++ .../sdo/SDOTransformerTestCaseBase.java | 79 ++++ .../databinding/sdo/SDOWrapperHandlerTestCase.java | 65 +++ .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 60 +++ .../META-INF/tuscany/databinding.sdo.scdl | 34 ++ .../databinding-sdo/src/test/resources/ipo.xsd | 118 +++++ .../src/test/resources/model/sca-core.xsd | 233 +++++++++ .../resources/model/sca-implementation-mock.xsd | 43 ++ .../databinding-sdo/src/test/resources/stock.xsd | 33 ++ .../databinding-sdo/src/test/resources/wrapper.xml | 9 + .../databinding-sdo/src/test/resources/wrapper.xsd | 38 ++ .../databinding/databinding-xmlbeans/.ruleset | 172 +++++++ .../databinding/databinding-xmlbeans/LICENSE.txt | 202 ++++++++ .../databinding/databinding-xmlbeans/NOTICE.txt | 14 + .../databinding/databinding-xmlbeans/pom.xml | 97 ++++ .../databinding/xmlbeans/Node2XmlObject.java | 56 +++ .../databinding/xmlbeans/XMLBeansDataBinding.java | 35 ++ .../xmlbeans/XMLStreamReader2XmlObject.java | 56 +++ .../databinding/xmlbeans/XmlObject2Node.java | 52 ++ .../xmlbeans/XmlObject2XMLStreamReader.java | 47 ++ .../META-INF/sca/databinding.xmlbeans.scdl | 43 ++ .../src/main/resources/META-INF/sca/default.scdl | 43 ++ .../resources/META-INF/sca/extension.composite | 22 + .../databinding/xmlbeans/XmlObjectTestCase.java | 99 ++++ .../src/test/resources/ipo.xsd | 118 +++++ .../src/test/resources/ipo.xsdconfig | 21 + .../sca/services/databinding/pom.xml | 70 +++ .../sca-java-integration/sca/services/idl/pom.xml | 61 +++ .../sca/services/idl/wsdl/.ruleset | 190 ++++++++ .../sca/services/idl/wsdl/LICENSE.txt | 202 ++++++++ .../sca/services/idl/wsdl/NOTICE.txt | 14 + .../sca/services/idl/wsdl/pom.xml | 57 +++ .../idl/wsdl/InterfaceWSDLIntrospector.java | 48 ++ .../idl/wsdl/InterfaceWSDLIntrospectorImpl.java | 102 ++++ .../tuscany/idl/wsdl/InterfaceWSDLLoader.java | 146 ++++++ .../tuscany/idl/wsdl/InvalidFragmentException.java | 30 ++ .../idl/wsdl/InvalidWSDLContributionException.java | 36 ++ .../tuscany/idl/wsdl/InvalidWSDLException.java | 34 ++ .../idl/wsdl/InvalidWSDLLocationException.java | 33 ++ .../idl/wsdl/NotSupportedWSDLException.java | 37 ++ .../idl/wsdl/UnresolveableResourceException.java | 34 ++ .../idl/wsdl/WSDLContributionProcessor.java | 263 +++++++++++ .../tuscany/idl/wsdl/WSDLDefinitionRegistry.java | 91 ++++ .../idl/wsdl/WSDLDefinitionRegistryImpl.java | 214 +++++++++ .../org/apache/tuscany/idl/wsdl/WSDLLoader.java | 110 +++++ .../tuscany/idl/wsdl/WSDLLoaderException.java | 45 ++ .../apache/tuscany/idl/wsdl/WSDLLoaderImpl.java | 141 ++++++ .../org/apache/tuscany/idl/wsdl/WSDLLocation.java | 60 +++ .../org/apache/tuscany/idl/wsdl/WSDLOperation.java | 525 +++++++++++++++++++++ .../tuscany/idl/wsdl/WSDLServiceContract.java | 60 +++ .../apache/tuscany/idl/wsdl/XMLSchemaRegistry.java | 87 ++++ .../tuscany/idl/wsdl/XMLSchemaRegistryImpl.java | 129 +++++ .../tuscany/idl/wsdl/XSDContributionProcessor.java | 136 ++++++ .../src/main/resources/META-INF/sca/default.scdl | 50 ++ .../resources/META-INF/sca/extension.composite | 22 + .../src/main/resources/META-INF/sca/idl.wsdl.scdl | 52 ++ .../InterfaceWSDLIntrospectorImplTestCase.java | 83 ++++ .../wsdl/WSDLContributionProcessorTestCase.java | 86 ++++ .../idl/wsdl/WSDLDefinitionRegistryTestCase.java | 91 ++++ .../tuscany/idl/wsdl/WSDLLoaderImplTestCase.java | 53 +++ .../tuscany/idl/wsdl/WSDLOperationTestCase.java | 115 +++++ .../idl/wsdl/WrapperStyleOperationTestCase.java | 72 +++ .../idl/wsdl/XMLSchemaRegistryImplTestCase.java | 105 +++++ .../idl/wsdl/XSDContributionProcessorTestCase.java | 92 ++++ .../org/apache/tuscany/idl/wsdl/example.wsdl | 26 + .../tuscany/idl/wsdl/invalid-stockquote.wsdl | 40 ++ .../resources/org/apache/tuscany/idl/wsdl/ipo.xsd | 118 +++++ .../org/apache/tuscany/idl/wsdl/stockquote.wsdl | 40 ++ .../org/apache/tuscany/idl/wsdl/test1.wsdl | 45 ++ .../org/apache/tuscany/idl/wsdl/test1.xsd | 15 + .../org/apache/tuscany/idl/wsdl/test2.wsdl | 63 +++ .../tuscany/idl/wsdl/unwrapped-stockquote.wsdl | 58 +++ branches/sca-java-integration/sca/services/pom.xml | 63 +++ .../sca/services/transports/http.jetty/.ruleset | 190 ++++++++ .../sca/services/transports/http.jetty/LICENSE.txt | 202 ++++++++ .../sca/services/transports/http.jetty/NOTICE.txt | 14 + .../sca/services/transports/http.jetty/pom.xml | 71 +++ .../apache/tuscany/service/jetty/JettyLogger.java | 106 +++++ .../apache/tuscany/service/jetty/JettyService.java | 38 ++ .../tuscany/service/jetty/JettyServiceImpl.java | 356 ++++++++++++++ .../tuscany/service/jetty/TransportMonitor.java | 42 ++ .../main/resources/META-INF/sca/http.jetty.scdl | 35 ++ .../main/resources/META-INF/sca/service.composite | 22 + .../service/jetty/JettyServiceImplTestCase.java | 220 +++++++++ 171 files changed, 15296 insertions(+) create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/.ruleset create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/NOTICE.txt create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/pom.xml create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandler.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessor.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/extension.composite create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/.ruleset create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/NOTICE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/pom.xml create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSON2XMLStreamReader.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSONDataBinding.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamReader2JSON.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamSerializer.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSON2OMElement.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONBadgerfishDataSource.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONDataSource.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/databinding.json.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/extension.composite create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/java/org/apache/tuscany/databinding/json/JSONTransformerTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/resources/ipo.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.checkstyle create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.ruleset create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/NOTICE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/pom.xml create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElement.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObjectSerializer.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/SDODataSource.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElement.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/databinding.sdo-axiom.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/extension.composite create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElementTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/MockTransformationContext.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/SDOTransformerTestCaseBase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElementTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/ipo.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/stock.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/.checkstyle create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/.ruleset create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/NOTICE.txt create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/pom.xml create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/extension.composite create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/stock.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xml create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xsd create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/.ruleset create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/NOTICE.txt create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/pom.xml create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/databinding.xmlbeans.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl create mode 100644 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/extension.composite create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd create mode 100755 branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig create mode 100644 branches/sca-java-integration/sca/services/databinding/pom.xml create mode 100644 branches/sca-java-integration/sca/services/idl/pom.xml create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/.ruleset create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/NOTICE.txt create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/pom.xml create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLContributionException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/extension.composite create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl create mode 100644 branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl create mode 100644 branches/sca-java-integration/sca/services/pom.xml create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/.ruleset create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/LICENSE.txt create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/NOTICE.txt create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/pom.xml create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/http.jetty.scdl create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/service.composite create mode 100644 branches/sca-java-integration/sca/services/transports/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java (limited to 'branches/sca-java-integration/sca/services') diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/.ruleset b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/LICENSE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/NOTICE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/pom.xml b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..c74f701ea1 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/pom.xml @@ -0,0 +1,148 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + databinding-jaxb + Apache Tuscany Data Binding for JAXB + Tuscany JAXB Data Binding + + + + + true + + java.net + java.net Maven 1.x Repository + https://maven-repository.dev.java.net/nonav/repository + legacy + + + + + + true + + java.net + java.net Maven 1.x Repository + https://maven-repository.dev.java.net/repository + legacy + + + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-integration-incubating-SNAPSHOT + compile + + + javax.xml.bind + jaxb-api + 2.0 + compile + + + javax.xml.ws + jaxws-api + + 2.1 + compile + + + com.sun.xml.bind + jaxb-impl + 2.0.4 + runtime + + + + javax.xml.bind + jsr173_api + + + + + + junit + junit + + + org.easymock + easymock + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + 1.1 + + + generate-jaxb + generate-test-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..34f3dbbac3 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java @@ -0,0 +1,72 @@ +/* + * 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.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class JAXB2Node extends TransformerExtension implements PullTransformer { + + public Node transform(Object source, TransformationContext tContext) { + if (source == null) { + return null; + } + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + // FIXME: The default Marshaller doesn't support + // marshaller.getNode() + Document document = DOMHelper.newDocument(); + JAXBElement jaxbElement = JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Object.class; + } + + public Class getTargetType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..0fc554d785 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java @@ -0,0 +1,192 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.beans.Introspector; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; + +public class JAXBContextHelper { + // TODO: Do we need to set them for source and target? + public static final String JAXB_CLASSES = "jaxb.classes"; + + public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath"; + + private JAXBContextHelper() { + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + // FIXME: We should check the context path or classes + // FIXME: What should we do if JAXB is an intermediate node? + DataType bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + String contextPath = (String)bindingContext.getMetadata(JAXB_CONTEXT_PATH); + if (contextPath == null) { + Operation op = (Operation)bindingContext.getOperation(); + contextPath = op != null ? (String)op.getMetaData().get(JAXB_CONTEXT_PATH) : null; + } + JAXBContext context = null; + if (contextPath != null) { + context = JAXBContext.newInstance(contextPath); + } else { + Class[] classes = (Class[])bindingContext.getMetadata(JAXB_CLASSES); + if (classes != null) { + context = JAXBContext.newInstance(classes); + } else { + Type type = bindingContext.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (cls.getPackage() != null) { + contextPath = cls.getPackage().getName(); + context = JAXBContext.newInstance(contextPath); + } + } + } + } + if (context == null) { + throw new TransformationException("JAXB context is not set for the transformation."); + } + return context; + } + + @SuppressWarnings("unchecked") + public static JAXBElement createJAXBElement(DataType dataType, Object value) { + if (value instanceof JAXBElement) { + return (JAXBElement)value; + } else { + Class type = (Class)dataType.getPhysical(); + Object logical = dataType.getLogical(); + QName elementName = JAXBDataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } else { + /** + * Set the declared type to Object.class so that xsi:type + * will be produced + */ + type = Object.class; + } + } else { + type = Object.class; + } + return new JAXBElement(elementName, type, value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class cls = getJavaType(dataType); + if (cls == JAXBElement.class) { + return createJAXBElement(dataType, value); + } else { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } + } + + public static Class getJavaType(DataType dataType) { + if (dataType == null) { + return null; + } + Type type = dataType.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (JAXBElement.class.isAssignableFrom(cls)) { + return null; + } else { + return cls; + } + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + return (Class)pType.getRawType(); + } + return null; + } + + public static XMLType getXmlTypeName(Class javaType) { + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + if (schema != null) { + namespace = schema.namespace(); + } + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default") && typeName.equals("")) { + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + namespace = rootElement.namespace(); + } else { + // FIXME: The namespace should be from the referencing + // property + namespace = null; + } + } else if (typeNamespace.equals("##default")) { + // namespace is from the package + } else { + namespace = typeNamespace; + } + + if (typeName.equals("##default")) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } else { + name = typeName; + } + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + if (xmlEnum != null) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } + } + if (name == null) { + return null; + } + return new XMLType(null, new QName(namespace, name)); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..6fc8510717 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java @@ -0,0 +1,114 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.ExceptionHandler; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; +import org.w3c.dom.Document; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends DataBindingExtension { + public static final String NAME = JAXBElement.class.getName(); + public static final String[] ALIASES = new String[] {"jaxb"}; + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public JAXBDataBinding() { + super(NAME, ALIASES, JAXBElement.class); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + if (JAXBElement.class.isAssignableFrom(javaType)) { + Type type = javaType.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = ((ParameterizedType)type); + Type rawType = parameterizedType.getRawType(); + if (rawType == JAXBElement.class) { + Type actualType = parameterizedType.getActualTypeArguments()[0]; + if (actualType instanceof Class) { + XMLType xmlType = JAXBContextHelper.getXmlTypeName((Class)actualType); + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + } + } + dataType.setLogical(XMLType.UNKNOWN); + dataType.setDataBinding(getName()); + return true; + } + + XMLType xmlType = JAXBContextHelper.getXmlTypeName(javaType); + if (xmlType == null) { + return false; + } + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + boolean isElement = false; + Class cls = arg.getClass(); + if (arg instanceof JAXBElement) { + isElement = true; + cls = ((JAXBElement)arg).getDeclaredType(); + } else { + arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg); + } + JAXBContext context = JAXBContext.newInstance(cls); + Document doc = DOMHelper.newDocument(); + context.createMarshaller().marshal(arg, doc); + JAXBElement element = context.createUnmarshaller().unmarshal(doc, cls); + return isElement ? element : element.getValue(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new JAXBExceptionHandler(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandler.java new file mode 100644 index 0000000000..6b0c7ab10c --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandler.java @@ -0,0 +1,106 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; + +import org.apache.tuscany.spi.databinding.ExceptionHandler; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +/** + * JAXB implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class JAXBExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = (Class)exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = (Class)faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exDataType) { + Class exceptionType = (Class) exDataType.getPhysical(); + WebFault webFault = exceptionType.getAnnotation(WebFault.class); + if (webFault == null) { + return null; + } else { + QName element = new QName(webFault.targetNamespace(), webFault.name()); + // TODO: Need to determine the fault bean class + // String faultBean = webFault.faultBean(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + // The logical type of a fault is the QName of the element that the + // only part in + // the fault message references + DataType faultType = + new DataType(JAXBDataBinding.NAME, faultBeanClass, new XMLType(element, null)); + // faultType.setMetadata(ElementInfo.class.getName(), new + // ElementInfo(element, null)); + return faultType; + } + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..449fc4c75e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java @@ -0,0 +1,123 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +/** + * JAXB WrapperHandler implementation + */ +public class JAXBWrapperHandler implements WrapperHandler> { + + public JAXBElement create(ElementInfo element, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + Object factory = factoryClass.newInstance(); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + Object value = typeClass.newInstance(); + return (JAXBElement)method.invoke(factory, new Object[] {value}); + } else { + throw new TransformationException("ObjectFactory cannot be resolved."); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement wrapper, int i, ElementInfo childElement, Object value) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + String property = properties[i]; + + try { + for (Method m : wrapperClass.getMethods()) { + if (m.getName().equals("set" + capitalize(property))) { + m.invoke(wrapperValue, new Object[] {value}); + return; + } + } + } catch (Throwable e) { + throw new TransformationException(e); + } + } + + private static String capitalize(String name) { + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#getChildren(java.lang.Object) + */ + public List getChildren(JAXBElement wrapper) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + List elements = new ArrayList(); + for (String p : properties) { + try { + Method method = wrapperClass.getMethod("get" + capitalize(p), (Class[])null); + Object value = method.invoke(wrapperValue, (Object[])null); + elements.add(value); + } catch (Throwable e) { + throw new TransformationException(e); + } + } + return elements; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessor.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..8ad3d38b82 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessor.java @@ -0,0 +1,107 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Map; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.xml.namespace.QName; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +import org.apache.tuscany.spi.idl.ElementInfo; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorExtension; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.WrapperInfo; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class JAXWSJavaInterfaceProcessor extends JavaInterfaceProcessorExtension { + + public JAXWSJavaInterfaceProcessor() { + super(); + } + + public void visitInterface(Class clazz, Class callbackClass, JavaServiceContract contract) + throws InvalidServiceContractException { + if (!contract.isRemotable()) { + return; + } + Map> operations = contract.getOperations(); + processInterface(clazz, contract, operations); + if (callbackClass != null) { + Map> callbackOperations = contract.getCallbackOperations(); + processInterface(callbackClass, contract, callbackOperations); + } + } + + private static String getValue(String value, String defaultValue) { + return "".equals(value) ? defaultValue : value; + } + + private void processInterface(Class clazz, JavaServiceContract contract, Map> operations) { + + for (Method method : clazz.getMethods()) { + Operation operation = operations.get(method.getName()); + + WebMethod webMethod = method.getAnnotation(WebMethod.class); + if (webMethod == null) { + return; + } + + String operationName = getValue(webMethod.operationName(), operation.getName()); + + RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class); + ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class); + if (requestWrapper == null) { + return; + } + + WebService webService = clazz.getAnnotation(WebService.class); + String tns = ""; + if (webService != null) { + tns = webService.targetNamespace(); + } + + 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); + + WrapperInfo wrapperInfo = + new WrapperInfo(JAXBDataBinding.NAME, new ElementInfo(inputWrapper, null), + new ElementInfo(outputWrapper, null), null, null); + operation.setWrapperStyle(true); + operation.setWrapper(wrapperInfo); + } + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..301e316889 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class Node2JAXB extends TransformerExtension implements PullTransformer { + + public Node2JAXB() { + super(); + } + + public Object transform(Node source, TransformationContext context) { + if (source == null) + return null; + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Node.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..273c15db1b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.io.Reader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class Reader2JAXB extends TransformerExtension implements + PullTransformer { + + public Object transform(final Reader source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(source); + Object result = unmarshaller.unmarshal(streamSource); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Reader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..3f6a2f64d3 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2JAXB extends TransformerExtension implements + PullTransformer { + + public XMLStreamReader2JAXB() { + super(); + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl new file mode 100644 index 0000000000..13a33a935c --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl @@ -0,0 +1,49 @@ + + + + + + org.apache.tuscany.sca.services.databinding + databinding-jaxb + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..00f321922e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,49 @@ + + + + + + org.apache.tuscany.sca.services.databinding + databinding-jaxb + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..36f0d251bb --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..ac12d2f2a8 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java @@ -0,0 +1,127 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.lang.annotation.Annotation; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * + */ +public class JAXBDataBindingTestCase extends TestCase { + private JAXBDataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new JAXBDataBinding(); + } + + /** + * Test method for + * {@link org.apache.tuscany.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class, Annotation)}. + */ + public final void testIntrospect() { + DataType dataType = new DataType(JAXBElement.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataType(MockJAXBElement.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(MockJAXBElement.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataType(USAddress.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataType(USState.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertEquals(USState.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USState"), ((XMLType)dataType.getLogical()).getTypeName()); + + } + + private static class MockJAXBElement extends JAXBElement { + + private static final long serialVersionUID = -2767569071002707973L; + + /** + * @param elementName + * @param type + * @param value + */ + public MockJAXBElement(QName elementName, Class type, PurchaseOrderType value) { + super(elementName, type, value); + } + + } + + @SuppressWarnings("unchecked") + public void testCopy() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + JAXBElement po = factory.createPurchaseOrder(poType); + JAXBElement copy = (JAXBElement)binding.copy(po); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getName()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonElement() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + poType.setComment("Comment"); + PurchaseOrderType copy = (PurchaseOrderType)binding.copy(poType); + assertTrue(copy instanceof PurchaseOrderType); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonRoot() { + ObjectFactory factory = new ObjectFactory(); + USAddress address = factory.createUSAddress(); + address.setCity("San Jose"); + USAddress copy = (USAddress)binding.copy(address); + assertTrue(copy instanceof USAddress); + assertEquals("San Jose", ((USAddress)copy).getCity()); + + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java new file mode 100644 index 0000000000..62990e38a6 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java @@ -0,0 +1,77 @@ +/* + * 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.tuscany.databinding.jaxb; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault; +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault_Exception; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import junit.framework.TestCase; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBExceptionHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + private JAXBExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBExceptionHandler(); + } + + public void testGetFaultType() { + DataType exType = new DataType(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(exType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(JAXBDataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataType(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataType(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..08583d9729 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java @@ -0,0 +1,158 @@ +/* + * 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.tuscany.databinding.jaxb; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +public class JAXBTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + DataType targetDataType = new DataType(Object.class, null); + targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataType(Object.class, null); + sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform2() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + QName root = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataType(PurchaseOrderType.class, root); + // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataType(PurchaseOrderType.class, root); + // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform3() throws Exception { + + DataType sourceDataType = new DataType(PurchaseOrderType.class, null); + sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); + Node node = t1.transform(po, tContext1); + + Assert.assertNotNull(node); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java new file mode 100644 index 0000000000..d6267013fe --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.tuscany.databinding.jaxb; + +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.ElementInfo; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBWrapperHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/IPO", "purchaseOrder"); + private JAXBWrapperHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBWrapperHandler(); + } + + public void testCreate() { + // ElementInfo element = new ElementInfo(ELEMENT, null); + // JAXBElement jaxbElement = handler.create(element, null); + } + + public void testSetChild() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + JAXBElement wrapper = factory.createPurchaseOrder(po); + handler.setChild(wrapper, 2, null, "Comment"); + } + + public void testGetChildren() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + po.setComment("Comment"); + JAXBElement wrapper = factory.createPurchaseOrder(po); + List children = handler.getChildren(wrapper); + assertNotNull(children); + assertEquals(4, children.size()); + assertEquals("Comment", children.get(2)); + assertNull(children.get(0)); + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java new file mode 100644 index 0000000000..240ffaea7b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java @@ -0,0 +1,59 @@ +package org.apache.tuscany.databinding.jaxb.fault; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for anonymous complex type. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"message", "symbol"}) +@XmlRootElement(name = "InvalidSymbolFault") +public class InvalidSymbolFault { + + @XmlElement(required = true) + protected String message; + @XmlElement(required = true) + protected String symbol; + + /** + * Gets the value of the message property. + * + * @return possible object is {@link String } + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value allowed object is {@link String } + */ + public void setMessage(String value) { + this.message = value; + } + + /** + * Gets the value of the symbol property. + * + * @return possible object is {@link String } + */ + public String getSymbol() { + return symbol; + } + + /** + * Sets the value of the symbol property. + * + * @param value allowed object is {@link String } + */ + public void setSymbol(String value) { + this.symbol = value; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..4a7d8d8660 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,44 @@ +package org.apache.tuscany.databinding.jaxb.fault; + +import javax.xml.ws.WebFault; + +/** + * This class was generated by the JAXWS SI. JAX-WS RI 2.1-02/02/2007 09:55 + * AM(vivekp)-FCS Generated source version: 2.1 + */ +@WebFault(name = "InvalidSymbolFault", targetNamespace = "http://www.example.com/stock") +public class InvalidSymbolFault_Exception extends Exception { + + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/.ruleset b/branches/sca-java-integration/sca/services/databinding/databinding-json/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/LICENSE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-json/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/NOTICE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-json/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/pom.xml b/branches/sca-java-integration/sca/services/databinding/databinding-json/pom.xml new file mode 100644 index 0000000000..9ebe626bd9 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/pom.xml @@ -0,0 +1,70 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + databinding-json + Apache Tuscany Data Binding for JSON + Tuscany JSON Data Binding + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-integration-incubating-SNAPSHOT + compile + + + org.codehaus.jettison + jettison + 1.0-beta-1 + compile + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.2 + + + xerces + xercesImpl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.2 + runtime + + + + junit + junit + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSON2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSON2XMLStreamReader.java new file mode 100644 index 0000000000..e48e8dbf27 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSON2XMLStreamReader.java @@ -0,0 +1,62 @@ +/* + * 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.tuscany.databinding.json; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader; +import org.json.JSONObject; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class JSON2XMLStreamReader extends TransformerExtension implements + PullTransformer { + + @Override + protected Class getSourceType() { + return JSONObject.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + public XMLStreamReader transform(JSONObject source, TransformationContext context) { + try { + return new BadgerFishXMLStreamReader(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSONDataBinding.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSONDataBinding.java new file mode 100644 index 0000000000..2cc8c1da37 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/JSONDataBinding.java @@ -0,0 +1,52 @@ +/* + * 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.tuscany.databinding.json; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.json.JSONObject; + +/** + * JAXB DataBinding + */ +public class JSONDataBinding extends DataBindingExtension { + public static final String NAME = JSONObject.class.getName(); + public static final String[] ALIASES = new String[] {"json"}; + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/json/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public JSONDataBinding() { + super(NAME, ALIASES, JSONObject.class); + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + JSONObject src = (JSONObject)arg; + return new JSONObject(src.toString()); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamReader2JSON.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamReader2JSON.java new file mode 100644 index 0000000000..872fe1cff3 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamReader2JSON.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.databinding.json; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter; +import org.json.JSONObject; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class XMLStreamReader2JSON extends TransformerExtension implements + PullTransformer { + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + protected Class getTargetType() { + return JSONObject.class; + } + + public JSONObject transform(XMLStreamReader source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + XMLStreamWriter jsonWriter = new BadgerFishXMLStreamWriter(writer); + XMLStreamSerializer serializer = new XMLStreamSerializer(); + serializer.serialize(source, jsonWriter); + return new JSONObject(writer.toString()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamSerializer.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamSerializer.java new file mode 100644 index 0000000000..74c39cba0f --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/XMLStreamSerializer.java @@ -0,0 +1,272 @@ +package org.apache.tuscany.databinding.json; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter + */ +public class XMLStreamSerializer implements XMLStreamConstants { + public static final String NAMESPACE_PREFIX = "ns"; + private static int namespaceSuffix; + + /* + * The behavior of the serializer is such that it returns when it encounters the starting element for the second + * time. The depth variable tracks the depth of the serilizer and tells it when to return. Note that it is assumed + * that this serialization starts on an Element. + */ + + /** + * Field depth + */ + private int depth; + + /** + * Generates a unique namespace prefix that is not in the scope of the NamespaceContext + * + * @param nsCtxt + * @return string + */ + private String generateUniquePrefix(NamespaceContext nsCtxt) { + String prefix = NAMESPACE_PREFIX + namespaceSuffix++; + // null should be returned if the prefix is not bound! + while (nsCtxt.getNamespaceURI(prefix) != null) { + prefix = NAMESPACE_PREFIX + namespaceSuffix++; + } + + return prefix; + } + + /** + * Method serialize. + * + * @param node + * @param writer + * @throws XMLStreamException + */ + public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException { + serializeNode(node, writer); + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + int count = reader.getAttributeCount(); + String prefix; + String namespaceName; + String writerPrefix; + for (int i = 0; i < count; i++) { + prefix = reader.getAttributePrefix(i); + namespaceName = reader.getAttributeNamespace(i); + /* + * Due to parser implementations returning null as the namespace URI (for the empty namespace) we need to + * make sure that we deal with a namespace name that is not null. The best way to work around this issue is + * to set the namespace uri to "" if it is null + */ + if (namespaceName == null) { + namespaceName = ""; + } + + writerPrefix = writer.getNamespaceContext().getPrefix(namespaceName); + + if (!"".equals(namespaceName)) { + // prefix has already being declared but this particular + // attrib has a + // no prefix attached. So use the prefix provided by the + // writer + if (writerPrefix != null && (prefix == null || prefix.equals(""))) { + writer.writeAttribute(writerPrefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + + // writer prefix is available but different from the + // current + // prefix of the attrib. We should be decalring the new + // prefix + // as a namespace declaration + } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) { + writer.writeNamespace(prefix, namespaceName); + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + + // prefix is null (or empty), but the namespace name is + // valid! it has not + // being written previously also. So we need to generate + // a prefix + // here + } else if (prefix == null || prefix.equals("")) { + prefix = generateUniquePrefix(writer.getNamespaceContext()); + writer.writeNamespace(prefix, namespaceName); + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + } else { + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + } + } else { + // empty namespace is equal to no namespace! + writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i)); + } + + } + } + + /** + * Method serializeCData. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeCData(reader.getText()); + } + + /** + * Method serializeComment. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeComment(reader.getText()); + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + String prefix = reader.getPrefix(); + String nameSpaceName = reader.getNamespaceURI(); + if (nameSpaceName != null) { + String writerPrefix = writer.getPrefix(nameSpaceName); + if (writerPrefix != null) { + writer.writeStartElement(nameSpaceName, reader.getLocalName()); + } else { + if (prefix != null) { + writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName); + writer.writeNamespace(prefix, nameSpaceName); + writer.setPrefix(prefix, nameSpaceName); + } else { + // [rfeng] We need to set default NS 1st before calling writeStateElement + writer.setDefaultNamespace(nameSpaceName); + writer.writeStartElement(nameSpaceName, reader.getLocalName()); + writer.writeDefaultNamespace(nameSpaceName); + } + } + } else { + writer.writeStartElement(reader.getLocalName()); + } + + // add the namespaces + int count = reader.getNamespaceCount(); + String namespacePrefix; + for (int i = 0; i < count; i++) { + namespacePrefix = reader.getNamespacePrefix(i); + // [rfeng] The following is commented out to allow to default ns + // if (namespacePrefix != null && namespacePrefix.length() == 0) { + // continue; + // } + + serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer); + } + + // add attributes + serializeAttributes(reader, writer); + + } + + /** + * Method serializeEndElement. + * + * @param writer + * @throws XMLStreamException + */ + protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndElement(); + } + + /** + * Method serializeNamespace. + * + * @param prefix + * @param uri + * @param writer + * @throws XMLStreamException + */ + private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException { + String prefix1 = writer.getPrefix(uri); + if (prefix1 == null) { + writer.writeNamespace(prefix, uri); + writer.setPrefix(prefix, uri); + } + } + + /** + * Method serializeNode. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + // TODO We get the StAXWriter at this point and uses it hereafter + // assuming that this is the only entry point + // to this class. + // If there can be other classes calling methodes of this we might + // need to change methode signatures to + // OMOutputer + while (true) { + int event = reader.getEventType(); + if (event == START_ELEMENT) { + serializeElement(reader, writer); + depth++; + } else if (event == ATTRIBUTE) { + serializeAttributes(reader, writer); + } else if (event == CHARACTERS) { + serializeText(reader, writer); + } else if (event == COMMENT) { + serializeComment(reader, writer); + } else if (event == CDATA) { + serializeCData(reader, writer); + } else if (event == END_ELEMENT) { + serializeEndElement(writer); + depth--; + } else if (event == START_DOCUMENT) { + depth++; // if a start document is found then increment + writer.writeStartDocument(); + // the depth + } else if (event == END_DOCUMENT) { + if (depth != 0) { + depth--; // for the end document - reduce the depth + } + writer.writeEndDocument(); + } + if (depth == 0) { + break; + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeCharacters(reader.getText()); + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSON2OMElement.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSON2OMElement.java new file mode 100644 index 0000000000..3ad5cca3f5 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSON2OMElement.java @@ -0,0 +1,83 @@ +/* + * 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.tuscany.databinding.json.axiom; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.databinding.json.JSONDataBinding; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; +import org.json.JSONObject; +import org.osoa.sca.annotations.Service; + +/** + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class JSON2OMElement extends TransformerExtension implements + PullTransformer { + + private OMFactory factory = OMAbstractFactory.getOMFactory(); + + @Override + protected Class getSourceType() { + return JSONObject.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + public OMElement transform(JSONObject source, TransformationContext context) { + try { + String ns = JSONDataBinding.ROOT_ELEMENT.getNamespaceURI(); + String name = JSONDataBinding.ROOT_ELEMENT.getLocalPart(); + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + ns = xmlType.getElementName().getNamespaceURI(); + name = xmlType.getElementName().getLocalPart(); + } + } + } + JSONBadgerfishDataSource ds = new JSONBadgerfishDataSource(source); + OMNamespace namespace = factory.createOMNamespace(ns, ""); + return factory.createOMElement(ds, name, namespace); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONBadgerfishDataSource.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONBadgerfishDataSource.java new file mode 100644 index 0000000000..22476b10af --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONBadgerfishDataSource.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.databinding.json.axiom; + +import javax.xml.stream.XMLStreamException; + +import org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in the + * OMSourcedElementImpl and can be used either to expand the tree or get the JSON String directly without expanding. + * This uses the "Badgerfish" JSON convention. + * + * @version $Rev$ $Date$ + */ + +public class JSONBadgerfishDataSource extends JSONDataSource { + + public JSONBadgerfishDataSource(JSONObject json) { + super(json); + } + + /** + * Gives the StAX reader using the "Badgerfish" formatted input JSON String. + * + * @return The XMLStreamReader according to the JSON String. + * @throws javax.xml.stream.XMLStreamException if there is an error while making the StAX reader. + */ + public javax.xml.stream.XMLStreamReader getReader() throws XMLStreamException { + try { + return new BadgerFishXMLStreamReader(json); + } catch (JSONException e) { + throw new XMLStreamException(e); + } + + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONDataSource.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONDataSource.java new file mode 100644 index 0000000000..744c5a407e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/java/org/apache/tuscany/databinding/json/axiom/JSONDataSource.java @@ -0,0 +1,174 @@ +/* + * 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.tuscany.databinding.json.axiom; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMException; +import org.apache.axiom.om.OMOutputFormat; +import org.codehaus.jettison.mapped.MappedXMLInputFactory; +import org.json.JSONObject; +import org.json.JSONTokener; + +/** + * JSONDataSource keeps the JSON String inside and consumes it when needed. This is to be kept in the + * OMSourcedElementImpl and can be used either to expand the tree or get the JSON String directly without expanding. + * This uses the "Mapped" JSON convention. + */ + +public class JSONDataSource implements OMDataSource { + protected JSONObject json; + + public JSONDataSource(JSONObject json) { + this.json = json; + } + + /** + * Writes JSON into the output stream. As this should write JSON, it directly gets the JSON string and writes it + * without expanding the tree. + * + * @param outputStream the stream to be written into + * @param omOutputFormat format of the message, this is ignored. + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message in to the output + * stream. + */ + public void serialize(OutputStream outputStream, OMOutputFormat omOutputFormat) + throws javax.xml.stream.XMLStreamException { + try { + String encoding = omOutputFormat == null ? "UTF-8" : omOutputFormat.getCharSetEncoding(); + outputStream.write(getJSONString().getBytes(encoding)); + } catch (IOException e) { + throw new OMException(); + } + } + + /** + * Writes JSON through the writer. As this should write JSON, it directly gets the JSON string and writes it without + * expanding the tree. + * + * @param writer Writer to be written into + * @param omOutputFormat format of the message, this is ignored. + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message through the writer. + */ + public void serialize(Writer writer, OMOutputFormat omOutputFormat) throws javax.xml.stream.XMLStreamException { + try { + writer.write(getJSONString()); + } catch (IOException e) { + throw new OMException(); + } + } + + /** + * Writes XML through the XMLStreamWriter. As the input data source is JSON, this method needs to get a StAX reader + * from that JSON String. Therefore this uses the getReader() method to get the StAX reader writes the events into + * the XMLStreamWriter. + * + * @param xmlStreamWriter StAX writer to be written into + * @throws javax.xml.stream.XMLStreamException if there is an error while writing the message through the StAX + * writer. + */ + public void serialize(javax.xml.stream.XMLStreamWriter xmlStreamWriter) throws javax.xml.stream.XMLStreamException { + XMLStreamReader reader = getReader(); + xmlStreamWriter.writeStartDocument(); + while (reader.hasNext()) { + int x = reader.next(); + switch (x) { + case XMLStreamConstants.START_ELEMENT: + xmlStreamWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader + .getNamespaceURI()); + int namespaceCount = reader.getNamespaceCount(); + for (int i = namespaceCount - 1; i >= 0; i--) { + xmlStreamWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i)); + } + int attributeCount = reader.getAttributeCount(); + for (int i = 0; i < attributeCount; i++) { + xmlStreamWriter.writeAttribute(reader.getAttributePrefix(i), + reader.getAttributeNamespace(i), + reader.getAttributeLocalName(i), + reader.getAttributeValue(i)); + } + break; + case XMLStreamConstants.START_DOCUMENT: + break; + case XMLStreamConstants.CHARACTERS: + xmlStreamWriter.writeCharacters(reader.getText()); + break; + case XMLStreamConstants.CDATA: + xmlStreamWriter.writeCData(reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + xmlStreamWriter.writeEndElement(); + break; + case XMLStreamConstants.END_DOCUMENT: + xmlStreamWriter.writeEndDocument(); + break; + case XMLStreamConstants.SPACE: + break; + case XMLStreamConstants.COMMENT: + xmlStreamWriter.writeComment(reader.getText()); + break; + case XMLStreamConstants.DTD: + xmlStreamWriter.writeDTD(reader.getText()); + break; + case XMLStreamConstants.PROCESSING_INSTRUCTION: + xmlStreamWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData()); + break; + case XMLStreamConstants.ENTITY_REFERENCE: + xmlStreamWriter.writeEntityRef(reader.getLocalName()); + break; + default: + throw new OMException(); + } + } + xmlStreamWriter.writeEndDocument(); + } + + /** + * Gives the StAX reader using the "Mapped" formatted input JSON String. + * + * @return The XMLStreamReader according to the JSON String. + * @throws javax.xml.stream.XMLStreamException if there is an error while making the StAX reader. + */ + + public javax.xml.stream.XMLStreamReader getReader() throws javax.xml.stream.XMLStreamException { + + Map nsMap = new HashMap(); + nsMap.put("", ""); + + // input factory for "Mapped" convention + MappedXMLInputFactory inputFactory = new MappedXMLInputFactory(nsMap); + String jsonString = this.getJSONString(); + return inputFactory.createXMLStreamReader(new JSONTokener(jsonString)); + } + + // returns the json string by consuming the JSON input stream. + protected String getJSONString() { + return json.toString(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/databinding.json.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/databinding.json.scdl new file mode 100644 index 0000000000..d8994b3058 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/databinding.json.scdl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..52bd695f67 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/java/org/apache/tuscany/databinding/json/JSONTransformerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/java/org/apache/tuscany/databinding/json/JSONTransformerTestCase.java new file mode 100644 index 0000000000..6d7b5a8aed --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/java/org/apache/tuscany/databinding/json/JSONTransformerTestCase.java @@ -0,0 +1,91 @@ +package org.apache.tuscany.databinding.json; + +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.databinding.json.axiom.JSON2OMElement; +import org.json.JSONObject; +import org.junit.Test; + +public class JSONTransformerTestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private static final String JSON_STR = + "{\"xsl:root\":{\"@xmlns\":{\"xsl\":\"http://foo.com\"},\"data\":{\"$\":\"my json string\"}}}"; + + @Test + public void testXML2JSON() throws Exception { + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + XMLStreamReader2JSON t1 = new XMLStreamReader2JSON(); + JSONObject json = t1.transform(reader, null); + Assert.assertNotNull(json); + + // Cannot round-trip as we hit a bug in Jettison + + JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); + XMLStreamReader reader2 = t2.transform(json, null); + StringWriter sw = new StringWriter(); + XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + new XMLStreamSerializer().serialize(reader2, streamWriter); + streamWriter.flush(); + System.out.println(sw.toString()); + + } + + @Test + public void testJSON2XML() throws Exception { + JSON2XMLStreamReader t2 = new JSON2XMLStreamReader(); + XMLStreamReader reader2 = t2.transform(new JSONObject(JSON_STR), null); + StringWriter sw = new StringWriter(); + XMLStreamWriter streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(sw); + new XMLStreamSerializer().serialize(reader2, streamWriter); + streamWriter.flush(); + Assert.assertEquals("my json string", sw + .toString()); + } + + @Test + public void testJSON2OMElement() throws Exception { + JSON2OMElement t1 = new JSON2OMElement(); + OMElement element = t1.transform(new JSONObject(JSON_STR), null); + StringWriter writer = new StringWriter(); + element.serialize(writer); + System.out.println(writer.toString()); + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/resources/ipo.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-json/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.checkstyle b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.checkstyle new file mode 100644 index 0000000000..142759d295 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.checkstyle @@ -0,0 +1,6 @@ + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.ruleset b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/LICENSE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/NOTICE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/pom.xml b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/pom.xml new file mode 100644 index 0000000000..b0c7107d5e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/pom.xml @@ -0,0 +1,138 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + databinding-sdo-axiom + Apache Tuscany Data Binding for SDO + Data Binding based on SDO. + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-integration-incubating-SNAPSHOT + compile + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.2 + + + xerces + xercesImpl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.2 + runtime + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 0.1-integration-incubating-SNAPSHOT + compile + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + junit + junit + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubator-SNAPSHOT + + + generate-po-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-test-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElement.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElement.java new file mode 100644 index 0000000000..4d9a2688d5 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElement.java @@ -0,0 +1,89 @@ +/* + * 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.tuscany.databinding.sdo2om; + +import static org.apache.tuscany.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.databinding.sdo.SDOContextHelper; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +/** + * SDO DataObject --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class DataObject2OMElement extends TransformerExtension implements + PullTransformer { + + public OMElement transform(DataObject source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + SDODataSource dataSource = new SDODataSource(source, helperContext); + OMFactory factory = OMAbstractFactory.getOMFactory(); + + OMNamespace namespace = null; + String localName = ROOT_ELEMENT.getLocalPart(); + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + namespace = + factory.createOMNamespace(xmlType.getElementName().getNamespaceURI(), xmlType.getElementName() + .getPrefix()); + localName = xmlType.getElementName().getLocalPart(); + } + } + } + if (namespace == null) { + namespace = + factory.createOMNamespace(ROOT_ELEMENT.getNamespaceURI(), ROOT_ELEMENT.getPrefix()); + } + + OMElement element = factory.createOMElement(dataSource, localName, namespace); + return element; + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return OMElement.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObjectSerializer.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObjectSerializer.java new file mode 100644 index 0000000000..7997d72002 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/DataObjectSerializer.java @@ -0,0 +1,408 @@ +package org.apache.tuscany.databinding.sdo2om; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sdo.impl.AttributeImpl; +import org.apache.tuscany.sdo.impl.ReferenceImpl; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XSDHelper; + +public class DataObjectSerializer { + private static final String ELEMENT_TEXT = "Text Element"; + + // static final String ELEMENT_TEXT = "Element Text"; + private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"); + + private Map declaredNamespaceMap = new HashMap(); + + private NameSpaceContextImpl namespaceContext = new NameSpaceContextImpl(); + + private DataObject rootDataObject; + + private String rootElementName; + + private String rootElementURI; + + private XMLStreamWriter xmlWriter; + + private XSDHelper xsdHelper; + + public DataObjectSerializer(DataObject rootObject, + XMLStreamWriter xmlWriter, + HelperContext helperCtx, + TransformationContext context) { + this.xmlWriter = xmlWriter; + this.rootDataObject = rootObject; + this.xsdHelper = helperCtx.getXSDHelper(); + this.rootElementName = xsdHelper.getLocalName(rootObject.getType()); + this.rootElementURI = rootDataObject.getType().getURI(); + + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (targetQName instanceof QName) { + QName name = (QName)targetQName; + this.rootElementName = name.getLocalPart(); + this.rootElementURI = name.getNamespaceURI(); + } + } + + } + + // private void serializeNamespace(String prefix, String URI, + // XMLStreamWriter writer) throws XMLStreamException { + // String prefix1 = writer.getPrefix(URI); + // if (prefix1 == null) { + // writer.writeNamespace(prefix, URI); + // writer.setPrefix(prefix, URI); + // } + // } + + public DataObjectSerializer(XMLDocument sourceDocument, XMLStreamWriter xmlWriter, HelperContext helperCtx) { + this.xmlWriter = xmlWriter; + this.rootDataObject = sourceDocument.getRootObject(); + this.rootElementName = sourceDocument.getRootElementName(); + this.rootElementURI = sourceDocument.getRootElementURI(); + this.xsdHelper = helperCtx.getXSDHelper(); + } + + protected class NameSpaceContextImpl implements NamespaceContext { + private int counter; + + private Map prefixToNamespaceMapping = new HashMap(); + + public NameSpaceContextImpl() { + prefixToNamespaceMapping.put("xml", "http://www.w3.org/XML/1998/namespace"); + prefixToNamespaceMapping.put("xmlns", "http://www.w3.org/2000/xmlns/"); + prefixToNamespaceMapping.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + } + + public synchronized QName createQName(String nsURI, String name) { + String prefix = nsURI != null ? (String)getPrefix(nsURI) : null; + if (prefix == null && nsURI != null && !nsURI.equals("")) { + prefix = "p" + (counter++); + } + if (prefix == null) { + prefix = ""; + } + if (nsURI != null) { + prefixToNamespaceMapping.put(prefix, nsURI); + declaredNamespaceMap.put(prefix, nsURI); + } + return new QName(nsURI, name, prefix); + } + + public String getNamespaceURI(String prefix) { + if (prefix == null) { + throw new IllegalArgumentException("Prefix is null"); + } + + String ns = (String)prefixToNamespaceMapping.get(prefix); + if (ns != null) { + return ns; + } else { + return null; + } + } + + public String getPrefix(String nsURI) { + if (nsURI == null) { + throw new IllegalArgumentException("Namespace is null"); + } + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + return (String)entry.getKey(); + } + } + return null; + } + + public Iterator getPrefixes(String nsURI) { + List prefixList = new ArrayList(); + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + prefixList.add(entry.getKey()); + } + } + return prefixList.iterator(); + } + + public void registerMapping(String prefix, String nsURI) { + prefixToNamespaceMapping.put(prefix, nsURI); + } + + public void removeMapping(String prefix) { + prefixToNamespaceMapping.remove(prefix); + } + } + + protected static class NameValuePair implements Map.Entry { + private Object key; + + private Object value; + + public NameValuePair(Object key, Object value) { + this.key = key; + this.value = value; + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object value) { + Object v = this.value; + this.value = value; + return v; + } + + } + + private static boolean isTransient(Property property, Object type) { + // HACK: We need some SDOUtil extension to understand a property is + // derived + EStructuralFeature feature = (EStructuralFeature)property; + if (ExtendedMetaData.INSTANCE.getGroup(feature) != null) { + return false; + } + feature = ExtendedMetaData.INSTANCE.getAffiliation((EClass)type, feature); + if (feature != null && feature != property) { + return false; + } + if (property instanceof ReferenceImpl) { + ReferenceImpl r = (ReferenceImpl)property; + if (r.isTransient()) { + return true; + } + EReference opposite = r.getEOpposite(); + if (opposite != null && opposite.isContainment()) { + return true; + } + } else if (property instanceof AttributeImpl) { + AttributeImpl a = (AttributeImpl)property; + if (a.isTransient()) { + return true; + } + EDataType d = (EDataType)a.getEType(); + if (!d.isSerializable()) { + return true; + } + } + return false; + } + + private void addListValue(List propertyList, + List children, + Property property, + List objList) throws XMLStreamException { + if (objList != null) { + for (int j = 0; j < objList.size(); j++) { + Object object = objList.get(j); + addSingleValue(propertyList, children, property, object); + } + } + } + + private void addProperty(List propertyList, + List children, + Property property, + Object value, + DataObject dataObject) throws XMLStreamException { + + if (property.isMany() && property.getContainingType().isOpen() && value instanceof Sequence) { + addSequenceValue(propertyList, children, (Sequence)value); + } else if (SDOUtil.isMany(property, dataObject) && value instanceof List) { + addListValue(propertyList, children, property, (List)value); + } else { + // Complex Type + addSingleValue(propertyList, children, property, value); + } + } + + private void addSequenceValue(List elements, List children, Sequence seq) + throws XMLStreamException { + if (seq != null && seq.size() > 0) { + for (int j = 0; j < seq.size(); j++) { + Object o = seq.getValue(j); + Property p = seq.getProperty(j); + addSingleValue(elements, children, p, o); + } + } + } + + private void addSingleValue(List propertyList, + List children, + Property property, + Object value) throws XMLStreamException { + String uri = xsdHelper.getNamespaceURI(property); + String name = xsdHelper.getLocalName(property); + QName qname = namespaceContext.createQName(uri, name); + Type propertyType = property.getType(); + + if (property.getName().equals("value") && uri == null && name.equals(":0")) { + propertyList.add(new NameValuePair(ELEMENT_TEXT, value.toString())); + } else if (value == null) { + NameValuePair entry = new NameValuePair(qname, null); + propertyList.add(entry); + } else if (propertyType.isDataType()) { + NameValuePair entry = new NameValuePair(qname, SDOUtil.convertToString(propertyType, value)); + propertyList.add(entry); + } else { + children.add((DataObject)value); + } + } + + private void registerNamespace(String prefix, String uri) { + if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) { + namespaceContext.registerMapping(prefix, uri); + declaredNamespaceMap.put(prefix, uri); + } + } + + public void serialize() throws XMLStreamException { + xmlWriter.setNamespaceContext(namespaceContext); + writeDataObject(rootDataObject, rootElementName, rootElementURI); + xmlWriter.flush(); + } + + private void writeDataObject(DataObject obj, String elementName, String elementURI) throws XMLStreamException { + List elementList = new ArrayList(); + List children = new ArrayList(); + List attributes = new ArrayList(); + + String typeName; + QName realTypeName = null; + + if (elementName != null) { + realTypeName = namespaceContext.createQName(elementURI, elementName); + String typeQName = realTypeName.getPrefix() + ":" + realTypeName.getLocalPart(); + declaredNamespaceMap.put(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + attributes.add(new NameValuePair(XSI_TYPE_QNAME, typeQName)); + registerNamespace(XSI_TYPE_QNAME.getPrefix(), XSI_TYPE_QNAME.getNamespaceURI()); + } else { + + typeName = xsdHelper.getLocalName(obj.getContainmentProperty()); + realTypeName = namespaceContext.createQName(obj.getType().getURI(), typeName); + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + } + + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + + if (obj.getType().isSequenced()) { + Sequence sequence = obj.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + Property property = sequence.getProperty(i); + Object value = sequence.getValue(i); + if (property == null) { + elementList.add(new NameValuePair(ELEMENT_TEXT, value)); + } else { + addProperty(elementList, children, property, value, obj); + } + } + + // Attributes are not in the sequence + List properties = obj.getInstanceProperties(); + for (Iterator i = properties.iterator(); i.hasNext();) { + Property property = (Property)i.next(); + if (xsdHelper.isAttribute(property) && obj.isSet(property) && !isTransient(property, obj.getType())) { + Object value = obj.get(property); + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(property), xsdHelper + .getLocalName(property)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(property.getType(), value))); + } + } + } else { + Iterator i = obj.getInstanceProperties().iterator(); + while (i.hasNext()) { + Property p = (Property)i.next(); + if (obj.isSet(p) && !isTransient(p, obj.getType())) { + Object value = obj.get(p); + if (xsdHelper.isAttribute(p)) { + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(p), xsdHelper.getLocalName(p)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(p.getType(), value))); + } else { + addProperty(elementList, children, p, value, obj); + } + } + } + } + + String prefix = realTypeName.getPrefix(); + String nameSpaceName = realTypeName.getNamespaceURI(); + + if (nameSpaceName != null) { + String writerPrefix = xmlWriter.getPrefix(nameSpaceName); + if (writerPrefix != null) { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + } else { + if (prefix != null) { + xmlWriter.writeStartElement(prefix, realTypeName.getLocalPart(), nameSpaceName); + xmlWriter.writeNamespace(prefix, nameSpaceName); + xmlWriter.setPrefix(prefix, nameSpaceName); + } else { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + xmlWriter.writeDefaultNamespace(nameSpaceName); + xmlWriter.setDefaultNamespace(nameSpaceName); + } + } + } else { + xmlWriter.writeStartElement(realTypeName.getLocalPart()); + } + + for (NameValuePair pair : attributes) { + QName name = (QName)pair.getKey(); + assert namespaceContext.getPrefix(name.getPrefix()).equals(name.getNamespaceURI()); + xmlWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), (String)pair + .getValue()); + } + + for (NameValuePair pair : elementList) { + if (ELEMENT_TEXT.equals(pair.getKey().toString())) { + xmlWriter.writeCharacters((String)pair.getValue()); + } else { + QName name = (QName)pair.getKey(); + xmlWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + xmlWriter.writeCharacters((String)pair.getValue()); + xmlWriter.writeEndElement(); + } + } + + for (DataObject child : children) { + writeDataObject(child, null, null); + } + xmlWriter.writeEndElement(); + + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/SDODataSource.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/SDODataSource.java new file mode 100644 index 0000000000..0eebcbf54b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/SDODataSource.java @@ -0,0 +1,66 @@ +package org.apache.tuscany.databinding.sdo2om; + +import static org.apache.tuscany.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axiom.om.impl.serialize.StreamingOMSerializer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class SDODataSource implements OMDataSource { + private HelperContext helperContext; + private XMLDocument sourceDocument; + + public SDODataSource(XMLDocument source, HelperContext helperContext) { + this.sourceDocument = source; + this.helperContext = helperContext; + } + + public SDODataSource(DataObject obj, HelperContext helperContext) { + this.helperContext = helperContext; + this.sourceDocument = + helperContext.getXMLHelper().createDocument(obj, + ROOT_ELEMENT.getNamespaceURI(), + ROOT_ELEMENT.getLocalPart()); + } + + public XMLStreamReader getReader() throws XMLStreamException { + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(sourceDocument); + } + + public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { + StreamingOMSerializer serializer = new StreamingOMSerializer(); + serializer.serialize(getReader(), xmlWriter); + } + + public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, output, null); + } catch (Exception e) { + throw new XMLStreamException(e); + } + } + + public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, writer, null); + } catch (IOException e) { + throw new XMLStreamException(e); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElement.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElement.java new file mode 100644 index 0000000000..389c6b4d79 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElement.java @@ -0,0 +1,64 @@ +/* + * 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.tuscany.databinding.sdo2om; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.databinding.sdo.SDOContextHelper; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO XMLDocument --> AXIOM OMElement transformer + * @version $Rev$ $Date$ + */ +@Service(Transformer.class) +public class XMLDocument2OMElement extends TransformerExtension implements + PullTransformer { + + public OMElement transform(XMLDocument source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + SDODataSource dataSource = new SDODataSource(source, helperContext); + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMNamespace namespace = factory.createOMNamespace(source.getRootElementURI(), source.getRootElementName()); + OMElement element = factory.createOMElement(dataSource, source.getRootElementName(), namespace); + return element; + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return OMElement.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/databinding.sdo-axiom.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/databinding.sdo-axiom.scdl new file mode 100644 index 0000000000..5be48ed134 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/databinding.sdo-axiom.scdl @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..be4b5fe07e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElementTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElementTestCase.java new file mode 100644 index 0000000000..18703dd087 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/DataObject2OMElementTestCase.java @@ -0,0 +1,38 @@ +package org.apache.tuscany.databinding.sdo2om; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataType(DataObject.class.getName(), DataObject.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataType(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + OMElement element = new DataObject2OMElement().transform(dataObject, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + StringWriter writer = new StringWriter(); + element.serialize(writer); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/MockTransformationContext.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/MockTransformationContext.java new file mode 100644 index 0000000000..d132ad66e8 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/MockTransformationContext.java @@ -0,0 +1,83 @@ +/* + * 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.tuscany.databinding.sdo2om; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; + +public class MockTransformationContext implements TransformationContext { + private DataType sourceDataType; + + private DataType targetDataType; + + private final Map, Object> metadata = new HashMap, Object>(); + + private WeakReference classLoaderRef; + + public MockTransformationContext() { + super(); + setClassLoader(Thread.currentThread().getContextClassLoader()); + } + + public MockTransformationContext(DataType sourceDataType, + DataType targetDataType, + ClassLoader classLoader, + Map, Object> metadata) { + super(); + this.sourceDataType = sourceDataType; + this.targetDataType = targetDataType; + setClassLoader(classLoader); + if (metadata != null) { + this.metadata.putAll(metadata); + } + } + + public DataType getSourceDataType() { + return sourceDataType; + } + + public DataType getTargetDataType() { + return targetDataType; + } + + public void setSourceDataType(DataType sourceDataType) { + this.sourceDataType = sourceDataType; + } + + public void setTargetDataType(DataType targetDataType) { + this.targetDataType = targetDataType; + } + + public final void setClassLoader(ClassLoader classLoader) { + this.classLoaderRef = new WeakReference(classLoader); + } + + public ClassLoader getClassLoader() { + return classLoaderRef.get(); + } + + public Map, Object> getMetadata() { + return metadata; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/SDOTransformerTestCaseBase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..2c5950d058 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/SDOTransformerTestCaseBase.java @@ -0,0 +1,78 @@ +/* + * 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.tuscany.databinding.sdo2om; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new MockTransformationContext(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new MockTransformationContext(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElementTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElementTestCase.java new file mode 100644 index 0000000000..f473eb86d4 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/java/org/apache/tuscany/databinding/sdo2om/XMLDocument2OMElementTestCase.java @@ -0,0 +1,45 @@ +package org.apache.tuscany.databinding.sdo2om; + +import java.io.StringWriter; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLDocument; + +/** + * + */ +public class XMLDocument2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataType(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataType(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + OMElement element = new XMLDocument2OMElement().transform(document, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + StringWriter writer = new StringWriter(); + element.serialize(writer); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/ipo.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/stock.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo-axiom/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.checkstyle b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.checkstyle new file mode 100644 index 0000000000..142759d295 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.checkstyle @@ -0,0 +1,6 @@ + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.ruleset b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/LICENSE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/NOTICE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/pom.xml b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/pom.xml new file mode 100755 index 0000000000..1b8b334358 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/pom.xml @@ -0,0 +1,119 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + databinding-sdo + Apache Tuscany Data Binding for SDO + Data Binding based on SDO. + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-integration-incubating-SNAPSHOT + compile + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubator-SNAPSHOT + compile + + + + org.apache.tuscany.sca.kernel + tuscany-core + 0.1-integration-incubating-SNAPSHOT + test + + + + junit + junit + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubator-SNAPSHOT + + + generate-po-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-test-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..c188e94f3b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class DataObject2String extends TransformerExtension implements + PullTransformer { + + public String transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..9c93d75adf --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class DataObject2XMLStreamReader extends TransformerExtension implements + PullTransformer { + + public XMLStreamReader transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + XMLDocument document = + xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + return streamHelper.createXMLStreamReader(document); + } catch (XMLStreamException e) { + // TODO: Add context to the exception + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java new file mode 100755 index 0000000000..25793d1777 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java @@ -0,0 +1,73 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.model.ModelObject; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Property; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * A SDO model-based Loader to load DataObject from the XML stream + */ +@EagerInit +public class DataObjectLoader extends LoaderExtension { + private QName elementName; + + public DataObjectLoader(@Autowire LoaderRegistry registry, + @Property(name = "namespace", required = true) String namespace, + @Property(name = "name", required = true) String name) { + super(registry); + this.elementName = new QName(namespace, name); + } + + public ModelDataObject load(CompositeComponent parent, + ModelObject object, + XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert elementName.equals(reader.getName()); + HelperContext helperContext = SDOContextHelper.getHelperContext(object); + TypeHelper typeHelper = helperContext.getTypeHelper(); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + DataObject dataObject = streamHelper.loadObject(reader); + // TODO: Is it required that the object always extends from ModelObject? + return new ModelDataObject(dataObject); + } + + @Override + public QName getXMLType() { + return elementName; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java new file mode 100644 index 0000000000..8d14773b88 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.ModelObject; + +import commonj.sdo.helper.HelperContext; + +/** + * The model object for import.sdo + * + * @version $Rev$ $Date$ + */ +public class ImportSDO extends ModelObject { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + private HelperContext helperContext; + + public ImportSDO(HelperContext helperContext) { + super(); + this.helperContext = helperContext; + } + + public HelperContext getHelperContext() { + return helperContext; + } +} \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java new file mode 100644 index 0000000000..31f17860b4 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java @@ -0,0 +1,57 @@ +/* + * 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.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.ComponentRegistrationException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.SCAObject; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.GenericBuilderExtension; + +import commonj.sdo.helper.HelperContext; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOBuilder extends GenericBuilderExtension { + + @Override + protected Class getModelType() { + return ImportSDO.class; + } + + public SCAObject build(SCAObject parent, ImportSDO modelObject, DeploymentContext deploymentContext) + throws BuilderException { + if (parent instanceof CompositeComponent) { + CompositeComponent component = (CompositeComponent)parent; + SDOHelperContext obj = new SDOHelperContext(component, modelObject.getHelperContext()); + try { + component.registerJavaObject(obj.getName(), HelperContext.class, obj.getHelperContext()); + } catch (ComponentRegistrationException e) { + throw new IllegalArgumentException(e); + } + return obj; + } else { + return null; + } + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java new file mode 100755 index 0000000000..f115fc78ec --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java @@ -0,0 +1,163 @@ +/* + * 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.tuscany.databinding.sdo; + +import static org.apache.tuscany.databinding.sdo.ImportSDO.IMPORT_SDO; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; +import org.apache.tuscany.spi.model.ModelObject; +import org.osoa.sca.annotations.Constructor; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + */ +public class ImportSDOLoader extends LoaderExtension { + + @Constructor( {"registry"}) + public ImportSDOLoader(@Autowire + LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ModelObject load(CompositeComponent parent, + ModelObject object, + XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert IMPORT_SDO.equals(reader.getName()); + + // FIXME: [rfeng] How to associate the TypeHelper with deployment + // context? + HelperContext helperContext = SDOContextHelper.getHelperContext(object); + + importFactory(reader, deploymentContext, helperContext); + importWSDL(reader, deploymentContext, helperContext); + LoaderUtil.skipToEndElement(reader); + return new ImportSDO(helperContext); + } + + private void importFactory(XMLStreamReader reader, DeploymentContext deploymentContext, HelperContext helperContext) + throws LoaderException { + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + // set TCCL as SDO needs it + ClassLoader cl = deploymentContext.getClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + Class factoryClass = cl.loadClass(factoryName); + register(factoryClass, helperContext); + } catch (Exception e) { + throw new LoaderException(e.getMessage(), e); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + } + + private static void register(Class factoryClass, HelperContext helperContext) throws Exception { + Field field = factoryClass.getField("INSTANCE"); + Object factory = field.get(null); + Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + method.invoke(factory, new Object[] {defaultContext}); + } + + private void importWSDL(XMLStreamReader reader, DeploymentContext deploymentContext, HelperContext helperContext) + throws LoaderException { + String location = reader.getAttributeValue(null, "location"); + if (location == null) { + location = reader.getAttributeValue(null, "wsdlLocation"); + } + if (location != null) { + try { + URL wsdlURL = null; + URI uri = URI.create(location); + if (uri.isAbsolute()) { + wsdlURL = uri.toURL(); + } + wsdlURL = deploymentContext.getClassLoader().getResource(location); + if (null == wsdlURL) { + LoaderException loaderException = new LoaderException("WSDL location error"); + loaderException.setResourceURI(location); + throw loaderException; + } + InputStream xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = helperContext.getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = defaultContext.getXSDHelper(); + ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + // set TCCL as SDO needs it + ClassLoader cl = deploymentContext.getClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } finally { + xsdInputStream.close(); + } + } catch (IOException e) { + LoaderException sfe = new LoaderException(e.getMessage()); + sfe.setResourceURI(location); + throw sfe; + } + } + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java new file mode 100755 index 0000000000..ba171af498 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.model.ModelObject; + +import commonj.sdo.DataObject; + +/** + * Wrapper of DataObject as a ModelObject + * + * @version $Rev$ $Date$ + */ +public class ModelDataObject extends ModelObject { + private DataObject dataObject; + + public ModelDataObject(DataObject dataObject) { + super(); + this.dataObject = dataObject; + } + + public DataObject getDataObject() { + return dataObject; + } + + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java new file mode 100644 index 0000000000..9d37c79228 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java @@ -0,0 +1,111 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.CompositeComponentType; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.ModelObject; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * Helper class to get TypeHelper from the context + */ +public final class SDOContextHelper { + private SDOContextHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null || context.getMetadata() == null) { + return getDefaultHelperContext(); + } + HelperContext helperContext = null; + CompositeComponent composite = (CompositeComponent)context.getMetadata().get(CompositeComponent.class); + if (composite != null) { +// SDOHelperContext sdoContext = +// (SDOHelperContext)composite.getExtensions().get(HelperContext.class.getName()); +// if (sdoContext != null) { +// helperContext = sdoContext.getHelperContext(); +// } + AtomicComponent child = (AtomicComponent)composite.getSystemChild(HelperContext.class.getName()); + try { + // The child can be null if no import.sdo is declared + if (child != null) { + helperContext = (HelperContext)child.getTargetInstance(); + } + } catch (TargetResolutionException e) { + helperContext = null; + } + } + if (helperContext == null) { + return getDefaultHelperContext(); + } else { + return helperContext; + } + } + + public static HelperContext getHelperContext(ModelObject model) { + HelperContext helperContext = null; + if (model instanceof CompositeComponentType) { + // HACK: Retrieve the SDO HelperContext from the + // CompositeComponentType + // extensions + helperContext = (HelperContext)model.getExtensions().get(ImportSDO.IMPORT_SDO); + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + ((CompositeComponentType)model).getDeclaredExtensions().put(ImportSDO.IMPORT_SDO, + helperContext); + } + } + + if (helperContext == null) { + helperContext = getDefaultHelperContext(); + } + + return helperContext; + } + + protected static HelperContext getDefaultHelperContext() { + // SDOUtil.createHelperContext(); + return HelperProvider.getDefaultContext(); + } + + public static QName getElement(DataType dataType) { + Object logical = dataType.getLogical(); + QName elementName = SDODataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + return elementName; + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..4178ee9f63 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java @@ -0,0 +1,122 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.ExceptionHandler; +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO Databinding + * + * @version $Reve$ $Date$ + */ +public class SDODataBinding extends DataBindingExtension { + public static final String NAME = DataObject.class.getName(); + public static final String[] ALIASES = new String[] {"sdo"}; + + public static final String ROOT_NAMESPACE = "commonj.sdo"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); + + private WrapperHandler wrapperHandler; + + public SDODataBinding() { + super(NAME, ALIASES, DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + HelperContext context = HelperProvider.getDefaultContext(); + // FIXME: Need a better to test dynamic SDO + if (DataObject.class.isAssignableFrom(javaType)) { + // Dynamic SDO + dataType.setDataBinding(getName()); + dataType.setLogical(XMLType.UNKNOWN); + return true; + } + // FIXME: We need to access HelperContext + Type type = context.getTypeHelper().getType(javaType); + if (type == null) { + return false; + } + if (type.isDataType()) { + // FIXME: Ignore simple types? + return false; + } + String namespace = type.getURI(); + String name = context.getXSDHelper().getLocalName(type); + QName xmlType = new QName(namespace, name); + dataType.setDataBinding(getName()); + dataType.setLogical(new XMLType(null, xmlType)); + return true; + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SDOSimpleTypeMapper(); + } + + @Override + public Object copy(Object arg) { + HelperContext context = HelperProvider.getDefaultContext(); + CopyHelper copyHelper = context.getCopyHelper(); + if (arg instanceof XMLDocument) { + XMLDocument document = (XMLDocument)arg; + DataObject dataObject = copyHelper.copy(document.getRootObject()); + return context.getXMLHelper().createDocument(dataObject, + document.getRootElementURI(), + document.getRootElementName()); + } else if (arg instanceof DataObject) { + return context.getCopyHelper().copy((DataObject)arg); + } else { + return super.copy(arg); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new SDOExceptionHandler(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java new file mode 100644 index 0000000000..28a36ea2c8 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java @@ -0,0 +1,123 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.ExceptionHandler; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class SDOExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + // FIXME: Need a way to pass in the HelperContext + private HelperContext helperContext = HelperProvider.getDefaultContext(); + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = (Class)exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = (Class)faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exceptionDataType) { + Class exceptionType = (Class) exceptionDataType.getPhysical(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + if (faultBeanClass == null) { + return null; + } + + QName faultElement = null; + try { + Field field = exceptionType.getField("FAULT_ELEMENT"); + faultElement = (QName)field.get(null); + } catch (NoSuchFieldException e) { + // Fall back to type inspection + Type type = helperContext.getTypeHelper().getType(faultBeanClass); + if (type != null) { + String ns = type.getURI(); + String name = helperContext.getXSDHelper().getLocalName(type); + faultElement = new QName(ns, name); + } + } catch (Throwable e) { + // Ignore + } + if (faultElement == null) { + return null; + } + DataType faultType = + new DataType(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); + return faultType; + + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java new file mode 100644 index 0000000000..3091d7ec8d --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java @@ -0,0 +1,48 @@ +/* + * 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.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.component.AbstractSCAObject; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.model.Scope; + +import commonj.sdo.helper.HelperContext; + +public class SDOHelperContext extends AbstractSCAObject { + private HelperContext helperContext; + + /** + * @param name + * @param parent + */ + public SDOHelperContext(CompositeComponent parent, HelperContext helperContext) { + super(HelperContext.class.getName(), parent); + this.helperContext = helperContext; + } + + public Scope getScope() { + return Scope.COMPOSITE; + } + + public HelperContext getHelperContext() { + return helperContext; + } + +} \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..3b57323c73 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.TransformationContext; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * SDO Java/XML mapping for simple XSD types + */ +public class SDOSimpleTypeMapper implements SimpleTypeMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public SDOSimpleTypeMapper() { + super(); + } + + public Object toJavaObject(QName typeName, String value, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..dfbf7dabce --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java @@ -0,0 +1,99 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * SDO Wrapper Handler + */ +public class SDOWrapperHandler implements WrapperHandler { + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#create(ElementInfo, TransformationContext) + */ + public Object create(ElementInfo element, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + QName typeName = element.getType().getQName(); + DataFactory dataFactory = helperContext.getDataFactory(); + DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart()); + } + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#setChild(java.lang.Object, int, ElementInfo, + * java.lang.Object) + */ + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + wrapperDO.set(i, value); + } + + @SuppressWarnings("unchecked") + public List getChildren(Object wrapper) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + List properties = wrapperDO.getInstanceProperties(); + List elements = new ArrayList(); + Type type = wrapperDO.getType(); + if (type.isSequenced()) { + // Add values in the sequence + Sequence sequence = wrapperDO.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + // Skip mixed text + if (sequence.getProperty(i) != null) { + elements.add(sequence.getValue(i)); + } + } + } else { + for (Property p : properties) { + Object child = wrapperDO.get(p); + if (p.isMany()) { + for (Object c : (Collection)child) { + elements.add(c); + } + } else { + elements.add(child); + } + } + } + return elements; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..bd288c74e7 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java @@ -0,0 +1,58 @@ +/* + * 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.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class String2DataObject extends TransformerExtension implements + PullTransformer { + + public DataObject transform(String source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return String.class; + } + + public Class getTargetType() { + return DataObject.class; + } + + public int getWeight() { + return 50; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..38f48cebee --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java @@ -0,0 +1,62 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.io.StringWriter; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class XMLDocument2String extends TransformerExtension implements + PullTransformer { + + public String transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..bd20089001 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +@Service(Transformer.class) +public class XMLDocument2XMLStreamReader extends TransformerExtension implements + PullTransformer { + /** + * @param source + * @param context + * @return + */ + public XMLStreamReader transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..c29413101d --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java @@ -0,0 +1,67 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +@Service(Transformer.class) +public class XMLStreamReader2DataObject extends TransformerExtension implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + // The XMLStreamHelper requires that the reader is posistioned at + // START_ELEMENT + while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { + source.next(); + } + return streamHelper.loadObject(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return DataObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..ff9e0aa2e1 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +@Service(Transformer.class) +public class XMLStreamReader2XMLDocument extends TransformerExtension implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.load(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XMLDocument.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl new file mode 100644 index 0000000000..e23b3f80bb --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl @@ -0,0 +1,72 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..2b2040c148 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,66 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..a9104cc401 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..8c4f243df5 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,67 @@ +/* + * 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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + */ +public class InvalidSymbolFault_Exception extends Exception { + /** + * Generated QName for the fault element + */ + public static final QName FAULT_ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..182156c7ac --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java @@ -0,0 +1,64 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType getSourceDataType() { + return new DataType(binding, PurchaseOrderType.class, ORDER_QNAME); + } + + @Override + protected DataType getTargetDataType() { + return new DataType>(String.class, String.class); + } + + public final void testTransform() { + String xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.indexOf("San Jose") != -1); + DataObject po = new String2DataObject().transform(xml, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + + public final void testXML() { + String xml = + ""; + DataObject dataObject = new String2DataObject().transform(xml, reversedContext); + context.setSourceDataType(new DataType(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..7a1f03e36f --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java @@ -0,0 +1,57 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; + +/** + * + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataType(binding, PurchaseOrderType.class, ORDER_QNAME); + } + + @Override + protected DataType getTargetDataType() { + return new DataType>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + break; + } + } + new XMLStreamReader2DataObject().transform(reader, reversedContext); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java new file mode 100755 index 0000000000..f38e0426cb --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java @@ -0,0 +1,82 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.io.StringReader; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.core.component.scope.CompositeScopeContainer; +import org.apache.tuscany.core.deployer.RootDeploymentContext; +import org.apache.tuscany.spi.deployer.DeploymentContext; + +import commonj.sdo.helper.XSDHelper; + +public class DataObjectLoaderTestCase extends TestCase { + + private XSDHelper xsdHelper = XSDHelper.INSTANCE; + + private QName name = new QName("http://www.osoa.org/xmlns/mock/0.9", "implementation.mock"); + + private String xml = + "" + + "" + + ""; + + @Override + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getClassLoader().getResource("model/sca-implementation-mock.xsd"); + // URL url = + // getClass().getClassLoader().getResource("model/sca-core.xsd"); + xsdHelper.define(url.openStream(), url.toExternalForm()); + } + + public void testLoader() throws Exception { + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); + int event = reader.getEventType(); + while (!(event == XMLStreamConstants.START_ELEMENT && reader.getName().equals(name)) && reader.hasNext()) { + event = reader.nextTag(); + } + DataObjectLoader loader = new DataObjectLoader(null, name.getNamespaceURI(), name.getLocalPart()); + DeploymentContext context = + new RootDeploymentContext(getClass().getClassLoader(), inputFactory, new CompositeScopeContainer(null), + null); + ModelDataObject modelObject = (ModelDataObject)loader.load(null, null, reader, context); + Assert.assertNotNull(modelObject.getDataObject()); + Assert.assertTrue(modelObject.getDataObject().getString("myAttr").equals("helloworld.HelloWorldImpl")); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java new file mode 100755 index 0000000000..e87526bb9a --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java @@ -0,0 +1,87 @@ +/* + * 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.tuscany.databinding.sdo; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.deployer.RootDeploymentContext; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; + +import com.example.ipo.sdo.SdoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOLoaderTestCase extends TestCase { + private static boolean inited; + + private ImportSDOLoader loader; + private XMLInputFactory xmlFactory; + private DeploymentContext deploymentContext; + + public void testMinimal() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO); + } + + public void testLocation() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO); + } + + public void testFactory() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof ImportSDO); + assertTrue(inited); + } + + protected void setUp() throws Exception { + super.setUp(); + loader = new ImportSDOLoader(null); + xmlFactory = XMLInputFactory.newInstance(); + deploymentContext = new RootDeploymentContext(getClass().getClassLoader(), xmlFactory, null, null); + } + + protected XMLStreamReader getReader(String xml) throws XMLStreamException { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); + reader.next(); + return reader; + } + + public static class MockFactory { + public static final Object INSTANCE = SdoFactory.INSTANCE; + + static { + ImportSDOLoaderTestCase.inited = true; + } + } +} + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..e2145f1a5c --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java @@ -0,0 +1,110 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * + */ +public class SDODataBindingTestCase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private SDODataBinding binding; + private HelperContext context; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + context = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(context); + } + + public final void testIntrospect() { + DataType dataType = new DataType(DataObject.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataType(PurchaseOrderType.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataType(USAddress.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + } + + public final void testCopyRoot() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + Object copy = binding.copy(po); + assertTrue(copy instanceof PurchaseOrderType); + assertTrue(po != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, (DataObject)copy)); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + public final void testCopyNonRoot() { + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + Object copy = binding.copy(address); + assertTrue(copy instanceof USAddress); + assertTrue(address != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)address, (DataObject)copy)); + assertEquals("San Jose", ((USAddress)copy).getCity()); + } + + public final void testCopyXMLDocument() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + XMLDocument doc = + context.getXMLHelper().createDocument((DataObject)po, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + Object copy = binding.copy(doc); + assertTrue(copy instanceof XMLDocument); + XMLDocument docCopy = (XMLDocument)copy; + assertTrue(doc != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, docCopy.getRootObject())); + assertEquals("Comment", ((PurchaseOrderType)docCopy.getRootObject()).getComment()); + } +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java new file mode 100644 index 0000000000..8226891c35 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandlerTestCase.java @@ -0,0 +1,81 @@ +/* + * 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.tuscany.databinding.sdo; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +import com.example.stock.sdo.InvalidSymbolFault; +import com.example.stock.sdo.StockFactory; +import com.example.stock.sdo.fault.InvalidSymbolFault_Exception; +import commonj.sdo.impl.HelperProvider; + +/** + * Test case for SDOExceptionHandler + */ +public class SDOExceptionHandlerTestCase extends TestCase { + // FIXME: Tuscany SDO impl uses _._type for anonymouse type, by the SDO + // spec, it should be same as the + // enclosing element/attribute name + private SDOExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new SDOExceptionHandler(); + StockFactory.INSTANCE.register(HelperProvider.getDefaultContext()); + } + + public void testGetFaultType() { + DataType execType = new DataType(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(execType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(InvalidSymbolFault_Exception.FAULT_ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(SDODataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataType(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataType(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..58a05fcf9b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,79 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..3ddd1c85dd --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandlerTestCase.java @@ -0,0 +1,65 @@ +/* + * 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.tuscany.databinding.sdo; + +import static junit.framework.Assert.assertEquals; + +import java.util.List; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.junit.Before; +import org.junit.Test; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandlerTestCase { + private HelperContext context; + private SDOWrapperHandler handler; + + @Before + public void setUp() throws Exception { + context = SDOUtil.createHelperContext(); + handler = new SDOWrapperHandler(); + } + + @Test + public void testWrapperAnyType() throws Exception { + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + + @Test + public void testWrapper() throws Exception { + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..c58636decc --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -0,0 +1,60 @@ +/* + * 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.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.helper.XMLDocument; + +/** + * + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataType(XMLDocument.class.getName(), XMLDocument.class, ORDER_QNAME); + } + + @Override + protected DataType getTargetDataType() { + return new DataType>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..8f4ee4be3e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/stock.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xml b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xml new file mode 100644 index 0000000000..3e7fe81817 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xml @@ -0,0 +1,9 @@ + + + message + symbol + message1 + symbol1 + symbol2 + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xsd new file mode 100644 index 0000000000..ea4dc5f7f3 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/test/resources/wrapper.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/.ruleset b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/LICENSE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/NOTICE.txt b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/pom.xml b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/pom.xml new file mode 100755 index 0000000000..ba111fc774 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/pom.xml @@ -0,0 +1,97 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + databinding-xmlbeans + Apache Tuscany Data Binding for XmlBeans + Tuscany XmlBeans Data Binding + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-integration-incubating-SNAPSHOT + compile + + + xmlbeans + xbean + 2.2.0 + compile + + + + junit + junit + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/xmlbeans-source + + + + + + + maven-antrun-plugin + + + generate-xmlbeans + generate-test-sources + + + + + + + + run + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java new file mode 100755 index 0000000000..0b4da53473 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class Node2XmlObject extends TransformerExtension implements + PullTransformer { + // private XmlOptions options; + + public XmlObject transform(Node source, TransformationContext context) { + try { + return XmlObject.Factory.parse(source); + } catch (XmlException e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XmlObject.class; + } + + public Class getSourceType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java new file mode 100644 index 0000000000..12057982e4 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java @@ -0,0 +1,35 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.xmlbeans.XmlObject; + +/** + * XMLBeans DataBinding + */ +public class XMLBeansDataBinding extends DataBindingExtension { + public static final String NAME = XmlObject.class.getName(); + + public XMLBeansDataBinding() { + super(NAME, XmlObject.class); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java new file mode 100755 index 0000000000..0e61bd9571 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java @@ -0,0 +1,56 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2XmlObject extends TransformerExtension implements PullTransformer { + // private XmlOptions options; + + public XmlObject transform(XMLStreamReader source, TransformationContext context) { + try { + return XmlObject.Factory.parse(source); + } catch (XmlException e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XmlObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java new file mode 100755 index 0000000000..8fc1e58bd5 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java @@ -0,0 +1,52 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class XmlObject2Node extends TransformerExtension implements + PullTransformer { + // private XmlOptions options; + + public Node transform(XmlObject source, TransformationContext context) { + if (source == null) + return null; + return source.newDomNode(); + } + + public Class getSourceType() { + return XmlObject.class; + } + + public Class getTargetType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java new file mode 100755 index 0000000000..8a12cf34f0 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlObject; + +public class XmlObject2XMLStreamReader extends TransformerExtension implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(XmlObject source, TransformationContext context) { + return source.newXMLStreamReader(); + } + + public Class getSourceType() { + return XmlObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/databinding.xmlbeans.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/databinding.xmlbeans.scdl new file mode 100644 index 0000000000..9c53d427e9 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/databinding.xmlbeans.scdl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..eee36ea6d4 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..40a6b56c01 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java new file mode 100755 index 0000000000..57fbae7e35 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java @@ -0,0 +1,99 @@ +/* + * 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.tuscany.databinding.xmlbeans; + +import java.io.StringReader; +import java.net.URL; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +import com.example.ipo.xmlbeans.PurchaseOrderDocument; + +public class XmlObjectTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + " Helen Zoe" + " 47 Eden Street" + + " Cambridge" + " CB1 1JR" + " " + " " + + " Robert Smith" + " 8 Oak Avenue" + " Old Town" + " PA" + + " 95819" + " " + " " + " " + + " Lapis necklace" + " 1" + " 99.95" + + " Want this for the holidays" + " 1999-12-05" + " " + " " + + ""; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testXmlObject() throws Exception { + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + XmlObject object2 = t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + Assert.assertNotNull(object3); + } + + public void testGeneratedXmlObject() throws Exception { + // URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + PurchaseOrderDocument object = PurchaseOrderDocument.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + PurchaseOrderDocument object2 = (PurchaseOrderDocument) t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + PurchaseOrderDocument object3 = (PurchaseOrderDocument) t4.transform(node, null); + Assert.assertNotNull(object3); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ + + + + + com.example.ipo.xmlbeans + + + diff --git a/branches/sca-java-integration/sca/services/databinding/pom.xml b/branches/sca-java-integration/sca/services/databinding/pom.xml new file mode 100644 index 0000000000..c92daa2a1e --- /dev/null +++ b/branches/sca-java-integration/sca/services/databinding/pom.xml @@ -0,0 +1,70 @@ + + + + + + org.apache.tuscany.sca.services + parent + 0.1-integration-incubating-SNAPSHOT + + + 4.0.0 + org.apache.tuscany.sca.services.databinding + parent + pom + Apache Tuscany SCA Data Bindings + + + + stable + + true + + + databinding-jaxb + databinding-sdo + databinding-sdo-axiom + + + + + integration + + databinding-jaxb + databinding-sdo + databinding-xmlbeans + databinding-sdo-axiom + + + + + unstable + + databinding-jaxb + databinding-sdo + databinding-xmlbeans + databinding-sdo-axiom + databinding-json + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/pom.xml b/branches/sca-java-integration/sca/services/idl/pom.xml new file mode 100644 index 0000000000..e66179bdc9 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/pom.xml @@ -0,0 +1,61 @@ + + + + + org.apache.tuscany.sca.services + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + org.apache.tuscany.sca.services.idl + parent + pom + Apache Tuscany SCA Interface Definition Languages + + + + + apache.snapshots + Apache Snapshot Repository + http://people.apache.org/repo/m2-snapshot-repository + + false + + + true + + + + apache.incubator + Apache Incubator Repository + http://people.apache.org/repo/m2-incubating-repository/ + + true + + + false + + + + + + wsdl + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/.ruleset b/branches/sca-java-integration/sca/services/idl/wsdl/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/LICENSE.txt b/branches/sca-java-integration/sca/services/idl/wsdl/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, serviceDefinition marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/NOTICE.txt b/branches/sca-java-integration/sca/services/idl/wsdl/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/pom.xml b/branches/sca-java-integration/sca/services/idl/wsdl/pom.xml new file mode 100644 index 0000000000..595632a3de --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/pom.xml @@ -0,0 +1,57 @@ + + + + + org.apache.tuscany.sca.services.idl + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + tuscany-wsdl + jar + Apache Tuscany WSDL + Tuscany WSDL Support. + + + + org.apache.tuscany.sca.kernel + tuscany-spi + ${sca.version} + compile + + + org.apache.ws.commons.schema + XmlSchema + + + + wsdl4j + wsdl4j + + + junit + junit + + + org.easymock + easymock + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java new file mode 100644 index 0000000000..1b9326acab --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java @@ -0,0 +1,48 @@ +/* + * 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.tuscany.idl.wsdl; + +import javax.wsdl.PortType; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes. + * + * @version $Rev$ $Date$ + */ +public interface InterfaceWSDLIntrospector { + + /** + * Introspect a WSDL portType and return a service contract definition. + * + * @param type the portType to inspect + * @return a WSDLServiceContract corresponding to the WSDL portType + */ + WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException; + + /** + * Introspect a WSDL portType and return a service contract definition. + * + * @param type the portType to inspect + * @param callback the callback portType to inspec + * @return a WSDLServiceContract corresponding to the WSDL portType + */ + WSDLServiceContract introspect(PortType type, PortType callback) throws InvalidServiceContractException; +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java new file mode 100644 index 0000000000..b705413fe1 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java @@ -0,0 +1,102 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.util.HashMap; +import java.util.Map; + +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.InteractionScope; +import org.osoa.sca.annotations.Constructor; + +/** + * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes. + */ +public class InterfaceWSDLIntrospectorImpl implements InterfaceWSDLIntrospector { + private WSDLDefinitionRegistry wsdlDefinitionRegistry; + + /** + * @param wsdlDefinitionRegistry + */ + @Constructor("wsdlDefinitionRegistry") + public InterfaceWSDLIntrospectorImpl(@Autowire WSDLDefinitionRegistry wsdlDefinitionRegistry) { + super(); + this.wsdlDefinitionRegistry = wsdlDefinitionRegistry; + } + + // FIXME: Do we want to deal with document-literal wrapped style based on the JAX-WS spec? + protected Map> introspectOperations(PortType portType) + throws InvalidServiceContractException { + Map> operations = + new HashMap>(); + for (Object op : portType.getOperations()) { + Operation wsdlOp = (Operation) op; + operations.put(wsdlOp.getName(), introspectOperation(wsdlOp)); + } + return operations; + } + + protected org.apache.tuscany.spi.model.Operation introspectOperation(Operation wsdlOp) + throws InvalidServiceContractException { + + WSDLOperation op = new WSDLOperation(wsdlOp, null, wsdlDefinitionRegistry.getSchemaRegistry()); + return op.getOperation(); + } + + /** + * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType) + */ + public WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException { + WSDLServiceContract contract = new WSDLServiceContract(); + contract.setPortType(portType); + contract.setInterfaceName(portType.getQName().getLocalPart()); + contract.setOperations(introspectOperations(portType)); + // FIXME: set to Non-conversational for now + contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); + return contract; + } + + /** + * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType, javax.wsdl.PortType) + */ + public WSDLServiceContract introspect(PortType portType, PortType callbackPortType) + throws InvalidServiceContractException { + assert portType != null : "PortType cannot be null"; + WSDLServiceContract contract = new WSDLServiceContract(); + // FIXME: set to Non-conversational for now + contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); + contract.setPortType(portType); + contract.setInterfaceName(portType.getQName().getLocalPart()); + contract.setOperations(introspectOperations(portType)); + if (callbackPortType != null) { + contract.setCallbackPortType(callbackPortType); + contract.setCallbackName(callbackPortType.getQName().getLocalPart()); + contract.setCallbackOperations(introspectOperations(callbackPortType)); + } + return contract; + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java new file mode 100644 index 0000000000..8ebf086091 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java @@ -0,0 +1,146 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import static org.osoa.sca.Constants.SCA_NS; +import org.osoa.sca.annotations.Constructor; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.loader.InvalidValueException; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.MissingResourceException; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Loads a WSDL interface definition from an XML-based assembly file + * + * @version $Rev$ $Date$ + */ +public class InterfaceWSDLLoader extends LoaderExtension { + public static final QName INTERFACE_WSDL = new QName(SCA_NS, "interface.wsdl"); + + private static final String WSDLI = "http://www.w3.org/2006/01/wsdl-instance"; + + private static final String WSDLI_LOCATION = "wsdlLocation"; + + private WSDLDefinitionRegistry wsdlRegistry; + + private InterfaceWSDLIntrospector introspector; + + @Constructor({"registry", "wsdlRegistry", "introspector"}) + public InterfaceWSDLLoader(@Autowire LoaderRegistry registry, + @Autowire WSDLDefinitionRegistry wsdlRegistry, + @Autowire InterfaceWSDLIntrospector introspector) { + super(registry); + this.wsdlRegistry = wsdlRegistry; + this.introspector = introspector; + } + + public QName getXMLType() { + return INTERFACE_WSDL; + } + + public WSDLServiceContract load( + CompositeComponent parent, + ModelObject object, XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert INTERFACE_WSDL.equals(reader.getName()); + + String interfaceURI = reader.getAttributeValue(null, "interface"); + if (interfaceURI == null) { + throw new InvalidValueException("interface"); + } + + String callbackURI = reader.getAttributeValue(null, "callbackInterface"); + String wsdlLocation = reader.getAttributeValue(WSDLI, WSDLI_LOCATION); + + Map, ModelObject> extensions = new HashMap, ModelObject>(); + while (true) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + ModelObject mo = registry.load(parent, null, reader, deploymentContext); + if (mo != null) { + extensions.put(mo.getClass(), mo); + } + } else if (event == XMLStreamConstants.END_ELEMENT) { + if (reader.getName().equals(INTERFACE_WSDL)) { + break; + } + } + } + // FIXME set the interaction scope + // serviceContract.setInteractionScope(StAXUtil.interactionScope(reader.getAttributeValue(null, "scope"))); + + if (wsdlLocation != null) { + try { + wsdlRegistry.loadDefinition(wsdlLocation, deploymentContext.getClassLoader()); + } catch (IOException e) { + throw new LoaderException(wsdlLocation, e); + } catch (WSDLException e) { + throw new LoaderException(wsdlLocation, e); + } + } + + PortType portType = getPortType(interfaceURI); + if (portType == null) { + throw new MissingResourceException(interfaceURI); + } + PortType callback = null; + if (callbackURI != null) { + callback = getPortType(callbackURI); + } + try { + WSDLServiceContract contract = introspector.introspect(portType, callback); + DataType dataType = (DataType) extensions.get(DataType.class); + if (dataType != null) { + contract.setDataBinding(dataType.getDataBinding()); + } + contract.getExtensions().putAll(extensions); + return contract; + } catch (InvalidServiceContractException e) { + throw new LoaderException(wsdlLocation, e); + } + } + + protected PortType getPortType(String uri) { + // Syntax: #wsdl.interface() + int index = uri.indexOf('#'); + String namespace = uri.substring(0, index); + String name = uri.substring(index + 1); + name = name.substring("wsdl.interface(".length(), name.length() - 1); + QName qname = new QName(namespace, name); + return wsdlRegistry.getPortType(qname); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java new file mode 100644 index 0000000000..a629ff4fbb --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidFragmentException extends WSDLLoaderException { + + public InvalidFragmentException(String message) { + super(message); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLContributionException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLContributionException.java new file mode 100644 index 0000000000..dedcf352ef --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLContributionException.java @@ -0,0 +1,36 @@ +/* + * 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.tuscany.idl.wsdl; + +import org.apache.tuscany.host.deployment.DeploymentException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + */ +public class InvalidWSDLContributionException extends DeploymentException { + + protected InvalidWSDLContributionException(String componentDefinitionLocatoin) { + super(componentDefinitionLocatoin); + } + + protected InvalidWSDLContributionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java new file mode 100644 index 0000000000..a22ab92863 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java @@ -0,0 +1,34 @@ +/* + * 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.tuscany.idl.wsdl; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * An exception to indicate the WSDL definition is invalid + * + * @version $Rev$ $Date$ + */ +public class InvalidWSDLException extends InvalidServiceContractException { + + public InvalidWSDLException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java new file mode 100644 index 0000000000..b2d77bf52f --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java @@ -0,0 +1,33 @@ +/* + * 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.tuscany.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidWSDLLocationException extends WSDLLoaderException { + + public InvalidWSDLLocationException(String message) { + super(message); + } + + public InvalidWSDLLocationException(Throwable cause) { + super(cause); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java new file mode 100644 index 0000000000..04cea4cefd --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java @@ -0,0 +1,37 @@ +/* + * 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.tuscany.idl.wsdl; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * An exception to indicate some WSDL styles that we don't support + * + * @version $Rev$ $Date$ + */ +public class NotSupportedWSDLException extends InvalidServiceContractException { + + public NotSupportedWSDLException(String message) { + super(message); + } + + public NotSupportedWSDLException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java new file mode 100644 index 0000000000..afb4ed3d40 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java @@ -0,0 +1,34 @@ +/* + * 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.tuscany.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class UnresolveableResourceException extends WSDLLoaderException { + + public UnresolveableResourceException(String message) { + super(message); + } + + public UnresolveableResourceException(String message, String identifier) { + super(message, identifier); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java new file mode 100644 index 0000000000..e438cd37cf --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessor.java @@ -0,0 +1,263 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLLocator; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.apache.tuscany.host.deployment.DeploymentException; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry; +import org.apache.tuscany.spi.extension.ContributionProcessorExtension; +import org.apache.tuscany.spi.model.Contribution; +import org.apache.tuscany.spi.model.DeployedArtifact; +import org.xml.sax.InputSource; + +/** + * The WSDL processor + * @version $Rev$ $Date$ + */ +public class WSDLContributionProcessor extends ContributionProcessorExtension { + + private final WSDLFactory wsdlFactory; + + private final ExtensionRegistry extensionRegistry; + + private final Map> definitionsByNamespace = new HashMap>(); + + private Monitor monitor; + + private XMLSchemaRegistry schemaRegistry; + + private ArtifactResolverRegistry artifactResolverRegistry; + + public WSDLContributionProcessor() throws WSDLException { + wsdlFactory = WSDLFactory.newInstance(); + extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry(); + } + + @Autowire + public void setSchemaRegistry(XMLSchemaRegistry schemaRegistry) { + this.schemaRegistry = schemaRegistry; + } + + @org.apache.tuscany.api.annotation.Monitor + public void setMonitor(Monitor monitor) { + this.monitor = monitor; + } + + public ExtensionRegistry getExtensionRegistry() { + return extensionRegistry; + } + + @SuppressWarnings("unchecked") + public Definition loadDefinition(Contribution contribution, String namespace, URI location, InputStream inputStream) + throws IOException, WSDLException, DeploymentException { + if (monitor != null) { + monitor.readingWSDL(namespace, location); + } + + WSDLReader reader = wsdlFactory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setExtensionRegistry(extensionRegistry); + + WSDLLocatorImpl locator = new WSDLLocatorImpl(contribution, location, inputStream); + Definition definition = reader.readWSDL(locator); + String definitionNamespace = definition.getTargetNamespace(); + if (namespace != null && !namespace.equals(definitionNamespace)) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + + definition.getTargetNamespace()); + } + + // Load inline schemas + registry.processModel(contribution, location, definition); + for (Object i : definition.getImports().values()) { + List imps = (List)i; + for (Import imp : imps) { + Definition imported = imp.getDefinition(); + if (imported != null) { + // TODO: + registry.processModel(contribution, URI.create(imp.getDefinition().getDocumentBaseURI()), definition); + } + } + } + + if (monitor != null) { + monitor.cachingDefinition(definitionNamespace, location); + } + List definitions = definitionsByNamespace.get(definitionNamespace); + if (definitions == null) { + definitions = new ArrayList(); + definitionsByNamespace.put(definitionNamespace, definitions); + } + definitions.add(definition); + + DeployedArtifact artifact = contribution.getArtifact(location); + artifact.addModelObject(Definition.class, definition.getTargetNamespace(), definition); + + return definition; + } + + public PortType getPortType(QName name) { + String namespace = name.getNamespaceURI(); + List definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + PortType portType = definition.getPortType(name); + if (portType != null) { + return portType; + } + } + return null; + } + + public Service getService(QName name) { + String namespace = name.getNamespaceURI(); + List definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + Service service = definition.getService(name); + if (service != null) { + return service; + } + } + return null; + } + + public static interface Monitor { + /** + * Monitor event emitted immediately before an attempt is made to read + * WSDL for the supplied namespace from the supplied location. + * + * @param namespace the target namespace expected in the WSDL; may be + * null + * @param location the location where we will attempt to read the WSDL + * definition from + */ + void readingWSDL(String namespace, URI location); + + /** + * Monitor event emitted immediately before registering a WSDL + * definition in the cache. + * + * @param namespace the target namespace for the WSDL + * @param location the location where the WSDL definition was read from + */ + void cachingDefinition(String namespace, URI location); + } + + public XMLSchemaRegistry getSchemaRegistry() { + if (schemaRegistry == null) { + // Default + schemaRegistry = new XMLSchemaRegistryImpl(); + } + return schemaRegistry; + } + + public class WSDLLocatorImpl implements WSDLLocator { + private Contribution contribution; + private InputStream inputStream; + private String baseURI; + private URI latestImportURI; + + public WSDLLocatorImpl(Contribution contribution, URI baseURI, InputStream is) { + this.contribution = contribution; + this.baseURI = baseURI.toString(); + this.inputStream = is; + } + + public void close() { + // inputStream.close(); + } + + public InputSource getBaseInputSource() { + return new InputSource(inputStream); + } + + public String getBaseURI() { + return baseURI; + } + + public InputSource getImportInputSource(String parentLocation, String importLocation) { + try { + URL url = artifactResolverRegistry.resolve(contribution, null, importLocation, parentLocation); + latestImportURI = url.toURI(); + return new InputSource(url.openStream()); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public String getLatestImportURI() { + return latestImportURI.toString(); + } + + } + + public String getContentType() { + return "application/vnd.tuscany.wsdl"; + } + + /** + * @param artifactResolverRegistry the artifactResolverRegistry to set + */ + @Autowire + public void setArtifactResolverRegistry(ArtifactResolverRegistry artifactResolverRegistry) { + this.artifactResolverRegistry = artifactResolverRegistry; + } + + public void processContent(Contribution contribution, URI source, InputStream inputStream) + throws DeploymentException, IOException { + try { + loadDefinition(contribution, null, source, inputStream); + } catch (WSDLException e) { + throw new InvalidWSDLContributionException(contribution.getArtifact(source).getLocation().toExternalForm(), e); + } + } + + public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException, + IOException { + // TODO Auto-generated method stub + + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java new file mode 100644 index 0000000000..f7fd7de5ae --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java @@ -0,0 +1,91 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; + +/** + * A service for caching WSDLs + * + * @version $Rev$ $Date$ + */ +@Deprecated +public interface WSDLDefinitionRegistry { + /** + * Loads and registers a WSDL Definition. + * + * @param namespace the expected namespace, or null if any namespace should be allowed + * @param location the location to load the definition from + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws WSDLException if there was a problem parsing the definition + */ + Definition loadDefinition(String namespace, URL location) throws IOException, WSDLException; + + /** + * Load and register a WSDL definition as specified in a WSDL2.0 wsdlLocation attribute. + * + * @param wsdlLocation the value of the wsdlLocation attribute + * @param classLoader application classloader used to support relative locations + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws WSDLException if there was a problem parsing the definition + */ + Definition loadDefinition(String wsdlLocation, ClassLoader classLoader) throws IOException, WSDLException; + + /** + * Returns the PortType with the supplied qualified name, or null if no such port has been defined. + * + * @param name the qualified name of the WSDL portType + * @return the PortType for the supplied name, or null if none has been defined + */ + PortType getPortType(QName name); + + /** + * Returns the ServiceDefinition with the supplied qualified name, or null if no such service has been defined. + * + * @param name the qualified name of the WSDL service + * @return the ServiceDefinition for the supplied name, or null if none has been defined + */ + Service getService(QName name); + + + /** + * Returns the ExtensionRegistry that is used when parsing WSDL documents during the loadDefinition call. + * + * @return the ExtensionRegistry that is used when parsing WSDL documents. + */ + ExtensionRegistry getExtensionRegistry(); + + /** + * Get the XMLSchemaRegistry + * + * @return + */ + XMLSchemaRegistry getSchemaRegistry(); + + Definition getDefinition(String wsdlNamespace); +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java new file mode 100644 index 0000000000..de0accd459 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java @@ -0,0 +1,214 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.annotation.Autowire; + +/** + * The default implementation of the runtime WSDL registry + * + * @version $Rev$ $Date$ + */ +public class WSDLDefinitionRegistryImpl implements WSDLDefinitionRegistry { + private final WSDLFactory wsdlFactory; + + private final ExtensionRegistry registry; + + private final Map definitionsByLocation = new HashMap(); + + private final Map> definitionsByNamespace = new HashMap>(); + + private Monitor monitor; + + private XMLSchemaRegistry schemaRegistry; + + public WSDLDefinitionRegistryImpl() throws WSDLException { + wsdlFactory = WSDLFactory.newInstance(); + registry = wsdlFactory.newPopulatedExtensionRegistry(); + } + + @Autowire + public void setSchemaRegistry(XMLSchemaRegistry schemaRegistry) { + this.schemaRegistry = schemaRegistry; + } + + @org.apache.tuscany.api.annotation.Monitor + public void setMonitor(Monitor monitor) { + this.monitor = monitor; + } + + public ExtensionRegistry getExtensionRegistry() { + return registry; + } + + public Definition loadDefinition(String wsdlLocation, ClassLoader classLoader) throws IOException, WSDLException { + int index = wsdlLocation.indexOf(' '); + if (index == -1) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); + } + String namespace = wsdlLocation.substring(0, index).trim(); + URL url; + URI uri; + try { + uri = new URI(wsdlLocation.substring(index + 1).trim()); + } catch (URISyntaxException e) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); + } + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = classLoader.getResource(uri.toString()); + if (url == null) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Resource not found: " + uri); + } + } + return loadDefinition(namespace, url); + } + + public Definition loadDefinition(String namespace, URL location) throws IOException, WSDLException { + Definition definition = definitionsByLocation.get(location); + if (definition != null) { + // return cached copy + return definition; + } + + if (monitor != null) { + monitor.readingWSDL(namespace, location); + } + WSDLReader reader = wsdlFactory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setExtensionRegistry(registry); + + definition = reader.readWSDL(location.toString()); + String definitionNamespace = definition.getTargetNamespace(); + if (namespace != null && !namespace.equals(definitionNamespace)) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + + definition.getTargetNamespace()); + } + + // Load inline schemas + getSchemaRegistry().loadSchemas(definition); + for (Object i : definition.getImports().values()) { + Import imp = (Import) i; + Definition imported = imp.getDefinition(); + if (imported != null) { + getSchemaRegistry().loadSchemas(imported); + } + } + + if (monitor != null) { + monitor.cachingDefinition(definitionNamespace, location); + } + definitionsByLocation.put(location, definition); + List definitions = definitionsByNamespace.get(definitionNamespace); + if (definitions == null) { + definitions = new ArrayList(); + definitionsByNamespace.put(definitionNamespace, definitions); + } + definitions.add(definition); + + return definition; + } + + public PortType getPortType(QName name) { + String namespace = name.getNamespaceURI(); + List definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + PortType portType = definition.getPortType(name); + if (portType != null) { + return portType; + } + } + return null; + } + + public Service getService(QName name) { + String namespace = name.getNamespaceURI(); + List definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + Service service = definition.getService(name); + if (service != null) { + return service; + } + } + return null; + } + + public static interface Monitor { + /** + * Monitor event emitted immediately before an attempt is made to read WSDL for the supplied namespace from the + * supplied location. + * + * @param namespace the target namespace expected in the WSDL; may be null + * @param location the location where we will attempt to read the WSDL definition from + */ + void readingWSDL(String namespace, URL location); + + /** + * Monitor event emitted immediately before registering a WSDL definition in the cache. + * + * @param namespace the target namespace for the WSDL + * @param location the location where the WSDL definition was read from + */ + void cachingDefinition(String namespace, URL location); + } + + public XMLSchemaRegistry getSchemaRegistry() { + if (schemaRegistry == null) { + // Default + schemaRegistry = new XMLSchemaRegistryImpl(); + } + return schemaRegistry; + } + + public Definition getDefinition(String wsdlNamespace) { + List definitions = definitionsByNamespace.get(wsdlNamespace); + if (definitions == null || definitions.size() < 1) { + return null; + } else { + return definitions.get(0); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java new file mode 100644 index 0000000000..fb90e839f5 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java @@ -0,0 +1,110 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.URI; +import java.util.Collection; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; + +/** + * Interface for implementations that allow WSDL definitions to be loaded. Currently we do not have a complete solution + * for handling both WSDL2.0 and WSDL1.1 definitions so the current implementation only deals with loading WSDL1.1. This + * will change in the near future (for example when Woden supports both forms) so all WSDL1.1 specific methods are + * deprecated. + * + * @version $Rev$ $Date$ + */ +public interface WSDLLoader { + /** + * Load a WSDL 1.1 Definition for a namespace from one of specified locations. + * + * @param namespace the namespace whose definition should be loaded + * @param locations a set of possible locations to load from + * @return the loaded Definition + * @throws WSDLException if there was a problem loading the definition + */ + @Deprecated + Definition loadDefinition(String namespace, Collection locations) + throws WSDLException, UnresolveableResourceException; + + /** + * Load a WSDL 1.1 Definition from the specified location + * + * @param location the location to load from + * @return the loaded Definition + * @throws WSDLException if there was a problem loading the definition + */ + @Deprecated + Definition loadDefinition(WSDLLocation location) throws WSDLException; + + /** + * Return the WSDL1.1 PortType for the specified interface IRI. + * + * @param interfaceIRI the WSDL2.0 interface IRI + * @param wsdlLocation the location of the WSDL instance + * @param base a Classloader from which to load + * @return the specified port type + */ + @Deprecated + PortType loadPortType(URI interfaceIRI, String wsdlLocation, ClassLoader base) + throws WSDLLoaderException, WSDLException; + + /** + * Parses a WSDL2.0 wsdlLocation attribute definition and returns a Collection of all locations it contains. + * + * @param wsdlLocation a list of namespace/location pairs as specified by WSDL2.0 + * @param base a ClassLoader to use to resolve relative URLs + * @return a collection of locations parsed from the string + * @throws InvalidWSDLLocationException + */ + Collection getLocations(String wsdlLocation, ClassLoader base) throws InvalidWSDLLocationException; + + /** + * Returns the fully qualified name of a WSDL interface parsed from a IRI as defined by WSDL2.0. The value of the + * IRI defines the namespace, the fragment specifies the interface component; for example + * http://example.org/TicketAgent.wsdl20#wsdl.interface(TicketAgent) + * + * @param interfaceIRI the IRI for the interface + * @return the qualified name of the interface + * @throws UnresolveableResourceException if the URI is relative + * @throws InvalidFragmentException if the fragment is incorrectly formed + */ + QName getInterfaceName(URI interfaceIRI) throws UnresolveableResourceException, InvalidFragmentException; + + /** + * Returns an interface parsed from a wsdl.interface fragment. + * + * @param fragment the fragment value + * @return the interface name + * @throws InvalidFragmentException if the fragment is incorrectly formed + */ + String getInterfaceName(String fragment) throws InvalidFragmentException; + + /** + * Returns a namespace parsed from an IRI. This is the URI with any fragment removed. + * + * @param iri the IRI + * @return a namespace created by stripping fragment information from the URI + * @throws UnresolveableResourceException if the URI is relative + */ + String getNamespace(URI iri) throws UnresolveableResourceException; +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java new file mode 100644 index 0000000000..1fececa62c --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.idl.wsdl; + +import org.apache.tuscany.api.TuscanyException; + +/** + * @version $Rev$ $Date$ + */ +public abstract class WSDLLoaderException extends TuscanyException { + protected WSDLLoaderException() { + } + + protected WSDLLoaderException(String message) { + super(message); + } + + protected WSDLLoaderException(String message, String identifier) { + super(message, identifier); + } + + protected WSDLLoaderException(String message, Throwable cause) { + super(message, cause); + } + + protected WSDLLoaderException(Throwable cause) { + super(cause); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java new file mode 100644 index 0000000000..ebf8cafedc --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java @@ -0,0 +1,141 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class WSDLLoaderImpl implements WSDLLoader { + private final WSDLFactory wsdlFactory; + + private final ExtensionRegistry registry; + + public WSDLLoaderImpl() throws WSDLException { + wsdlFactory = WSDLFactory.newInstance(); + registry = wsdlFactory.newPopulatedExtensionRegistry(); + } + + public PortType loadPortType(URI interfaceIRI, String wsdlLocation, ClassLoader base) + throws WSDLLoaderException, WSDLException { + Collection locations = getLocations(wsdlLocation, base); + QName interfaceName = getInterfaceName(interfaceIRI); + + Definition definition = loadDefinition(interfaceName.getNamespaceURI(), locations); + return definition.getPortType(interfaceName); + } + + public Definition loadDefinition(String namespace, Collection locations) + throws WSDLException, UnresolveableResourceException { + for (WSDLLocation location : locations) { + if (namespace.equals(location.getNamespace()) && location.getLocation() != null) { + return loadDefinition(location); + } + } + throw new UnresolveableResourceException(namespace); + } + + public Definition loadDefinition(WSDLLocation location) throws WSDLException { + String namespace = location.getNamespace(); + + WSDLReader reader = wsdlFactory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setExtensionRegistry(registry); + + Definition definition = reader.readWSDL(location.getLocation().toString()); + String definitionNamespace = definition.getTargetNamespace(); + if (namespace != null && !namespace.equals(definitionNamespace)) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + + definition.getTargetNamespace()); + } + return definition; + } + + public Collection getLocations(String wsdlLocation, ClassLoader base) + throws InvalidWSDLLocationException { + String parts[] = wsdlLocation.split("\\s"); + // check the number of parts is a multiple of two + if ((parts.length & 1) != 0) { + throw new InvalidWSDLLocationException(wsdlLocation); + } + List locations = new ArrayList(parts.length >>> 1); + for (int i = 0; i < parts.length; i += 2) { + URL url; + try { + URI uri = new URI(parts[i + 1]); + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = base.getResource(uri.toString()); + } + } catch (MalformedURLException e) { + throw new InvalidWSDLLocationException(e); + } catch (URISyntaxException e) { + throw new InvalidWSDLLocationException(e); + } + WSDLLocation location = new WSDLLocation(parts[i], url); + locations.add(location); + } + return locations; + } + + public QName getInterfaceName(URI interfaceIRI) throws UnresolveableResourceException, InvalidFragmentException { + String namespace = getNamespace(interfaceIRI); + String interfaceName = getInterfaceName(interfaceIRI.getFragment()); + return new QName(namespace, interfaceName); + } + + public String getInterfaceName(String fragment) throws InvalidFragmentException { + if (fragment == null) { + throw new InvalidFragmentException("missing fragment"); + } + String[] parts = fragment.split("\\s"); + for (String part : parts) { + if (part.startsWith("wsdl.interface(") && part.charAt(part.length() - 1) == ')') { + return part.substring(15, part.length() - 1); + } + } + throw new InvalidFragmentException(fragment); + } + + public String getNamespace(URI iri) throws UnresolveableResourceException { + if (!iri.isAbsolute()) { + throw new UnresolveableResourceException("No namespace defined in", iri.toString()); + } + StringBuilder s = new StringBuilder(); + s.append(iri.getScheme()); + s.append(':'); + s.append(iri.getSchemeSpecificPart()); + return s.toString(); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java new file mode 100644 index 0000000000..a124294c3a --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java @@ -0,0 +1,60 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.URL; + +/** + * A location where the WSDL for a namespace can be found. + * + * @version $Rev$ $Date$ + */ +public class WSDLLocation { + private final String namespace; + private final URL location; + + /** + * Constructor specifying a namespace and where its WSDL can be found. + * + * @param namespace the target namespace + * @param location the location of the WSDL + */ + public WSDLLocation(String namespace, URL location) { + this.namespace = namespace; + this.location = location; + } + + /** + * Returns the target namespace. + * + * @return the target namespace + */ + public String getNamespace() { + return namespace; + } + + /** + * Returns the location where the WSDL definition can be found. + * + * @return the location where the WSDL definition can be found + */ + public URL getLocation() { + return location; + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java new file mode 100644 index 0000000000..2cc501ac9e --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java @@ -0,0 +1,525 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.DataBinding; +import org.apache.tuscany.spi.idl.ElementInfo; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.ServiceFaultException; +import org.apache.tuscany.spi.idl.TypeInfo; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.WrapperInfo; +import org.apache.tuscany.spi.model.DataType; + +import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaObject; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; +import org.apache.ws.commons.schema.XmlSchemaParticle; +import org.apache.ws.commons.schema.XmlSchemaSequence; +import org.apache.ws.commons.schema.XmlSchemaSimpleType; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * Metadata for a WSDL operation + * + * @version $Rev$ $Date$ + */ +public class WSDLOperation { + protected XMLSchemaRegistry schemaRegistry; + protected Operation operation; + protected org.apache.tuscany.spi.model.Operation operationModel; + protected DataType>> inputType; + protected DataType outputType; + protected List> faultTypes; + private String dataBinding; + + /** + * @param operation The WSDL4J operation + * @param dataBinding The default databinding + * @param schemaRegistry The XML Schema registry + */ + public WSDLOperation(Operation operation, String dataBinding, XMLSchemaRegistry schemaRegistry) { + super(); + this.operation = operation; + this.dataBinding = dataBinding; + this.schemaRegistry = schemaRegistry; + this.wrapper = new Wrapper(); + } + + private Wrapper wrapper; + + private Boolean wrapperStyle; + + /** + * Test if the operation qualifies wrapper style as defined by the JAX-WS + * 2.0 spec + * + * @return true if the operation qualifies wrapper style, otherwise false + */ + public boolean isWrapperStyle() throws InvalidWSDLException { + if (wrapperStyle == null) { + wrapperStyle = + wrapper.getInputChildElements() != null && (operation.getOutput() == null || wrapper + .getOutputChildElements() != null); + } + return wrapperStyle; + } + + public Wrapper getWrapper() throws InvalidWSDLException { + if (!isWrapperStyle()) { + throw new IllegalStateException("The operation is not wrapper style."); + } else { + return wrapper; + } + } + + /** + * @return + * @throws InvalidServiceContractException + */ + public DataType>> getInputType() throws InvalidServiceContractException { + if (inputType == null) { + Input input = operation.getInput(); + Message message = (input == null) ? null : input.getMessage(); + inputType = getMessageType(message); + inputType.setDataBinding(DataBinding.IDL_INPUT); + } + return inputType; + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public DataType getOutputType() throws InvalidServiceContractException { + if (outputType == null) { + Output output = operation.getOutput(); + Message outputMsg = (output == null) ? null : output.getMessage(); + + List outputParts = (outputMsg == null) ? null : outputMsg.getOrderedParts(null); + if (outputParts != null && outputParts.size() > 0) { + if (outputParts.size() > 1) { + // We don't support output with multiple parts + throw new NotSupportedWSDLException("Multi-part output is not supported"); + } + Part part = (Part)outputParts.get(0); + outputType = new WSDLPart(part, Object.class).getDataType(); + // outputType.setMetadata(WSDLOperation.class.getName(), this); + } + } + return outputType; + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public List> getFaultTypes() throws InvalidServiceContractException { + if (faultTypes == null) { + Collection faults = operation.getFaults().values(); + faultTypes = new ArrayList>(); + for (Object f : faults) { + Fault fault = (Fault)f; + Message faultMsg = fault.getMessage(); + List faultParts = faultMsg.getOrderedParts(null); + if (faultParts.size() != 1) { + throw new NotSupportedWSDLException("The fault message MUST have a single part"); + } + Part part = (Part)faultParts.get(0); + WSDLPart wsdlPart = new WSDLPart(part, ServiceFaultException.class); + faultTypes.add(wsdlPart.getDataType()); + } + } + return faultTypes; + } + + private DataType>> getMessageType(Message message) throws InvalidServiceContractException { + List> partTypes = new ArrayList>(); + if (message != null) { + Collection parts = message.getOrderedParts(null); + for (Object p : parts) { + WSDLPart part = new WSDLPart((Part)p, Object.class); + DataType partType = part.getDataType(); + partTypes.add(partType); + } + } + return new DataType>>(dataBinding, Object[].class, partTypes); + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public org.apache.tuscany.spi.model.Operation getOperation() throws InvalidServiceContractException { + if (operationModel == null) { + boolean oneway = (operation.getOutput() == null); + operationModel = + new org.apache.tuscany.spi.model.Operation( + operation.getName(), + getInputType(), + getOutputType(), + getFaultTypes(), + oneway, + dataBinding, + org.apache.tuscany.spi.model.Operation.NO_CONVERSATION); + operationModel.setWrapperStyle(isWrapperStyle()); + // operationModel.setMetaData(WSDLOperation.class.getName(), this); + if (isWrapperStyle()) { + WrapperInfo wrapperInfo = getWrapper().getWrapperInfo(); + operationModel.setWrapper(wrapperInfo); + // Register the operation with the types + for (DataType d : wrapperInfo.getUnwrappedInputType().getLogical()) { + d.setOperation(operationModel); + } + if (wrapperInfo.getUnwrappedOutputType() != null) { + wrapperInfo.getUnwrappedOutputType().setOperation(operationModel); + } + } + } + inputType.setOperation(operationModel); + if (outputType != null) { + outputType.setOperation(operationModel); + } + return operationModel; + } + + /** + * Metadata for a WSDL part + */ + public class WSDLPart { + private Part part; + + private XmlSchemaElement element; + + private DataType dataType; + + public WSDLPart(Part part, Class javaType) throws InvalidWSDLException { + this.part = part; + QName elementName = part.getElementName(); + if (elementName != null) { + element = schemaRegistry.getElement(elementName); + if (element == null) { + throw new InvalidWSDLException("Element cannot be resolved", elementName.toString()); + } + } else { + // Create an faked XSD element to host the metadata + element = new XmlSchemaElement(); + element.setName(part.getName()); + element.setQName(new QName(null, part.getName())); + QName typeName = part.getTypeName(); + if (typeName != null) { + XmlSchemaType type = schemaRegistry.getType(typeName); + if (type == null) { + throw new InvalidWSDLException("Type cannot be resolved", typeName.toString()); + } + element.setSchemaType(type); + element.setSchemaTypeName(type.getQName()); + } + } + dataType = new DataType(dataBinding, javaType, new XMLType(getElementInfo(element))); + // dataType.setMetadata(WSDLPart.class.getName(), this); + // dataType.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + } + + /** + * @return the element + */ + public XmlSchemaElement getElement() { + return element; + } + + /** + * @return the part + */ + public Part getPart() { + return part; + } + + /** + * @return the dataType + */ + public DataType getDataType() { + return dataType; + } + } + + /** + * The "Wrapper Style" WSDL operation is defined by The Java API for + * XML-Based Web Services (JAX-WS) 2.0 specification, section 2.3.1.2 + * Wrapper Style.

A WSDL operation qualifies for wrapper style mapping + * only if the following criteria are met: + *

    + *
  • (i) The operation’s input and output messages (if present) each + * contain only a single part + *
  • (ii) The input message part refers to a global element declaration + * whose localname is equal to the operation name + *
  • (iii) The output message part refers to a global element declaration + *
  • (iv) The elements referred to by the input and output message parts + * (henceforth referred to as wrapper elements) are both complex types + * defined using the xsd:sequence compositor + *
  • (v) The wrapper elements only contain child elements, they must not + * contain other structures such as wildcards (element or attribute), + * xsd:choice, substitution groups (element references are not permitted) or + * attributes; furthermore, they must not be nillable. + *
+ */ + public class Wrapper { + private XmlSchemaElement inputWrapperElement; + + private XmlSchemaElement outputWrapperElement; + + private List inputElements; + + private List outputElements; + + private DataType>> unwrappedInputType; + + private DataType unwrappedOutputType; + + private transient WrapperInfo wrapperInfo; + + private List getChildElements(XmlSchemaElement element) throws InvalidWSDLException { + if (element == null) { + return null; + } + if (element.isNillable()) { + // Wrapper element cannot be nillable + return null; + } + XmlSchemaType type = element.getSchemaType(); + if (type == null) { + String qName = element.getQName().toString(); + throw new InvalidWSDLException("The XML schema element does not have a type", qName); + } + if (!(type instanceof XmlSchemaComplexType)) { + // Has to be a complexType + return null; + } + XmlSchemaComplexType complexType = (XmlSchemaComplexType)type; + if (complexType.getAttributes().getCount() != 0 || complexType.getAnyAttribute() != null) { + // No attributes + return null; + } + XmlSchemaParticle particle = complexType.getParticle(); + if (particle == null) { + // No particle + return Collections.emptyList(); + } + if (!(particle instanceof XmlSchemaSequence)) { + return null; + } + XmlSchemaSequence sequence = (XmlSchemaSequence)complexType.getParticle(); + XmlSchemaObjectCollection items = sequence.getItems(); + List childElements = new ArrayList(); + for (int i = 0; i < items.getCount(); i++) { + XmlSchemaObject schemaObject = items.getItem(i); + if (!(schemaObject instanceof XmlSchemaElement)) { + return null; + } + XmlSchemaElement childElement = (XmlSchemaElement)schemaObject; + if (childElement.getName() == null || childElement.getRefName() != null) { + return null; + } + // TODO: Do we support maxOccurs >1 ? + if (childElement.getMaxOccurs() > 1) { + return null; + } + childElements.add(childElement); + } + return childElements; + } + + /** + * Return a list of child XSD elements under the wrapped request element + * + * @return a list of child XSD elements or null if if the request + * element is not wrapped + */ + public List getInputChildElements() throws InvalidWSDLException { + if (inputElements != null) { + return inputElements; + } + Input input = operation.getInput(); + if (input != null) { + Message inputMsg = input.getMessage(); + Collection parts = inputMsg.getParts().values(); + if (parts.size() != 1) { + return null; + } + Part part = (Part)parts.iterator().next(); + QName elementName = part.getElementName(); + if (elementName == null) { + return null; + } + if (!operation.getName().equals(elementName.getLocalPart())) { + return null; + } + inputWrapperElement = schemaRegistry.getElement(elementName); + if (inputWrapperElement == null) { + throw new InvalidWSDLException("The element is not declared in a XML schema", elementName + .toString()); + } + inputElements = getChildElements(inputWrapperElement); + return inputElements; + } else { + return null; + } + } + + /** + * Return a list of child XSD elements under the wrapped response + * element + * + * @return a list of child XSD elements or null if if the response + * element is not wrapped + */ + public List getOutputChildElements() throws InvalidWSDLException { + if (outputElements != null) { + return outputElements; + } + Output output = operation.getOutput(); + if (output != null) { + Message outputMsg = output.getMessage(); + Collection parts = outputMsg.getParts().values(); + if (parts.size() != 1) { + return null; + } + Part part = (Part)parts.iterator().next(); + QName elementName = part.getElementName(); + if (elementName == null) { + throw new InvalidWSDLException("The element is not declared in the XML schema", part.getName()); + } + outputWrapperElement = schemaRegistry.getElement(elementName); + if (outputWrapperElement == null) { + return null; + } + outputElements = getChildElements(outputWrapperElement); + // FIXME: Do we support multiple child elements for the + // response? + return outputElements; + } else { + return null; + } + } + + /** + * @return the inputWrapperElement + */ + public XmlSchemaElement getInputWrapperElement() { + return inputWrapperElement; + } + + /** + * @return the outputWrapperElement + */ + public XmlSchemaElement getOutputWrapperElement() { + return outputWrapperElement; + } + + /* + public DataType>> getUnwrappedInputType() throws InvalidWSDLException { + if (unwrappedInputType == null) { + List> childTypes = new ArrayList>(); + for (XmlSchemaElement element : getInputChildElements()) { + DataType type = + new DataType(dataBinding, Object.class, new XMLType(getElementInfo(element))); + // type.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + childTypes.add(type); + } + unwrappedInputType = + new DataType>>("idl:unwrapped.input", Object[].class, childTypes); + } + return unwrappedInputType; + } + + public DataType getUnwrappedOutputType() throws InvalidServiceContractException { + if (unwrappedOutputType == null) { + List elements = getOutputChildElements(); + if (elements != null && elements.size() > 0) { + if (elements.size() > 1) { + // We don't support output with multiple parts + throw new NotSupportedWSDLException("Multi-part output is not supported"); + } + XmlSchemaElement element = elements.get(0); + unwrappedOutputType = + new DataType(dataBinding, Object.class, new XMLType(getElementInfo(element))); + // unwrappedOutputType.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + } + } + return unwrappedOutputType; + } + */ + + public WrapperInfo getWrapperInfo() throws InvalidServiceContractException { + if (wrapperInfo == null) { + ElementInfo in = getElementInfo(getInputWrapperElement()); + ElementInfo out = getElementInfo(getOutputWrapperElement()); + List inChildren = new ArrayList(); + for (XmlSchemaElement e : getInputChildElements()) { + inChildren.add(getElementInfo(e)); + } + List outChildren = new ArrayList(); + if (out != null) { + for (XmlSchemaElement e : getOutputChildElements()) { + outChildren.add(getElementInfo(e)); + } + } + wrapperInfo = + new WrapperInfo(dataBinding, in, out, inChildren, outChildren); + } + return wrapperInfo; + } + } + + private static ElementInfo getElementInfo(XmlSchemaElement element) { + if (element == null) { + return null; + } + return new ElementInfo(element.getQName(), getTypeInfo(element.getSchemaType())); + } + + private static TypeInfo getTypeInfo(XmlSchemaType type) { + if (type == null) { + return null; + } + XmlSchemaType baseType = (XmlSchemaType)type.getBaseSchemaType(); + QName name = type.getQName(); + boolean simple = (type instanceof XmlSchemaSimpleType); + if (baseType == null) { + return new TypeInfo(name, simple, null); + } else { + return new TypeInfo(name, simple, getTypeInfo(baseType)); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java new file mode 100644 index 0000000000..f498dc66ea --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java @@ -0,0 +1,60 @@ +/* + * 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.tuscany.idl.wsdl; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * Represents a service contract specified by a WSDL + * + * @version $Rev$ $Date$ + */ +public class WSDLServiceContract extends ServiceContract { + private PortType portType; + private PortType callbackPortType; + + /** + * + */ + public WSDLServiceContract() { + super(); + this.remotable = true; // WSDL interface is always remotable by the SCA spec + } + + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public PortType getCallbackPortType() { + return callbackPortType; + } + + public void setCallbackPortType(PortType callbackPortType) { + this.callbackPortType = callbackPortType; + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java new file mode 100644 index 0000000000..681e08be4d --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java @@ -0,0 +1,87 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * A service for caching XML Schemas + * + * @version $Rev$ $Date$ + */ +public interface XMLSchemaRegistry { + /** + * Load all inline schemas from the WSDL definition + * + * @param definition The WSDL defintion whose types element contains a list of schemas + * @return A list of inline schemas + */ + List loadSchemas(Definition definition); + + /** + * Loads and registers a XML schema. + * + * @param namespace the expected namespace, or null if any namespace should be allowed + * @param location the location to load the schema from + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws XmlSchemaException if there was a problem parsing the schema + */ + XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException; + + /** + * Load and register a XML schema as specified in a XSD schemaLocation attribute. + * + * @param schemaLocation the value of the schemaLocation attribute + * @param classLoader application classloader used to support relative locations + * @return the loaded schema + * @throws IOException if there was a problem reading the document + * @throws XmlSchemaException if there was a problem parsing the schema + */ + XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException; + + /** + * Returns the XSD Element with the supplied qualified name, or null if no such element has been defined. + * + * @param name the qualified name of the XSD element + * @return the XSD element for the supplied name, or null if none has been defined + */ + XmlSchemaElement getElement(QName name); + + /** + * Returns the XmlSchemaType with the supplied qualified name, or null if no such type has been defined. + * + * @param name the qualified name of the XSD type + * @return the XSD type for the supplied name, or null if none has been defined + */ + XmlSchemaType getType(QName name); + + + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java new file mode 100644 index 0000000000..08600e4b7e --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java @@ -0,0 +1,129 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.schema.Schema; +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaType; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Element; + +/** + * Default implementation of XMLSchemaRegistry + */ +@Service(XMLSchemaRegistry.class) +public class XMLSchemaRegistryImpl implements XMLSchemaRegistry { + private final XmlSchemaCollection collection; + + /** + * @param collection + */ + public XMLSchemaRegistryImpl(XmlSchemaCollection collection) { + super(); + this.collection = collection; + } + + public XMLSchemaRegistryImpl() { + super(); + this.collection = new XmlSchemaCollection(); + } + + public XmlSchemaElement getElement(QName name) { + return collection.getElementByQName(name); + } + + public XmlSchemaType getType(QName name) { + return collection.getTypeByQName(name); + } + + public List loadSchemas(Definition definition) { + Types types = definition.getTypes(); + if (types == null) { + return Collections.emptyList(); + } + List schemas = new ArrayList(); + for (Object ext : types.getExtensibilityElements()) { + if (ext instanceof Schema) { + Element element = ((Schema) ext).getElement(); + XmlSchema s = collection.read(element, element.getBaseURI()); + schemas.add(s); + } + } + return schemas; + } + + public XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException { + XmlSchema schema; + XmlSchema[] schemaList = collection.getXmlSchema(location.toExternalForm()); + if (schemaList != null && schemaList.length > 0) { + schema = schemaList[0]; + } else { + InputStream is = location.openStream(); + schema = collection.read(new InputStreamReader(is), null); + is.close(); + } + if (namespace != null && schema != null && !namespace.equals(schema.getTargetNamespace())) { + throw new XmlSchemaException(namespace + " != " + schema.getTargetNamespace()); + } + return schema; + } + + public XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException { + int index = schemaLocation.indexOf(' '); + if (index == -1) { + throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation); + } + String namespace = schemaLocation.substring(0, index).trim(); + URL url; + URI uri; + try { + uri = new URI(schemaLocation.substring(index + 1).trim()); + } catch (URISyntaxException e) { + throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation); + } + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = classLoader.getResource(uri.toString()); + if (url == null) { + throw new XmlSchemaException("Resource cannot be resolved: schemaLocation: " + schemaLocation); + } + } + return loadSchema(namespace, url); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java new file mode 100644 index 0000000000..43c5c05ea4 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessor.java @@ -0,0 +1,136 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URL; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.schema.Schema; + +import org.apache.tuscany.host.deployment.DeploymentException; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry; +import org.apache.tuscany.spi.extension.ContributionProcessorExtension; +import org.apache.tuscany.spi.model.Contribution; +import org.apache.tuscany.spi.model.DeployedArtifact; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.resolver.URIResolver; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; + +/** + * The XSD processor + * + * @version $Rev$ $Date$ + */ +public class XSDContributionProcessor extends ContributionProcessorExtension { + + private ArtifactResolverRegistry artifactResolverRegistry; + + public XSDContributionProcessor() throws WSDLException { + } + + /** + * URI resolver implementation for xml schema + */ + protected class URIResolverImpl implements URIResolver { + private Contribution contribution; + + public URIResolverImpl(Contribution contriution) { + this.contribution = contriution; + } + + public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, + java.lang.String schemaLocation, + java.lang.String baseUri) { + try { + URL url = artifactResolverRegistry.resolve(contribution, targetNamespace, schemaLocation, baseUri); + return new InputSource(url.openStream()); + } catch (IOException e) { + return null; + } + } + + } + + @SuppressWarnings("unchecked") + public XmlSchema loadSchema(Contribution contribution, String namespace, URI location, InputStream inputStream) + throws IOException, DeploymentException { + XmlSchemaCollection collection = new XmlSchemaCollection(); + collection.setSchemaResolver(new URIResolverImpl(contribution)); + XmlSchema schema = collection.read(new InputStreamReader(inputStream), null); + + if (namespace != null && schema != null && !namespace.equals(schema.getTargetNamespace())) { + throw new XmlSchemaException(namespace + " != " + schema.getTargetNamespace()); + } + + DeployedArtifact artifact = contribution.getArtifact(location); + artifact.addModelObject(XmlSchema.class, schema.getTargetNamespace(), schema); + return schema; + } + + public void loadSchemas(Contribution contribution, URI source, Definition definition) { + Types types = definition.getTypes(); + if (types != null) { + DeployedArtifact artifact = contribution.getArtifact(source); + XmlSchemaCollection collection = new XmlSchemaCollection(); + for (Object ext : types.getExtensibilityElements()) { + if (ext instanceof Schema) { + Element element = ((Schema)ext).getElement(); + XmlSchema s = collection.read(element, element.getBaseURI()); + artifact.addModelObject(XmlSchema.class, s.getTargetNamespace(), s); + } + } + } + } + + public String getContentType() { + return "application/vnd.tuscany.xsd"; + } + + /** + * @param artifactResolverRegistry the artifactResolverRegistry to set + */ + @Autowire + public void setArtifactResolverRegistry(ArtifactResolverRegistry artifactResolverRegistry) { + this.artifactResolverRegistry = artifactResolverRegistry; + } + + public void processContent(Contribution contribution, URI source, InputStream inputStream) + throws DeploymentException, IOException { + loadSchema(contribution, null, source, inputStream); + } + + public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException, + IOException { + if (modelObject instanceof Definition) { + loadSchemas(contribution, source, (Definition)modelObject); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..266b74ffe1 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,50 @@ + + + + + + + org.apache.tuscany.sca.services.idl + wsdl + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/extension.composite b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/extension.composite new file mode 100644 index 0000000000..e689b1f23e --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/extension.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl new file mode 100644 index 0000000000..666f5f9bcf --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl @@ -0,0 +1,52 @@ + + + + + + + org.apache.tuscany.sca.services.idl + wsdl + 0.1-integration-incubating-SNAPSHOT + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java new file mode 100644 index 0000000000..7cc17d6e65 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java @@ -0,0 +1,83 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.URL; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; + +/** + * Test case for InterfaceWSDLIntrospectorImpl + */ +public class InterfaceWSDLIntrospectorImplTestCase extends TestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + private PortType portType; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + portType = definition.getPortType(PORTTYPE_NAME); + } + + public final void testIntrospectPortType() throws InvalidServiceContractException { + InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry); + WSDLServiceContract contract = introspector.introspect(portType); + Assert.assertEquals(contract.getInterfaceName(), "StockQuotePortType"); + Map> operations = contract.getOperations(); + Assert.assertEquals(1, operations.size()); + Operation operation = operations.get("getLastTradePrice"); + Assert.assertNotNull(operation); + DataType>> inputType = operation.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + DataType returnType = operation.getOutputType(); + Assert.assertNotNull(returnType); + Assert.assertEquals(0, operation.getFaultTypes().size()); + Assert.assertEquals(1, operation.getWrapper().getInputChildElements().size()); + Assert.assertEquals(1, operation.getWrapper().getOutputChildElements().size()); + } + + public final void testIntrospectPortTypePortType() throws InvalidServiceContractException { + InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry); + WSDLServiceContract contract = introspector.introspect(portType, portType); + Assert.assertEquals("StockQuotePortType", contract.getInterfaceName()); + Assert.assertEquals("StockQuotePortType", contract.getCallbackName()); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java new file mode 100644 index 0000000000..ee4143af48 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLContributionProcessorTestCase.java @@ -0,0 +1,86 @@ +/* + * 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.tuscany.idl.wsdl; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.isNull; +import static org.easymock.EasyMock.replay; + +import java.net.URI; +import java.net.URL; + +import javax.wsdl.Definition; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry; +import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry; +import org.apache.tuscany.spi.model.Contribution; +import org.apache.tuscany.spi.model.DeployedArtifact; + +/** + * @version $Rev$ $Date$ + */ +public class WSDLContributionProcessorTestCase extends TestCase { + private WSDLContributionProcessor processor; + + protected void setUp() throws Exception { + super.setUp(); + processor = new WSDLContributionProcessor(); + ArtifactResolverRegistry registry = createMock(ArtifactResolverRegistry.class); + URL url = getClass().getResource("test2.wsdl"); + expect(registry.resolve(isA(Contribution.class), + (String)isNull(), + isA(String.class), + isA(String.class))).andReturn(url).anyTimes(); + processor.setArtifactResolverRegistry(registry); + replay(registry); + + ContributionProcessorRegistry processorRegistry = createMock(ContributionProcessorRegistry.class); + processorRegistry.processModel(isA(Contribution.class), isA(URI.class), isA(Definition.class)); + expectLastCall().anyTimes(); + replay(processorRegistry); + processor.setContributionProcessorRegistry(processorRegistry); + } + + public void testLoad() throws Exception { + URI uri = URI.create("sca://contribution/001"); + Contribution contribution = new Contribution(uri); + + addArtifact(contribution, "sca://contribution/001/test1.wsdl"); + addArtifact(contribution, "sca://contribution/001/test2.wsdl"); + addArtifact(contribution, "sca://contribution/001/ipo.xsd"); + + URL url = getClass().getResource("test1.wsdl"); + try { + processor.processContent(contribution, URI.create("sca://contribution/001/test1.wsdl"), url.openStream()); + } catch (Throwable e) { + fail(e.getMessage()); + } + } + + private DeployedArtifact addArtifact(Contribution contribution, String artifact) { + DeployedArtifact a1 = new DeployedArtifact(URI.create(artifact)); + contribution.addArtifact(a1); + return a1; + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java new file mode 100644 index 0000000000..d878b465a8 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java @@ -0,0 +1,91 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; +import junit.framework.Assert; + +/** + * Verifies the default WSDL registry implementation + * + * @version $Rev$ $Date$ + */ +public class WSDLDefinitionRegistryTestCase extends TestCase { + private static final String NS = "http://www.example.org"; + private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { + public void readingWSDL(String namespace, URL location) { + } + + public void cachingDefinition(String namespace, URL location) { + } + }; + private WSDLDefinitionRegistryImpl wsdlRegistry; + private ClassLoader cl; + private URL exampleWsdl; + + + public void testLoadFromAbsoluteWSDLLocation() { + try { + Definition def = wsdlRegistry.loadDefinition(NS + ' ' + exampleWsdl, cl); + Assert.assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } catch (WSDLException e) { + Assert.fail(e.getMessage()); + } + } + + public void testLoadFromRelativeWSDLLocation() { + try { + Definition def = wsdlRegistry.loadDefinition(NS + " org/apache/tuscany/idl/wsdl/example.wsdl", cl); + Assert.assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } catch (WSDLException e) { + Assert.fail(e.getMessage()); + } + } + + public void testGetDefinition() { + try { + wsdlRegistry.loadDefinition(NS + ' ' + exampleWsdl, cl); + Assert.assertNotNull(wsdlRegistry.getDefinition(NS)); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } catch (WSDLException e) { + Assert.fail(e.getMessage()); + } + } + + protected void setUp() throws Exception { + super.setUp(); + wsdlRegistry = new WSDLDefinitionRegistryImpl(); + wsdlRegistry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + wsdlRegistry.setMonitor(NULL_MONITOR); + exampleWsdl = getClass().getResource("example.wsdl"); + cl = getClass().getClassLoader(); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java new file mode 100644 index 0000000000..c05cf9770f --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java @@ -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.tuscany.idl.wsdl; + +import java.net.URI; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class WSDLLoaderImplTestCase extends TestCase { + private WSDLLoaderImpl loader; + private URI exampleURI; + private QName exampleName; + + public void testGetNamespace() throws UnresolveableResourceException { + assertEquals("http://example.org/TicketAgent.wsdl20", loader.getNamespace(exampleURI)); + } + + public void testGetInterfaceNameFromFragment() throws UnresolveableResourceException, InvalidFragmentException { + assertEquals("TicketAgent", loader.getInterfaceName("wsdl.interface(TicketAgent)")); + } + + public void testGetInterfaceNameFromURI() throws UnresolveableResourceException, InvalidFragmentException { + assertEquals(exampleName, loader.getInterfaceName(exampleURI)); + } + + protected void setUp() throws Exception { + super.setUp(); + loader = new WSDLLoaderImpl(); + exampleURI = URI.create("http://example.org/TicketAgent.wsdl20#wsdl.interface(TicketAgent)"); + exampleName = new QName("http://example.org/TicketAgent.wsdl20", "TicketAgent"); + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java new file mode 100644 index 0000000000..b61db4c5d9 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java @@ -0,0 +1,115 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.XMLType; +import org.apache.tuscany.spi.model.DataType; + +/** + * Test case for WSDLOperation + */ +public class WSDLOperationTestCase extends TestCase { + private static final QName PORTTYPE_NAME = + new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + } + + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + + DataType>> inputType = op.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePrice"), inputType + .getLogical().get(0).getLogical().getElementName()); + + DataType outputType = op.getOutputType(); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePriceResponse"), + outputType.getLogical().getElementName()); + Assert.assertTrue(op.isWrapperStyle()); + + DataType>> unwrappedInputType = op.getWrapper().getWrapperInfo().getUnwrappedInputType(); + List> childTypes = unwrappedInputType.getLogical(); + Assert.assertEquals(1, childTypes.size()); + DataType childType = childTypes.get(0); + Assert.assertEquals(new QName(null, "tickerSymbol"), childType.getLogical().getElementName()); + + childType = op.getWrapper().getWrapperInfo().getUnwrappedOutputType(); + Assert.assertEquals(new QName(null, "price"), childType.getLogical().getElementName()); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("unwrapped-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(1, op.getInputType().getLogical().size()); + + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(2, op.getInputType().getLogical().size()); + } + + public final void testInvalidWSDL() throws Exception { + URL url = getClass().getResource("invalid-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + + try { + op.isWrapperStyle(); + fail("InvalidWSDLException should have been thrown"); + } catch (InvalidWSDLException e) { + // Expected + } + + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java new file mode 100644 index 0000000000..748c790297 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.net.URL; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Test case for WSDLOperation + */ +public class WrapperStyleOperationTestCase extends TestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + } + + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertTrue(op.isWrapperStyle()); + Assert.assertEquals(1, op.getWrapper().getInputChildElements().size()); + Assert.assertEquals(1, op.getWrapper().getOutputChildElements().size()); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("unwrapped-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java new file mode 100644 index 0000000000..60433d3bc1 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java @@ -0,0 +1,105 @@ +/* + * 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.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; +import org.apache.ws.commons.schema.XmlSchemaSequence; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * Verifies the default XSD registry implementation + * + * @version $Rev$ $Date$ + */ +public class XMLSchemaRegistryImplTestCase extends TestCase { + private static final QName PO_ELEMENT_NAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private static final QName PO_TYPE_NAME = new QName("http://www.example.com/IPO", "PurchaseOrderType"); + + private static final String NS = "http://example.com/stockquote.xsd"; + private static final QName GET_LAST_TRADE_PRICE_ELEMENT_NAME = new QName(NS, "getLastTradePrice"); + + private XMLSchemaRegistryImpl xsdRegistry; + + private WSDLDefinitionRegistryImpl wsdlRegistry; + + private ClassLoader cl; + + private URL wsdl; + + public void testLoadFromAbsoluteWSDLLocation() { + try { + Definition definition = wsdlRegistry.loadDefinition(null, wsdl); + List schemas = xsdRegistry.loadSchemas(definition); + Assert.assertTrue(schemas.size() == 1); + XmlSchema schema = schemas.get(0); + XmlSchemaElement element = schema.getElementByName(GET_LAST_TRADE_PRICE_ELEMENT_NAME); + Assert.assertNotNull(element); + XmlSchemaType type = element.getSchemaType(); + XmlSchemaComplexType complexType = (XmlSchemaComplexType) type; + XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle(); + XmlSchemaObjectCollection items = sequence.getItems(); + Assert.assertTrue(items.getItem(0) instanceof XmlSchemaElement); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + public void testSchemaLocation() throws IOException { + String schemaLocation = "http://www.example.com/IPO org/apache/tuscany/idl/wsdl/ipo.xsd"; + XmlSchema schema = xsdRegistry.loadSchema(schemaLocation, cl); + Assert.assertNotNull(schema); + Assert.assertNotNull(schema.getElementByName(PO_ELEMENT_NAME)); + Assert.assertNotNull(xsdRegistry.getElement(PO_ELEMENT_NAME)); + Assert.assertNotNull(schema.getTypeByName(PO_TYPE_NAME)); + Assert.assertNotNull(xsdRegistry.getType(PO_TYPE_NAME)); + + + schemaLocation = "http://www.example.com/IPO1 org/apache/tuscany/idl/wsdl/ipo.xsd"; + try { + schema = xsdRegistry.loadSchema(schemaLocation, cl); + Assert.fail(""); + } catch (XmlSchemaException e) { + Assert.assertTrue(e.getMessage().contains("http://www.example.com/IPO1 !=")); + } + } + + protected void setUp() throws Exception { + super.setUp(); + xsdRegistry = new XMLSchemaRegistryImpl(); + wsdlRegistry = new WSDLDefinitionRegistryImpl(); + wsdlRegistry.setSchemaRegistry(xsdRegistry); + wsdl = getClass().getResource("stockquote.wsdl"); + cl = getClass().getClassLoader(); + } + +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java new file mode 100644 index 0000000000..93fc898cc6 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XSDContributionProcessorTestCase.java @@ -0,0 +1,92 @@ +/* + * 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.tuscany.idl.wsdl; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.isNull; +import static org.easymock.EasyMock.replay; + +import java.net.URI; +import java.net.URL; +import java.util.Map; + +import javax.wsdl.Definition; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry; +import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry; +import org.apache.tuscany.spi.model.Contribution; +import org.apache.tuscany.spi.model.DeployedArtifact; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaImport; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; + +/** + * @version $Rev$ $Date$ + */ +public class XSDContributionProcessorTestCase extends TestCase { + private XSDContributionProcessor processor; + + protected void setUp() throws Exception { + super.setUp(); + processor = new XSDContributionProcessor(); + ArtifactResolverRegistry registry = createMock(ArtifactResolverRegistry.class); + URL url = getClass().getResource("ipo.xsd"); + expect(registry.resolve(isA(Contribution.class), isA(String.class), isA(String.class), (String)isNull())).andReturn(url) + .anyTimes(); + processor.setArtifactResolverRegistry(registry); + replay(registry); + + ContributionProcessorRegistry processorRegistry = createMock(ContributionProcessorRegistry.class); + processorRegistry.processModel(isA(Contribution.class), isA(URI.class), isA(Definition.class)); + replay(processorRegistry); + processor.setContributionProcessorRegistry(processorRegistry); + } + + public void testLoad() throws Exception { + URI uri = URI.create("sca://contribution/001"); + Contribution contribution = new Contribution(uri); + + URI a1 = URI.create("sca://contribution/001/test1.xsd"); + addArtifact(contribution, a1); + URI a2 = URI.create("sca://contribution/001/ipo.xsd"); + addArtifact(contribution, a2); + + URL url = getClass().getResource("test1.xsd"); + processor.processContent(contribution, new URI("sca://contribution/001/test1.xsd"), url.openStream()); + DeployedArtifact da1 = contribution.getArtifact(a1); + Map schemas = da1.getModelObjects(XmlSchema.class); + assertEquals(1, schemas.size()); + assertTrue(schemas.containsKey("http://www.example.com/Customer")); + XmlSchema schema = (XmlSchema) schemas.values().iterator().next(); + XmlSchemaObjectCollection includes = schema.getIncludes(); + assertEquals(1, includes.getCount()); + XmlSchemaImport imported = (XmlSchemaImport) includes.getItem(0); + assertEquals("http://www.example.com/IPO", imported.getSchema().getTargetNamespace()); + } + + private DeployedArtifact addArtifact(Contribution contribution, URI artifact) { + DeployedArtifact a1 = new DeployedArtifact(artifact); + contribution.addArtifact(a1); + return a1; + } +} diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl new file mode 100644 index 0000000000..5e8e5dad0d --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl @@ -0,0 +1,26 @@ + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl new file mode 100644 index 0000000000..38f9cb05d2 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd new file mode 100644 index 0000000000..5468542693 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd @@ -0,0 +1,118 @@ + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl new file mode 100644 index 0000000000..7be1c896a3 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl new file mode 100644 index 0000000000..786c602e24 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd new file mode 100644 index 0000000000..fa4328939e --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test1.xsd @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl new file mode 100644 index 0000000000..0cd6819841 --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/test2.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl new file mode 100644 index 0000000000..2fade0036c --- /dev/null +++ b/branches/sca-java-integration/sca/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/pom.xml b/branches/sca-java-integration/sca/services/pom.xml new file mode 100644 index 0000000000..6e57489604 --- /dev/null +++ b/branches/sca-java-integration/sca/services/pom.xml @@ -0,0 +1,63 @@ + + + + + org.apache.tuscany.sca + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + org.apache.tuscany.sca.services + parent + pom + Apache Tuscany SCA Services + + + + + apache.snapshots + Apache Snapshot Repository + http://people.apache.org/repo/m2-snapshot-repository + + false + + + true + + + + apache.incubator + Apache Incubator Repository + http://people.apache.org/repo/m2-incubating-repository/ + + true + + + false + + + + + + idl + databinding + transports/http.jetty + + diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/.ruleset b/branches/sca-java-integration/sca/services/transports/http.jetty/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/LICENSE.txt b/branches/sca-java-integration/sca/services/transports/http.jetty/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/NOTICE.txt b/branches/sca-java-integration/sca/services/transports/http.jetty/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/pom.xml b/branches/sca-java-integration/sca/services/transports/http.jetty/pom.xml new file mode 100644 index 0000000000..1caa4a7d0d --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/pom.xml @@ -0,0 +1,71 @@ + + + + + org.apache.tuscany.sca.services + parent + 0.1-integration-incubating-SNAPSHOT + + 4.0.0 + tuscany-http-jetty + Apache Tuscany Jetty HTTP Service + Tuscany Jetty HTTP Service + + + + org.apache.tuscany.sca.kernel + tuscany-spi + ${sca.version} + compile + + + org.mortbay.jetty + jetty + 6.1.0 + compile + + + org.mortbay.jetty + jetty-util + 6.1.0 + compile + + + javax.servlet + servlet-api + 2.5 + compile + + + org.apache.geronimo.specs + geronimo-j2ee-connector_1.5_spec + compile + + + junit + junit + + + org.easymock + easymock + + + + diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java new file mode 100644 index 0000000000..d42b301fbb --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java @@ -0,0 +1,106 @@ +/* + * 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.tuscany.service.jetty; + +import org.mortbay.log.Logger; + +/** + * Serves as a wrapper for a {@link TransportMonitor} to replace Jetty's logging mechanism + * + * @version $Rev$ $Date$ + */ +public class JettyLogger implements Logger { + + private TransportMonitor monitor; + private boolean debugEnabled; + + public void setMonitor(TransportMonitor monitor) { + this.monitor = monitor; + } + + public boolean isDebugEnabled() { + return debugEnabled; + } + + public void setDebugEnabled(boolean debugEnabled) { + this.debugEnabled = debugEnabled; + } + + public void info(String msg, Object arg0, Object arg1) { + if (monitor != null) { + monitor.debug(msg, arg0, arg1); + } else if (debugEnabled) { + System.err.println(":INFO: " + format(msg, arg0, arg1)); + } + } + + public void debug(String msg, Throwable th) { + if (debugEnabled) { + if (monitor != null) { + monitor.debug(msg, th); + } else { + System.err.println(":DEBUG: " + msg); + th.printStackTrace(); + } + } + } + + public void debug(String msg, Object arg0, Object arg1) { + if (debugEnabled) { + if (monitor != null) { + monitor.debug(msg, arg0, arg1); + } else { + System.err.println(":DEBUG: " + format(msg, arg0, arg1)); + } + } + } + + public void warn(String msg, Object arg0, Object arg1) { + if (monitor != null) { + monitor.warn(msg, arg0, arg1); + } else if (debugEnabled) { + System.err.println(":WARN: " + format(msg, arg0, arg1)); + } + } + + public void warn(String msg, Throwable th) { + if (monitor != null) { + monitor.warn(msg, th); + } else if (debugEnabled) { + System.err.println(":WARN: " + msg); + th.printStackTrace(); + } + } + + public Logger getLogger(String name) { + return this; + } + + private String format(String msg, Object arg0, Object arg1) { + int i0 = msg.indexOf("{}"); + int i1 = i0 < 0 ? -1 : msg.indexOf("{}", i0 + 2); + if (arg1 != null && i1 >= 0) { + msg = msg.substring(0, i1) + arg1 + msg.substring(i1 + 2); + } + if (arg0 != null && i0 >= 0) { + msg = msg.substring(0, i0) + arg0 + msg.substring(i0 + 2); + } + return msg; + } +} diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java new file mode 100644 index 0000000000..6fd68813df --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.service.jetty; + +import org.apache.tuscany.spi.host.ServletHost; + +import org.mortbay.jetty.Server; + +/** + * Implementations provide a Jetty transport service to the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface JettyService extends ServletHost { + + /** + * Returns the active Jetty server + */ + Server getServer(); + + +} diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java new file mode 100644 index 0000000000..e71e8333d6 --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java @@ -0,0 +1,356 @@ +/* + * 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.tuscany.service.jetty; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.resource.spi.work.Work; +import javax.servlet.Servlet; +import javax.servlet.ServletException; + +import org.apache.tuscany.api.annotation.Monitor; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.SCAObjectStartException; +import org.apache.tuscany.spi.host.ServletHost; +import org.apache.tuscany.spi.services.work.WorkScheduler; +import org.mortbay.jetty.Connector; +import org.mortbay.jetty.Server; +import org.mortbay.jetty.handler.ContextHandler; +import org.mortbay.jetty.nio.SelectChannelConnector; +import org.mortbay.jetty.security.SslSocketConnector; +import org.mortbay.jetty.servlet.ServletHandler; +import org.mortbay.jetty.servlet.ServletHolder; +import org.mortbay.jetty.servlet.ServletMapping; +import org.mortbay.jetty.servlet.SessionHandler; +import org.mortbay.log.Log; +import org.mortbay.log.Logger; +import org.mortbay.thread.BoundedThreadPool; +import org.mortbay.thread.ThreadPool; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +/** + * Implements an HTTP transport service using Jetty. + * + * @version $$Rev$$ $$Date: 2007-02-21 13:28:30 +0000 (Wed, 21 Feb + * 2007) $$ + */ +@Scope("COMPOSITE") +@Service(ServletHost.class) +@EagerInit +public class JettyServiceImpl implements JettyService { + + private static final String ROOT = "/"; + private static final int ERROR = 0; + private static final int UNINITIALIZED = 0; + private static final int STARTING = 1; + private static final int STARTED = 2; + private static final int STOPPING = 3; + private static final int STOPPED = 4; + + private final Object joinLock = new Object(); + private int state = UNINITIALIZED; + private int httpPort = 8080; + private int httpsPort = 8484; + private String keystore; + private String certPassword; + private String keyPassword; + private boolean sendServerVersion; + private boolean https; + private TransportMonitor monitor; + private WorkScheduler scheduler; + private boolean debug; + private Server server; + private Connector connector; + private ServletHandler servletHandler; + + static { + // hack to replace the static Jetty logger + System.setProperty("org.mortbay.log.class", JettyLogger.class.getName()); + + } + + public JettyServiceImpl(@Monitor + TransportMonitor monitor, @Autowire + WorkScheduler scheduler) { + this.monitor = monitor; + this.scheduler = scheduler; + // Jetty uses a static logger, so jam in the monitor into a static + // reference + Logger logger = Log.getLogger(null); + if (logger instanceof JettyLogger) { + JettyLogger jettyLogger = (JettyLogger)logger; + jettyLogger.setMonitor(this.monitor); + if (debug) { + jettyLogger.setDebugEnabled(true); + } + } + + httpPort = Integer.getInteger("Tuscany.JettyService.httpPort", httpPort); + + } + + @Property + public void setHttpPort(int httpPort) { + this.httpPort = httpPort; + } + + @Property + public void setHttpsPort(int httpsPort) { + this.httpsPort = httpsPort; + } + + @Property + public void setSendServerVersion(boolean sendServerVersion) { + this.sendServerVersion = sendServerVersion; + } + + @Property + public void setHttps(boolean https) { + this.https = https; + } + + @Property + public void setKeystore(String keystore) { + this.keystore = keystore; + } + + @Property + public void setCertPassword(String certPassword) { + this.certPassword = certPassword; + } + + @Property + public void setKeyPassword(String keyPassword) { + this.keyPassword = keyPassword; + } + + @Property + public void setDebug(boolean val) { + debug = val; + } + + @Init + public void init() throws Exception { + state = STARTING; + } + + @Destroy + public void destroy() throws Exception { + if (state == STARTED) { + state = STOPPING; + synchronized (joinLock) { + joinLock.notifyAll(); + } + server.stop(); + state = STOPPED; + // monitor.shutdown(); + } + } + + public void registerMapping(String path, Servlet servlet) { + if (state == STARTING) { + + try { + server = new Server(); + if (scheduler == null) { + BoundedThreadPool threadPool = new BoundedThreadPool(); + threadPool.setMaxThreads(100); + server.setThreadPool(threadPool); + } else { + server.setThreadPool(new TuscanyThreadPool()); + } + if (connector == null) { + if (https) { + Connector httpConnector = new SelectChannelConnector(); + httpConnector.setPort(httpPort); + SslSocketConnector sslConnector = new SslSocketConnector(); + sslConnector.setPort(httpsPort); + sslConnector.setKeystore(keystore); + sslConnector.setPassword(certPassword); + sslConnector.setKeyPassword(keyPassword); + server.setConnectors(new Connector[] {httpConnector, sslConnector}); + } else { + SelectChannelConnector selectConnector = new SelectChannelConnector(); + selectConnector.setPort(httpPort); + server.setConnectors(new Connector[] {selectConnector}); + } + } else { + connector.setPort(httpPort); + server.setConnectors(new Connector[] {connector}); + } + + ContextHandler contextHandler = new ContextHandler(); + contextHandler.setContextPath(ROOT); + server.setHandler(contextHandler); + + SessionHandler sessionHandler = new SessionHandler(); + servletHandler = new ServletHandler(); + sessionHandler.addHandler(servletHandler); + + contextHandler.setHandler(sessionHandler); + + server.setStopAtShutdown(true); + server.setSendServerVersion(sendServerVersion); + // monitor.started(); + server.start(); + state = STARTED; + } catch (Exception e) { + state = ERROR; + throw new SCAObjectStartException(e); + } + } + + ServletHolder holder = new ServletHolder(servlet); + servletHandler.addServlet(holder); + ServletMapping mapping = new ServletMapping(); + mapping.setServletName(holder.getName()); + mapping.setPathSpec(path); + servletHandler.addServletMapping(mapping); + } + + public Servlet unregisterMapping(String path) { + Servlet removedServlet = null; + List mappings = new ArrayList(Arrays.asList(servletHandler.getServletMappings())); + for (ServletMapping mapping : mappings) { + if (Arrays.asList(mapping.getPathSpecs()).contains(path)) { + try { + removedServlet = servletHandler.getServlet(mapping.getServletName()).getServlet(); + } catch (ServletException e) { + throw new IllegalStateException(e); + } + mappings.remove(mapping); + break; + } + } + if (removedServlet != null) { + servletHandler.setServletMappings((ServletMapping[])mappings.toArray(new ServletMapping[mappings.size()])); + } + return removedServlet; + } + + public boolean isMappingRegistered(String path) { + ServletMapping[] mappings = servletHandler.getServletMappings(); + for (ServletMapping mapping : mappings) { + if (Arrays.asList(mapping.getPathSpecs()).contains(path)) { + return true; + } + } + return false; + } + + public void registerComposite(File compositeLocation) throws IOException { + throw new UnsupportedOperationException(); + } + + public Server getServer() { + return server; + } + + public int getHttpPort() { + return httpPort; + } + + /** + * An integration wrapper to enable use of a {@link WorkScheduler} with + * Jetty + */ + private class TuscanyThreadPool implements ThreadPool { + + public boolean dispatch(Runnable job) { + scheduler.scheduleWork(new TuscanyWork(job)); + return true; + } + + public void join() throws InterruptedException { + synchronized (joinLock) { + joinLock.wait(); + } + } + + public int getThreads() { + throw new UnsupportedOperationException(); + } + + public int getIdleThreads() { + throw new UnsupportedOperationException(); + } + + public boolean isLowOnThreads() { + // TODO FIXME + return false; + } + + public void start() throws Exception { + + } + + public void stop() throws Exception { + + } + + public boolean isRunning() { + return state == STARTING || state == STARTED; + } + + public boolean isStarted() { + return state == STARTED; + } + + public boolean isStarting() { + return state == STARTING; + } + + public boolean isStopping() { + return state == STOPPING; + } + + public boolean isFailed() { + return state == ERROR; + } + } + + /** + * A unit of work dispatched to the runtime work scheduler + */ + private class TuscanyWork implements Work { + + Runnable job; + + public TuscanyWork(Runnable job) { + this.job = job; + } + + public void release() { + } + + public void run() { + job.run(); + } + } + +} diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java new file mode 100644 index 0000000000..c68eacd21c --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java @@ -0,0 +1,42 @@ +/* + * 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.tuscany.service.jetty; + +/** + * The monitoring interfaces used by the Jetty system service + * + * @version $$Rev$$ $$Date$$ + */ +public interface TransportMonitor { + + /** + * Called after the service is initialized + */ + void started(); + + /** + * Called after the service is stopped + */ + void shutdown(); + + void warn(String msg, Object...args); + + void debug(String msg, Object...args); + +} diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/http.jetty.scdl b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/http.jetty.scdl new file mode 100644 index 0000000000..27673adde2 --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/http.jetty.scdl @@ -0,0 +1,35 @@ + + + + + org.apache.tuscany.sca.services + http-jetty + 0.1-integration-incubating-SNAPSHOT + + + + + http.JettyService + + + + + + + diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/service.composite b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/service.composite new file mode 100644 index 0000000000..762d47dc5d --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/main/resources/META-INF/sca/service.composite @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/transports/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java b/branches/sca-java-integration/sca/services/transports/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java new file mode 100644 index 0000000000..503d5a588e --- /dev/null +++ b/branches/sca-java-integration/sca/services/transports/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java @@ -0,0 +1,220 @@ +/* + * 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.tuscany.service.jetty; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.ConnectException; +import java.net.Socket; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.spi.services.work.WorkScheduler; + +import junit.framework.TestCase; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class JettyServiceImplTestCase extends TestCase { + + private static final String REQUEST1_HEADER = + "GET / HTTP/1.0\n" + + "Host: localhost\n" + + "Content-Type: text/xml\n" + + "Connection: close\n" + + "Content-Length: "; + private static final String REQUEST1_CONTENT = + ""; + private static final String REQUEST1 = + REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT; + + private static final int HTTP_PORT = 8585; + + private TransportMonitor monitor; + private WorkScheduler scheduler; + private ExecutorService executor = Executors.newCachedThreadPool(); + + /** + * Verifies requests are properly routed according to the servlet mapping + */ + public void testRegisterServletMapping() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, null); + service.setHttpPort(HTTP_PORT); + service.init(); + TestServlet servlet = new TestServlet(); + service.registerMapping("/", servlet); + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + os.write(REQUEST1.getBytes()); + os.flush(); + read(client); + service.destroy(); + assertTrue(servlet.invoked); + } + + public void testIsMappingRegistered() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, null); + service.setHttpPort(HTTP_PORT); + service.init(); + TestServlet servlet = new TestServlet(); + service.registerMapping("/foo", servlet); + assertTrue(service.isMappingRegistered("/foo")); + assertFalse(service.isMappingRegistered("/bar")); + service.destroy(); + } + + public void testUnregisterMapping() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, null); + service.setHttpPort(HTTP_PORT); + service.init(); + TestServlet servlet = new TestServlet(); + service.registerMapping("/foo", servlet); + assertTrue(service.isMappingRegistered("/foo")); + service.unregisterMapping("/foo"); + assertFalse(service.isMappingRegistered("/foo")); + service.destroy(); + } + + public void testRequestSession() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, scheduler); + service.setDebug(true); + service.setHttpPort(HTTP_PORT); + service.init(); + TestServlet servlet = new TestServlet(); + service.registerMapping("/", servlet); + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + os.write(REQUEST1.getBytes()); + os.flush(); + read(client); + service.destroy(); + assertTrue(servlet.invoked); + assertNotNull(servlet.sessionId); + } + + public void testUseWorkScheduler() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, scheduler); + service.setDebug(true); + service.setHttpPort(HTTP_PORT); + service.init(); + TestServlet servlet = new TestServlet(); + service.registerMapping("/", servlet); + Socket client = new Socket("127.0.0.1", HTTP_PORT); + OutputStream os = client.getOutputStream(); + os.write(REQUEST1.getBytes()); + os.flush(); + read(client); + service.destroy(); + assertTrue(servlet.invoked); + } + + public void testRestart() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, null); + service.setHttpPort(HTTP_PORT); + service.init(); + service.destroy(); + service.init(); + service.destroy(); + } + + public void testNoMappings() throws Exception { + JettyServiceImpl service = new JettyServiceImpl(monitor, null); + service.setHttpPort(HTTP_PORT); + service.init(); + Exception ex = null; + try { + new Socket("127.0.0.1", HTTP_PORT); + } catch (ConnectException e) { + ex = e; + } + assertNotNull(ex); + service.destroy(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + //executor.submit(); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + monitor = createMock(TransportMonitor.class); + scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + + expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + executor.execute(runnable); + return null; + } + }); + replay(scheduler); + } + + private static String read(Socket socket) throws IOException { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); + StringBuffer sb = new StringBuffer(); + String str; + while ((str = reader.readLine()) != null) { + sb.append(str); + } + return sb.toString(); + } finally { + if (reader != null) { + reader.close(); + } + } + } + + private class TestServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + boolean invoked; + String sessionId; + + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + invoked = true; + sessionId = req.getSession().getId(); + OutputStream writer = resp.getOutputStream(); + try { + writer.write("result".getBytes()); + } finally { + writer.close(); + } + } + + + } +} -- cgit v1.2.3