commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r471112 - in /jakarta/commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/io/ test/java/org/apache/commons/scxml/io/
Date Sat, 04 Nov 2006 04:10:39 GMT
Author: rahul
Date: Fri Nov  3 20:10:38 2006
New Revision: 471112

URL: http://svn.apache.org/viewvc?view=rev&rev=471112
Log:
Ensure white box behavior of the <state> element's src attribute. Add a test that illustrates
this, with chained documents and cross-document transition targets.

Added:
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
  (with props)
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
  (with props)
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
  (with props)
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
  (with props)
Modified:
    jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
    jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java

Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java?view=diff&rev=471112&r1=471111&r2=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
Fri Nov  3 20:10:38 2006
@@ -722,7 +722,7 @@
             final ExtendedBaseRules scxmlRules, final List customActions,
             final SCXML scxml, final PathResolver pr, final int parent) {
         scxmlRules.add(xp, new ObjectCreateRule(State.class));
-        addStatePropertiesRules(xp, scxmlRules, customActions, pr);
+        addStatePropertiesRules(xp, scxmlRules, customActions, pr, scxml);
         addDatamodelRules(xp + XPF_DM, scxmlRules, scxml, pr);
         addInvokeRules(xp + XPF_INV, scxmlRules, customActions, pr, scxml);
         addInitialRules(xp + XPF_INI, scxmlRules, customActions, pr, scxml);
@@ -764,13 +764,15 @@
      * @param customActions The list of custom actions this digester needs
      *                      to be able to process
      * @param pr The PathResolver
+     * @param scxml The root document, if this one is src'ed in
      */
     private static void addStatePropertiesRules(final String xp,
             final ExtendedBaseRules scxmlRules, final List customActions,
-            final PathResolver pr) {
+            final PathResolver pr, final SCXML scxml) {
         scxmlRules.add(xp, new SetPropertiesRule(new String[] {"id", "final"},
             new String[] {"id", "isFinal"}));
-        scxmlRules.add(xp, new DigestSrcAttributeRule(customActions, pr));
+        scxmlRules.add(xp, new DigestSrcAttributeRule(scxml,
+            customActions, pr));
     }
 
     /**
@@ -841,7 +843,8 @@
             final ExtendedBaseRules scxmlRules, final List customActions,
             final PathResolver pr, final SCXML scxml) {
         scxmlRules.add(xp, new ObjectCreateRule(Initial.class));
-        addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr);
+        addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr,
+            scxml);
         scxmlRules.add(xp, new UpdateModelRule(scxml));
         addTransitionRules(xp + XPF_TR, scxmlRules, "setTransition",
             pr, customActions);
@@ -863,7 +866,8 @@
             final ExtendedBaseRules scxmlRules, final List customActions,
             final PathResolver pr, final SCXML scxml) {
         scxmlRules.add(xp, new ObjectCreateRule(History.class));
-        addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr);
+        addPseudoStatePropertiesRules(xp, scxmlRules, customActions, pr,
+            scxml);
         scxmlRules.add(xp, new UpdateModelRule(scxml));
         scxmlRules.add(xp, new SetPropertiesRule(new String[] {"type"},
             new String[] {"type"}));
@@ -882,13 +886,15 @@
      * @param customActions The list of custom actions this digester needs
      *                      to be able to process
      * @param pr The PathResolver
+     * @param scxml The root document, if this one is src'ed in
      */
     private static void addPseudoStatePropertiesRules(final String xp,
             final ExtendedBaseRules scxmlRules, final List customActions,
-            final PathResolver pr) {
+            final PathResolver pr, final SCXML scxml) {
         scxmlRules.add(xp, new SetPropertiesRule(new String[] {"id"},
             new String[] {"id"}));
-        scxmlRules.add(xp, new DigestSrcAttributeRule(customActions, pr));
+        scxmlRules.add(xp, new DigestSrcAttributeRule(scxml, customActions,
+            pr));
         addParentRule(xp, scxmlRules, 1);
     }
 
@@ -1347,6 +1353,11 @@
         private PathResolver pr;
 
         /**
+         * The root document.
+         */
+        private SCXML root;
+
+        /**
          * The list of custom actions the parent document is capable of
          * processing (and hence, the child should be, by transitivity).
          * @see CustomAction
@@ -1361,6 +1372,8 @@
          *
          * @see PathResolver
          * @see CustomAction
+         *
+         * TODO: Remove in v1.0
          */
         public DigestSrcAttributeRule(final List customActions,
                 final PathResolver pr) {
@@ -1370,6 +1383,24 @@
         }
 
         /**
+         * Constructor.
+         * @param root The root document, if this one is src'ed in
+         * @param pr The PathResolver
+         * @param customActions The list of custom actions this digester needs
+         *                      to be able to process
+         *
+         * @see PathResolver
+         * @see CustomAction
+         */
+        public DigestSrcAttributeRule(final SCXML root,
+                final List customActions, final PathResolver pr) {
+            super();
+            this.root = root;
+            this.customActions = customActions;
+            this.pr = pr;
+        }
+
+        /**
          * @see Rule#begin(String, String, Attributes)
          */
         public final void begin(final String namespace, final String name,
@@ -1386,11 +1417,22 @@
             Digester externalSrcDigester;
             if (pr == null) {
                 path = src;
-                externalSrcDigester = newInstance(scxml, null, customActions);
+                if (root != null) {
+                    externalSrcDigester = newInstance(root, null,
+                        customActions);
+                } else {
+                    externalSrcDigester = newInstance(scxml, null,
+                        customActions);
+                }
             } else {
                 path = pr.resolvePath(src);
-                externalSrcDigester = newInstance(scxml, pr.getResolver(src),
-                    customActions);
+                if (root != null) {
+                    externalSrcDigester = newInstance(root,
+                        pr.getResolver(src), customActions);
+                } else {
+                    externalSrcDigester = newInstance(scxml,
+                        pr.getResolver(src), customActions);
+                }
             }
 
             try {

Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java?view=diff&rev=471112&r1=471111&r2=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
(original)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/IOTestSuite.java
Fri Nov  3 20:10:38 2006
@@ -50,6 +50,7 @@
         suite.setName("Commons-SCXML IO Tests");
         suite.addTest(SCXMLDigesterTest.suite());
         suite.addTest(SCXMLSerializerTest.suite());
+        suite.addTest(StateSrcTest.suite());
         return suite;
     }
 }

Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java?view=auto&rev=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
(added)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
Fri Nov  3 20:10:38 2006
@@ -0,0 +1,93 @@
+/*
+ * 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.commons.scxml.io;
+
+import java.net.URL;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.State;
+/**
+ * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}
+ * Test white box nature of <state> element "src" attribute.
+ */
+public class StateSrcTest extends TestCase {
+    /**
+     * Construct a new instance of SCXMLDigesterTest with
+     * the specified name
+     */
+    public StateSrcTest(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(StateSrcTest.class);
+        suite.setName("SCXML Digester Tests");
+        return suite;
+    }
+
+    // Test data
+    private URL src01;
+    private SCXML scxml;
+    private SCXMLExecutor exec;
+
+    /**
+     * Set up instance variables required by this test case.
+     */
+    public void setUp() {
+        src01 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/io/src-test-1.xml");
+    }
+
+    /**
+     * Tear down instance variables required by this test case.
+     */
+    public void tearDown() {
+        src01 = null;
+        scxml = null;
+        exec = null;
+    }
+
+    /**
+     * Test the implementation
+     */
+    public void testRecursiveSrcInclude() {
+        scxml = SCXMLTestHelper.digest(src01);
+        assertNotNull(scxml);
+        exec = SCXMLTestHelper.getExecutor(scxml);
+        assertNotNull(exec);
+        Set states = exec.getCurrentStatus().getStates();
+        assertEquals(1, states.size());
+        assertEquals("srctest3", ((State) states.iterator().next()).getId());
+        states = SCXMLTestHelper.fireEvent(exec, "src.test");
+        assertEquals(1, states.size());
+        assertEquals("srctest1end", ((State) states.iterator().next()).getId());
+        assertTrue(exec.getCurrentStatus().isFinal());
+    }
+
+     public static void main(String args[]) {
+        TestRunner.run(suite());
+    }
+}
+

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/StateSrcTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml?view=auto&rev=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
(added)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
Fri Nov  3 20:10:38 2006
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<!-- Used for SrcTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+       version="1.0"
+       initialstate="srctest1">
+
+    <state id="srctest1" src="src-test-2.xml">
+        <transition event="src.test" target="srctest3end"/>
+        <transition event="srctest1.done" target="srctest1end"/>
+    </state>
+
+    <state id="srctest1end" final="true"/>
+
+</scxml>
+

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-1.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml?view=auto&rev=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
(added)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
Fri Nov  3 20:10:38 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<!-- Used for SrcTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+       version="1.0"
+       initialstate="srctest2">
+
+    <state id="srctest2" src="src-test-3.xml">
+        <transition event="srctest2.done" target="srctest2end"/>
+    </state>
+
+    <state id="srctest2end" final="true"/>
+
+</scxml>
+

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-2.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml?view=auto&rev=471112
==============================================================================
--- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
(added)
+++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
Fri Nov  3 20:10:38 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+ * 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.
+-->
+<!-- Used for SrcTest.java in io package -->
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+       version="1.0"
+       initialstate="srctest3">
+
+    <state id="srctest3"/>
+
+    <state id="srctest3end" final="true"/>
+
+</scxml>
+

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/src-test-3.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message