You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2008/06/17 23:49:37 UTC
svn commit: r668845 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml/io/
main/java/org/apache/commons/scxml/model/
test/java/org/apache/commons/scxml/io/
Author: rahul
Date: Tue Jun 17 14:49:36 2008
New Revision: 668845
URL: http://svn.apache.org/viewvc?rev=668845&view=rev
Log:
Support the "initial" attribute of the <scxml> element (same functionality as the "initialstate" attribute, which will no longer be supported in next major release).
Reported by Landon Ouyang <Landon DOT Ouyang AT itt DOT com>, on the user list.
Added:
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml (with props)
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
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/io/SCXMLSerializer.java
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLParserTest.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/ModelUpdater.java Tue Jun 17 14:49:36 2008
@@ -57,16 +57,15 @@
* @throws ModelException If the object model is flawed
*/
static void updateSCXML(final SCXML scxml) throws ModelException {
- // Watch case, slightly unfortunate naming ;-)
- String initialstate = scxml.getInitialstate();
- //we have to use getTargets() here since the initialState can be
+ String initial = scxml.getInitial();
+ //we have to use getTargets() here since the initialTarget can be
//an indirect descendant
TransitionTarget initialTarget = (TransitionTarget) scxml.getTargets().
- get(initialstate);
+ get(initial);
if (initialTarget == null) {
// Where do we, where do we go?
logAndThrowModelError(ERR_SCXML_NO_INIT, new Object[] {
- initialstate });
+ initial });
}
scxml.setInitialTarget(initialTarget);
Map targets = scxml.getTargets();
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLDigester.java Tue Jun 17 14:49:36 2008
@@ -1469,7 +1469,7 @@
// All targets pulled in since its not a src fragment
Initial ini = new Initial();
Transition t = new Transition();
- t.setNext(externalSCXML.getInitialstate());
+ t.setNext(externalSCXML.getInitial());
ini.setTransition(t);
s.setInitial(ini);
Map children = externalSCXML.getChildren();
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=668845&r1=668844&r2=668845&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 Tue Jun 17 14:49:36 2008
@@ -1494,7 +1494,7 @@
// All targets pulled in since its not a src fragment
Initial ini = new Initial();
Transition t = new Transition();
- t.setNext(externalSCXML.getInitialstate());
+ t.setNext(externalSCXML.getInitial());
ini.setTransition(t);
s.setInitial(ini);
Map children = externalSCXML.getChildren();
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java Tue Jun 17 14:49:36 2008
@@ -90,7 +90,7 @@
new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n").
append("<scxml xmlns=\"").append(NAMESPACE_SCXML).
append("\" version=\"").append(scxml.getVersion()).
- append("\" initialstate=\"").append(scxml.getInitialstate()).
+ append("\" initial=\"").append(scxml.getInitial()).
append("\">\n");
if (XFORMER == null) {
org.apache.commons.logging.Log log = LogFactory.
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/SCXML.java Tue Jun 17 14:49:36 2008
@@ -60,7 +60,7 @@
/**
* The initial transition target ID (used by XML Digester only).
*/
- private String initialstate;
+ private String initial;
/**
* Optional property holding the data model for this SCXML document.
@@ -261,20 +261,44 @@
* Get the ID of the initial state.
*
* @return String Returns the initial state ID (used by XML Digester only).
- * @see #getInitialState()
+ * @see #getInitialTarget()
+ * @deprecated Use {@link #getInitial()} instead.
*/
public final String getInitialstate() {
- return initialstate;
+ return initial;
}
/**
* Set the ID of the initial state.
*
* @param initialstate The initial state ID (used by XML Digester only).
- * @see #setInitialState(State)
+ * @see #setInitialTarget(TransitionTarget)
+ * @deprecated Use {@link #setInitial(String)} instead.
*/
public final void setInitialstate(final String initialstate) {
- this.initialstate = initialstate;
+ this.initial = initialstate;
+ }
+
+ /**
+ * Get the ID of the initial transition target.
+ *
+ * @return String Returns the initial transition target ID
+ * (used by XML Digester only).
+ * @see #getInitialTarget()
+ */
+ public final String getInitial() {
+ return initial;
+ }
+
+ /**
+ * Set the ID of the initial transition target.
+ *
+ * @param initial The initial transition target ID
+ * (used by XML Digester only).
+ * @see #setInitialTarget(TransitionTarget)
+ */
+ public final void setInitial(final String initial) {
+ this.initial = initial;
}
}
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLParserTest.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLParserTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLParserTest.java Tue Jun 17 14:49:36 2008
@@ -24,6 +24,7 @@
import junit.textui.TestRunner;
import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.model.Final;
import org.apache.commons.scxml.model.SCXML;
/**
* Unit tests {@link org.apache.commons.scxml.SCXMLParser}.
@@ -44,7 +45,7 @@
}
// Test data
- private URL microwave03, microwave04;
+ private URL microwave03, microwave04, scxmlinitialattr;
private SCXML scxml;
private String scxmlAsString;
@@ -56,6 +57,8 @@
getResource("org/apache/commons/scxml/env/jexl/microwave-03.xml");
microwave04 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml/env/jexl/microwave-04.xml");
+ scxmlinitialattr = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/io/scxml-initial-attr.xml");
}
/**
@@ -84,6 +87,15 @@
assertNotNull(scxmlAsString);
}
+ public void testSCXMLParserInitialAttr() {
+ scxml = SCXMLTestHelper.parse(scxmlinitialattr);
+ assertNotNull(scxml);
+ scxmlAsString = serialize(scxml);
+ assertNotNull(scxmlAsString);
+ Final foo = (Final) scxml.getInitialTarget();
+ assertEquals("foo", foo.getId());
+ }
+
private String serialize(final SCXML scxml) {
scxmlAsString = SCXMLSerializer.serialize(scxml);
assertNotNull(scxmlAsString);
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java?rev=668845&r1=668844&r2=668845&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java Tue Jun 17 14:49:36 2008
@@ -56,12 +56,12 @@
public void testSerializeSCXMLNoStates() {
SCXML scxml = new SCXML();
scxml.setVersion("version1");
- scxml.setInitialstate("off");
+ scxml.setInitial("off");
scxml.addChild(new State());
String assertValue = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<scxml xmlns=\"http://www.w3.org/2005/07/scxml\" version=\"version1\" "
- + "initialstate=\"off\">\n <state>\n </state>\n</scxml>\n";
+ + "initial=\"off\">\n <state>\n </state>\n</scxml>\n";
assertEquals(assertValue, SCXMLSerializer.serialize(scxml));
}
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml?rev=668845&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml Tue Jun 17 14:49:36 2008
@@ -0,0 +1,25 @@
+<?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"
+ initial="foo">
+
+ <final id="foo"/>
+
+</scxml>
Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/scxml-initial-attr.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL