commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r954102 - /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl
Date Sat, 12 Jun 2010 19:40:19 GMT
Author: jbeard
Date: Sat Jun 12 19:40:19 2010
New Revision: 954102

URL: http://svn.apache.org/viewvc?rev=954102&view=rev
Log:
Intermediate commit.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl?rev=954102&r1=954101&r2=954102&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractEnumeratedStatechartGenerator.xsl
Sat Jun 12 19:40:19 2010
@@ -31,7 +31,7 @@
 
 		//tag each state object with an int id to map from object to id
 		//only needed for history
-		<for-each select="$basicStates>
+		<for-each select="$basicStates">
 			<value-of select="@id"/>.id = <value-of select="@c:stateNum"/>;
 		</for-each>
 
@@ -44,12 +44,17 @@
 		<call-template name="genTriggerExternalObject"/>
 
 		//needed for debugging
-		{self.genTriggerIdToNameMap()}
+		<call-template name="genTriggerIdToNameMap"/>
 
 		//transition functions
-		{util.foreach(conf.transitions,function(transition){return self.genStateTriggerDispatcher(transition.parent(),transition)})}
+		<for-each select="$transitions">
+			<call-template name="genTriggerDispatcherContext">
+				<with-param name="s" select=".."/>
+				<with-param name="t" select="."/>
+			</call-template>
+		</for-each>
 
-		{self.genEnumeratedHooks()}
+		<call-template name="genEnumeratedHooks"/>
 	</template>
 
 	<template name="genTriggerExternalObject"> 
@@ -96,177 +101,144 @@
 				<variable name="defaultTransitions"	
 					select="s:transition[not(@event)]"/>
 
-				<!-- FIXME: figure out proper comma usage -->
-				<!--generate stuff for default transitions-->
-				<for-each select="$defaultTransitions">
-					<!-- generate code here -->
-					$nt
-				</for-each>
+				[
 
-				<for-each select="$eventsEnum">
-					<sort select="c:id"/>	
+					<!-- FIXME: figure out proper comma usage -->
+					<!--generate stuff for default transitions-->
+					<for-each select="$defaultTransitions">
+						<!-- generate code here -->
+						$nt
+					</for-each>
 
-					<variable name="currentEvent" select="."/>
-				
-					<!--get the corresponding transition-->
-					<variable name="correspondingTransitions" 
-						select="$currentState/s:transition[@event = $currentEvent]"/>
+					<for-each select="$eventsEnum">
+						<sort select="c:id"/>	
 
+						<variable name="currentEvent" select="."/>
 					
-					<for-each select="$correspondingTransitions">
-						<!-- TODO: generate code here... -->
+						<!--get the corresponding transition-->
+						<variable name="correspondingTransitions" 
+							select="$currentState/s:transition[@event = $currentEvent]"/>
+
+						<for-each select="$correspondingTransitions">
+							<!-- generate code here -->
+							<apply-templates select="s:*"/>
+						</for-each>
+											
+						<if test="not(position() = last())">
+						,
+						</if>
 					</for-each>
-					
-
-				</for-each>
+				]
+				<if test="not(position() = last())">
+				,
+				</if>
 			</for-each>
 			
-			self.transitionTable.map(function(row){
-				return '[' +row.map(function(action){
-				if(action){
-					return action.toString();
-				}
-				else return "$nt";
-			}).join(',') +']\n';
-		}).join(',') + ']';
+	</template>
+
+	<template name="genTriggerDispatcherContext">
+		<param name="s"/>
+		<param name="t"/>
+
+		var <value-of select="$t/@c:tName"/> = function(){
+			<choose>
+				<when test="$s/@isHistory">
+					<call-template name="genHistoryTriggerDispatcher">
+						<with-param name="s" select="$s"/>
+						<with-param name="t" select="$t"/>
+					</call-template>
+				</when>
+				<otherwise>
+					<call-template name="genTriggerDispatcherContents">
+						<with-param name="s" select="$s"/>
+						<with-param name="t" select="$t"/>
+					</call-template>
+				</otherwise>
+			</choose>
+		}
+	</template>
+
+	<template name="genExternalTriggerDispatcher">
+		<param name="t"/>
+
+		this.<value-of select="$t/@event"> = function(){
+			if(isInStableState){
+				runToCompletion(<value-of select="$t/@event">);
+			}else{
+				return undefined;
+			}
+		}
+	</template>
+
+	<template name="genNonParallelSubstateConfigurationSetString">
+		<param name="t"/>
+
+		currentConfiguration = [
+			<for-each select="$t/c:targets/c:target/c:targetState">
+				<variable name="targetStateId" select="."/>
+				<value-of select="$allStates[@id = $targetStateId]/@c:enumId"/>
+
+				<if test="not(position() = last())"> , </if>
+			</for-each>
+		]; 
+	</template>
+
+	<template name="genParallelSubstateConfigurationSetString">
+		<param name="s"/>
+		<param name="t"/>
+
+		currentConfiguration.splice(currentConfiguration.indexOf(<value-of select="$s/@c:enumId"/>),1,
+			<for-each select="$t/c:targets/c:target/c:targetState">
+				<variable name="targetStateId" select="."/>
+				<value-of select="$allStates[@id = $targetStateId]/@c:enumId"/>
+
+				<if test="not(position() = last())"> , </if>
+			</for-each>);
+	</template>
+
+	<template name="genInitialization">
+		<!-- we just need to know what the initial state is -->
+		<variable name="initialStateName" 
+			select="$allStates[@id = /s:scxml/s:initial/s:transition/c:targets/c:target/c:targetState]/@c:enumId"/>
+
+		this.initialize = function(){
+			currentConfiguration = [<value-of select="$initialStateName"/>];
+			runToCompletion();
+			mainLoop();
+		}
+	</template>
+
+	<template name="genSend">
+		<param name="send"/>
+
+		<if test="send">
+			<variable name="sendEvent" select="$send/@event"/>
+			<variable name="sendDelay" select="number($send/@delay)"/>
+
+			<choose>
+				<when test="$sendDelay">
+					//set timeout
+					toReturn = window.setTimeout(function(){
+						self.GEN(<value-of select="$sendEvent"/>);
+					}, <value-of select="$sendDelay*1000"/>);
+				</when>
+				<otherwise>
+					//just add the event to the outer queue
+					toReturn = innerEventQueue.push(<value-of select="$sendEvent"/>);
+				</otherwise>
+			</choose>
+		</if>
+	</template>
+
+	<template name="genHistoryTriggerDispatcherHistoryStateReference">
+		<param name="s"/>
+
+		<value-of select="$s/@id"/>
 	</template>
 
 	<template name="genStateHooks"/>
