tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r447249 - in /incubator/tuscany/java/sca: databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ kernel/core/src/main/java/org/apache/tusca...
Date Mon, 18 Sep 2006 05:26:20 GMT
Author: rfeng
Date: Sun Sep 17 22:26:19 2006
New Revision: 447249

URL: http://svn.apache.org/viewvc?view=rev&rev=447249
Log:
Add support to propagate TypeHelper from import.sdo loader to databinding transformers

Modified:
    incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
    incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java
    incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java

Modified: incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
(original)
+++ incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java
Sun Sep 17 22:26:19 2006
@@ -22,26 +22,26 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.net.URL;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import commonj.sdo.helper.TypeHelper;
-import commonj.sdo.helper.XSDHelper;
-
 import org.apache.tuscany.sdo.util.SDOUtil;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.extension.LoaderExtension;
 import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.spi.loader.LoaderUtil;
 import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
 import org.apache.tuscany.spi.model.ModelObject;
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.annotation.Autowire;
-
 import org.osoa.sca.Version;
 import org.osoa.sca.annotations.Constructor;
 
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
 /**
  * Loader that handles <import.sdo> elements.
  * 
@@ -59,9 +59,10 @@
         return IMPORT_SDO;
     }
 
-    public ModelObject load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext
deploymentContext) throws XMLStreamException,
-            LoaderException {
+    public ModelObject load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext
deploymentContext)
+        throws XMLStreamException, LoaderException {
         assert IMPORT_SDO.equals(reader.getName());
+
         // FIXME: [rfeng] How to associate the TypeHelper with deployment context?
         TypeHelper typeHelper = TypeHelper.INSTANCE;
         if (deploymentContext != null && deploymentContext.getParent() != null) {
@@ -75,7 +76,7 @@
         importFactory(reader, deploymentContext);
         importWSDL(reader, deploymentContext, typeHelper);
         LoaderUtil.skipToEndElement(reader);
-        return null;
+        return new SDOType(typeHelper);
     }
 
     private void importFactory(XMLStreamReader reader, DeploymentContext deploymentContext)
throws LoaderException {
@@ -87,6 +88,7 @@
                 ClassLoader cl = deploymentContext.getClassLoader();
                 Thread.currentThread().setContextClassLoader(cl);
                 Class<?> factoryClass = cl.loadClass(factoryName);
+                // FIXME: We require the SDO to provide an API to register static types in
a given TypeHelper
                 SDOUtil.registerStaticTypes(factoryClass);
             } catch (ClassNotFoundException e) {
                 throw new LoaderException(e.getMessage(), e);
@@ -96,7 +98,8 @@
         }
     }
 
-    private void importWSDL(XMLStreamReader reader, DeploymentContext deploymentContext,
TypeHelper typeHelper) throws LoaderException {
+    private void importWSDL(XMLStreamReader reader, DeploymentContext deploymentContext,
TypeHelper typeHelper)
+        throws LoaderException {
         String location = reader.getAttributeValue(null, "location");
         if (location == null)
             location = reader.getAttributeValue(null, "wsdlLocation");
@@ -125,6 +128,19 @@
                 sfe.setResourceURI(location);
                 throw sfe;
             }
+        }
+    }
+
+    public static class SDOType extends ModelObject {
+        private TypeHelper typeHelper;
+
+        public SDOType(TypeHelper typeHelper) {
+            super();
+            this.typeHelper = typeHelper;
+        }
+
+        public TypeHelper getTypeHelper() {
+            return typeHelper;
         }
     }
 }

Modified: incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java
(original)
+++ incubator/tuscany/java/sca/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java
Sun Sep 17 22:26:19 2006
@@ -20,7 +20,8 @@
 package org.apache.tuscany.databinding.sdo;
 
 import org.apache.tuscany.databinding.TransformationContext;
-import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType;
+import org.apache.tuscany.spi.component.CompositeComponent;
 
 import commonj.sdo.helper.TypeHelper;
 
@@ -31,14 +32,20 @@
     private SDODataTypeHelper() {
     }
 
-    public static TypeHelper getTypeHelper(TransformationContext context, boolean source)
{
-        if (context == null) {
+    public static TypeHelper getTypeHelper(TransformationContext context) {
+        TypeHelper typeHelper = null;
+        if (context == null || context.getMetadata() == null) {
             return TypeHelper.INSTANCE;
         }
-        DataType<?> dataType = source ? context.getSourceDataType() : context.getTargetDataType();
-        TypeHelper typeHelper = (TypeHelper) dataType.getMetadata(TypeHelper.class.getName());
+        CompositeComponent composite = (CompositeComponent) context.getMetadata().get(CompositeComponent.class);
+        if (composite != null) {
+            SDOType sdoType = (SDOType) composite.getExtensions().get(SDOType.class);
+            if (sdoType != null) {
+                typeHelper = sdoType.getTypeHelper();
+            }
+        }
         if (typeHelper == null) {
-            typeHelper = TypeHelper.INSTANCE;
+            return TypeHelper.INSTANCE;
         }
         return typeHelper;
     }

Modified: incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
(original)
+++ incubator/tuscany/java/sca/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java
Sun Sep 17 22:26:19 2006
@@ -19,6 +19,7 @@
 package org.apache.tuscany.databinding.sdo;
 
 import java.io.StringReader;
+
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -26,6 +27,7 @@
 import junit.framework.TestCase;
 
 import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType;
 import org.apache.tuscany.spi.deployer.DeploymentContext;
 import org.apache.tuscany.spi.loader.LoaderException;
 
@@ -42,13 +44,13 @@
     public void testMinimal() throws XMLStreamException, LoaderException {
         String xml = "<import.sdo xmlns='http://www.osoa.org/xmlns/sca/1.0'/>";
         XMLStreamReader reader = getReader(xml);
-        assertNull(loader.load(null, reader, deploymentContext));
+        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
     }
 
     public void testLocation() throws XMLStreamException, LoaderException {
         String xml = "<import.sdo xmlns='http://www.osoa.org/xmlns/sca/1.0' location='ipo.xsd'/>";
         XMLStreamReader reader = getReader(xml);
-        assertNull(loader.load(null, reader, deploymentContext));
+        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
     }
     
     public void testFactory() throws XMLStreamException, LoaderException {
@@ -56,7 +58,7 @@
                 + "factory='org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory'/>";
         XMLStreamReader reader = getReader(xml);
         assertFalse(inited);
-        assertNull(loader.load(null, reader, deploymentContext));
+        assertTrue(loader.load(null, reader, deploymentContext) instanceof SDOType);
         assertTrue(inited);
     }
 

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
(original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
Sun Sep 17 22:26:19 2006
@@ -82,22 +82,6 @@
             }
         }
 
-        /*
-        // add in components and services from included composites
-        for (Include include : componentType.getIncludes().values()) {
-            CompositeComponentType<?, ?, ?> included = include.getIncluded();
-            allComponents.addAll(included.getComponents().values());
-            for (ServiceDefinition serviceDefinition : included.getServices().values()) {
-                if (serviceDefinition instanceof BoundServiceDefinition) {
-                    BoundServiceDefinition<? extends Binding> boundService =
-                        (BoundServiceDefinition<? extends Binding>) serviceDefinition;
-                    allBoundServices.add(boundService);
-                }
-            }
-            // TODO how to include references
-        }
-        */
-
         String name = componentDefinition.getName();
         CompositeComponentImpl component = new CompositeComponentImpl(name, parent, null,
connector, null);
         for (BoundReferenceDefinition<? extends Binding> referenceDefinition : allBoundReferences)
{
@@ -115,6 +99,10 @@
         for (ReferenceDefinition targetlessReferenceDef : allTargetlessReferences) {
             component.register(builderRegistry.build(component, targetlessReferenceDef, deploymentContext));
         }
+        
+        // HACK: [rfeng] We need a better way to propagate model extensions to SCAObject.
+        component.getExtensions().putAll(componentType.getExtensions());
+        
         return component;
     }
 

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
(original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
Sun Sep 17 22:26:19 2006
@@ -101,6 +101,11 @@
                                 ccl.addURL(artifact.getUrl());
                             }
                         }
