tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r577121 - in /incubator/tuscany/branches/sca-java-1.0: itest/properties/src/main/java/mysca/test/myservice/impl/ itest/properties/src/main/resources/ modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/ modules/...
Date Wed, 19 Sep 2007 00:28:39 GMT
Author: rfeng
Date: Tue Sep 18 17:28:38 2007
New Revision: 577121

URL: http://svn.apache.org/viewvc?rev=577121&view=rev
Log:
Check in the databinding improvement as it fixes TUSCANY-1735

Added:
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java
      - copied unchanged from r576725, incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java
      - copied unchanged from r576725, incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java
      - copied unchanged from r576725, incubator/tuscany/java/sca/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java
Modified:
    incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/java/mysca/test/myservice/impl/MyServiceImpl.java
    incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/resources/PropertyTest.composite
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
    incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
    incubator/tuscany/branches/sca-java-1.0/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java

Modified: incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/java/mysca/test/myservice/impl/MyServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/java/mysca/test/myservice/impl/MyServiceImpl.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/java/mysca/test/myservice/impl/MyServiceImpl.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/java/mysca/test/myservice/impl/MyServiceImpl.java
Tue Sep 18 17:28:38 2007
@@ -37,7 +37,7 @@
     protected String year = "2006";
 
     @ComponentName
-    private String componentName;
+    protected String componentName;
 
 
     private Logger logger;

Modified: incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/resources/PropertyTest.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/resources/PropertyTest.composite?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/resources/PropertyTest.composite
(original)
+++ incubator/tuscany/branches/sca-java-1.0/itest/properties/src/main/resources/PropertyTest.composite
Tue Sep 18 17:28:38 2007
@@ -20,6 +20,7 @@
        xmlns:foo="http://foo" 
        xmlns:cust="http://www.example.com/Customer"
        xmlns:dbsdo="http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0"
+       xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://foo"
        name="PropertyTest"
 	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java
