diff options
Diffstat (limited to 'branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org')
20 files changed, 0 insertions, 1576 deletions
diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java deleted file mode 100755 index 405de57ab3..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.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.sca.databinding.sdo; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLHelper; - -public class DataObject2String extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java deleted file mode 100755 index 5b258b5429..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.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.sca.databinding.sdo; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sdo.helper.XMLStreamHelper; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -public class DataObject2XMLStreamReader extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java deleted file mode 100644 index c83e93dc4e..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java +++ /dev/null @@ -1,37 +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.sca.databinding.sdo; - - -/** - * @version $Rev$ $Date$ - */ -public class DuplicateHelperContextException extends RuntimeException { - private static final long serialVersionUID = -5229624905543066038L; - - /** - * Constructor specifying message and the ID of the duplicate HelperContext. - * - * @param message exception message - * @param identifier the id of the HelperContext that is already present - */ - public DuplicateHelperContextException(String message) { - super(message); - } -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java deleted file mode 100644 index 561e5f3b39..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java +++ /dev/null @@ -1,110 +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.sca.databinding.sdo; - -import java.beans.Introspector; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.implementation.java.JavaImplementation; -import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl; -import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; -import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException; -import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor; - -import commonj.sdo.helper.HelperContext; - -/** - * Processes {@link @HelperContext} annotations on a component implementation - * and adds a {@link JavaMappedProperty} to the component type which will be - * used to inject the appropriate context - * - * @version $Rev$ $Date$ - */ -public class HelperContextProcessor extends BaseJavaClassVisitor { - private HelperContextRegistry registry; - - /** - * @param registry - */ - public HelperContextProcessor(AssemblyFactory assemblyFactory, HelperContextRegistry registry) { - super(assemblyFactory); - this.registry = registry; - } - - /** - * Takes a setter or getter method name and converts it to a property name - * according to JavaBean conventions. For example, <code>setFoo(var)</code> - * is returned as property <code>foo<code> - */ - public static String toPropertyName(String name) { - if (!name.startsWith("set")) { - return name; - } - return Introspector.decapitalize(name.substring(3)); - } - - public void visitMethod(Method method, - JavaImplementation type) throws IntrospectionException { - if (!method.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { - return; - } - if (method.getParameterTypes().length != 1) { - throw new IllegalArgumentException("HelperContext setter must have one parameter: " + method); - } - Class<?> paramType = method.getParameterTypes()[0]; - if (HelperContext.class == paramType) { - String name = toPropertyName(method.getName()); - JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(method, 0)); -// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); - type.getResources().put(name, resource); - } - } - - public void visitField(Field field, - JavaImplementation type) throws IntrospectionException { - if (!field.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { - return; - } - Class<?> paramType = field.getType(); - if (HelperContext.class == paramType) { - String name = field.getName(); - JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(field)); -// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); - type.getResources().put(name, resource); - } - } - - /* - private class HelperContextFactory implements ObjectFactory<HelperContext> { - private URI id; - - public HelperContextFactory(URI id) { - super(); - this.id = id; - } - - public HelperContext getInstance() throws ObjectCreationException { - return registry.getHelperContext(id); - } - - } - */ -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java deleted file mode 100644 index 75d9d33cbb..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java +++ /dev/null @@ -1,52 +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.sca.databinding.sdo; - -import commonj.sdo.helper.HelperContext; - -/** - * A registry for SDO HelperContext - * - * @version $Rev$ $Date$ - */ -public interface HelperContextRegistry { - /** - * Register a HelperContext with the id - * - * @param id - * @param context - */ - void register(Object id, HelperContext context) throws DuplicateHelperContextException; - - /** - * Unregister the HelperContext - * - * @param id - */ - void unregister(Object id); - - /** - * Get the HelperContext associated with the id - * - * @param id The URI of the HelperContext - * @return - */ - HelperContext getHelperContext(Object id); -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java deleted file mode 100644 index 429946f78d..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java +++ /dev/null @@ -1,49 +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.sca.databinding.sdo; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import commonj.sdo.helper.HelperContext; - -/** - * A registry for SDO HelperContext - * - * @version $Rev$ $Date$ - */ -public class HelperContextRegistryImpl implements HelperContextRegistry { - private final Map<Object, HelperContext> registry = new ConcurrentHashMap<Object, HelperContext>(); - - public synchronized void register(Object id, HelperContext context) { - if (registry.containsKey(id)) { - throw new DuplicateHelperContextException("Duplicate HelperContext: " + id); - } - registry.put(id, context); - } - - public void unregister(Object id) { - registry.remove(id); - } - - public HelperContext getHelperContext(Object id) { - return registry.get(id); - } -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java deleted file mode 100644 index 30a3e1c3a9..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java +++ /dev/null @@ -1,78 +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.sca.databinding.sdo; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.impl.BaseImpl; - -import commonj.sdo.helper.HelperContext; - -/** - * The model object for import.sdo - * - * @version $Rev$ $Date$ - */ -public class ImportSDO extends BaseImpl { - public static final QName IMPORT_SDO = - new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); - - private HelperContext helperContext; - private String factoryClassName; - private String schemaLocation; - - public ImportSDO(HelperContext helperContext) { - super(); - this.helperContext = helperContext; - setUnresolved(true); - } - - public HelperContext getHelperContext() { - return helperContext; - } - - /** - * @return the factoryClassName - */ - public String getFactoryClassName() { - return factoryClassName; - } - - /** - * @param factoryClassName the factoryClassName to set - */ - public void setFactoryClassName(String factoryClassName) { - this.factoryClassName = factoryClassName; - } - - /** - * @return the schemaLocation - */ - public String getSchemaLocation() { - return schemaLocation; - } - - /** - * @param schemaLocation the schemaLocation to set - */ - public void setSchemaLocation(String schemaLocation) { - this.schemaLocation = schemaLocation; - } -}
\ No newline at end of file diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java deleted file mode 100755 index 87b6cb3e4a..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java +++ /dev/null @@ -1,192 +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.sca.databinding.sdo; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static org.apache.tuscany.sca.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 javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.service.ContributionReadException; -import org.apache.tuscany.sca.contribution.service.ContributionResolveException; -import org.apache.tuscany.sca.contribution.service.ContributionWriteException; -import org.apache.tuscany.sdo.util.SDOUtil; - -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 ImportSDOProcessor implements StAXArtifactProcessor<ImportSDO> { - private HelperContextRegistry helperContextRegistry; - - public ImportSDOProcessor(HelperContextRegistry helperContextRegistry) { - super(); - this.helperContextRegistry = helperContextRegistry; - } - - public QName getXMLType() { - return IMPORT_SDO; - } - - public ImportSDO read(XMLStreamReader reader) throws ContributionReadException { - assert IMPORT_SDO.equals(reader.getName()); - - HelperContext helperContext = null; - - // FIXME: [rfeng] How to get the enclosing composite? - int id = System.identityHashCode(reader); - // FIXME: [rfeng] How to associate the TypeHelper with deployment - // context? - synchronized (helperContextRegistry) { - helperContext = helperContextRegistry.getHelperContext(id); - if (helperContext == null) { - helperContext = SDOUtil.createHelperContext(); - helperContextRegistry.register(id, helperContext); - } - } - - ImportSDO importSDO = new ImportSDO(helperContext); - String factoryName = reader.getAttributeValue(null, "factory"); - if (factoryName != null) { - importSDO.setFactoryClassName(factoryName); - } - String location = reader.getAttributeValue(null, "location"); - if (location != null) { - importSDO.setSchemaLocation(location); - } - - // Skip to end element - try { - while (reader.hasNext()) { - if (reader.next() == END_ELEMENT && ImportSDO.IMPORT_SDO.equals(reader.getName())) { - break; - } - } - } catch (XMLStreamException e) { - throw new ContributionReadException(e); - } - return importSDO; - } - - private void importFactory(ImportSDO importSDO) throws ContributionResolveException { - String factoryName = importSDO.getFactoryClassName(); - if (factoryName != null) { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - try { - Class<?> factoryClass = cl.loadClass(factoryName); - register(factoryClass, importSDO.getHelperContext()); - } catch (Exception e) { - throw new ContributionResolveException(e); - } - importSDO.setUnresolved(false); - } - } - - 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(ImportSDO importSDO) throws ContributionResolveException { - String location = importSDO.getSchemaLocation(); - if (location != null) { - try { - URL wsdlURL = null; - URI uri = URI.create(location); - if (uri.isAbsolute()) { - wsdlURL = uri.toURL(); - } - wsdlURL = Thread.currentThread().getContextClassLoader().getResource(location); - if (null == wsdlURL) { - ContributionResolveException loaderException = new ContributionResolveException( - "WSDL location error"); - throw loaderException; - } - InputStream xsdInputStream = wsdlURL.openStream(); - try { - XSDHelper xsdHelper = importSDO.getHelperContext().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 cl = Thread.currentThread().getContextClassLoader(); - xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); - } finally { - xsdInputStream.close(); - } - } catch (IOException e) { - throw new ContributionResolveException(e); - } - importSDO.setUnresolved(false); - } - } - - public QName getArtifactType() { - return ImportSDO.IMPORT_SDO; - } - - public void write(ImportSDO model, XMLStreamWriter outputSource) throws ContributionWriteException { - // TODO Auto-generated method stub - - } - - public Class<ImportSDO> getModelType() { - return ImportSDO.class; - } - - public void resolve(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { - importFactory(importSDO); - importWSDL(importSDO); - if (!importSDO.isUnresolved()) { - resolver.addModel(importSDO); - } - } - -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java deleted file mode 100644 index 78058a5969..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java +++ /dev/null @@ -1,106 +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.sca.databinding.sdo; - -import java.awt.Component; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.util.XMLType; -import org.apache.tuscany.sdo.util.SDOUtil; - -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; - Component composite = (Component)context.getMetadata().get(Component.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 { - // helperContext = (HelperContext)child.getTargetInstance(); - // } catch (TargetResolutionException e) { - // helperContext = null; - // } - } - if (helperContext == null) { - return getDefaultHelperContext(); - } else { - return helperContext; - } - } - - public static HelperContext getHelperContext(Composite model) { - HelperContext helperContext = null; - for (Object ext : model.getExtensions()) { - if (ext instanceof HelperContext) { - helperContext = (HelperContext)ext; - break; - } - } - if (helperContext == null) { - helperContext = SDOUtil.createHelperContext(); - model.getExtensions().add(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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java deleted file mode 100644 index 2736d4bbde..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/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.sca.databinding.sdo; - -import java.lang.annotation.Annotation; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.ExceptionHandler; -import org.apache.tuscany.sca.databinding.SimpleTypeMapper; -import org.apache.tuscany.sca.databinding.WrapperHandler; -import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -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 BaseDataBinding { - 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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java deleted file mode 100644 index 1056d2ec38..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java +++ /dev/null @@ -1,124 +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.sca.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.sca.databinding.ExceptionHandler; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -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 DataTypeImpl<XMLType>(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); - return faultType; - - } - -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java deleted file mode 100644 index f4e2044aa2..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/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.sca.databinding.sdo; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.SimpleTypeMapper; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sdo.util.SDOUtil; - -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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java deleted file mode 100644 index d89627da71..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/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.sca.databinding.sdo; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.WrapperHandler; -import org.apache.tuscany.sca.interfacedef.util.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.sca.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.sca.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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java deleted file mode 100755 index 01ec74bb30..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java +++ /dev/null @@ -1,55 +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.sca.databinding.sdo; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLHelper; - -public class String2DataObject extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java deleted file mode 100644 index d11e6e46d9..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java +++ /dev/null @@ -1,59 +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.sca.databinding.sdo; - -import java.io.StringWriter; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; -import commonj.sdo.helper.XMLHelper; - -public class XMLDocument2String extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java deleted file mode 100755 index 9e888258f0..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java +++ /dev/null @@ -1,63 +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.sca.databinding.sdo; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sdo.helper.XMLStreamHelper; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; - -public class XMLDocument2XMLStreamReader extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java deleted file mode 100755 index 8797ed1f28..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java +++ /dev/null @@ -1,64 +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.sca.databinding.sdo; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sdo.helper.XMLStreamHelper; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.helper.HelperContext; - -public class XMLStreamReader2DataObject extends BaseTransformer<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-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java deleted file mode 100755 index 43b05d9cb8..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.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.sca.databinding.sdo; - -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; -import org.apache.tuscany.sdo.helper.XMLStreamHelper; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.helper.HelperContext; -import commonj.sdo.helper.XMLDocument; - -public class XMLStreamReader2XMLDocument extends BaseTransformer<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; - } - -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java deleted file mode 100644 index 9b6beead14..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java +++ /dev/null @@ -1,37 +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.sca.databinding.sdo.api; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * This annotation can be used by component implementation class to receive the - * SDO HelperContext. - * - * @version $Rev$ $Date$ - */ -@Target({METHOD, FIELD}) -@Retention(RUNTIME) -public @interface HelperContext { -} diff --git a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java b/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java deleted file mode 100644 index 4f6caa6ec0..0000000000 --- a/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java +++ /dev/null @@ -1,80 +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.sca.databinding.sdo.module; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.core.ModuleActivator; -import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; -import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; -import org.apache.tuscany.sca.databinding.sdo.DataObject2String; -import org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader; -import org.apache.tuscany.sca.databinding.sdo.HelperContextProcessor; -import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistry; -import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistryImpl; -import org.apache.tuscany.sca.databinding.sdo.ImportSDOProcessor; -import org.apache.tuscany.sca.databinding.sdo.SDODataBinding; -import org.apache.tuscany.sca.databinding.sdo.String2DataObject; -import org.apache.tuscany.sca.databinding.sdo.XMLDocument2String; -import org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader; -import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject; -import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument; -import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospectorExtensionPoint; - -/** - * @version $Rev$ $Date$ - */ -public class SDODataBindingModuleActivator implements ModuleActivator { - - public Object[] getExtensionPoints() { - return null; - } - - public void start(ExtensionPointRegistry registry) { - ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); - AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); - - DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); - dataBindings.addDataBinding(new SDODataBinding()); - - StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - HelperContextRegistry contextRegistry = new HelperContextRegistryImpl(); - processors.addArtifactProcessor(new ImportSDOProcessor(contextRegistry)); - - TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); - transformers.addTransformer(new DataObject2String()); - transformers.addTransformer(new DataObject2XMLStreamReader()); - transformers.addTransformer(new XMLDocument2String()); - transformers.addTransformer(new String2DataObject()); - transformers.addTransformer(new XMLDocument2XMLStreamReader()); - transformers.addTransformer(new XMLStreamReader2DataObject()); - transformers.addTransformer(new XMLStreamReader2XMLDocument()); - - JavaClassIntrospectorExtensionPoint introspectors = registry.getExtensionPoint(JavaClassIntrospectorExtensionPoint.class); - introspectors.addClassVisitor(new HelperContextProcessor(assemblyFactory, contextRegistry)); - - } - - public void stop(ExtensionPointRegistry registry) { - } - -} |