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/07/29 00:04:03 UTC
svn commit: r680525 - in /commons/proper/scxml/branches/J6/src:
main/java/org/apache/commons/scxml/semantics/
test/java/org/apache/commons/scxml/invoke/
Author: rahul
Date: Mon Jul 28 15:04:02 2008
New Revision: 680525
URL: http://svn.apache.org/viewvc?rev=680525&view=rev
Log:
Port r680521 from trunk.
Correct semantics for <param> with only the "name" attribute.
Variant of a patch by Edzard Hoefig <info at edzard dot net>.
SCXML-77
Added:
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java (with props)
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml (with props)
Modified:
commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeTestSuite.java
Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=680525&r1=680524&r2=680525&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java (original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java Mon Jul 28 15:04:02 2008
@@ -92,6 +92,12 @@
*/
private static final String NAMESPACES_KEY = "_ALL_NAMESPACES";
+ /**
+ * Suffix for error event that are triggered in reaction to invalid data
+ * model locations.
+ */
+ private static final String ERR_ILLEGAL_ALLOC = ".error.illegalalloc";
+
/**
* Zero-length array of {@link TransitionTarget}s.
*/
@@ -761,16 +767,33 @@
for (Param p : params) {
String argExpr = p.getExpr();
Object argValue = null;
+ ctx.setLocal(NAMESPACES_KEY, p.getNamespaces());
+ // Do we have an "expr" attribute?
if (argExpr != null && argExpr.trim().length() > 0) {
try {
- ctx.setLocal(NAMESPACES_KEY, p.getNamespaces());
argValue = eval.eval(ctx, argExpr);
- ctx.setLocal(NAMESPACES_KEY, null);
+ } catch (SCXMLExpressionException see) {
+ errRep.onError(ErrorConstants.EXPRESSION_ERROR,
+ see.getMessage(), i);
+ }
+ } else {
+ // No. Does value of "name" attribute refer to a valid
+ // location in the data model?
+ try {
+ argValue = eval.evalLocation(ctx, p.getName());
+ if (argValue == null) {
+ // Generate error, 4.3.1 in WD-scxml-20080516
+ TriggerEvent te = new TriggerEvent(s.getId()
+ + ERR_ILLEGAL_ALLOC,
+ TriggerEvent.ERROR_EVENT);
+ internalEvents.add(te);
+ }
} catch (SCXMLExpressionException see) {
errRep.onError(ErrorConstants.EXPRESSION_ERROR,
see.getMessage(), i);
}
}
+ ctx.setLocal(NAMESPACES_KEY, null);
args.put(p.getName(), argValue);
}
try {
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java?rev=680525&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java Mon Jul 28 15:04:02 2008
@@ -0,0 +1,154 @@
+/*
+ * 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.invoke;
+
+import java.net.URL;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.scxml.SCInstance;
+import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLTestHelper;
+import org.apache.commons.scxml.TriggerEvent;
+import org.apache.commons.scxml.env.jexl.JexlContext;
+import org.apache.commons.scxml.env.jexl.JexlEvaluator;
+import org.apache.commons.scxml.invoke.Invoker;
+import org.apache.commons.scxml.invoke.InvokerException;
+import org.apache.commons.scxml.model.ModelException;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+// Tests for 4.3.1 in WD-scxml-20080516
+public class InvokeParamNameTest extends TestCase {
+
+ public InvokeParamNameTest(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(InvokeParamNameTest.class);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { InvokeParamNameTest.class.getName()};
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ private URL invoker04;
+ private SCXMLExecutor exec;
+
+ static String lastSource;
+ static Map<String, Object> lastParams;
+
+ public void setUp() {
+ invoker04 = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/invoke/invoker-04.xml");
+ exec = SCXMLTestHelper.getExecutor(invoker04,
+ new JexlContext(), new JexlEvaluator());
+ exec.registerInvokerClass("x-test", DummyInvoker.class);
+ }
+
+ public void tearDown() {
+ exec.unregisterInvokerClass("x-test");
+ invoker04 = null;
+ }
+
+ private void trigger() throws ModelException {
+ lastParams = null;
+ lastSource = null;
+ exec.triggerEvent(new TriggerEvent("test.trigger",
+ TriggerEvent.SIGNAL_EVENT));
+ }
+
+ // Tests "param" element with "name" and "expr" attribute
+ public void testNameAndExpr() {
+ try {
+ trigger();
+ assertTrue(lastSource.endsWith("TestSrc"));
+ final Map.Entry<String, Object> e = (Map.Entry<String, Object>)
+ lastParams.entrySet().iterator().next();
+ assertEquals("ding", e.getKey());
+ assertEquals("foo", e.getValue());
+ } catch (ModelException e) {
+ fail("ModelException: " + e.getMessage());
+ }
+ }
+
+ // Tests "param" element with only a "name" attribute
+ public void testSoleNameLocation() {
+ try {
+ trigger(); trigger();
+ final Element e = (Element)lastParams.values().iterator().next();
+ assertNotNull(e);
+ assertEquals("bar", e.getNodeName());
+ assertEquals(Node.TEXT_NODE, e.getFirstChild().getNodeType());
+ assertEquals("foo", e.getFirstChild().getNodeValue());
+ } catch (ModelException e) {
+ fail("ModelException: " + e.getMessage());
+ }
+ }
+
+ // Tests "param" element with a single, wrong "name" attribute
+ public void testWrongNameLocation() {
+ try {
+ trigger(); trigger(); trigger();
+ assertEquals(1, exec.getCurrentStatus().getEvents().size());
+ final TriggerEvent evt = (TriggerEvent)
+ exec.getCurrentStatus().getEvents().iterator().next();
+ assertTrue(evt.getName().endsWith("error.illegalalloc"));
+ } catch (ModelException e) {
+ fail("ModelException: " + e.getMessage());
+ }
+ }
+
+ public static class DummyInvoker implements Invoker {
+
+ public void invoke(String source, Map<String, Object> params)
+ throws InvokerException {
+ lastSource = source;
+ lastParams = params;
+ }
+
+ public String lastSource() {
+ return lastSource;
+ }
+
+ public Map<String, Object> lastParams() {
+ return lastParams;
+ }
+
+ public void cancel() throws InvokerException {
+ // Not needed
+ }
+
+ public void parentEvents(TriggerEvent[] evts) throws InvokerException {
+ // Not needed
+ }
+
+ public void setParentStateId(String parentStateId) {
+ // Not needed
+ }
+
+ public void setSCInstance(SCInstance scInstance) {
+ // Not needed
+ }
+ }
+
+}
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeParamNameTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeTestSuite.java?rev=680525&r1=680524&r2=680525&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeTestSuite.java (original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/InvokeTestSuite.java Mon Jul 28 15:04:02 2008
@@ -48,6 +48,7 @@
TestSuite suite = new TestSuite();
suite.setName("Commons-SCXML Invoke Tests");
suite.addTest(InvokeTest.suite());
+ suite.addTest(InvokeParamNameTest.suite());
return suite;
}
}
Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml?rev=680525&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml (added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml Mon Jul 28 15:04:02 2008
@@ -0,0 +1,55 @@
+<?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.
+-->
+<!-- A fictitious state machine used by test cases.
+ Meant to illustrate the usage of SCXML <param> element as part
+ of an invocation using a custom invoker -->
+
+<scxml xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ initialstate="wait">
+
+ <datamodel>
+ <data id="foo">
+ <bar>foo</bar>
+ </data>
+ </datamodel>
+
+ <state id="wait">
+ <transition event="test.trigger" target="first"/>
+ </state>
+
+ <state id="first">
+ <invoke src="FirstTestSrc" targettype="x-test">
+ <param name="ding" expr="Data(foo,'node()')"/>
+ </invoke>
+ <transition event="test.trigger" target="second"/>
+ </state>
+
+ <state id="second">
+ <invoke src="SecondTestSrc" targettype="x-test">
+ <param name="Data(foo,'node()')"/>
+ </invoke>
+ <transition event="test.trigger" target="third"/>
+ </state>
+
+ <state id="third">
+ <invoke src="ThirdTestSrc" targettype="x-test">
+ <param name="Data(foo,'gibberish')"/>
+ </invoke>
+ </state>
+</scxml>
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/invoke/invoker-04.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL