You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2006/08/31 01:03:07 UTC

svn commit: r438699 - in /incubator/tuscany/java/sca/databinding: databinding-framework/src/main/java/org/apache/tuscany/databinding/ databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/ databinding-framework/src/main/java/org/...

Author: rfeng
Date: Wed Aug 30 16:03:06 2006
New Revision: 438699

URL: http://svn.apache.org/viewvc?rev=438699&view=rev
Log:
Reactivate DataBinding and DataBindingRegistry, Add JAXB and SDO DataBinding for DataType introspection

Added:
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java   (with props)
    incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java   (with props)
Removed:
    incubator/tuscany/java/sca/databinding/databinding-framework/src/test/resources/test.composite
Modified:
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/resources/META-INF/sca/databinding.scdl
    incubator/tuscany/java/sca/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.databinding;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * DataBinding represents a data format provider, for example, SDO, JAXB and AXIOM
+ */
+public interface DataBinding {
+    /**
+     * The name of a databinding should be case-insensitive and unique
+     * @return The name of the databinding
+     */
+    String getName();
+    
+    /**
+     * Introspect a java class or interface to create a DataType model
+     * @param javaType The java class or interface to be introspected
+     * @return The newly created DataType or null if the java type is not supported 
+     * by this databinding
+     */
+    DataType introspect(Class<?> javaType);
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tuscany.databinding;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * The registry for data bindings
+ */
+public interface DataBindingRegistry {
+    /**
+     * Register a data binding
+     * @param dataBinding
+     */
+    public void register(DataBinding dataBinding);
+
+    /**
+     * Look up a data binding by id
+     * @param id
+     * @return
+     */
+    public DataBinding getDataBinding(String id);
+
+    /**
+     * Unregister a data binding
+     * @param id
+     * @return
+     */
+    public DataBinding unregister(String id);
+    
+    /**
+     * Introspect the java class to figure out what DataType supports it
+     * @param javaType The java class or interface
+     * @return
+     */
+    public DataType<?> introspectType(Class<?> javaType);
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,82 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tuscany.databinding.extension;
+
+import org.apache.tuscany.databinding.DataBinding;
+import org.apache.tuscany.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.model.DataType;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * Base Implementation of DataBinding
+ */
+@org.osoa.sca.annotations.Scope("MODULE")
+public abstract class DataBindingExtension implements DataBinding {
+    protected DataBindingRegistry registry;
+
+    protected Class<?> baseType = null;
+
+    protected String name = null;
+
+    /**
+     * Create a databinding with the base java type whose name will be used as the name of 
+     * the databinding
+     * 
+     * @param baseType The base java class or interface representing the databinding, 
+     * for example, org.w3c.dom.Node
+     */
+    protected DataBindingExtension(Class<?> baseType) {
+        this(baseType.getName(), baseType);
+    }
+
+    /**
+     * Create a databinding with the name and base java type 
+     *
+     * @param name The name of the databinding
+     * @param baseType The base java class or interface representing the databinding, 
+     * for example, org.w3c.dom.Node
+     */
+    protected DataBindingExtension(String name, Class<?> baseType) {
+        this.name = name;
+        this.baseType = baseType;
+    }
+
+    @Autowire
+    public void setDataBindingRegistry(DataBindingRegistry registry) {
+        this.registry = registry;
+    }
+
+    @Init(eager = true)
+    public void init() {
+        registry.register(this);
+    }
+
+    public DataType introspect(Class<?> javaType) {
+        if (baseType.isAssignableFrom(javaType)) {
+            DataType<Class> dataType = new DataType<Class>(name, javaType, baseType);
+            return dataType;
+        } else {
+            return null;
+        }
+    }
+
+    public final String getName() {
+        return name;
+    }
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,71 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tuscany.databinding.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.databinding.DataBinding;
+import org.apache.tuscany.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * The default implementation of a data binding registry
+ */
+public class DataBindingRegistryImpl implements DataBindingRegistry {
+    private final Map<String, DataBinding> bindings = new HashMap<String, DataBinding>();
+
+    /**
+     * @see org.apache.tuscany.databinding.DataBindingRegistry#getDataBinding(java.lang.String)
+     */
+    public DataBinding getDataBinding(String id) {
+        return bindings.get(id.toLowerCase());
+    }
+
+    /**
+     * @see org.apache.tuscany.databinding.DataBindingRegistry#register(org.apache.tuscany.databinding.DataBinding)
+     */
+    public void register(DataBinding dataBinding) {
+        bindings.put(dataBinding.getName().toLowerCase(), dataBinding);
+    }
+
+    /**
+     * @see org.apache.tuscany.databinding.DataBindingRegistry#unregister(java.lang.String)
+     */
+    public DataBinding unregister(String id) {
+        return bindings.remove(id.toLowerCase());
+    }
+
+    @Init(eager = true)
+    public void init() {
+    }
+
+    @SuppressWarnings("unchecked")
+    public DataType<?> introspectType(Class<?> javaType) {
+        DataType<?> dataType = null;
+        for (DataBinding binding : bindings.values()) {
+            dataType = binding.introspect(javaType);
+            if (dataType != null) {
+                return dataType;
+            }
+        }
+        return null;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,55 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tuscany.databinding.impl;
+
+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.model.DataType;
+import org.osoa.sca.annotations.Constructor;
+
+/**
+ * The StAX loader for data type
+ */
+public class DataTypeLoader extends LoaderExtension<DataType> {
+    public static final QName DATA_BINDING = new QName("http://tuscany.apache.org/xmlns/databinding/1.0", "databinding");
+
+    @Constructor({"registry"})
+    public DataTypeLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
+    }
+
+    @Override
+    public QName getXMLType() {
+        return DATA_BINDING;
+    }
+
+    public DataType load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+        assert DATA_BINDING.equals(reader.getName());
+        String name = reader.getAttributeValue(null, "name");
+        DataType dataType = new DataType<Class>(name, Object.class, Object.class);
+        return dataType;
+    }    
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataTypeLoader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.impl;
+
+import org.apache.tuscany.databinding.extension.DataBindingExtension;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * Simple databinding represented by a base java type. A SCDL property className is used to customize
+ * this component. 
+ * <p>
+ * The following illustrates how a simple data binding can be registered as a SCA component.<p>
+ * &lt;component name="databinding.MyDataBinding"&gt;<br>
+ * &nbsp;&nbsp;&lt;system:implementation.java class="org.apache.tuscany.databinding.impl.SimpleDataBinding"/&gt;<br>
+ * &nbsp;&nbsp;&lt;property name="className"&gt;my.Type&lt;/property&gt;<br>
+ * &lt/component&gt;
+ */
+public class SimpleDataBinding extends DataBindingExtension {
+
+    public SimpleDataBinding(@Property(name = "className") String className) throws MissingResourceException {
+        super(resolve(className));
+    }
+
+    private static Class<?> resolve(String className) throws MissingResourceException {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            return Class.forName(className, false, classLoader);
+        } catch (ClassNotFoundException e) {
+            classLoader = SimpleDataBinding.class.getClassLoader();
+            try {
+                return Class.forName(className, false, classLoader);
+            } catch (ClassNotFoundException e1) {
+                MissingResourceException mre = new MissingResourceException(className, e1);
+                throw mre;
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/SimpleDataBinding.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/resources/META-INF/sca/databinding.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/resources/META-INF/sca/databinding.scdl?rev=438699&r1=438698&r2=438699&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/resources/META-INF/sca/databinding.scdl (original)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/resources/META-INF/sca/databinding.scdl Wed Aug 30 16:03:06 2006
@@ -27,9 +27,14 @@
         <system:implementation.system class="org.apache.tuscany.databinding.impl.TransformerRegistryImpl" />
     </component>
 
-    <!-- Transformer registry -->
-    <component name="dataBindingLoader">
-        <system:implementation.system class="org.apache.tuscany.databinding.impl.DataBindingDefinitionLoader" />
+    <component name="dataType.loader">
+        <system:implementation.system class="org.apache.tuscany.databinding.impl.DataTypeLoader" />
+    </component>
+    
+    <!-- Simple databindings -->
+    <component name="databinding.dom">
+        <system:implementation.system class="org.apache.tuscany.databinding.impl.SimpleDataBinding" />
+        <property name="className">org.w3c.dom.Node</property>
     </component>
 
 </composite>

Added: incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,85 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.tuscany.databinding.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.databinding.DataBinding;
+import org.apache.tuscany.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.easymock.EasyMock;
+import org.xml.sax.ContentHandler;
+
+/**
+ * 
+ */
+public class DataBindingRegistryImplTestCase extends TestCase {
+    private DataBindingRegistry registry;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        registry = new DataBindingRegistryImpl();
+    }
+
+    public void testRegistry() {
+        DataBinding db1 = createMock(DataBinding.class);
+        expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes();
+        DataType<Class> dataType1 = new DataType<Class>(ContentHandler.class, ContentHandler.class);
+        expect(db1.introspect(ContentHandler.class)).andReturn(dataType1);
+        expect(db1.introspect((Class) EasyMock.anyObject())).andReturn(null).anyTimes();
+        replay(db1);
+
+        registry.register(db1);
+
+        DataBinding db2 = createMock(DataBinding.class);
+        expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes();
+        DataType<Class> dataType2 = new DataType<Class>(XMLStreamReader.class, XMLStreamReader.class);
+        expect(db2.introspect(XMLStreamReader.class)).andReturn(dataType2);
+        expect(db2.introspect((Class) EasyMock.anyObject())).andReturn(null).anyTimes();
+        replay(db2);
+
+        registry.register(db2);
+
+        String name = db1.getName();
+        DataBinding db3 = registry.getDataBinding(name);
+        Assert.assertTrue(db1 == db3);
+
+        DataType<?> dt = registry.introspectType(ContentHandler.class);
+        Assert.assertEquals(dataType1, dt);
+        Assert.assertTrue(dt.getDataBinding().equalsIgnoreCase(name));
+
+        registry.unregister(name);
+        DataBinding db4 = registry.getDataBinding(name);
+        Assert.assertNull(db4);
+
+        dt = registry.introspectType(ContentHandler.class);
+        Assert.assertNull(dt);
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.databinding.jaxb;
+
+import java.beans.Introspector;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.databinding.extension.DataBindingExtension;
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * 
+ */
+public class JAXBDataBinding extends DataBindingExtension {
+
+    @Override
+    public DataType introspect(Class<?> javaType) {
+        if (JAXBElement.class.isAssignableFrom(javaType)) {
+            Type type = javaType.getGenericSuperclass();
+            if (type instanceof ParameterizedType) {
+                ParameterizedType parameterizedType = ((ParameterizedType) type);
+                Type rawType = parameterizedType.getRawType();
+                if (rawType == JAXBElement.class) {
+                    Type actualType = parameterizedType.getActualTypeArguments()[0];
+                    if (actualType instanceof Class) {
+                        return introspect((Class<?>) actualType);
+                    }
+                }
+            }
+            return new DataType<QName>(getName(), javaType, null);
+        }
+
+        String namespace = null;
+        String name = null;
+        Package pkg = javaType.getPackage();
+        if (pkg != null) {
+            XmlSchema schema = pkg.getAnnotation(XmlSchema.class);
+            namespace = schema.namespace();
+        }
+        XmlType type = javaType.getAnnotation(XmlType.class);
+        if (type != null) {
+            String typeNamespace = type.namespace();
+            String typeName = type.name();
+
+            if (typeNamespace.equals("##default") && typeName.equals("")) {
+                XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class);
+                if (rootElement != null) {
+                    namespace = rootElement.namespace();
+                } else {
+                    // FIXME: The namespace should be from the referencing property
+                    namespace = null;
+                }
+            } else if (typeNamespace.equals("##default")) {
+                // namespace is from the package
+            } else {
+                namespace = typeNamespace;
+            }
+
+            if (typeName.equals("##default")) {
+                name = Introspector.decapitalize(javaType.getSimpleName());
+            } else {
+                name = typeName;
+            }
+        } else {
+            XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class);
+            if (xmlEnum != null) {
+                name = Introspector.decapitalize(javaType.getSimpleName());
+            }
+        }
+        if (namespace == null && name == null) {
+            return null;
+        }
+        QName xmlType = new QName(namespace, name);
+        DataType<QName> dataType = new DataType<QName>(getName(), javaType, xmlType);
+        return dataType;
+    }
+
+    public JAXBDataBinding() {
+        super(JAXBElement.class);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.databinding.jaxb;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.jaxb.PurchaseOrderType;
+import com.example.ipo.jaxb.USAddress;
+import com.example.ipo.jaxb.USState;
+
+/**
+ * 
+ */
+public class JAXBDataBindingTestCase extends TestCase {
+    private JAXBDataBinding binding;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        binding = new JAXBDataBinding();
+    }
+
+    /**
+     * Test method for {@link org.apache.tuscany.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class)}.
+     */
+    public final void testIntrospect() {
+        DataType<?> dataType = binding.introspect(JAXBElement.class);
+        Assert.assertTrue(dataType.getDataBinding().equals(binding.getName()));
+        Assert.assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == null);
+        dataType = binding.introspect(MockJAXBElement.class);
+        Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical());
+        Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical());
+        dataType = binding.introspect(USAddress.class);
+        Assert.assertEquals(USAddress.class, dataType.getPhysical());
+        Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical());
+        dataType = binding.introspect(USState.class);
+        Assert.assertTrue(dataType.getDataBinding().equals(binding.getName()));
+        Assert.assertEquals(USState.class, dataType.getPhysical());
+        Assert.assertEquals(new QName("http://www.example.com/IPO", "USState"), dataType.getLogical());
+
+    }
+
+    private static class MockJAXBElement extends JAXBElement<PurchaseOrderType> {
+
+        private static final long serialVersionUID = -2767569071002707973L;
+
+        /**
+         * @param elementName
+         * @param type
+         * @param value
+         */
+        public MockJAXBElement(QName elementName, Class<PurchaseOrderType> type, PurchaseOrderType value) {
+            super(elementName, type, value);
+        }
+
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,57 @@
+/*
+ * 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.databinding.extension.DataBindingExtension;
+import org.apache.tuscany.spi.model.DataType;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * 
+ */
+public class SDODataBinding extends DataBindingExtension {
+
+    @Override
+    public DataType introspect(Class<?> javaType) {
+        if (javaType == DataObject.class) {
+            return new DataType<QName>(getName(), javaType, null);
+        }
+        Type type = TypeHelper.INSTANCE.getType(javaType);
+        if (type == null) {
+            return null;
+        }
+        String namespace = type.getURI();
+        String name = XSDHelper.INSTANCE.getLocalName(type);
+        QName xmlType = new QName(namespace, name);
+        DataType<QName> dataType = new DataType<QName>(getName(), javaType, xmlType);
+        return dataType;
+    }
+
+    public SDODataBinding() {
+        super(DataObject.class);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java?rev=438699&view=auto
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java (added)
+++ incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java Wed Aug 30 16:03:06 2006
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.databinding.sdo;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.tuscany.spi.model.DataType;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import com.example.ipo.sdo.SdoFactory;
+import com.example.ipo.sdo.USAddress;
+import commonj.sdo.DataObject;
+
+/**
+ * 
+ */
+public class SDODataBindingTestCase extends TestCase {
+    private SDODataBinding binding;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        binding = new SDODataBinding();
+        SDOUtil.registerStaticTypes(SdoFactory.class);
+    }
+
+    public final void testIntrospect() {
+        DataType<?> dataType = binding.introspect(DataObject.class);
+        Assert.assertTrue(dataType.getDataBinding().equals(binding.getName()));
+        Assert.assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == null);
+        dataType = binding.introspect(PurchaseOrderType.class);
+        Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical());
+        Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical());
+        dataType = binding.introspect(USAddress.class);
+        Assert.assertEquals(USAddress.class, dataType.getPhysical());
+        Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical());
+    }
+}

Propchange: incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl?rev=438699&r1=438698&r2=438699&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl (original)
+++ incubator/tuscany/java/sca/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl Wed Aug 30 16:03:06 2006
@@ -20,7 +20,7 @@
     <service name="ClientService">
         <interface.java class="org.apache.tuscany.databinding.sample.Client" />
         <reference>Client</reference>
-        <binding.sca/>
+        <!-- <binding.sca/> -->
         <db:databinding name="sdo"/>
     </service>
 
@@ -32,7 +32,7 @@
 
     <reference name="EchoReference">
         <interface.java interface="org.apache.tuscany.databinding.sample.Echo" />
-        <binding.sca/>
+        <!-- <binding.sca/> -->
     </reference>
 
 </composite>



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org