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/24 02:19:10 UTC

svn commit: r434266 - in /incubator/tuscany/java/sca: databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/ databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/ databinding/databinding-framewor...

Author: rfeng
Date: Wed Aug 23 17:19:08 2006
New Revision: 434266

URL: http://svn.apache.org/viewvc?rev=434266&view=rev
Log:
Remove DataBinding and DataBindingRegistry. From now on, we use the dataBinding (a string id) from the DataType as the key for the transformer registry.

Removed:
    incubator/tuscany/java/sca/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomBinding.java
    incubator/tuscany/java/sca/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/CastorBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/DataBindingRegistry.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/extension/DataBindingExtension.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImpl.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/DOMBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/InputStreamBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/OutputStreamBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/SAXBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/SAXContentHandlerBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/StAXBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/StreamBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/WriterBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLEventReaderBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLEventWriterBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamReaderBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStreamWriterBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/xml/XMLStringBinding.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/DataBindingRegistryImplTestCase.java
Modified:
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/Mediator.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/MediatorImpl.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/TransformerRegistryImpl.java
    incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/MediatorImplTestCase.java
    incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java

Modified: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/Mediator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/Mediator.java?rev=434266&r1=434265&r2=434266&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/Mediator.java (original)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/Mediator.java Wed Aug 23 17:19:08 2006
@@ -23,26 +23,26 @@
 /**
  * This interface will be used as a Tuscany system service to perform data mediations
  * 
- * Mediate the data from one binding type to the other one
+ * Mediate the data from one type to the other one
  *
  */
 public interface Mediator {
 
     /**
-     * Mediate the data from the source binding type to the target binding type
-     * @param source
-     * @param sourceBinding
-     * @param targetBinding
+     * Mediate the data from the source type to the target type
+     * @param source The data to be mediated
+     * @param sourceDataType Data type for the source data
+     * @param targetDataType Data type for the target data
      * @return
      */
-    public Object mediate(Object source, DataType sourceBinding, DataType targetBinding);
+    public Object mediate(Object source, DataType sourceDataType, DataType targetDataType);
     /**
-     * Mediate the data
-     * @param source
-     * @param target
-     * @param sourceBinding
-     * @param targetBinding
+     * Mediate the source data into the target which is a sink to receive the data
+     * @param source The data to be mediated
+     * @param target The sink to receive data
+     * @param sourceDataType Data type for the source data
+     * @param targetDataType Data type for the target data
      */
-    public void mediate(Object source, Object target, DataType sourceBinding, DataType targetBinding);
+    public void mediate(Object source, Object target, DataType sourceDataType, DataType targetDataType);
     
 }

Modified: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/MediatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/MediatorImpl.java?rev=434266&r1=434265&r2=434266&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/MediatorImpl.java (original)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/MediatorImpl.java Wed Aug 23 17:19:08 2006
@@ -21,7 +21,6 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.tuscany.databinding.DataBindingRegistry;
 import org.apache.tuscany.databinding.DataPipe;
 import org.apache.tuscany.databinding.Mediator;
 import org.apache.tuscany.databinding.PullTransformer;
@@ -39,8 +38,6 @@
 @Scope("MODULE")
 public class MediatorImpl implements Mediator {
 
-    private DataBindingRegistry dataBindingRegistry;
-
     private TransformerRegistry transformerRegistry;
 
     @Autowire
@@ -48,20 +45,13 @@
         this.transformerRegistry = transformerRegistry;
     }
 
