From 9bed5ae38c581999db465b42b504026a7097af95 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:11:56 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835141 13f79535-47bb-0310-9956-ffa450edef68 --- .../databinding/databinding-axiom/.ruleset | 172 ++++++++++++++ .../databinding/databinding-axiom/LICENSE.txt | 202 +++++++++++++++++ .../databinding/databinding-axiom/NOTICE.txt | 14 ++ .../services/databinding/databinding-axiom/pom.xml | 77 +++++++ .../databinding/axiom/AxiomDataBinding.java | 72 ++++++ .../databinding/axiom/OMElement2Object.java | 40 ++++ .../databinding/axiom/OMElement2String.java | 62 +++++ .../axiom/OMElement2XMLStreamReader.java | 50 +++++ .../databinding/axiom/OMElementWrapperHandler.java | 67 ++++++ .../databinding/axiom/Object2OMElement.java | 54 +++++ .../databinding/axiom/String2OMElement.java | 88 ++++++++ .../axiom/XMLStreamReader2OMElement.java | 90 ++++++++ .../resources/META-INF/sca/databinding.axiom.scdl | 57 +++++ .../src/main/resources/META-INF/sca/default.scdl | 56 +++++ .../databinding/axiom/OMElementTestCase.java | 81 +++++++ .../databinding-axiom/src/test/resources/ipo.xml | 33 +++ .../databinding-axiom/src/test/resources/ipo.xsd | 118 ++++++++++ .../src/test/resources/order.wsdl | 58 +++++ .../databinding/databinding-castor/.ruleset | 172 ++++++++++++++ .../databinding/databinding-castor/LICENSE.txt | 202 +++++++++++++++++ .../databinding/databinding-castor/NOTICE.txt | 14 ++ .../databinding/databinding-castor/pom.xml | 127 +++++++++++ .../tuscany/databinding/castor/Castor2Node.java | 63 ++++++ .../tuscany/databinding/castor/Castor2SAX.java | 63 ++++++ .../tuscany/databinding/castor/Castor2Writer.java | 62 +++++ .../databinding/castor/InputSource2Castor.java | 63 ++++++ .../tuscany/databinding/castor/Node2Castor.java | 63 ++++++ .../tuscany/databinding/castor/Reader2Castor.java | 64 ++++++ .../databinding/castor/Castor2NodeTestCase.java | 69 ++++++ .../src/test/resources/binding.xml | 9 + .../databinding-castor/src/test/resources/ipo.xsd | 118 ++++++++++ .../exolab/castor/builder/castorbuilder.properties | 67 ++++++ .../services/databinding/databinding-jaxb/.ruleset | 172 ++++++++++++++ .../databinding/databinding-jaxb/LICENSE.txt | 202 +++++++++++++++++ .../databinding/databinding-jaxb/NOTICE.txt | 14 ++ .../services/databinding/databinding-jaxb/pom.xml | 141 ++++++++++++ .../apache/tuscany/databinding/jaxb/JAXB2Node.java | 71 ++++++ .../databinding/jaxb/JAXBContextHelper.java | 110 +++++++++ .../tuscany/databinding/jaxb/JAXBDataBinding.java | 109 +++++++++ .../databinding/jaxb/JAXBWrapperHandler.java | 102 +++++++++ .../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 ++++ .../databinding/jaxb/JAXBDataBindingTestCase.java | 83 +++++++ .../tuscany/databinding/jaxb/JAXBTestCase.java | 158 +++++++++++++ .../databinding-jaxb/src/test/resources/ipo.xsd | 118 ++++++++++ .../services/databinding/databinding-sdo/.ruleset | 172 ++++++++++++++ .../databinding/databinding-sdo/LICENSE.txt | 202 +++++++++++++++++ .../databinding/databinding-sdo/NOTICE.txt | 14 ++ .../services/databinding/databinding-sdo/pom.xml | 104 +++++++++ .../tuscany/databinding/sdo/DataObject2String.java | 68 ++++++ .../sdo/DataObject2XMLStreamReader.java | 72 ++++++ .../tuscany/databinding/sdo/DataObjectLoader.java | 89 ++++++++ .../tuscany/databinding/sdo/ImportSDOLoader.java | 155 +++++++++++++ .../tuscany/databinding/sdo/ModelDataObject.java | 38 ++++ .../tuscany/databinding/sdo/SDODataBinding.java | 65 ++++++ .../tuscany/databinding/sdo/SDODataTypeHelper.java | 54 +++++ .../tuscany/databinding/sdo/SDOObjectFactory.java | 47 ++++ .../databinding/sdo/SDOSimpleTypeMapper.java | 69 ++++++ .../tuscany/databinding/sdo/SDOWrapperHandler.java | 72 ++++++ .../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 | 68 ++++++ .../src/main/resources/META-INF/sca/default.scdl | 66 ++++++ .../databinding/sdo/DataObject2StringTestCase.java | 63 ++++++ .../sdo/DataObject2XMLStreamReaderTestCase.java | 56 +++++ .../databinding/sdo/DataObjectLoaderTestCase.java | 73 ++++++ .../databinding/sdo/ImportSDOLoaderTestCase.java | 87 +++++++ .../databinding/sdo/SDODataBindingTestCase.java | 61 +++++ .../sdo/SDOTransformerTestCaseBase.java | 76 +++++++ .../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 ++++ .../services/databinding/databinding-test/.ruleset | 172 ++++++++++++++ .../databinding/databinding-test/LICENSE.txt | 202 +++++++++++++++++ .../databinding/databinding-test/NOTICE.txt | 14 ++ .../services/databinding/databinding-test/pom.xml | 222 ++++++++++++++++++ .../apache/tuscany/databinding/JAXBTestCase.java | 119 ++++++++++ .../databinding/TransformationTestCase.java | 250 +++++++++++++++++++++ .../tuscany/databinding/XmlObjectTestCase.java | 110 +++++++++ .../apache/tuscany/databinding/sample/Client.java | 26 +++ .../tuscany/databinding/sample/ClientImpl.java | 50 +++++ .../sample/DataBindingBootStrapTest.java | 115 ++++++++++ .../apache/tuscany/databinding/sample/Echo.java | 42 ++++ .../tuscany/databinding/sample/EchoImpl.java | 43 ++++ .../src/test/resources/META-INF/sca/default.scdl | 34 +++ .../META-INF/tuscany/databinding.axiom.scdl | 52 +++++ .../META-INF/tuscany/databinding.jaxb.scdl | 43 ++++ .../META-INF/tuscany/databinding.sdo.scdl | 58 +++++ .../META-INF/tuscany/databinding.xmlbeans.scdl | 43 ++++ .../resources/META-INF/tuscany/interface.wsdl.scdl | 44 ++++ .../META-INF/tuscany/test-extensions.scdl | 30 +++ .../databinding-test/src/test/resources/ipo.xml | 33 +++ .../databinding-test/src/test/resources/ipo.xsd | 118 ++++++++++ .../src/test/resources/ipo.xsdconfig | 21 ++ .../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 ++++ .../src/main/resources/META-INF/sca/default.scdl | 43 ++++ .../databinding/xmlbeans/XmlObjectTestCase.java | 99 ++++++++ .../src/test/resources/ipo.xsd | 118 ++++++++++ .../src/test/resources/ipo.xsdconfig | 21 ++ .../pre-spec-changes/services/databinding/pom.xml | 42 ++++ 116 files changed, 9602 insertions(+) create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig create mode 100644 sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml (limited to 'sca-java-1.x/branches/pre-spec-changes/services/databinding') diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml new file mode 100755 index 0000000000..9f5b4a31e1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml @@ -0,0 +1,77 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-SNAPSHOT + + 4.0.0 + databinding-axiom + Apache Tuscany Data Binding for Axiom + Tuscany Axiom Data Binding + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-pre-spec-SNAPSHOT + compile + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + + + + xerces + xercesImpl + 2.8.1 + + + + org.apache.ws.commons.axiom + axiom-impl + runtime + + + junit + junit + + + + woodstox + wstx-asl + + + commons-logging + commons-logging + 1.1 + test + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..771e7221ef --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.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.axiom; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.api.TuscanyRuntimeException; +import org.apache.tuscany.spi.databinding.DataBinding; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.osoa.sca.annotations.Service; + +/** + * DataBinding for AXIOM + */ +@Service(DataBinding.class) +public class AxiomDataBinding extends DataBindingExtension { + + public static final String NAME = OMElement.class.getName(); + + public AxiomDataBinding() { + super(OMElement.class); + } + + /** + * @see org.apache.tuscany.spi.databinding.extension.DataBindingExtension#getWrapperHandler() + */ + @Override + public WrapperHandler getWrapperHandler() { + return new OMElementWrapperHandler(); + } + + public Object copy(Object source) { + if ( OMElement.class.isAssignableFrom(source.getClass()) ) { + try { + OMElement sourceElement = (OMElement)source; + StringWriter writer = new StringWriter(); + sourceElement.serialize(writer); + + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(writer.toString().getBytes())); + OMElement copyElement = builder.getDocumentElement(); + return copyElement; + } catch ( XMLStreamException e ) { + throw new IllegalArgumentException(e); + } + } + return super.copy(source); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..91b1f4da90 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java @@ -0,0 +1,40 @@ +/* + * 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.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.SimpleType2JavaTransformer; +import org.osoa.sca.annotations.Service; + +/** + * Transformer to convert data from a simple java bject to OMElement + */ +@Service(Transformer.class) +public class OMElement2Object extends SimpleType2JavaTransformer { + + @Override + protected String getText(OMElement source) { + return source.getText(); + } + + public Class getSourceType() { + return OMElement.class; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java new file mode 100755 index 0000000000..52be08537d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.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.axiom; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +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; + +/** + * Transformer to convert data from an OMElement to XML String + */ +@Service(Transformer.class) +public class OMElement2String extends TransformerExtension implements PullTransformer { + // private XmlOptions options; + + public String transform(OMElement source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + source.serialize(writer); + return writer.toString(); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100755 index 0000000000..343408a027 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java @@ -0,0 +1,50 @@ +/* + * 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.axiom; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +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; + +@Service(Transformer.class) +public class OMElement2XMLStreamReader extends TransformerExtension implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + return source.getXMLStreamReader(); + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..0ba2863735 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.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.axiom; + +import java.util.Iterator; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +/** + * OMElement wrapper handler implementation + */ +public class OMElementWrapperHandler implements WrapperHandler { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(ElementInfo element, TransformationContext context) { + OMElement wrapper = factory.createOMElement(element.getQName(), null); + return wrapper; + } + + public Object getChild(OMElement wrapper, int i, ElementInfo element) { + int index = 0; + for (Iterator e = wrapper.getChildElements(); e.hasNext();) { + OMElement child = (OMElement) e.next(); + if (index != i) { + index++; + continue; + } + if (child.getQName().equals(element.getQName())) { + return child; + } + } + return null; + } + + public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { + wrapper.addChild((OMElement) value); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..5416b5239e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java @@ -0,0 +1,54 @@ +/* + * 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.axiom; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.Java2SimpleTypeTransformer; +import org.apache.tuscany.spi.idl.ElementInfo; +import org.osoa.sca.annotations.Service; + +/** + * Transformer to convert data from an simple OMElement to Java Object + */ +@Service(Transformer.class) +public class Object2OMElement extends Java2SimpleTypeTransformer { + + private OMFactory factory; + + public Object2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + protected OMElement createElement(ElementInfo element, String text, TransformationContext context) { + OMElement omElement = factory.createOMElement(element.getQName(), null); + factory.createOMText(omElement, text); + return omElement; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java new file mode 100755 index 0000000000..59ac5423d7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java @@ -0,0 +1,88 @@ +/* + * 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.axiom; + +import java.io.ByteArrayInputStream; + +import javax.xml.namespace.QName; + +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.axiom.om.impl.builder.StAXOMBuilder; +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.model.DataType; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class String2OMElement extends TransformerExtension implements + PullTransformer { + + @SuppressWarnings("unchecked") + public OMElement transform(String source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(source.getBytes())); + OMElement element = builder.getDocumentElement(); + adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + /** + * @param context + * @param element + */ + private void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (!(targetQName instanceof QName)) { + return; + } + if (!element.getQName().equals(targetQName)) { + // TODO: Throw expection or switch to the new Element + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = (QName)targetQName; + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100755 index 0000000000..5b2c89b443 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java @@ -0,0 +1,90 @@ +/* + * 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.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +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.axiom.om.impl.builder.StAXOMBuilder; +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.model.DataType; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2OMElement extends TransformerExtension implements + PullTransformer { + + public XMLStreamReader2OMElement() { + super(); + } + + public OMElement transform(XMLStreamReader source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(source); + OMElement element = builder.getDocumentElement(); + adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + /** + * @param context + * @param element + */ + private void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (!(targetQName instanceof QName)) { + return; + } + if (!element.getQName().equals(targetQName)) { + // TODO: Throw expection or switch to the new Element + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = (QName)targetQName; + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl new file mode 100644 index 0000000000..ecdaab994e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl @@ -0,0 +1,57 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..2350c77b17 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,56 @@ + + + + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java new file mode 100755 index 0000000000..2351b7da97 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.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.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; + +public class OMElementTestCase 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" + " " + " " + ""; + + public final void testStringTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStringTransform2() { + String str = + "Robert"; + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(str, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStAXTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + + OMElement2XMLStreamReader t2 = new OMElement2XMLStreamReader(); + XMLStreamReader reader = t2.transform(element, null); + + XMLStreamReader2OMElement t3 = new XMLStreamReader2OMElement(); + OMElement element2 = t3.transform(reader, null); + + Assert.assertEquals(element2.getQName(), element.getQName()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), element2.getQName()); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml new file mode 100755 index 0000000000..58058dbe1a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml @@ -0,0 +1,33 @@ + + + + + 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 + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl new file mode 100644 index 0000000000..cde45f12ae --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml new file mode 100755 index 0000000000..a0db5b75d5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml @@ -0,0 +1,127 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-SNAPSHOT + + 4.0.0 + databinding-castor + Apache Tuscany Data Binding for Castor + Tuscany Castor Data Binding + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-pre-spec-SNAPSHOT + compile + + + + org.codehaus.castor + castor + 1.0.5 + compile + + + adaptx + adaptx + + + javax.transaction + jta + + + + + + org.codehaus.castor + adaptx + 0.9.14 + compile + + + + + + junit + junit + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/castor-source + + + + + + + maven-antrun-plugin + + + generate-castor + generate-test-sources + + + + + + + + + run + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java new file mode 100755 index 0000000000..9ae0335ada --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java @@ -0,0 +1,63 @@ +/* + * 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.castor; + +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.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class Castor2Node extends TransformerExtension implements PullTransformer { + private Class type; + + public Castor2Node(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return Node.class; + } + + public Class getSourceType() { + return type; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public Node transform(Object source, TransformationContext context) { + try { + Document document = DOMHelper.newDocument(); + Marshaller.marshal(source, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java new file mode 100644 index 0000000000..643d6fb4ad --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java @@ -0,0 +1,63 @@ +/* + * 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.castor; + +import java.io.Writer; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; + +public class Castor2SAX extends TransformerExtension implements PushTransformer { + private Class type; + + /** + * @param type + */ + public Castor2SAX(Class type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return Writer.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, Writer writer, TransformationContext context) { + try { + Marshaller.marshal(source, writer); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java new file mode 100644 index 0000000000..f477273387 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.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.castor; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.xml.sax.ContentHandler; + +public class Castor2Writer extends TransformerExtension implements PushTransformer { + private Class type; + + /** + * @param type + */ + public Castor2Writer(Class type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return ContentHandler.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, ContentHandler contentHandler, TransformationContext context) { + try { + Marshaller.marshal(source, contentHandler); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java new file mode 100644 index 0000000000..61bac7d20f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java @@ -0,0 +1,63 @@ +/* + * 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.castor; + +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.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +public class InputSource2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public InputSource2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return InputSource.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(InputSource source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java new file mode 100644 index 0000000000..fa5a15b3ba --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java @@ -0,0 +1,63 @@ +/* + * 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.castor; + +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.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.w3c.dom.Node; + +public class Node2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public Node2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Node.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Node source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java new file mode 100644 index 0000000000..a8ade1bda5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.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.castor; + +import java.io.Reader; + +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.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; + +public class Reader2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public Reader2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Reader.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Reader source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java new file mode 100644 index 0000000000..3ea86321e7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.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.castor; + +import java.io.StringReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.w3c.dom.Node; + +import com.example.ipo.castor.PurchaseOrderType; + +public class Castor2NodeTestCase 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" + + " " + + " " + + ""; + + public void testTransform() throws Exception { + Reader2Castor t1 = new Reader2Castor(PurchaseOrderType.class); + PurchaseOrderType po = t1.transform(new StringReader(IPO_XML), null); + Castor2Node t2 = new Castor2Node(PurchaseOrderType.class); + Node node = t2.transform(po, null); + Assert.assertNotNull(node); + + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml new file mode 100755 index 0000000000..9b66de4cca --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties new file mode 100644 index 0000000000..d6f593fd00 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties @@ -0,0 +1,67 @@ +# +# Property file for SourceCodeGenerator +# +# $Id: castorbuilder.properties,v 1.3 2004/05/06 08:20:51 kvisco Exp $ + +# To enable bound properties uncomment the following line. Please +# note that currently *all* fields will be treated as bound properties +# when enabled. This will change in the future when we introduce +# fine grained control over each class and it's properties. +# +#org.exolab.castor.builder.boundproperties=true + +# Java class mapping of 's and 's +# +# FIXME: There's a bug in the castor-generated code which cannot handle subutype correctly +# http://jira.codehaus.org/browse/CASTOR-1475 +org.exolab.castor.builder.javaclassmapping=type +org.exolab.castor.builder.javaVersion=5.0 + + +# This property allows one to specify the super class of *all* +# generated classes +# +#org.exolab.castor.builder.superclass=com.xyz.BaseObject + +# XML namespace mapping to Java packages +# +#org.exolab.castor.builder.nspackages=\ + http://www.xyz.com/schemas/project=com.xyz.schemas.project,\ + http://www.xyz.com/schemas/person=com.xyz.schemas.person + +# Set to true if you want to generate the equals method +# for each generated class +# false by default +# +#org.exolab.castor.builder.equalsmethod=true + +# Set to true if you want to use Object Wrappers instead +# of primitives (e.g Float instead of float). +# false by default. +# +#org.exolab.castor.builder.primitivetowrapper=false + +# Set to true if you want the generated class descriptors to +# expose the element and attribute names they contain. +# false by default. +# +#org.exolab.castor.builder.classdescfieldnames=false + +# Set to true if you want the generated source code to contain +# Extra methods for the collection fields, such as get/set using +# the collection type in addition to the type-safe array. +# Set this to true if you want your code to be more compatible +# with Castor JDO. This is false by default. +# +#org.exolab.castor.builder.extraCollectionMethods=true + +# Use old-style (Castor 0.9.3.9) of naming that uppercases +# names after an underscore +# +#org.exolab.castor.xml.JavaNaming.upperCaseAfterUnderscore=true + +# This property specifies whether generated enumerated type +# classes implement the EnumeratedTypeAccess interface. +# false by default +#org.exolab.castor.builder.enumTypeAccessInterface=true + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..99ad0f9d39 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml @@ -0,0 +1,141 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-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-pre-spec-SNAPSHOT + compile + + + javax.xml.bind + jaxb-api + 2.0 + 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..607b515809 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java @@ -0,0 +1,71 @@ +/* + * 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.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(); + marshaller.marshal(JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source), + 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..457232635f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.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.jaxb; + +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.XmlRootElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; + +public class JAXBContextHelper { + private static final QName JAXB_ELEMENT = new QName("http://jaxb", "element"); + // 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 { + Object logical = dataType.getLogical(); + if (!(logical instanceof QName)) { + logical = JAXB_ELEMENT; + } + return new JAXBElement((QName)logical, (Class)dataType.getPhysical(), value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class cls = (Class)dataType.getPhysical(); + XmlRootElement element = cls.getAnnotation(XmlRootElement.class); + if (element == null) { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } else { + QName root = new QName(element.namespace(), element.name()); + return new JAXBElement(root, (Class)dataType.getPhysical(), value); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..c43e9bcd42 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java @@ -0,0 +1,109 @@ +/* + * 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.JAXBElement; +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.extension.DataBindingExtension; +import org.apache.tuscany.spi.model.DataType; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends DataBindingExtension { + + public static final String NAME = JAXBElement.class.getName(); + + @Override + public DataType introspect(Class javaType) { + 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) { + return introspect((Class) actualType); + } + } + } + return new DataType(getName(), javaType, null); + } + + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + 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 (namespace == null && name == null) { + return null; + } + QName xmlType = new QName(namespace, name); + DataType dataType = new DataType(getName(), javaType, xmlType); + return dataType; + } + + public JAXBDataBinding() { + super(NAME, JAXBElement.class); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..507f36eb19 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.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.databinding.jaxb; + +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +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 { + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + Class factoryClass = Class.forName(factoryClassName, true, context.getClassLoader()); + 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 Object getChild(JAXBElement wrapper, int i, ElementInfo element) { + try { + Object value = wrapper.getValue(); + PropertyDescriptor descriptors[] = + Introspector.getBeanInfo(wrapper.getDeclaredType()).getPropertyDescriptors(); + for (PropertyDescriptor d : descriptors) { + if (d.getName().equals(element.getQName().getLocalPart())) { + return d.getReadMethod().invoke(value, new Object[] {}); + } + } + return null; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement wrapper, int i, ElementInfo childElement, Object value) { + try { + Object wrapperValue = wrapper.getValue(); + PropertyDescriptor descriptors[] = + Introspector.getBeanInfo(wrapper.getDeclaredType()).getPropertyDescriptors(); + for (PropertyDescriptor d : descriptors) { + if (d.getName().equals(childElement.getQName().getLocalPart())) { + d.getWriteMethod().invoke(wrapperValue, new Object[] { value }); + break; + } + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..301e316889 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..273c15db1b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..3f6a2f64d3 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl new file mode 100644 index 0000000000..be6b90026e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..02800fd3e9 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,49 @@ + + + + + + org.apache.tuscany.sca.services.databinding + databinding-jaxb + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..1b80be724f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.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.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.model.DataType; + +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)}. + */ + public final void testIntrospect() { + DataType dataType = binding.introspect(JAXBElement.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == null); + dataType = binding.introspect(MockJAXBElement.class); + Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical()); + dataType = binding.introspect(USAddress.class); + Assert.assertEquals(USAddress.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical()); + dataType = binding.introspect(USState.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertEquals(USState.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USState"), dataType.getLogical()); + + } + + 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); + } + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..08583d9729 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml new file mode 100755 index 0000000000..84e8b084ea --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml @@ -0,0 +1,104 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-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-pre-spec-SNAPSHOT + compile + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubator-SNAPSHOT + compile + + + + org.apache.tuscany.sca.kernel + core + 0.1-pre-spec-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-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..9125980eed --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java @@ -0,0 +1,68 @@ +/* + * 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 { + + private static final String TUSCANY_SDO = "http://tuscany.apache.org/xmlns/sdo/1.0-SNAPSHOT"; + + public String transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + Object logicalType = context.getSourceDataType().getLogical(); + if (logicalType instanceof QName) { + QName elementName = (QName) logicalType; + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } else { + return xmlHelper.save(source, TUSCANY_SDO, "dataObject"); + } + } 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..2892b1bc4d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.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.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 = SDODataTypeHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + Object logicalType = context.getSourceDataType().getLogical(); + QName elementName = + (logicalType instanceof QName) ? (QName) logicalType : new QName("commonj.sdo", "dataObject"); + 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java new file mode 100755 index 0000000000..5706005252 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.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.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.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.StAXElementLoader; +import org.apache.tuscany.spi.model.ModelObject; +import org.apache.tuscany.spi.annotation.Autowire; +import org.osoa.sca.annotations.EagerInit; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +/** + * A SDO model-based Loader to load DataObject from the XML stream + * + */ +@EagerInit +public class DataObjectLoader implements StAXElementLoader { + protected LoaderRegistry registry; + private QName propertyQName; + + public DataObjectLoader(Property property) { + super(); + this.propertyQName = new QName(XSDHelper.INSTANCE.getNamespaceURI(property), + XSDHelper.INSTANCE.getLocalName(property)); + } + + public DataObjectLoader(QName propertyQName) { + super(); + this.propertyQName = propertyQName; + } + + public ModelObject load(CompositeComponent parent, ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert propertyQName.equals(reader.getName()); + // TODO: We need a way to get TypeHelper from deploymentContext + TypeHelper typeHelper = TypeHelper.INSTANCE; + 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); + } + + @Autowire + public void setRegistry(LoaderRegistry registry) { + this.registry = registry; + } + + @Init + public void start() { + registry.registerLoader(propertyQName, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(propertyQName, this); + } + + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java new file mode 100755 index 0000000000..92b1036bc0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java @@ -0,0 +1,155 @@ +/* + * 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.IOException; +import java.io.InputStream; +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.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.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; + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + */ +public class ImportSDOLoader extends LoaderExtension { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + @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 = null; + if (deploymentContext != null && deploymentContext.getParent() != null) { + helperContext = (HelperContext)deploymentContext.getParent().getExtension(HelperContext.class.getName()); + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + deploymentContext.getParent().putExtension(HelperContext.class.getName(), helperContext); + } + } + + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + } + + importFactory(reader, deploymentContext); + importWSDL(reader, deploymentContext, helperContext); + LoaderUtil.skipToEndElement(reader); + return new SDOType(helperContext); + } + + private void importFactory(XMLStreamReader reader, DeploymentContext deploymentContext) 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); + // FIXME: We require the SDO to provide an API to register + // static types in a given TypeHelper + SDOUtil.registerStaticTypes(factoryClass); + } catch (ClassNotFoundException e) { + throw new LoaderException(e.getMessage(), e); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + } + + 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(); + } + } catch (IOException e) { + LoaderException sfe = new LoaderException(e.getMessage()); + sfe.setResourceURI(location); + throw sfe; + } + } + } + + public static class SDOType extends ModelObject { + private HelperContext helperContext; + + public SDOType(HelperContext typeHelper) { + super(); + this.helperContext = typeHelper; + } + + public HelperContext getHelperContext() { + return helperContext; + } + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java new file mode 100755 index 0000000000..a3870b5e9a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.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.databinding.sdo; + +import org.apache.tuscany.spi.model.ModelObject; + +import commonj.sdo.DataObject; + +public class ModelDataObject extends ModelObject { + private DataObject dataObject; + + public ModelDataObject(DataObject dataObject) { + super(); + this.dataObject = dataObject; + } + + public DataObject getDataObject() { + return dataObject; + } + + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..213dfd9280 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.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 javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * + */ +public class SDODataBinding extends DataBindingExtension { + private WrapperHandler wrapperHandler; + + @Override + public DataType introspect(Class javaType) { + if (javaType == DataObject.class) { + return new DataType(getName(), javaType, null); + } + Type type = TypeHelper.INSTANCE.getType(javaType); + if (type == null || type.isDataType()) { + return null; + } + String namespace = type.getURI(); + String name = XSDHelper.INSTANCE.getLocalName(type); + QName xmlType = new QName(namespace, name); + DataType dataType = new DataType(getName(), javaType, xmlType); + return dataType; + } + + public SDODataBinding() { + super(DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java new file mode 100644 index 0000000000..7cb52e366e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java @@ -0,0 +1,54 @@ +/* + * 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.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.databinding.TransformationContext; + +import commonj.sdo.helper.HelperContext; + +/** + * Helper class to get TypeHelper from the transformation context + */ +public class SDODataTypeHelper { + private SDODataTypeHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null || context.getMetadata() == null) { + return SDOUtil.createHelperContext(); + } + HelperContext helperContext = null; + CompositeComponent composite = (CompositeComponent)context.getMetadata().get(CompositeComponent.class); + if (composite != null) { + SDOType sdoType = (SDOType)composite.getExtensions().get(SDOType.class); + if (sdoType != null) { + helperContext = sdoType.getHelperContext(); + } + } + if (helperContext == null) { + return SDOUtil.createHelperContext(); + } else { + return helperContext; + } + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java new file mode 100755 index 0000000000..0c3e74cdc7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.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 commonj.sdo.DataObject; +import commonj.sdo.helper.CopyHelper; +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.ObjectCreationException; + +/** + * Creates new instances of an SDO + * + * @version $Rev$ $Date$ + */ +public class SDOObjectFactory implements ObjectFactory { + + private DataObject dataObject; + + public SDOObjectFactory(DataObject dataObject) { + this.dataObject = dataObject; + } + + public DataObject getInstance() throws ObjectCreationException { + return CopyHelper.INSTANCE.copy(dataObject); + } + + public void releaseInstance(DataObject instance) { + } + +} + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..a363a8a3ec --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.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.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 org.apache.tuscany.spi.idl.TypeInfo; + +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(TypeInfo simpleType, String value, TransformationContext context) { + QName typeName = simpleType.getQName(); + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(TypeInfo simpleType, Object obj, TransformationContext context) { + QName typeName = simpleType.getQName(); + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..7074687722 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.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.sdo; + +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.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 = SDODataTypeHelper.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#getChild(java.lang.Object, + * int, ElementInfo) + */ + public Object getChild(Object wrapper, int i, ElementInfo element) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + return wrapperDO.get(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(childElement.getQName().getLocalPart(), value); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..64c79a3bd0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 = SDODataTypeHelper.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..16e2714a89 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 = SDODataTypeHelper.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..53343aba6b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 = SDODataTypeHelper.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..2a4ce83eb6 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 = SDODataTypeHelper.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..616d2139d4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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 = SDODataTypeHelper.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl new file mode 100644 index 0000000000..84ac5cc58a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl @@ -0,0 +1,68 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..19a00aa147 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,66 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 1.0-incubator-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..28a885cd16 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java @@ -0,0 +1,63 @@ +/* + * 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, orderQName); + } + + @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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..5ab23c6df1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.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.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, orderQName); + } + + @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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java new file mode 100755 index 0000000000..33ae6bbe97 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.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 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(name); + 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java new file mode 100755 index 0000000000..ff6f07427c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.sdo.model.ModelFactory; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; + +/** + * @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 SDOType); + } + + public void testLocation() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof SDOType); + } + + public void testFactory() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof SDOType); + 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 = ModelFactory.INSTANCE; + + static { + ImportSDOLoaderTestCase.inited = true; + } + } +} + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..438de93c76 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.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 junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; +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; + +/** + * + */ +public class SDODataBindingTestCase extends TestCase { + private SDODataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + SDOUtil.registerStaticTypes(SdoFactory.class); + } + + public final void testIntrospect() { + DataType dataType = binding.introspect(DataObject.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == null); + dataType = binding.introspect(PurchaseOrderType.class); + Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical()); + dataType = binding.introspect(USAddress.class); + Assert.assertEquals(USAddress.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical()); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..c7403410ef --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,76 @@ +/* + * 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.sdo.util.SDOUtil; +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; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected String binding = DataObject.class.getName(); + + protected static final QName orderQName = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + SDOUtil.registerStaticTypes(SdoFactory.class); + 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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..a7f391216b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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; +import commonj.sdo.helper.XMLHelper; + +/** + * + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataType(XMLDocument.class.getName(), XMLDocument.class, orderQName); + } + + @Override + protected DataType getTargetDataType() { + return new DataType>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + XMLHelper.INSTANCE.createDocument(dataObject, orderQName.getNamespaceURI(), orderQName.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(orderQName.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(orderQName.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..8f4ee4be3e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml new file mode 100755 index 0000000000..37386075a0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml @@ -0,0 +1,222 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-SNAPSHOT + + + 4.0.0 + databinding-test + jar + Apache Tuscany Data Binding Integration Test + Apache Tuscany Data Binding Integration Test + + + + + true + + java.net + java.net Maven 1.x Repository + https://maven-repository.dev.java.net/nonav/repository + legacy + + + + + + org.apache.tuscany.sca.kernel + tuscany-spi + 0.1-pre-spec-SNAPSHOT + compile + + + org.apache.tuscany.sca.services.databinding + databinding-jaxb + ${pom.version} + compile + + + org.apache.tuscany.sca.services.databinding + databinding-xmlbeans + ${pom.version} + compile + + + org.apache.tuscany.sca.services.databinding + databinding-axiom + ${pom.version} + compile + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + ${pom.version} + compile + + + org.apache.tuscany.sca.services.idl + wsdl + ${pom.version} + compile + + + + junit + junit + + + org.easymock + easymock + + + + com.sun.xml.bind + jaxb-impl + 2.0.4 + test + + + + javax.xml.bind + jsr173_api + + + + + + org.apache.tuscany.sca + test + 0.1-pre-spec-SNAPSHOT + test + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + target/sdo-source + target/xmlbeans-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + + + generate-sdo + generate-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + 1.1 + + + generate-jaxb + generate-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + maven-antrun-plugin + + + xmlbeans + xbean + 2.1.0 + + + stax + stax-api + 1.0.1 + + + + + + + generate-xmlbeans + generate-sources + + + + + + + + + run + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java new file mode 100755 index 0000000000..894bee16e4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java @@ -0,0 +1,119 @@ +/* + * 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; + +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.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB; +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +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 { + // 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); + + 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); + + // XMLStreamReader to JAXB + XMLStreamReader2JAXB t2 = new XMLStreamReader2JAXB(); + Object object2 = t2.transform(reader, 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 t3 = new JAXB2Node(); + Node node = t3.transform(object2, tContext1); + + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + + Assert.assertNotNull(object3); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java new file mode 100755 index 0000000000..613bcd9cf8 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java @@ -0,0 +1,250 @@ +/* + * 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; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBElement; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.core.databinding.impl.TransformerRegistryImpl; +import org.apache.tuscany.core.databinding.xml.Node2String; +import org.apache.tuscany.core.databinding.xml.String2Node; +import org.apache.tuscany.core.databinding.xml.String2XMLStreamReader; +import org.apache.tuscany.core.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.databinding.axiom.OMElement2String; +import org.apache.tuscany.databinding.axiom.OMElement2XMLStreamReader; +import org.apache.tuscany.databinding.axiom.String2OMElement; +import org.apache.tuscany.databinding.axiom.XMLStreamReader2OMElement; +import org.apache.tuscany.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB; +import org.apache.tuscany.databinding.sdo.DataObject2XMLStreamReader; +import org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2DataObject; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument; +import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2Node; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +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.Transformer; +import org.apache.tuscany.spi.databinding.TransformerRegistry; +import org.apache.tuscany.spi.model.DataType; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class TransformationTestCase 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 TransformerRegistry registry; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + registry = new TransformerRegistryImpl(); + + List transformers = new ArrayList(); + + // Adding JAXB transformers + transformers.add(new JAXB2Node()); + transformers.add(new Node2JAXB()); + transformers.add(new XMLStreamReader2JAXB()); + + // Adding XMLBeans transformers + transformers.add(new XmlObject2Node()); + transformers.add(new XmlObject2XMLStreamReader()); + transformers.add(new Node2XmlObject()); + transformers.add(new XMLStreamReader2XmlObject()); + + transformers.add(new DataObject2XMLStreamReader()); + transformers.add(new XMLStreamReader2DataObject()); + + transformers.add(new XMLDocument2XMLStreamReader()); + transformers.add(new XMLStreamReader2XMLDocument()); + + transformers.add(new String2XMLStreamReader()); + transformers.add(new XMLStreamReader2String()); + + transformers.add(new String2Node()); + transformers.add(new Node2String()); + + transformers.add(new OMElement2String()); + transformers.add(new String2OMElement()); + + transformers.add(new XMLStreamReader2OMElement()); + transformers.add(new OMElement2XMLStreamReader()); + + for (Transformer transformer : transformers) { + registry.registerTransformer(transformer); + } + + // System.out.println(registry); + + URL xsdFile = getClass().getClassLoader().getResource("ipo.xsd"); + XSDHelper.INSTANCE.define(xsdFile.openStream(), null); + } + + @SuppressWarnings("unchecked") + // XMLBeans --> SDO + public void testTransformation1() throws Exception { + URL xsdFile = getClass().getClassLoader().getResource("ipo.xsd"); + HelperContext helperContext = SDOUtil.createHelperContext(); + XSDHelper xsdHelper = helperContext.getXSDHelper(); + xsdHelper.define(xsdFile.openStream(), xsdFile.toExternalForm()); + + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + List path = + registry.getTransformerChain(XmlObject.class.getName(), DataObject.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + tContext.getMetadata().put(SDOType.class, new SDOType(helperContext)); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof DataObject); + + } + + @SuppressWarnings("unchecked") + // SDO --> DOM + public void testTransformation2() throws Exception { + // System.out.println(registry); + + URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + XMLDocument object = XMLHelper.INSTANCE.load(xmlFile.openStream()); + + List path = + registry.getTransformerChain(XMLDocument.class.getName(), Node.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof Node); + + } + + @SuppressWarnings("unchecked") + // SDO --> JAXB + public void testTransformation3() throws Exception { + // System.out.println(registry); + + URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + XMLDocument object = XMLHelper.INSTANCE.load(xmlFile.openStream()); + + List path = + registry.getTransformerChain(XMLDocument.class.getName(), JAXBElement.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof Object); + + } + + private TransformationContext createTransformationContext() { + DataType dataType = new DataType(Object.class, null); + dataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(dataType).anyTimes(); + + expect(tContext.getSourceDataType()).andReturn(dataType).anyTimes(); + Map, Object> metadata = new HashMap, Object>(); + expect(tContext.getMetadata()).andReturn(metadata).anyTimes(); + replay(tContext); + return tContext; + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java new file mode 100755 index 0000000000..78d51352cb --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.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; + +import java.io.StringReader; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2Node; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +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 testTransform() throws Exception { + 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(xmlFile); // 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); } + */ + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java new file mode 100644 index 0000000000..8ddc625d66 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java @@ -0,0 +1,26 @@ +/* + * 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.sample; + +/** + * @version $Rev$ $Date$ + */ +public interface Client { + void call(Object po); +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java new file mode 100644 index 0000000000..2d33a8666b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java @@ -0,0 +1,50 @@ +/* + * 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.sample; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class ClientImpl implements Client { + + private Echo echoReference; + + @Constructor + public ClientImpl(@Reference(name = "echoReference", required = true) + Echo echoReference) { + this.echoReference = echoReference; + } + + public void call(Object po) { + Object ret = null; + if (po instanceof PurchaseOrderType) { + ret = echoReference.echoJAXB((PurchaseOrderType)po); + } else if (po instanceof com.example.ipo.sdo.PurchaseOrderType) { + ret = echoReference.echoSDO((com.example.ipo.sdo.PurchaseOrderType)po); + } else if (po instanceof com.example.ipo.xmlbeans.PurchaseOrderType) { + ret = echoReference.echoXMLBeans((com.example.ipo.xmlbeans.PurchaseOrderType)po); + } + System.out.println("Returned message: " + ret); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.java new file mode 100644 index 0000000000..ff44dfb68d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.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.databinding.sample; + +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.bind.JAXBElement; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.databinding.sdo.String2DataObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.xmlbeans.PurchaseOrderDocument; +import commonj.sdo.DataObject; + +/** + * @version $Rev$ $Date$ + */ +public class DataBindingBootStrapTest extends SCATestCase { + 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 Client client; + private String contextPath = "com.example.ipo.jaxb"; + + @SuppressWarnings("unchecked") + public void testDataBindingBootstrap() throws Exception { + 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); + + String2DataObject t1 = new String2DataObject(); + DataObject po1 = t1.transform(IPO_XML, null); + client.call(po1); + + XMLStreamReader reader = + XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + PurchaseOrderDocument po2 = (PurchaseOrderDocument)t2.transform(reader, null); + client.call(po2.getPurchaseOrder()); + + Reader2JAXB t3 = new Reader2JAXB(); + JAXBElement po3 = + (JAXBElement)t3.transform(new StringReader(IPO_XML), tContext); + client.call(po3.getValue()); + + } + + protected void setUp() throws Exception { + setApplicationSCDL(getClass(), "META-INF/sca/default.scdl"); + addExtension("test-extensions", getClass().getClassLoader() + .getResource("META-INF/tuscany/test-extensions.scdl")); + super.setUp(); + CompositeContext context = CurrentCompositeContext.getContext(); + client = context.locateService(Client.class, "Client"); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java new file mode 100644 index 0000000000..c44e575e26 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.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.databinding.sample; + +import org.apache.tuscany.api.annotation.DataType; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +import com.example.ipo.jaxb.PurchaseOrderType; + + +/** + * @version $Rev$ $Date$ + */ +@Remotable +@Service +public interface Echo { + @DataType(name="javax.xml.bind.JAXBElement") + PurchaseOrderType echoJAXB(PurchaseOrderType po); + + @DataType(name="commonj.sdo.DataObject") + com.example.ipo.sdo.PurchaseOrderType echoSDO(com.example.ipo.sdo.PurchaseOrderType po); + + @DataType(name="org.apache.xmlbeans.XmlObject") + com.example.ipo.xmlbeans.PurchaseOrderType echoXMLBeans(com.example.ipo.xmlbeans.PurchaseOrderType po); +} \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java new file mode 100644 index 0000000000..775c0317a4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.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.sample; + +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class EchoImpl implements Echo { + + public PurchaseOrderType echoJAXB(PurchaseOrderType po) { + System.out.println("JAXB: " + po); + return po; + } + + public com.example.ipo.sdo.PurchaseOrderType echoSDO(com.example.ipo.sdo.PurchaseOrderType po) { + System.out.println("SDO: " + po); + return po; + } + + public com.example.ipo.xmlbeans.PurchaseOrderType echoXMLBeans(com.example.ipo.xmlbeans.PurchaseOrderType po) { + System.out.println("XMLBeans: " + po); + return po; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..7e4ed88498 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl @@ -0,0 +1,34 @@ + + + + + + + + + Echo + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl new file mode 100644 index 0000000000..e4fe956e61 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl new file mode 100644 index 0000000000..3b7cd0c32a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..36577487ba --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl new file mode 100644 index 0000000000..2cadfbbca1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl new file mode 100644 index 0000000000..9a15675f9f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl new file mode 100644 index 0000000000..88bb3b856d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl @@ -0,0 +1,30 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml new file mode 100755 index 0000000000..58058dbe1a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml @@ -0,0 +1,33 @@ + + + + + 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 + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ + + + + + com.example.ipo.xmlbeans + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml new file mode 100755 index 0000000000..9cdc7660ec --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml @@ -0,0 +1,97 @@ + + + + + org.apache.tuscany.sca.services.databinding + parent + 0.1-pre-spec-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-pre-spec-SNAPSHOT + compile + + + xmlbeans + xbean + 2.1.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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java new file mode 100755 index 0000000000..0b4da53473 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java new file mode 100644 index 0000000000..12057982e4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java new file mode 100755 index 0000000000..0e61bd9571 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java new file mode 100755 index 0000000000..8fc1e58bd5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java new file mode 100755 index 0000000000..8a12cf34f0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..2cadfbbca1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java new file mode 100755 index 0000000000..57fbae7e35 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/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/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ + + + + + com.example.ipo.xmlbeans + + + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml new file mode 100644 index 0000000000..af5af8c5f0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml @@ -0,0 +1,42 @@ + + + + + + org.apache.tuscany.sca.services + parent + 0.1-pre-spec-SNAPSHOT + + + 4.0.0 + org.apache.tuscany.sca.services.databinding + parent + pom + Tuscany SCA Data Bindings + + + databinding-axiom + databinding-castor + databinding-jaxb + databinding-sdo + databinding-xmlbeans + databinding-test + + -- cgit v1.2.3