commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r954052 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt: AbstractStatechartGenerator.xsl snippets.txt
Date Sat, 12 Jun 2010 19:34:18 GMT
Author: jbeard
Date: Sat Jun 12 19:34:17 2010
New Revision: 954052

URL: http://svn.apache.org/viewvc?rev=954052&view=rev
Log:
Did a bit more work on AbstractStatechartGenerator.xsl

Added:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt   (with props)
Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl?rev=954052&r1=954051&r2=954052&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/AbstractStatechartGenerator.xsl Sat
Jun 12 19:34:17 2010
@@ -4,31 +4,40 @@
 	version="1.0">
 	<output method="text"/>
 
-	<param name="noIndexOf"/>
-	<param name="noMap"/>
+	<param name="log" select="true()"/>
+	<param name="noIndexOf" select="true()"/>
+	<param name="noMap" select="true()"/>
 	<param name="name"/>
 
 	<template match="/s:scxml">
-		<!--
-			{conf.noIndexOf ? self.genNoIndexOfArrayPrototypeExtension() : ""}
-		
-			{conf.noMap ? self.genNoMapArrayPrototypeExtension() : ""}
-		-->
 
-		<text>function </text><value-of select="$name" /><text>StatechartExecutionContext(){
+		<if test="$noIndexOf">
+			<call-template name="genNoIndexOfArrayPrototypeExtension"/>
+		</if>
+
+		<if test="$noMap">
+			<call-template name="genNoMapArrayPrototypeExtension"/>
+		</if>
+
+		function <value-of select="$name"/>StatechartExecutionContext(){
 
 				var self = this;	//used in the rare occasions we call public functions from inside this
class
 
 				//abstract state
-		</text>
-		<apply-templates match=".//s:transition[@event.length() > 0]"/>
 
-		<text>
+				<call-template name="genAbstractState">
+					<with-param name="events" select=".//s:transition/@event"/>
+				</call-template>
+
 				//states
-		</text>
-		<apply-templates match=".//s:state"/>
+				<for-each select=".//s:state | .//s:initial | .//s:parallel ">
+					<call-template name="genState">
+						<with-param name="state" select="."/>
+					</call-template>
+				</for-each>
 
 		
+				<!--
 				//states enum for glass-box unit testing
 				{self.genStatesEnum(conf.basicStates)}
 
@@ -48,16 +57,157 @@
 
 				//start static boilerplate code
 				{self.genBoilerplateDispatchCode(conf.dispatchInvocation)}
+				-->
 
 			}
 
-		</text>
-		<value-of select="@profile"/>
-		<apply-templates select="s:state | s:initial | s:parallel"/>
 	</template>
 	
-	<template match="s:state | s:initial | s:parallel">
-		<value-of select="@id"/>
+	<template name="genAbstractState">
+		<param name="events"/>
+
+		var AbstractState = new function(){
+			//triggers are methods
+
+			<for-each select="$events">
+			this.<value-of select="."/> = function(){};
+			</for-each>
+
+			this.$default = function(){};
+		}
+	</template>
+
+	<template name="genState">
+		<param name="state"/>
+
+		<variable name="stateName" select="$state/@id"/>
+
+		<variable name="parentName">
+			<choose>
+				<when test="$state/../@id">
+					<value-of select="$state/../@id"/>
+				</when>
+				<otherwise>
+					<value-of select="'AbstractState'"/>
+				</otherwise>
+			</choose>
+		</variable>
+
+		<variable name="historyState" select="$state/history"/>
+		
+		<variable name="constructorFunctionName" select="concat($stateName,'Constructor')"/>
+
+		<!--
+					var stateName = state.@id;
+					var parentName = state.parent() ? state.parent().@id : "AbstractState";
+					var historyState = state.history;
+					var hasHistoryState = historyState.length() > 0;
+					var constructorFunctionName = stateName + "Constructor";
+		-->
+
+		var <value-of select="$stateName"/> = (function(){
+
+			function <value-of select="$constructorFunctionName"/>(){
+				this.parent = <value-of select="$parentName"/>;
+
+				this.initial = null;
+
+				<!--FIXME-->
+				this.depth = {self.computeDepth(state)};
+
+				this.historyState = null;
+
+				<if test="$state/self::history">
+					this.parent.historyState = this; //init parent's pointer to history state
+				</if>
+
+				<if test="$state/self::initial">
+					this.parent.initial = this; //init parent's pointer to initial state
+				</if>
+				
+				this.toString = function(){
+					return "<value-of select="$stateName"/>"
+				}
+
+				this.enterAction = function(){
+					<if test="$log">
+						console.log("entering ' + <value-of select="$stateName"/> + '");
+					</if>
+
+					<for-each select="$state/onentry/*">
+						<call-template name="genExecutableContent">
+							<with-param name="executableNode" select="."/>
+						</call-template>
+					</for-each>
+				}
+
+				this.exitAction = function(){
+					<if test="$log">
+						console.log("exiting ' + <value-of select="$stateName"/> + '");
+					</if>
+
+					<if test="historyState">
+						this.historyState.lastConfiguration = currentConfiguration.slice();
+					</if>
+
+
+					<for-each select="$state/onexit/*">
+						<call-template name="genExecutableContent">
+							<with-param name="executableNode" select="."/>
+						</call-template>
+					</for-each>
+
+				}
+
+				<call-template name="genStateHooks">
+					<with-param name="state" select="."/>
+				</call-template>
+				
+
+			}
+			<value-of select="$constructorFunctionName"/>.prototype = <value-of select="$parentName"/>;
+			return new <value-of select="$constructorFunctionName"/>();
+		})();
+
 	</template>
+
+	<template name="genExecutableContent">
+		<param name="executableNode"/>
+
+		//executable content goes here
+	</template>
+
+	<template name="genStateHooks">
+		<param name="s"/>
+		
+		//gen state hooks here
+	</template>
+
+
+	<template name="genNoIndexOfArrayPrototypeExtension">
+		if(!Array.indexOf){
+			Array.prototype.indexOf = function(obj){
+				for(var i=0; i &lt; this.length; i++){
+					if(this[i]==obj){
+						return i;
+					}
+				}
+				return -1;
+			}
+		}
+	</template>
+
+	<template name="genNoMapArrayPrototypeExtension">
+		if(!Array.map){
+			Array.prototype.map = function(fn){
+				var toReturn = [];
+				for(var i=0; i &lt; this.length; i++){
+					toReturn[i]=fn(this[i]);
+				}
+				return toReturn;
+			}
+		}
+	</template>
+
 </stylesheet>
 

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt?rev=954052&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt Sat Jun 12 19:34:17 2010
@@ -0,0 +1,6 @@
+				<for-each select=".//s:state">
+					<call-template name="genState">
+						<with-param name="state" select="."/>
+					</call-template>
+				</for-each>
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/snippets.txt
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message