-    @Autowire
-    public void setDataBindingRegistry(DataBindingRegistry dataBindingRegistry) {
-        this.dataBindingRegistry = dataBindingRegistry;
-    }
-
-    /*
-     * 
-     * @see org.apache.tuscany.databinding.Mediator#mediate(java.lang.Object, java.lang.Object, java.lang.Object,
-     *      org.apache.tuscany.databinding.TransformationContext)
+    /**
+     * @see org.apache.tuscany.databinding.Mediator#mediate(java.lang.Object, org.apache.tuscany.spi.model.DataType, org.apache.tuscany.spi.model.DataType)
      */
     @SuppressWarnings("unchecked")
     public Object mediate(Object source, DataType sourceDataType, DataType targetDataType) {
-        String sourceId = dataBindingRegistry.introspectType(sourceDataType).getName();
-        String targetId = dataBindingRegistry.introspectType(targetDataType).getName();
+        String sourceId = sourceDataType.getDataBinding();
+        String targetId = targetDataType.getDataBinding();
         List<Transformer> path = transformerRegistry.getTransformerChain(sourceId, targetId);
 
         Object result = source;
@@ -87,8 +77,8 @@
 
     @SuppressWarnings("unchecked")
     public void mediate(Object source, Object target, DataType sourceDataType, DataType targetDataType) {
-        String sourceId = dataBindingRegistry.introspectType(sourceDataType).getName();
-        String targetId = dataBindingRegistry.introspectType(targetDataType).getName();
+        String sourceId = sourceDataType.getDataBinding();
+        String targetId = targetDataType.getDataBinding();
         List<Transformer> path = transformerRegistry.getTransformerChain(sourceId, targetId);
 
         Object result = source;

Modified: incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/TransformerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/TransformerRegistryImpl.java?rev=434266&r1=434265&r2=434266&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/TransformerRegistryImpl.java (original)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/main/java/org/apache/tuscany/databinding/impl/TransformerRegistryImpl.java Wed Aug 23 17:19:08 2006
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.tuscany.databinding.TransformationException;
 import org.apache.tuscany.databinding.Transformer;
 import org.apache.tuscany.databinding.TransformerRegistry;
 import org.apache.tuscany.databinding.util.DirectedGraph;
@@ -29,10 +30,10 @@
 public class TransformerRegistryImpl implements TransformerRegistry {
 
     private final DirectedGraph<Object, Transformer> graph = new DirectedGraph<Object, Transformer>();
-    
+
     @Init(eager = true)
     public void init() {
-    }    
+    }
 
     public void registerTransformer(Object sourceType, Object resultType, int weight, Transformer transformer) {
         graph.addEdge(sourceType, resultType, transformer, weight);
@@ -54,6 +55,12 @@
     public List<Transformer> getTransformerChain(Object sourceType, Object resultType) {
         List<Transformer> transformers = new ArrayList<Transformer>();
         DirectedGraph<Object, Transformer>.Path path = graph.getShortestPath(sourceType, resultType);
+        if (path == null) {
+            TransformationException ex = new TransformationException("No path found for the transformation");
+            ex.addContextName("Source: " + sourceType.toString());
+            ex.addContextName("Target: " + resultType.toString());
+            throw ex;
+        }
         for (DirectedGraph<Object, Transformer>.Edge edge : path.getEdges()) {
             transformers.add(edge.getValue());
         }

Modified: incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/MediatorImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/MediatorImplTestCase.java?rev=434266&r1=434265&r2=434266&view=diff
==============================================================================
--- incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/MediatorImplTestCase.java (original)
+++ incubator/tuscany/java/sca/databinding/databinding-framework/src/test/java/org/apache/tuscany/databinding/impl/MediatorImplTestCase.java Wed Aug 23 17:19:08 2006
@@ -24,24 +24,19 @@
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
-import org.apache.tuscany.databinding.DataBindingRegistry;
 import org.apache.tuscany.databinding.TransformationContext;
 import org.apache.tuscany.databinding.TransformerRegistry;
 import org.apache.tuscany.databinding.trax.Node2String;
 import org.apache.tuscany.databinding.trax.Node2Writer;
 import org.apache.tuscany.databinding.trax.String2SAX;
-import org.apache.tuscany.databinding.xml.DOMBinding;
 import org.apache.tuscany.databinding.xml.SAX2DOMPipe;
-import org.apache.tuscany.databinding.xml.SAXContentHandlerBinding;
-import org.apache.tuscany.databinding.xml.WriterBinding;
-import org.apache.tuscany.databinding.xml.XMLStringBinding;
 import org.apache.tuscany.spi.model.DataType;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 /**
- * 
+ * Test case for MediatorImpl
  */
 public class MediatorImplTestCase extends TestCase {
     private static final String IPO_XML = "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
@@ -56,15 +51,9 @@
             + "</ipo:purchaseOrder>";
 
     private MediatorImpl mediator;
-    private DataBindingRegistry bindingRegistry;
 
     protected void setUp() throws Exception {
         super.setUp();
-        bindingRegistry = new DataBindingRegistryImpl();
-        bindingRegistry.register(new DOMBinding());
-        bindingRegistry.register(new SAXContentHandlerBinding());
-        bindingRegistry.register(new WriterBinding());
-        bindingRegistry.register(new XMLStringBinding());
         
         TransformerRegistry registry = new TransformerRegistryImpl();
         registry.registerTransformer(new String2SAX());
@@ -74,7 +63,6 @@
 
         mediator = new MediatorImpl();
         mediator.setTransformerRegistry(registry);
-        mediator.setDataBindingRegistry(bindingRegistry);
     }
 
     @SuppressWarnings("unchecked")

Modified: incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java?rev=434266&r1=434265&r2=434266&view=diff
==============================================================================
--- incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java (original)
+++ incubator/tuscany/java/sca/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java Wed Aug 23 17:19:08 2006
@@ -23,27 +23,28 @@
 import java.lang.reflect.Type;
 
 /**
- * Representation of the type of data associated with an operation.
- * Data is represented in two forms: the physical form used by the runtime and a logical
- * form used by the assembly. The physical form is a Java Type because the runtime is written in Java.
- * This may be the same form used by the application but it may not; for example, an application
- * that is performing stream processing may want a physical form such as an {@link java.io.InputStream InputStream}
- * to semantially operate on application data such as a purchase order.
- * The logical description is that used by the assembly model and is an identifier into some well-known type space;
- * examples may be a Java type represented by its Class or an XML type represented by its QName.
- * Every data type may also contain metadata describing the expected data; for example, it could specify a preferred
- * data binding technology or the size of a typical instance.
- *
+ * Representation of the type of data associated with an operation. Data is represented in two forms: the physical form used by the runtime and a
+ * logical form used by the assembly. The physical form is a Java Type because the runtime is written in Java. This may be the same form used by the
+ * application but it may not; for example, an application that is performing stream processing may want a physical form such as an
+ * {@link java.io.InputStream InputStream} to semantially operate on application data such as a purchase order. The logical description is that used
+ * by the assembly model and is an identifier into some well-known type space; examples may be a Java type represented by its Class or an XML type
+ * represented by its QName. Every data type may also contain metadata describing the expected data; for example, it could specify a preferred data
+ * binding technology or the size of a typical instance.
+ * 
  * @version $Rev$ $Date$
  */
 public class DataType<L> extends ModelObject {
+    private String dataBinding = Object.class.getName();
+
     private final Type physical;
+
     private final L logical;
+
     private final Map<String, Object> metadata = new HashMap<String, Object>();
 
     /**
      * Construct a data type specifying the physical and logical types.
-     *
+     * 
      * @param physical the physical class used by the runtime
      * @param logical the logical type
      * @see #getLogical()
@@ -51,10 +52,20 @@
     public DataType(Type physical, L logical) {
         this.physical = physical;
         this.logical = logical;
+        if (physical instanceof Class) {
+            this.dataBinding = ((Class) physical).getName();
+        }
+    }
+
+    public DataType(String dataBinding, Type physical, L logical) {
+        this.dataBinding = dataBinding;
+        this.physical = physical;
+        this.logical = logical;
     }
 
     /**
      * Returns the physical type used by the runtime.
+     * 
      * @return the physical type used by the runtime
      */
     public Type getPhysical() {
@@ -62,13 +73,12 @@
     }
 
     /**
-     * Returns the logical identifier used by the assembly.
-     * The type of this value identifies the logical type system in use. Known values are:
+     * Returns the logical identifier used by the assembly. The type of this value identifies the logical type system in use. Known values are:
      * <ul>
-     * <li>a java.lang.reflect.Type identifies a Java type by name and ClassLoader;
-     * this includes Java Classes as they are specializations of Type</li>
+     * <li>a java.lang.reflect.Type identifies a Java type by name and ClassLoader; this includes Java Classes as they are specializations of Type</li>
      * <li>a javax.xml.namespace.QName identifies an XML type by local name and namespace</li>
      * </ul>
+     * 
      * @return the logical type name
      */
     public L getLogical() {
@@ -77,7 +87,7 @@
 
     /**
      * Returns all metadata about this type.
-     *
+     * 
      * @return all metadata about this type
      */
     public Map<String, ?> getMetadata() {
@@ -86,7 +96,7 @@
 
     /**
      * Returns the specified metadata item or null if not present.
-     *
+     * 
      * @param name the name of the metadata item
      * @return the value, or null if not present
      */
@@ -96,7 +106,7 @@
 
     /**
      * Sets the specified metadata value. A null value undefines it.
-     *
+     * 
      * @param name the name of the metadata item
      * @param value the value, or null to undefine
      * @return the old value for the item, or null if not present
@@ -107,5 +117,9 @@
         } else {
             return metadata.put(name, value);
         }
+    }
+
+    public String getDataBinding() {
+        return dataBinding;
     }
 }



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