Tue Sep 18 17:28:38 2007
@@ -110,15 +110,21 @@
 
     public Object getChild(OMElement wrapper, ElementInfo childElement, int index, TransformationContext
context) {
         int pos = 0;
+        String wrapperNS = wrapper.getQName().getNamespaceURI();
         for (Iterator i = wrapper.getChildElements(); i.hasNext();) {
             OMElement e = (OMElement)i.next();
             if (pos == index) {
                 TypeInfo type = childElement.getType();
-                if (type != null) {
+                if (!childElement.getQName().equals(e.getQName()) && type != null)
{
                     OMAttribute attr = e.getAttribute(XSI_TYPE_QNAME);
                     if (attr == null) {
-                        OMNamespace ns =
-                            e.getOMFactory().createOMNamespace(type.getQName().getNamespaceURI(),
"_typens_");
+                        String typeNS = type.getQName().getNamespaceURI();
+                        if (wrapperNS != null) {
+                            // FIXME: [rfeng] Workaround for TUSCANY-1713, assuming the type
+                            // namespace is the same as the wrapper
+                            typeNS = wrapperNS;
+                        }
+                        OMNamespace ns = e.getOMFactory().createOMNamespace(typeNS, "_typens_");
                         e.declareNamespace(ns);
                         OMNamespace xsiNS =
                             e.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(),

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java
Tue Sep 18 17:28:38 2007
@@ -18,18 +18,7 @@
  */
 package org.apache.tuscany.sca.databinding.saxon;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.stream.StreamSource;
 
 import net.sf.saxon.om.NodeInfo;
 
@@ -37,10 +26,11 @@
 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.sca.databinding.impl.DOMHelper;
 
 import commonj.sdo.DataObject;
+import commonj.sdo.helper.XMLDocument;
 import commonj.sdo.helper.XMLHelper;
-import commonj.sdo.impl.HelperProvider;
 
 /**
  * Transforms SDO DataObject-s to NodeInfo objects needed by Saxon parser
@@ -64,7 +54,8 @@
     }
 
     public NodeInfo transform(DataObject source, TransformationContext context) {
-        XMLHelper helper = HelperProvider.INSTANCE.xmlHelper();
+        // FIXME: Need to create the HelperContext from the transformation context
+        XMLHelper helper = XMLHelper.INSTANCE;
         String name = null;
         if (source.getClass().getInterfaces().length > 0) {
             name = source.getClass().getInterfaces()[0].getSimpleName();
@@ -76,32 +67,15 @@
             name = Character.toLowerCase(name.charAt(0)) + name.substring(1, name.length());
         }
 
-        DOMResult domResult = new DOMResult();
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try {
-            helper.save(source, null, name, baos);
-            baos.flush();
-            baos.close();
-        } catch (IOException e) {
-            throw new TransformationException(e);
-        }
-
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        Source src = new StreamSource(bais);
-
         try {
-            Transformer transformer = TransformerFactory.newInstance().newTransformer();
-            transformer.transform(src, domResult);
-        } catch (TransformerConfigurationException e) {
-            throw new TransformationException(e);
-        } catch (TransformerFactoryConfigurationError e) {
-            throw new TransformationException(e);
-        } catch (TransformerException e) {
+            DOMResult domResult = new DOMResult(DOMHelper.newDocument());
+            XMLDocument xmlDoc = helper.createDocument(source, null, name);
+            helper.save(xmlDoc, domResult, null);
+            return node2NodeInfoTransformer.transform(domResult.getNode(), context);
+        } catch (Exception e) {
             throw new TransformationException(e);
         }
 
-        return node2NodeInfoTransformer.transform(domResult.getNode(), context);
     }
 
     @Override
@@ -116,7 +90,7 @@
 
     @Override
     public int getWeight() {
-        return 10;
+        return 30 + node2NodeInfoTransformer.getWeight();
     }
 
 }

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java
Tue Sep 18 17:28:38 2007
@@ -22,7 +22,6 @@
 
 import net.sf.saxon.Configuration;
 import net.sf.saxon.event.Builder;
-import net.sf.saxon.om.DocumentInfo;
 import net.sf.saxon.om.NodeInfo;
 import net.sf.saxon.trans.XPathException;
 
@@ -30,6 +29,7 @@
 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.sca.databinding.impl.DOMHelper;
 import org.w3c.dom.Node;
 
 /**
@@ -46,9 +46,10 @@
         if (configuration == null) {
             configuration = new Configuration();
         }
-        DocumentInfo docInfo = null;
+        NodeInfo docInfo = null;
         try {
-        	docInfo = (DocumentInfo)Builder.build(new DOMSource(source), null, configuration);
+            source = DOMHelper.promote(source);
+            docInfo = Builder.build(new DOMSource(source), null, configuration);
         } catch (XPathException e) {
             throw new TransformationException(e);
         }

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java
Tue Sep 18 17:28:38 2007
@@ -18,21 +18,15 @@
  */
 package org.apache.tuscany.sca.databinding.saxon;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 
 import net.sf.saxon.om.NodeInfo;
 
 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.w3c.dom.Document;
 
@@ -59,7 +53,7 @@
 
     public NodeInfo2DataObjectTransformer() {
         this.nodeInfo2NodeTransformer = new NodeInfo2NodeTransformer();
-    }    
+    }
 
     @Override
     protected Class getSourceType() {
@@ -73,7 +67,7 @@
 
     @Override
     public int getWeight() {
-        return 10 + nodeInfo2NodeTransformer.getWeight();
+        return 30 + nodeInfo2NodeTransformer.getWeight();
     }
 
     public DataObject transform(NodeInfo source, TransformationContext context) {
@@ -83,30 +77,12 @@
     }
 
     private DataObject produceResult(Document doc) {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        StreamResult streamResult = new StreamResult(baos);
-        try {
-            Transformer transformer = TransformerFactory.newInstance().newTransformer();
-            transformer.transform(new DOMSource(doc), streamResult);
-        } catch (TransformerConfigurationException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (TransformerFactoryConfigurationError e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (TransformerException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
         try {
-            baos.flush();
-            baos.close();
+            DataObject resultingObject =
+                XMLHelper.INSTANCE.load(new DOMSource(doc), doc.getDocumentURI(), null).getRootObject();
+            return resultingObject;
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new TransformationException(e);
         }
-        DataObject resultingObject = XMLHelper.INSTANCE.load(new String(baos.toByteArray())).getRootObject();
-
-        return resultingObject;
     }
 }

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
Tue Sep 18 17:28:38 2007
@@ -107,10 +107,10 @@
      */
     public DataType getWrapperType(ElementInfo element, List<ElementInfo> childElements,
TransformationContext context) {
         // FIXME: [rfeng] Temporarily disable the wrapping support for SDO to work around
a few issues
-        // in the WSDL-less story
-        if (true) {
-            return null;
-        }
+        // in the WSDL-less story: https://issues.apache.org/jira/browse/TUSCANY-1713
+//        if (true) {
+//            return null;
+//        }
         HelperContext helperContext = SDOContextHelper.getHelperContext(context);
         Type sdoType = getSDOType(helperContext, element);
         if (sdoType != null) {

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
Tue Sep 18 17:28:38 2007
@@ -23,3 +23,5 @@
 org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader;source=commonj.sdo.helper.XMLDocument,target=javax.xml.stream.XMLStreamReader,weight=10
 org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.DataObject,weight=15
 org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.helper.XMLDocument,weight=15
+org.apache.tuscany.sca.databinding.sdo.DataObject2Node;source=commonj.sdo.DataObject,target=org.w3c.dom.Node,weight=40
+org.apache.tuscany.sca.databinding.sdo.Node2DataObject;source=org.w3c.dom.Node,target=commonj.sdo.DataObject,weight=40

Modified: incubator/tuscany/branches/sca-java-1.0/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java?rev=577121&r1=577120&r2=577121&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.0/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
(original)
+++ incubator/tuscany/branches/sca-java-1.0/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
Tue Sep 18 17:28:38 2007
@@ -23,8 +23,10 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
 /**
@@ -71,6 +73,41 @@
         String qname =
             (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart()
: name.getLocalPart();
         return document.createElementNS(name.getNamespaceURI(), qname);
+    }
+
+    /**
+     * Wrap an element as a DOM document
+     * @param node
+     * @return
+     */
+    public static Document promote(Node node) {
+        if (node instanceof Document) {
+            return (Document)node;
+        }
+        Element element = (Element)node;
+        Document doc = element.getOwnerDocument();
+        if (doc.getDocumentElement() == element) {
+            return doc;
+        }
+        doc = (Document)element.getOwnerDocument().cloneNode(false);
+        Element schema = (Element)doc.importNode(element, true);
+        doc.appendChild(schema);
+        Node parent = element.getParentNode();
+        while (parent instanceof Element) {
+            Element root = (Element)parent;
+            NamedNodeMap nodeMap = root.getAttributes();
+            for (int i = 0; i < nodeMap.getLength(); i++) {
+                Attr attr = (Attr)nodeMap.item(i);
+                String name = attr.getName();
+                if ("xmlns".equals(name) || name.startsWith("xmlns:")) {
+                    if (schema.getAttributeNode(name) == null) {
+                        schema.setAttributeNodeNS((Attr)doc.importNode(attr, true));
+                    }
+                }
+            }
+            parent = parent.getParentNode();
+        }
+        return doc;
     }
 
 }



---------------------------------------------------------------------
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