+                    } else {
+                        // HACK: [rfeng] Add as an unknown model extension
+                        if (o != null) {
+                            composite.getExtensions().put(o.getClass(), o);
+                        }    
                     }
                     reader.next();
                     break;

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java
Sun Sep 17 22:26:19 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.spi.component;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -40,6 +41,7 @@
     protected Map<EventFilter, List<RuntimeEventListener>> listeners;
     private final String name;
     private final CompositeComponent parent;
+    private final Map<Object, Object> extensions = new HashMap<Object, Object>();
 
     public AbstractSCAObject(String name, CompositeComponent parent) {
         this.name = name;
@@ -108,5 +110,9 @@
 
     public String toString() {
         return "[" + name + "] in state [" + super.toString() + ']';
+    }
+
+    public Map<Object, Object> getExtensions() {
+        return extensions;
     }
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java
Sun Sep 17 22:26:19 2006
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.spi.component;
 
+import java.util.Map;
+
 import org.apache.tuscany.spi.Lifecycle;
 import org.apache.tuscany.spi.event.EventPublisher;
 import org.apache.tuscany.spi.model.Scope;
@@ -56,5 +58,12 @@
      * as wiring of its children
      */
     void prepare();
+    
+    /**
+     * The extensions map contains other runtime context such as type systems for various
databindings
+     * 
+     * @return A live map of extended context
+     */
+    Map<Object, Object> getExtensions();
 
 }

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java?view=diff&rev=447249&r1=447248&r2=447249
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java
Sun Sep 17 22:26:19 2006
@@ -27,12 +27,12 @@
  * @version $Rev$ $Date$
  */
 public abstract class ModelObject {
-    private final Map<?, ?> extensions = new HashMap<Object, Object>();
+    private final Map<Object, Object> extensions = new HashMap<Object, Object>();
 
     protected ModelObject() {
     }
 
-    public Map<?, ?> getExtensions() {
+    public Map<Object, Object> getExtensions() {
         return extensions;
     }
 }



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


Mime
View raw message