diff options
Diffstat (limited to 'branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache')
18 files changed, 0 insertions, 1397 deletions
diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java deleted file mode 100755 index c188e94f3b..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.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.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> { - - public String transform(DataObject source, TransformationContext context) { - try { - HelperContext helperContext = SDOContextHelper.getHelperContext(context); - XMLHelper xmlHelper = helperContext.getXMLHelper(); - QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); - return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - public Class getSourceType() { - return DataObject.class; - } - - public Class getTargetType() { - return String.class; - } - - public int getWeight() { - return 40; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java deleted file mode 100755 index 9c93d75adf..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java +++ /dev/null @@ -1,70 +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 = SDOContextHelper.getHelperContext(context); - XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); - QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); - XMLHelper xmlHelper = helperContext.getXMLHelper(); - XMLDocument document = - xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); - return streamHelper.createXMLStreamReader(document); - } catch (XMLStreamException e) { - // TODO: Add context to the exception - throw new TransformationException(e); - } - } - - public Class getSourceType() { - return DataObject.class; - } - - public Class getTargetType() { - return XMLStreamReader.class; - } - - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java deleted file mode 100755 index 25793d1777..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java +++ /dev/null @@ -1,73 +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.annotation.Autowire; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.LoaderExtension; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.ModelObject; -import org.osoa.sca.annotations.EagerInit; -import org.osoa.sca.annotations.Property; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -/** - * A SDO model-based Loader to load DataObject from the XML stream - */ -@EagerInit -public class DataObjectLoader extends LoaderExtension<ModelDataObject> { - private QName elementName; - - public DataObjectLoader(@Autowire LoaderRegistry registry, - @Property(name = "namespace", required = true) String namespace, - @Property(name = "name", required = true) String name) { - super(registry); - this.elementName = new QName(namespace, name); - } - - public ModelDataObject load(CompositeComponent parent, - ModelObject object, - XMLStreamReader reader, - DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { - assert elementName.equals(reader.getName()); - HelperContext helperContext = SDOContextHelper.getHelperContext(object); - TypeHelper typeHelper = helperContext.getTypeHelper(); - XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); - DataObject dataObject = streamHelper.loadObject(reader); - // TODO: Is it required that the object always extends from ModelObject? - return new ModelDataObject(dataObject); - } - - @Override - public QName getXMLType() { - return elementName; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.java deleted file mode 100644 index 8d14773b88..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDO.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 javax.xml.namespace.QName; - -import org.apache.tuscany.spi.model.ModelObject; - -import commonj.sdo.helper.HelperContext; - -/** - * The model object for import.sdo - * - * @version $Rev$ $Date$ - */ -public class ImportSDO extends ModelObject { - public static final QName IMPORT_SDO = - new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); - - private HelperContext helperContext; - - public ImportSDO(HelperContext helperContext) { - super(); - this.helperContext = helperContext; - } - - public HelperContext getHelperContext() { - return helperContext; - } -}
\ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java deleted file mode 100644 index 31f17860b4..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOBuilder.java +++ /dev/null @@ -1,57 +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.builder.BuilderException; -import org.apache.tuscany.spi.component.ComponentRegistrationException; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.GenericBuilderExtension; - -import commonj.sdo.helper.HelperContext; - -/** - * @version $Rev$ $Date$ - */ -public class ImportSDOBuilder extends GenericBuilderExtension<SCAObject, ImportSDO> { - - @Override - protected Class<ImportSDO> getModelType() { - return ImportSDO.class; - } - - public SCAObject build(SCAObject parent, ImportSDO modelObject, DeploymentContext deploymentContext) - throws BuilderException { - if (parent instanceof CompositeComponent) { - CompositeComponent component = (CompositeComponent)parent; - SDOHelperContext obj = new SDOHelperContext(component, modelObject.getHelperContext()); - try { - component.registerJavaObject(obj.getName(), HelperContext.class, obj.getHelperContext()); - } catch (ComponentRegistrationException e) { - throw new IllegalArgumentException(e); - } - return obj; - } else { - return null; - } - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java deleted file mode 100755 index f115fc78ec..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java +++ /dev/null @@ -1,163 +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 static org.apache.tuscany.databinding.sdo.ImportSDO.IMPORT_SDO; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URL; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.extension.LoaderExtension; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.LoaderUtil; -import org.apache.tuscany.spi.model.ModelObject; -import org.osoa.sca.annotations.Constructor; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XSDHelper; -import commonj.sdo.impl.HelperProvider; - -/** - * Loader that handles <import.sdo> elements. - * - * @version $Rev$ $Date$ - */ -public class ImportSDOLoader extends LoaderExtension { - - @Constructor( {"registry"}) - public ImportSDOLoader(@Autowire - LoaderRegistry registry) { - super(registry); - } - - public QName getXMLType() { - return IMPORT_SDO; - } - - public ModelObject load(CompositeComponent parent, - ModelObject object, - XMLStreamReader reader, - DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { - assert IMPORT_SDO.equals(reader.getName()); - - // FIXME: [rfeng] How to associate the TypeHelper with deployment - // context? - HelperContext helperContext = SDOContextHelper.getHelperContext(object); - - importFactory(reader, deploymentContext, helperContext); - importWSDL(reader, deploymentContext, helperContext); - LoaderUtil.skipToEndElement(reader); - return new ImportSDO(helperContext); - } - - private void importFactory(XMLStreamReader reader, DeploymentContext deploymentContext, HelperContext helperContext) - throws LoaderException { - String factoryName = reader.getAttributeValue(null, "factory"); - if (factoryName != null) { - ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); - try { - // set TCCL as SDO needs it - ClassLoader cl = deploymentContext.getClassLoader(); - Thread.currentThread().setContextClassLoader(cl); - Class<?> factoryClass = cl.loadClass(factoryName); - register(factoryClass, helperContext); - } catch (Exception e) { - throw new LoaderException(e.getMessage(), e); - } finally { - Thread.currentThread().setContextClassLoader(oldCL); - } - } - } - - private static void register(Class factoryClass, HelperContext helperContext) throws Exception { - Field field = factoryClass.getField("INSTANCE"); - Object factory = field.get(null); - Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); - method.invoke(factory, new Object[] {helperContext}); - - // FIXME: How do we associate the application HelperContext with the one - // imported by the composite - HelperContext defaultContext = HelperProvider.getDefaultContext(); - method.invoke(factory, new Object[] {defaultContext}); - } - - private void importWSDL(XMLStreamReader reader, DeploymentContext deploymentContext, HelperContext helperContext) - throws LoaderException { - String location = reader.getAttributeValue(null, "location"); - if (location == null) { - location = reader.getAttributeValue(null, "wsdlLocation"); - } - if (location != null) { - try { - URL wsdlURL = null; - URI uri = URI.create(location); - if (uri.isAbsolute()) { - wsdlURL = uri.toURL(); - } - wsdlURL = deploymentContext.getClassLoader().getResource(location); - if (null == wsdlURL) { - LoaderException loaderException = new LoaderException("WSDL location error"); - loaderException.setResourceURI(location); - throw loaderException; - } - InputStream xsdInputStream = wsdlURL.openStream(); - try { - XSDHelper xsdHelper = helperContext.getXSDHelper(); - xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); - } finally { - xsdInputStream.close(); - } - // FIXME: How do we associate the application HelperContext with the one - // imported by the composite - HelperContext defaultContext = HelperProvider.getDefaultContext(); - xsdInputStream = wsdlURL.openStream(); - try { - XSDHelper xsdHelper = defaultContext.getXSDHelper(); - ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); - try { - // set TCCL as SDO needs it - ClassLoader cl = deploymentContext.getClassLoader(); - Thread.currentThread().setContextClassLoader(cl); - xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); - } finally { - Thread.currentThread().setContextClassLoader(oldCL); - } - } finally { - xsdInputStream.close(); - } - } catch (IOException e) { - LoaderException sfe = new LoaderException(e.getMessage()); - sfe.setResourceURI(location); - throw sfe; - } - } - } -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java deleted file mode 100755 index ba171af498..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java +++ /dev/null @@ -1,43 +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; - -/** - * Wrapper of DataObject as a ModelObject - * - * @version $Rev$ $Date$ - */ -public class ModelDataObject extends ModelObject { - private DataObject dataObject; - - public ModelDataObject(DataObject dataObject) { - super(); - this.dataObject = dataObject; - } - - public DataObject getDataObject() { - return dataObject; - } - - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java deleted file mode 100644 index 9d37c79228..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOContextHelper.java +++ /dev/null @@ -1,111 +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.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.TargetResolutionException; -import org.apache.tuscany.spi.databinding.TransformationContext; -import org.apache.tuscany.spi.idl.XMLType; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.ModelObject; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.impl.HelperProvider; - -/** - * Helper class to get TypeHelper from the context - */ -public final class SDOContextHelper { - private SDOContextHelper() { - } - - public static HelperContext getHelperContext(TransformationContext context) { - if (context == null || context.getMetadata() == null) { - return getDefaultHelperContext(); - } - HelperContext helperContext = null; - CompositeComponent composite = (CompositeComponent)context.getMetadata().get(CompositeComponent.class); - if (composite != null) { -// SDOHelperContext sdoContext = -// (SDOHelperContext)composite.getExtensions().get(HelperContext.class.getName()); -// if (sdoContext != null) { -// helperContext = sdoContext.getHelperContext(); -// } - AtomicComponent child = (AtomicComponent)composite.getSystemChild(HelperContext.class.getName()); - try { - // The child can be null if no import.sdo is declared - if (child != null) { - helperContext = (HelperContext)child.getTargetInstance(); - } - } catch (TargetResolutionException e) { - helperContext = null; - } - } - if (helperContext == null) { - return getDefaultHelperContext(); - } else { - return helperContext; - } - } - - public static HelperContext getHelperContext(ModelObject model) { - HelperContext helperContext = null; - if (model instanceof CompositeComponentType) { - // HACK: Retrieve the SDO HelperContext from the - // CompositeComponentType - // extensions - helperContext = (HelperContext)model.getExtensions().get(ImportSDO.IMPORT_SDO); - if (helperContext == null) { - helperContext = SDOUtil.createHelperContext(); - ((CompositeComponentType<?, ?, ?>)model).getDeclaredExtensions().put(ImportSDO.IMPORT_SDO, - helperContext); - } - } - - if (helperContext == null) { - helperContext = getDefaultHelperContext(); - } - - return helperContext; - } - - protected static HelperContext getDefaultHelperContext() { - // SDOUtil.createHelperContext(); - return HelperProvider.getDefaultContext(); - } - - public static QName getElement(DataType<?> dataType) { - Object logical = dataType.getLogical(); - QName elementName = SDODataBinding.ROOT_ELEMENT; - if (logical instanceof XMLType) { - XMLType xmlType = (XMLType)logical; - QName element = xmlType.getElementName(); - if (element != null) { - elementName = element; - } - } - return elementName; - } -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java deleted file mode 100644 index 4178ee9f63..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java +++ /dev/null @@ -1,122 +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.lang.annotation.Annotation; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.databinding.ExceptionHandler; -import org.apache.tuscany.spi.databinding.SimpleTypeMapper; -import org.apache.tuscany.spi.databinding.WrapperHandler; -import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; -import org.apache.tuscany.spi.idl.XMLType; -import org.apache.tuscany.spi.model.DataType; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.CopyHelper; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.impl.HelperProvider; - -/** - * SDO Databinding - * - * @version $Reve$ $Date$ - */ -public class SDODataBinding extends DataBindingExtension { - public static final String NAME = DataObject.class.getName(); - public static final String[] ALIASES = new String[] {"sdo"}; - - public static final String ROOT_NAMESPACE = "commonj.sdo"; - public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); - - private WrapperHandler<Object> wrapperHandler; - - public SDODataBinding() { - super(NAME, ALIASES, DataObject.class); - wrapperHandler = new SDOWrapperHandler(); - } - - @Override - public boolean introspect(DataType dataType, Annotation[] annotations) { - Object physical = dataType.getPhysical(); - if (!(physical instanceof Class)) { - return false; - } - Class javaType = (Class)physical; - HelperContext context = HelperProvider.getDefaultContext(); - // FIXME: Need a better to test dynamic SDO - if (DataObject.class.isAssignableFrom(javaType)) { - // Dynamic SDO - dataType.setDataBinding(getName()); - dataType.setLogical(XMLType.UNKNOWN); - return true; - } - // FIXME: We need to access HelperContext - Type type = context.getTypeHelper().getType(javaType); - if (type == null) { - return false; - } - if (type.isDataType()) { - // FIXME: Ignore simple types? - return false; - } - String namespace = type.getURI(); - String name = context.getXSDHelper().getLocalName(type); - QName xmlType = new QName(namespace, name); - dataType.setDataBinding(getName()); - dataType.setLogical(new XMLType(null, xmlType)); - return true; - } - - @Override - public WrapperHandler getWrapperHandler() { - return wrapperHandler; - } - - public SimpleTypeMapper getSimpleTypeMapper() { - return new SDOSimpleTypeMapper(); - } - - @Override - public Object copy(Object arg) { - HelperContext context = HelperProvider.getDefaultContext(); - CopyHelper copyHelper = context.getCopyHelper(); - if (arg instanceof XMLDocument) { - XMLDocument document = (XMLDocument)arg; - DataObject dataObject = copyHelper.copy(document.getRootObject()); - return context.getXMLHelper().createDocument(dataObject, - document.getRootElementURI(), - document.getRootElementName()); - } else if (arg instanceof DataObject) { - return context.getCopyHelper().copy((DataObject)arg); - } else { - return super.copy(arg); - } - } - - @Override - public ExceptionHandler getExceptionHandler() { - return new SDOExceptionHandler(); - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java deleted file mode 100644 index 28a36ea2c8..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOExceptionHandler.java +++ /dev/null @@ -1,123 +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.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.databinding.ExceptionHandler; -import org.apache.tuscany.spi.idl.XMLType; -import org.apache.tuscany.spi.model.DataType; - -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.impl.HelperProvider; - -/** - * SDO implementation of ExceptionHandler - * - * @version $Rev$ $Date$ - */ -public class SDOExceptionHandler implements ExceptionHandler { - private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; - - // FIXME: Need a way to pass in the HelperContext - private HelperContext helperContext = HelperProvider.getDefaultContext(); - - /** - * <ul> - * <li>WrapperException(String message, FaultBean faultInfo) <br> - * A constructor where WrapperException is replaced with the name of the - * generated wrapper exception and FaultBean is replaced by the name of the - * generated fault bean. - * <li> WrapperException(String message, FaultBean faultInfo, Throwable - * cause) <br> - * A constructor whereWrapperException is replaced with the name of the - * generated wrapper exception and FaultBean is replaced by the name of the - * generated fault bean. The last argument, cause, may be used to convey - * protocol specific fault information - * </ul> - */ - public Exception createException(DataType<DataType> exceptionType, String message, Object faultInfo, Throwable cause) { - Class exceptionClass = (Class)exceptionType.getPhysical(); - DataType<?> faultBeanType = exceptionType.getLogical(); - Class faultBeanClass = (Class)faultBeanType.getPhysical(); - try { - Constructor constructor = - exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); - return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); - } catch (Throwable e) { - throw new IllegalArgumentException(e); - } - } - - public Object getFaultInfo(Exception exception) { - if (exception == null) { - return null; - } - try { - Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); - return method.invoke(exception, (Object[])null); - } catch (Throwable e) { - throw new IllegalArgumentException(e); - } - } - - public DataType<?> getFaultType(DataType exceptionDataType) { - Class exceptionType = (Class) exceptionDataType.getPhysical(); - Class faultBeanClass = null; - try { - Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); - faultBeanClass = method.getReturnType(); - } catch (NoSuchMethodException e) { - faultBeanClass = null; - } - if (faultBeanClass == null) { - return null; - } - - QName faultElement = null; - try { - Field field = exceptionType.getField("FAULT_ELEMENT"); - faultElement = (QName)field.get(null); - } catch (NoSuchFieldException e) { - // Fall back to type inspection - Type type = helperContext.getTypeHelper().getType(faultBeanClass); - if (type != null) { - String ns = type.getURI(); - String name = helperContext.getXSDHelper().getLocalName(type); - faultElement = new QName(ns, name); - } - } catch (Throwable e) { - // Ignore - } - if (faultElement == null) { - return null; - } - DataType<XMLType> faultType = - new DataType<XMLType>(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); - return faultType; - - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java deleted file mode 100644 index 3091d7ec8d..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOHelperContext.java +++ /dev/null @@ -1,48 +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.component.AbstractSCAObject; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.model.Scope; - -import commonj.sdo.helper.HelperContext; - -public class SDOHelperContext extends AbstractSCAObject { - private HelperContext helperContext; - - /** - * @param name - * @param parent - */ - public SDOHelperContext(CompositeComponent parent, HelperContext helperContext) { - super(HelperContext.class.getName(), parent); - this.helperContext = helperContext; - } - - public Scope getScope() { - return Scope.COMPOSITE; - } - - public HelperContext getHelperContext() { - return helperContext; - } - -}
\ No newline at end of file diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java deleted file mode 100644 index 3b57323c73..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.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.namespace.QName; - -import org.apache.tuscany.sdo.util.SDOUtil; -import org.apache.tuscany.spi.databinding.SimpleTypeMapper; -import org.apache.tuscany.spi.databinding.TransformationContext; - -import commonj.sdo.Type; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.TypeHelper; - -/** - * SDO Java/XML mapping for simple XSD types - */ -public class SDOSimpleTypeMapper implements SimpleTypeMapper { - public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; - - public SDOSimpleTypeMapper() { - super(); - } - - public Object toJavaObject(QName typeName, String value, TransformationContext context) { - Type type = null; - if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { - type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); - } else { - HelperContext helperContext = SDOContextHelper.getHelperContext(context); - TypeHelper typeHelper = helperContext.getTypeHelper(); - type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); - } - return SDOUtil.createFromString(type, value); - } - - public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) { - Type type = null; - if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { - type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); - } else { - HelperContext helperContext = SDOContextHelper.getHelperContext(context); - TypeHelper typeHelper = helperContext.getTypeHelper(); - type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); - } - return SDOUtil.convertToString(type, obj); - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java deleted file mode 100644 index dfbf7dabce..0000000000 --- a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java +++ /dev/null @@ -1,99 +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.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.databinding.TransformationContext; -import org.apache.tuscany.spi.databinding.WrapperHandler; -import org.apache.tuscany.spi.idl.ElementInfo; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Sequence; -import commonj.sdo.Type; -import commonj.sdo.helper.DataFactory; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -/** - * SDO Wrapper Handler - */ -public class SDOWrapperHandler implements WrapperHandler<Object> { - - /** - * @see org.apache.tuscany.spi.databinding.WrapperHandler#create(ElementInfo, TransformationContext) - */ - public Object create(ElementInfo element, TransformationContext context) { - HelperContext helperContext = SDOContextHelper.getHelperContext(context); - QName typeName = element.getType().getQName(); - DataFactory dataFactory = helperContext.getDataFactory(); - DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); - XMLHelper xmlHelper = helperContext.getXMLHelper(); - return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart()); - } - - /** - * @see org.apache.tuscany.spi.databinding.WrapperHandler#setChild(java.lang.Object, int, ElementInfo, - * java.lang.Object) - */ - public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { - DataObject wrapperDO = - (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; - wrapperDO.set(i, value); - } - - @SuppressWarnings("unchecked") - public List getChildren(Object wrapper) { - DataObject wrapperDO = - (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; - List<Property> properties = wrapperDO.getInstanceProperties(); - List<Object> elements = new ArrayList<Object>(); - Type type = wrapperDO.getType(); - if (type.isSequenced()) { - // Add values in the sequence - Sequence sequence = wrapperDO.getSequence(); - for (int i = 0; i < sequence.size(); i++) { - // Skip mixed text - if (sequence.getProperty(i) != null) { - elements.add(sequence.getValue(i)); - } - } - } else { - for (Property p : properties) { - Object child = wrapperDO.get(p); - if (p.isMany()) { - for (Object c : (Collection<?>)child) { - elements.add(c); - } - } else { - elements.add(child); - } - } - } - return elements; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java deleted file mode 100755 index bd288c74e7..0000000000 --- a/branches/sca-java-integration/sca/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 = SDOContextHelper.getHelperContext(context); - XMLHelper xmlHelper = helperContext.getXMLHelper(); - return xmlHelper.load(source).getRootObject(); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - public Class getSourceType() { - return String.class; - } - - public Class getTargetType() { - return DataObject.class; - } - - public int getWeight() { - return 50; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java deleted file mode 100644 index 38f48cebee..0000000000 --- a/branches/sca-java-integration/sca/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 = SDOContextHelper.getHelperContext(context); - XMLHelper xmlHelper = helperContext.getXMLHelper(); - StringWriter writer = new StringWriter(); - xmlHelper.save(source, writer, null); - return writer.toString(); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - public Class getSourceType() { - return XMLDocument.class; - } - - public Class getTargetType() { - return String.class; - } - - public int getWeight() { - return 40; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java deleted file mode 100755 index bd20089001..0000000000 --- a/branches/sca-java-integration/sca/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 = SDOContextHelper.getHelperContext(context); - XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); - return streamHelper.createXMLStreamReader(source); - } catch (XMLStreamException e) { - throw new TransformationException(e); - } - } - - public Class getSourceType() { - return XMLDocument.class; - } - - public Class getTargetType() { - return XMLStreamReader.class; - } - - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java deleted file mode 100755 index c29413101d..0000000000 --- a/branches/sca-java-integration/sca/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 = SDOContextHelper.getHelperContext(context); - XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); - // The XMLStreamHelper requires that the reader is posistioned at - // START_ELEMENT - while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { - source.next(); - } - return streamHelper.loadObject(source); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - public Class getTargetType() { - return DataObject.class; - } - - public Class getSourceType() { - return XMLStreamReader.class; - } - - public int getWeight() { - return 15; - } - -} diff --git a/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/branches/sca-java-integration/sca/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java deleted file mode 100755 index ff9e0aa2e1..0000000000 --- a/branches/sca-java-integration/sca/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 = SDOContextHelper.getHelperContext(context); - XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); - return streamHelper.load(source); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - public Class getTargetType() { - return XMLDocument.class; - } - - public Class getSourceType() { - return XMLStreamReader.class; - } - - public int getWeight() { - return 15; - } - -} |