From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/databinding/sdo/DataObject2String.java | 69 ++++++ .../sdo/DataObject2XMLStreamReader.java | 72 +++++++ .../tuscany/databinding/sdo/DataObjectLoader.java | 87 ++++++++ .../tuscany/databinding/sdo/ImportSDOLoader.java | 146 +++++++++++++ .../tuscany/databinding/sdo/ModelDataObject.java | 38 ++++ .../tuscany/databinding/sdo/SDODataBinding.java | 65 ++++++ .../tuscany/databinding/sdo/SDODataTypeHelper.java | 52 +++++ .../tuscany/databinding/sdo/SDOObjectFactory.java | 47 +++++ .../databinding/sdo/SDOSimpleTypeMapper.java | 69 ++++++ .../tuscany/databinding/sdo/SDOWrapperHandler.java | 83 ++++++++ .../tuscany/databinding/sdo/String2DataObject.java | 58 +++++ .../databinding/sdo/XMLDocument2String.java | 63 ++++++ .../sdo/XMLDocument2XMLStreamReader.java | 65 ++++++ .../sdo/XMLStreamReader2DataObject.java | 66 ++++++ .../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 | 86 ++++++++ .../databinding/sdo/SDODataBindingTestCase.java | 61 ++++++ .../sdo/SDOTransformerTestCaseBase.java | 81 +++++++ .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 60 ++++++ .../META-INF/tuscany/databinding.sdo.scdl | 34 +++ .../databinding-sdo/src/test/resources/ipo.xsd | 136 ++++++++++++ .../src/test/resources/model/sca-core.xsd | 233 +++++++++++++++++++++ .../resources/model/sca-implementation-mock.xsd | 43 ++++ 28 files changed, 2101 insertions(+) create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..bae01a69b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.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.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.TypeHelper; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class DataObject2String extends TransformerExtension implements + PullTransformer { + + private static final String TUSCANY_SDO = "http://incubator.apache.org/tuscany/xmlns/sdo/1.0-incubator-M2"; + + public String transform(DataObject source, TransformationContext context) { + try { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..8caba8458d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/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.TypeHelper; +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 { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + Object logicalType = context.getSourceDataType().getLogical(); + QName elementName = + (logicalType instanceof QName) ? (QName) logicalType : new QName("commonj.sdo", "dataObject"); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java new file mode 100755 index 0000000000..cd45575004 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.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 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 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 + * + */ +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, 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(eager = true) + public void start() { + registry.registerLoader(propertyQName, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(propertyQName, this); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java new file mode 100755 index 0000000000..ac8ca776c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.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.TypeHelper; +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://incubator.apache.org/tuscany/xmlns/databinding/sdo/1.0-incubator-M2", "import.sdo"); + + @Constructor( { "registry" }) + public ImportSDOLoader(@Autowire LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ModelObject load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext) + throws XMLStreamException, LoaderException { + assert IMPORT_SDO.equals(reader.getName()); + + // FIXME: [rfeng] How to associate the TypeHelper with deployment context? + TypeHelper typeHelper = TypeHelper.INSTANCE; + if (deploymentContext != null && deploymentContext.getParent() != null) { + typeHelper = (TypeHelper) deploymentContext.getParent().getExtension(TypeHelper.class.getName()); + if (typeHelper == null) { + typeHelper = SDOUtil.createTypeHelper(); + deploymentContext.getParent().putExtension(TypeHelper.class.getName(), typeHelper); + } + } + + importFactory(reader, deploymentContext); + importWSDL(reader, deploymentContext, typeHelper); + LoaderUtil.skipToEndElement(reader); + return new SDOType(typeHelper); + } + + 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, TypeHelper typeHelper) + 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 = SDOUtil.createXSDHelper(typeHelper); + 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 TypeHelper typeHelper; + + public SDOType(TypeHelper typeHelper) { + super(); + this.typeHelper = typeHelper; + } + + public TypeHelper getTypeHelper() { + return typeHelper; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java new file mode 100644 index 0000000000..9d88c9fa58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.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.sdo; + +import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.databinding.TransformationContext; + +import commonj.sdo.helper.TypeHelper; + +/** + * Helper class to get TypeHelper from the transformation context + */ +public class SDODataTypeHelper { + private SDODataTypeHelper() { + } + + public static TypeHelper getTypeHelper(TransformationContext context) { + TypeHelper typeHelper = null; + if (context == null || context.getMetadata() == null) { + return TypeHelper.INSTANCE; + } + CompositeComponent composite = (CompositeComponent) context.getMetadata().get(CompositeComponent.class); + if (composite != null) { + SDOType sdoType = (SDOType) composite.getExtensions().get(SDOType.class); + if (sdoType != null) { + typeHelper = sdoType.getTypeHelper(); + } + } + if (typeHelper == null) { + return TypeHelper.INSTANCE; + } + return typeHelper; + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..78e2c4e0c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/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.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 { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + 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 { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + if (typeHelper == null) { + typeHelper = TypeHelper.INSTANCE; + } + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..d34b389458 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.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.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +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) { + TypeHelper typeHelper = TypeHelper.INSTANCE; + if (context != null) { + DataType targetType = context.getTargetDataType(); + if (targetType != null) { + typeHelper = (TypeHelper) targetType.getMetadata(TypeHelper.class.getName()); + if (typeHelper == null) { + typeHelper = TypeHelper.INSTANCE; + } + } + } + QName typeName = element.getType().getQName(); + DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper); + DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..81b0b7dbcc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import org.apache.tuscany.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.TypeHelper; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class String2DataObject extends TransformerExtension implements PullTransformer { + + public DataObject transform(String source, TransformationContext context) { + try { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..8870000838 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.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 java.io.StringWriter; + +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.TypeHelper; +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 { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..92563f37d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.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.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.TypeHelper; +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 { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..e00396820a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.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.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.TypeHelper; + +@Service(Transformer.class) +public class XMLStreamReader2DataObject extends TransformerExtension implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + // 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..063fbca812 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; + +@Service(Transformer.class) +public class XMLStreamReader2XMLDocument extends TransformerExtension implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + TypeHelper typeHelper = SDODataTypeHelper.getTypeHelper(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl new file mode 100644 index 0000000000..245f06e1cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/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-M2-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..e554690be9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,66 @@ + + + + + + + org.apache.tuscany.sca.services.databinding + databinding-sdo + 1.0-incubator-M2-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java new file mode 100755 index 0000000000..8cdbf0a295 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/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.ModuleScopeContainer; +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 ModuleScopeContainer(), null); + ModelDataObject modelObject = (ModelDataObject) loader.load(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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java new file mode 100755 index 0000000000..b2acb139f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.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.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, reader, deploymentContext) instanceof SDOType); + } + + public void testLocation() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType); + } + + public void testFactory() throws XMLStreamException, LoaderException { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + assertTrue(loader.load(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 = null; + + static { + ImportSDOLoaderTestCase.inited = true; + } + } +} + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..848dde6e13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +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; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * 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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; + +import commonj.sdo.helper.XMLDocument; +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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..70b4028e8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/sca-java-1.x/branches/sca-java-M2/sca/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/sca-java-M2/sca/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3