tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r659153 - in /incubator/tuscany/java/sca/modules/databinding/src: main/java/org/apache/tuscany/sca/databinding/ main/java/org/apache/tuscany/sca/databinding/impl/ main/java/org/apache/tuscany/sca/databinding/xml/ test/java/org/apache/tuscan...
Date Thu, 22 May 2008 16:43:58 GMT
Author: rfeng
Date: Thu May 22 09:43:58 2008
New Revision: 659153

URL: http://svn.apache.org/viewvc?rev=659153&view=rev
Log:
Add a test case for XMLDocumentStreamReader to be able to wrap an element-braketed XML fragment

Added:
    incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
  (with props)
Modified:
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
    incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java

Modified: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java?rev=659153&r1=659152&r2=659153&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
(original)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
Thu May 22 09:43:58 2008
@@ -29,12 +29,27 @@
  * @version $Rev$ $Date$
  */
 public interface TransformationContext {
-    
+
+    /**
+     * @return
+     */
     Operation getSourceOperation();
+
+    /**
+     * @param sourceOperation
+     */
     void setSourceOperation(Operation sourceOperation);
+
+    /**
+     * @return
+     */
     Operation getTargetOperation();
+
+    /**
+     * @param targetOperation
+     */
     void setTargetOperation(Operation targetOperation);
-    
+
     /**
      * Get the source data type
      * 

Modified: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java?rev=659153&r1=659152&r2=659153&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
(original)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
Thu May 22 09:43:58 2008
@@ -63,7 +63,7 @@
      * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType()
      */
     @Override
-    protected Class getSourceType() {
+    protected Class<Object> getSourceType() {
         return Object.class;
     }
 
@@ -71,7 +71,7 @@
      * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
      */
     @Override
-    protected Class getTargetType() {
+    protected Class<Object> getTargetType() {
         return Object.class;
     }
 

Modified: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java?rev=659153&r1=659152&r2=659153&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java
(original)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java
Thu May 22 09:43:58 2008
@@ -49,6 +49,8 @@
     // produce events
 
     private XMLStreamReader realReader;
+    private boolean fragment;
+    private int level = 0;
 
     private int state = STATE_INIT;
 
@@ -66,6 +68,7 @@
         // If the real reader is positioned at START_DOCUMENT, always use
         // the real reader
         if (realReader.getEventType() == START_DOCUMENT) {
+            fragment = false;
             state = STATE_SWITCHED;
         }
     }
@@ -409,11 +412,26 @@
                     state = STATE_COMPLETED;
                 } else if (!realReader.hasNext()) {
                     state = STATE_COMPLETE_AT_NEXT;
+                } 
+                if (fragment && returnEvent == END_ELEMENT) {
+                    level--;
+                    if (level == 0) {
+                        // We are now at the end of the top-level element in the fragment
+                        state = STATE_COMPLETE_AT_NEXT;
+                    }
+                }
+                if (fragment && returnEvent == START_ELEMENT) {
+                    level++;
                 }
                 break;
             case STATE_INIT:
                 state = STATE_SWITCHED;
                 returnEvent = realReader.getEventType();
+                if (returnEvent == START_ELEMENT) {
+                    // The real reader is positioned at the top-level element in the fragment
+                    level = 0;
+                    fragment = true;
+                }
                 break;
             case STATE_COMPLETE_AT_NEXT:
                 state = STATE_COMPLETED;
@@ -431,7 +449,18 @@
 
     public int nextTag() throws XMLStreamException {
         if (isDelegating()) {
-            return realReader.nextTag();
+            int returnEvent = realReader.nextTag();
+            if (fragment && returnEvent == END_ELEMENT) {
+                level--;
+                if (level == 0) {
+                    // We are now at the end of the top-level element in the fragment
+                    state = STATE_COMPLETE_AT_NEXT;
+                }
+            }
+            if (fragment && returnEvent == START_ELEMENT) {
+                level++;
+            }
+            return returnEvent;
         } else {
             throw new XMLStreamException();
         }

Added: incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java?rev=659153&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
(added)
+++ incubator/tuscany/java/sca/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
Thu May 22 09:43:58 2008
@@ -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.sca.databinding.impl;
+
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.databinding.xml.XMLDocumentStreamReader;
+import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XMLDocumentStreamReaderTestCase {
+    private final static String xml = "<e1><e2 a2=\"a2\"><e4>E4</e4></e2><e3
a3=\"a3\"/></e1>";
+
+    @org.junit.Test
+    public void testReader() throws Exception {
+        XMLInputFactory factory = XMLInputFactory.newInstance();
+        XMLStreamReader r1 = factory.createXMLStreamReader(new StringReader(xml));
+        XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1);
+        XMLStreamReader2String t1 = new XMLStreamReader2String();
+        String result = t1.transform(r2, null);
+        System.out.println(result);
+        XMLStreamReader r3 = factory.createXMLStreamReader(new StringReader(xml));
+        r3.nextTag();
+        r3.nextTag();
+        Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType());
+        Assert.assertEquals(new QName(null, "e2"), r3.getName());
+        XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3);
+        result = t1.transform(r4, null);
+        System.out.println(result);
+    }
+}

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

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



Mime
View raw message