commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r634858 [2/2] - in /commons/proper/scxml/branches/J5: ./ src/main/java/org/apache/commons/scxml/env/javascript/ src/test/java/org/apache/commons/scxml/ src/test/java/org/apache/commons/scxml/env/javascript/
Date Fri, 07 Mar 2008 23:19:02 GMT
Added: commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml?rev=634858&view=auto
==============================================================================
--- commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
(added)
+++ commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
Fri Mar  7 15:18:48 2008
@@ -0,0 +1,149 @@
+<?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 Javascript environment: example script -->
+<scxml xmlns        = 'http://www.w3.org/2005/07/scxml'
+       xmlns:scxml  = 'http://commons.apache.org/scxml'
+       initialstate = 'start'
+       version      = '1.0'>
+
+ <!-- DATA MODEL -->
+
+ <datamodel>
+  <data name='jungle'>
+   <animals xmlns=''>
+    <lion>
+     <name>Simba</name>
+     <age>12</age>
+    </lion>
+    <tiger>
+     <name>Sher Khan</name>
+     <age>13</age>
+    </tiger>
+   </animals>
+  </data>
+ </datamodel>
+
+ <!-- INITIALISATION -->
+
+ <state id='start'>
+  <onentry>
+   <log expr='"Starting Javascript sample script: " + new Date()' />
+  </onentry>
+  <transition target='javascript' />
+ </state>
+
+ <!-- JAVASCRIPT -->
+
+ <state id='javascript'>
+  <onentry>
+   <scxml:var name='factorial' expr='new Function("N","if (N == 1)
+                                                          return N;
+                                                          else
+                                                          return N * factorial(N-1)")' />
+  </onentry>
+  <initial>
+   <transition target='javascript.simple' />
+  </initial>
+
+  <!-- SIMPLE JAVASCRIPT EXPRESSIONS -->
+
+  <state id='javascript.simple'>
+   <onentry>
+    <log expr='"Arithmetic: " + (1 + 2 + 3 + 4 + 5)'    />
+    <log expr='"Boolean   : " + ((1 + 2) &lt; (3 + 4))' />
+    <log expr='"String    : " + "QWERTY"'               />
+   </onentry>
+   <transition target='javascript.var' />
+  </state>
+
+  <!-- SCXML VAR -->
+
+  <state id='javascript.var'>
+   <onentry>
+    <scxml:var name='snake_name' expr='"Kaa"' />
+    <scxml:var name='snake_age'  expr='"99"'  />
+    <log expr='"Snake: " + snake_name + "," + (snake_age + 1)'  />
+   </onentry>
+   <transition target='javascript.datamodel' />
+  </state>
+
+  <!-- SCXML DATA MODEL -->
+
+  <state id='javascript.datamodel'>
+   <onentry>
+    <log expr='"Lion : " + Data(jungle,"animals/lion/name")  + "," + Data(jungle,"animals/lion/age")'
 />
+    <log expr='"Tiger: " + Data(jungle,"animals/tiger/name") + "," + Data(jungle,"animals/tiger/age")'
/>
+    <assign location='Data(jungle,"animals/lion/age")'  expr='new Number(Data(jungle,"animals/lion/age"))
+ 3'     />
+    <assign location='Data(jungle,"animals/tiger/age")' expr='new Number(Data(jungle,"animals/lion/age"))
+ 4'     />
+    <log expr='"Lion : " + Data(jungle,"animals/lion/name")  + "," + Data(jungle,"animals/lion/age")'
 />
+    <log expr='"Tiger: " + Data(jungle,"animals/tiger/name") + "," + Data(jungle,"animals/tiger/age")'
/>
+   </onentry>
+   <transition target='javascript.functions.inline' />
+  </state>
+
+  <!-- JAVASCRIPT FUNCTIONS -->
+
+  <state id='javascript.functions.inline'>
+   <onentry>
+    <log expr='function fibonacci()
+                        { return 1 + 1 + 2 + 3 + 5;
+                        };
+
+               "FIBONACCI(5) : " + fibonacci()' />
+   </onentry>
+   <transition target='javascript.functions.var' />
+  </state>
+
+  <state id='javascript.functions.var'>
+   <onentry>
+    <scxml:var name='fibonacci' expr='new Function("return 1 + 1 + 2 + 3 + 5 + 6")' />
+    <log expr='"FIBONACCI(6) : " + fibonacci()' />
+   </onentry>
+   <transition target='javascript.functions.global' />
+  </state>
+
+  <state id='javascript.functions.global'>
+   <onentry>
+    <log expr='"factorial: " + factorial(5)' />
+   </onentry>
+   <transition target='javascript.functions.print' />
+  </state>
+
+  <state id='javascript.functions.print'>
+   <onentry>
+    <log expr='function debug(msg)
+                        { println("** " + msg + " **");
+                          return "ok"
+                        }
+
+               debug("This is the Javascript println() function")' />
+   </onentry>
+   <transition target='end' />
+  </state>
+
+ </state>
+
+ <!-- DONE -->
+
+ <state id='end' final='true' >
+  <onentry>
+   <log expr='"Ending Javascript sample script: " + new Date()' />
+  </onentry>
+ </state>
+
+</scxml>

Propchange: commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J5/src/test/java/org/apache/commons/scxml/env/javascript/example-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message