diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:56 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:11:56 +0000 |
commit | 9bed5ae38c581999db465b42b504026a7097af95 (patch) | |
tree | a32b086a857a4556b8aec1aa9ed3a586efd9461e /branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org | |
parent | ece4fd35da7b7fc76264776f81705e6b5b52d3e0 (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835141 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org')
15 files changed, 0 insertions, 1043 deletions
diff --git a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java deleted file mode 100755 index 9125980eed..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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<DataObject, String> implements - PullTransformer<DataObject, String> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java deleted file mode 100755 index 2892b1bc4d..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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<DataObject, XMLStreamReader> implements - PullTransformer<DataObject, XMLStreamReader> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java deleted file mode 100755 index 5706005252..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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<ModelObject> { - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java deleted file mode 100755 index 92b1036bc0..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java deleted file mode 100755 index a3870b5e9a..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java deleted file mode 100644 index 213dfd9280..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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<Object> wrapperHandler; - - @Override - public DataType introspect(Class<?> javaType) { - if (javaType == DataObject.class) { - return new DataType<QName>(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<QName> dataType = new DataType<QName>(getName(), javaType, xmlType); - return dataType; - } - - public SDODataBinding() { - super(DataObject.class); - wrapperHandler = new SDOWrapperHandler(); - } - - @Override - public WrapperHandler getWrapperHandler() { - return wrapperHandler; - } - -} diff --git a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java deleted file mode 100644 index 7cb52e366e..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java deleted file mode 100755 index 0c3e74cdc7..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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<DataObject> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java deleted file mode 100644 index a363a8a3ec..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java deleted file mode 100644 index 7074687722..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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<Object> { - - /** - * @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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java deleted file mode 100755 index 64c79a3bd0..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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<String, DataObject> implements - PullTransformer<String, DataObject> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java deleted file mode 100644 index 16e2714a89..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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<XMLDocument, String> implements - PullTransformer<XMLDocument, String> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java deleted file mode 100755 index 53343aba6b..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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<XMLDocument, XMLStreamReader> implements - PullTransformer<XMLDocument, XMLStreamReader> { - /** - * @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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java deleted file mode 100755 index 2a4ce83eb6..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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<XMLStreamReader, DataObject> implements - PullTransformer<XMLStreamReader, DataObject> { - - 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/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java deleted file mode 100755 index 616d2139d4..0000000000 --- a/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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<XMLStreamReader, XMLDocument> implements - PullTransformer<XMLStreamReader, XMLDocument> { - - 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; - } - -} |