-	<template name="genExternalTriggerDispatcher"/>
-	<template name="genParallelSubstateConfigurationSetString"/>
-	<template name="genNonParallelSubstateConfigurationSetString"/>
-	<template name="genInitialization"/>
-	<template name="genTriggerDispatcherContext"/>
-
-<!--
-
-				//this should be overrridden by subclasses
-				self.genEnumeratedHooks = function(){
-					return "";
-				}
-
-				//@override
-				self.genTriggerDispatcherContext = function (params,s,t){
-					return <>
-						var {t.@msdl::tName} = function()&#x7B;
-							{params.isHistory ? 
-								self.genHistoryTriggerDispatcher(params,s,t) : 
-								self.genTriggerDispatcherContents(params,s,t) }
-						&#x7D;
-					</>
-				}
-
-
-				//enumeration of triggers
-				self.genTriggerIntEnum = function(){
-					return "";
-				}
-
-				self.genStateTransitionTable = function(){
-					return 'var STATE_TRANSITION_TABLE = [' + self.transitionTable.map(function(row){
-						return '[' +row.map(function(action){
-							if(action){
-								return action.toString();
-							}
-							else return "$nt";
-						}).join(',') +']\n';
-					}).join(',') + ']';
-				}
-
-				self.genExternalTriggerDispatcher = function(t){
-					return <>
-						this.{t.@event} = function()&#x7B;
-							if(isInStableState)&#x7B;
-								runToCompletion({t.@event});
-							&#x7D;else&#x7B;
-								return undefined;
-							&#x7D;
-						&#x7D;
-					</>;
-				}
-
-				self.genNonParallelSubstateConfigurationSetString = function(s,t){
-					return <>
-								currentConfiguration = [{util.foreach(t.msdl::targets
-																.msdl::target
-																.msdl::targetState,function(s){
-																	return conf.allStates.(@id == s.toString()).msdl::enumId.toString() + ","}).slice(0,-1)}];

-					</>
-				}
-
-				self.genParallelSubstateConfigurationSetString = function(s,t){
-					return <>
-								currentConfiguration.splice(currentConfiguration.indexOf({s.msdl::enumId.toString()}),1,
-										{util.foreach(t.msdl::targets
-													.msdl::target
-													.msdl::targetState,function(s){
-														return conf.allStates.(@id == s.toString()).msdl::enumId.toString() + ","}).slice(0,-1)});

-					</>
-				}
-
-
-				self.genInitialization = function(){
-					//we just need to know what the initial state is
-					var initialStateName = conf.allStates.(@id == conf.
-											scxml.
-											initial.
-											transition.
-											msdl::targets.
-											msdl::target.
-											msdl::targetState.
-											toString()).msdl::enumId.toString();
-
-					return <>
-						this.initialize = function()&#x7B;
-							currentConfiguration = [{initialStateName}];
-							runToCompletion();
-							mainLoop();
-						&#x7D;
-					</>;
-				}
-
-
-				self.genSend = function(send){
-					var toReturn="";
-
-					if(send.length()){
-						var sendEvent = send.@event.toString();
-						var sendDelay = parseInt(send.@delay.toString());	//fixme: not sure what the units
are
-
-						if(sendDelay){
-							//set timeout
-							toReturn =  <>
-							window.setTimeout(function()&#x7B;
-								self.GEN({sendEvent});
-							&#x7D;,{sendDelay*1000});
-								</>
-						}else{
-							//just add the event to the outer queue
-							toReturn = <>
-								innerEventQueue.push({sendEvent});
-								</>
-						}
-					}
-
-					return toReturn;
-				}
-
-				self.genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS = function(){
-					return "newConfiguration.map(function(sObj){return sObj.id})";
-				}
-
-				self.genHistoryTriggerDispatcherHistoryStateReference = function(s){
-					return s.@id
-				}
-
-				self.genHistoryTriggerDispatcherInnerForEachStateReference = function(){
-					return "STATE_INT_ID_TO_OBJECT_MAP[state]";
-				}
-
-				self.genNonBasicTriggerDispatcherExitBlockIteratorExpression = function(){
-					return "currentConfiguration.map(function(state){return STATE_INT_ID_TO_OBJECT_MAP[state]}
)";	
-				}
--->
+	<template name="genEnumeratedHooks"/>
+	<template name="genTriggerIntEnum"/>
 </stylesheet>
 
 



Mime
View raw message