Author: rahul Date: Fri Nov 21 13:53:12 2008 New Revision: 719725 URL: http://svn.apache.org/viewvc?rev=719725&view=rev Log: Support initial attribute of <state> SCXML-86
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml (with props) Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java?rev=719725&r1=719724&r2=719725&view=diff ============================================================================== --- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java (original) +++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLParser.java Fri Nov 21 13:53:12 2008 @@ -855,7 +855,9 @@ private static void addStatePropertiesRules(final String xp, final ExtendedBaseRules scxmlRules, final List customActions, final PathResolver pr, final SCXML scxml) { - scxmlRules.add(xp, new SetPropertiesRule()); + scxmlRules.add(xp, new SetPropertiesRule( + new String[] {"id", "final", "initial"}, + new String[] {"id", "final", "first"})); scxmlRules.add(xp, new DigestSrcAttributeRule(scxml, customActions, pr)); } Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java?rev=719725&r1=719724&r2=719725&view=diff ============================================================================== --- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java (original) +++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java Fri Nov 21 13:53:12 2008 @@ -191,6 +191,33 @@ } /** + * Get the initial state's ID. + * + * @return The initial state's string ID. + */ + public final String getFirst() { + if (initial != null) { + return initial.getTransition().getNext(); + } + return null; + } + + /** + * Set the initial state by its ID string. + * + * @param target + * The initial target's ID to set. + */ + public final void setFirst(final String target) { + Transition t = new Transition(); + t.setNext(target); + Initial ini = new Initial(); + ini.setTransition(t); + ini.setParent(this); + this.initial = ini; + } + + /** * Get the map of child states (may be empty). * * @return Map Returns the children. Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java?rev=719725&r1=719724&r2=719725&view=diff ============================================================================== --- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java (original) +++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StateTest.java Fri Nov 21 13:53:12 2008 @@ -16,8 +16,12 @@ */ package org.apache.commons.scxml.model; +import java.net.URL; import java.util.List; +import org.apache.commons.scxml.SCXMLExecutor; +import org.apache.commons.scxml.SCXMLTestHelper; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -36,13 +40,23 @@ String[] testCaseName = { StateTest.class.getName()}; junit.textui.TestRunner.main(testCaseName); } - + + // Test data private State state; - + private URL state01; + private SCXMLExecutor exec; + public void setUp() { state = new State(); + state01 = this.getClass().getClassLoader(). + getResource("org/apache/commons/scxml/model/state-01.xml"); } - + + public void tearDown() { + state01 = null; + exec = null; + } + public void testGetTransitionsListNull() { assertNull(state.getTransitionsList("event")); } @@ -155,5 +169,13 @@ assertFalse(state.isRegion()); } - + + public void testInitialAttribute() { + SCXML scxml = SCXMLTestHelper.parse(state01); + assertNotNull(scxml); + exec = SCXMLTestHelper.getExecutor(scxml); + assertNotNull(exec); + assertEquals("s11", ((State) exec.getCurrentStatus().getStates().iterator().next()).getId()); + } + } Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml?rev=719725&view=auto ============================================================================== --- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml (added) +++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml Fri Nov 21 13:53:12 2008 @@ -0,0 +1,24 @@ +<?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. +--> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="s1"> + + <state id="s1" initial="s11"> + <final id="s11"/> + </state> + +</scxml> Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/state-01.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL