commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r954087 - in /commons/sandbox/gsoc/2010/scxml-js/trunk: run.sh src/scxml/cgf/SCXMLCompiler.js test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl test/xslt/computeLCA.xsl
Date Sat, 12 Jun 2010 19:38:30 GMT
Author: jbeard
Date: Sat Jun 12 19:38:30 2010
New Revision: 954087

URL: http://svn.apache.org/viewvc?rev=954087&view=rev
Log:
Intermediate commit. Fixed some problems with computeLCA.xsl

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh?rev=954087&r1=954086&r2=954087&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/run.sh Sat Jun 12 19:38:30 2010
@@ -6,4 +6,4 @@
 
 dn=`dirname $0`
 abspath=`cd $dn; pwd`
-java -cp ./lib/java/js.jar:./lib/java/commons-cli.jar:./lib/java/serializer.jar:./lib/java/xalan.jar:./lib/java/xercesImpl.jar:./lib/java/xml-apis.jar
org.mozilla.javascript.tools.shell.Main -debug runner.js $abspath src/scxml/cgf/main $*
+java -cp ./lib/java/js.jar:./lib/java/commons-cli.jar org.mozilla.javascript.tools.shell.Main
-debug runner.js $abspath src/scxml/cgf/main $*

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js?rev=954087&r1=954086&r2=954087&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/scxml/cgf/SCXMLCompiler.js Sat Jun 12 19:38:30
2010
@@ -151,102 +151,26 @@ require.def("src/scxml/cgf/SCXMLCompiler
 					options.noMap = options.noForEach = options.noIndexOf = true;
 				}
 
-
-				//var scxmlRoot = parseSCXML(readFile(xmlFile));
-
-				//FIXME: later on, change architecture to use dependency injection, 
-				//so we are just given an xml doc to manipulate
-				importPackage(Packages.org.w3c.dom);
-				importPackage(javax.xml.parsers);
-				importPackage(javax.xml.xpath);
-
-				// Set up a DOM tree to query.
-				dfactory = DocumentBuilderFactory.newInstance();
-				dfactory.setNamespaceAware(true);
-				var doc = dfactory.newDocumentBuilder().parse(xmlFile);
-
-				var scxmlNs = "http://www.w3.org/2005/07/scxml";
-	
-				var personalNamespaceContext = new javax.xml.namespace.NamespaceContext({
-				       getNamespaceURI : function(prefix)
-					{
-						//default namespace
-						if(prefix.equals("s"))
-							return scxmlNs;
-						else
-							return scxmlNs;
-					},
-					
-					getPrefix : function(namespace)
-					{
-						return null;
-					},
-
-					getPrefixes : function(namespace)
-					{
-					    return null;
-					}
-
-				});
-
-				var factory = XPathFactory.newInstance();
-
-				function nodesetToJsArray (args){
-					var toReturn = [];
-
-					for(var i = 0; i < args.length; i++){
-						toReturn.push(args.item(i));
-					}
-
-					return toReturn;
-				}
-
-				function $(query){
-					xpath = factory.newXPath();
-					xpath.setNamespaceContext(personalNamespaceContext);
-
-					var expr = xpath.compile(query);
-					var result = expr.evaluate(doc, XPathConstants.NODESET);
-
-					print(result);
-					print(result.length);
-
-					var arr = nodesetToJsArray(result);
-					return arr;
-				}
-
-
+				var scxmlRoot = parseSCXML(readFile(xmlFile));
 
 				//do a bit of verification and normalization transformations
 
 				//make all names we will use for variables legal
-				var transitions = $("//s:transition");
-				transitions.forEach(function(n){
-					n.setAttributeNS(null,"event",
-						makeLegalLValue(
-							n.getAttributeNS(null,"event")));
-				});
+				scxmlRoot..transition.(@event.length() && (@event = makeLegalLValue(@event)));
 
 				//make sure root has an id
-				doc.documentElement.setAttributeNS(null,"id","Root");
+				scxmlRoot.@id = "Root"
 
 				//normalize initial states
-				/*
-				$("//s:*[@initial]").forEach(function(n){
-					var newInitial = doc.createElementNS(scxmlNs,"initial");
-					var newTransition = doc.createElementNS(scxmlNs,"transition");
-
-					n.appendChild(newInitial);
-					newInitial.appendChild(newTransition);
-
-					newInitial.setAttributeNS(null,"target",
-						n.getAttributeNS(null,"initial"));
-
-					//TODO: delete attribute somehow
+				util.foreach(scxmlRoot..*.(@initial.length() > 0),function(s){
+					s.initial.transition.@target = s.@initial.toString();
+					delete s.@initial;
 				});
-				*/
 
-				/*
+				//make sure all transitions have id's
+				//var transitionid = 0;
+				//scxml..transition.(!@id.length() && (@id = "transition_" + transitionid++));
+
 				//we use both a dictionary and an array so that we can use both forEach and "in", which
makes the code pretty
 				var stateTagsArray = ["state", "parallel" , "final" , "initial" , "scxml" , "history"
];
 				var stateTagsHash = {}
@@ -286,8 +210,8 @@ require.def("src/scxml/cgf/SCXMLCompiler
 				conf.parallelRegions = conf.parallels.state;
 
 				conf.parallelsAndDescendantStates = conf.parallels + conf.parallels..*.(localName() in
stateTagsHash);
-				*/
-				/*
+
+
 				//make sure all states have id's
 				var idNum = 0;
 				util.foreach(conf.allStates.(@id.length() == 0),function(s){
@@ -422,9 +346,8 @@ require.def("src/scxml/cgf/SCXMLCompiler
 
 				});
 				
-				//print(scxmlRoot);
-				//debugger;
-				//return scxmlRoot;
+
+				return scxmlRoot;
 
 				//do transforms
 				importPackage(javax.xml.transform);
@@ -442,19 +365,22 @@ require.def("src/scxml/cgf/SCXMLCompiler
 				var transformer = tFactory.newTransformer(new StreamSource("./test/xslt/StatePatternStatechartGenerator.xsl"));
 			
 				//set parameters
-				for(var oName in options){
-					transformer.setParameter(oName,options[oName]);
+				/*
+				for(var paramName in conf){
+					transformer.setParameter(paramName,conf[paramName]);
 				}
+				*/
 
 				transformer.transform(new StreamSource("build/tmp.xml"), new StreamResult(outWriter));
 				var transformedJs = new String(outWriter.toString());	//convert him from Java string
to js string for js_beautify
 
 				if(options.beautify){
+					debugger;
 					transformedJs = js_beautify(transformedJs);
 				}
 
 				return transformedJs; 
-				*/
+
 				/*
 				var generatorConstructor;
 				switch(options.backend){

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl?rev=954087&r1=954086&r2=954087&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/changeTransitionsPointingToCompoundStatesToPointToInitialStates.xsl
Sat Jun 12 19:38:30 2010
@@ -37,10 +37,31 @@
 
 		<xsl:variable name="targetState" select="//*[(self::s:state or self::s:parallel) and
@id = $targetId]"/>
 
+		<xsl:variable name="isTargetStateComposite" select="$targetState
+			and $targetState//s:*[(self::s:state or self::s:parallel or self::s:final or self::s:initial
or self::s:scxml or self::s:history)]"/>
+	
+		<xsl:variable name="targetStateInitialId" select="$targetState/s:initial/@id"/>
+
+		<!--
+		<xsl:message>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>targetId: </xsl:text>
+			<xsl:value-of select="$targetId"/>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>targetState: </xsl:text>
+			<xsl:value-of select="$targetState/@id"/>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>isTargetStateComposite: </xsl:text>
+			<xsl:value-of select="$isTargetStateComposite"/>
+			<xsl:text>&#10;</xsl:text>
+			<xsl:text>targetStateInitialId: </xsl:text>
+			<xsl:value-of select="$targetStateInitialId"/>
+		</xsl:message>
+		-->
+
 		<xsl:copy>
 			<xsl:choose>
-				<xsl:when test="$targetState
-					and $targetState//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial
or self::s:scxml or self::s:history)]">
+				<xsl:when test="$isTargetStateComposite">
 					<xsl:value-of select="$targetState/s:initial/@id"/>		
 				</xsl:when>
 				<xsl:otherwise>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl?rev=954087&r1=954086&r2=954087&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/xslt/computeLCA.xsl Sat Jun 12 19:38:30
2010
@@ -56,22 +56,20 @@
 		<xsl:message>
 			<xsl:text>&#10;</xsl:text>
 			<xsl:text>Current: </xsl:text>
-			<xsl:text>&#10;</xsl:text>
 			<xsl:value-of select="$current/@id"/>
 			<xsl:text>&#10;</xsl:text>
 			<xsl:text>End: </xsl:text>
-			<xsl:text>&#10;</xsl:text>
 			<xsl:value-of select="$end/@id"/>
 			<xsl:text>&#10;</xsl:text>
 		</xsl:message>
 		-->
 
-		<xsl:variable name="parent" select="$current/parent::*"/>
-
 		<xsl:if test="not($current=$end)">
 
+			<xsl:variable name="parent" select="$current/parent::*"/>
+
 			<c:state>
-				<xsl:value-of select="$parent/@id"/>
+				<xsl:value-of select="$current/@id"/>
 			</c:state>
 
 			<xsl:call-template name="genStateTree">
@@ -98,26 +96,35 @@
 				<!-- http://stackoverflow.com/questions/538293/find-common-parent-using-xpath -->
 				<xsl:variable name="lca" select="$srcState/ancestor::* [count(. | $targetState/ancestor::*)
= count($targetState/ancestor::*) ] [1]" />
 
+				<!-- call recursive function to populate exit and entry paths -->
 				<!--
 				<xsl:message>
 					<xsl:text>START&#10;</xsl:text>
-					<xsl:value-of select="$lca/@id"/><xsl:text>&#10;</xsl:text>
-					<xsl:text>END&#10;</xsl:text>
+					<xsl:text>srcState: </xsl:text>
+					<xsl:value-of select="$srcState/@id"/>
+					<xsl:text>&#10;</xsl:text>
 				</xsl:message>
 				-->
-				<!-- call recursive function to populate exit and entry paths -->
-				<c:enterpath>
+
+				<c:exitpath>
 					<xsl:call-template name="genStateTree">
 						<xsl:with-param name="current" select="$srcState"/>
 						<xsl:with-param name="end" select="$lca"/>
 					</xsl:call-template>
-				</c:enterpath>
-				<c:exitpath>
+				</c:exitpath>
+
+				<!--
+				<xsl:message>
+					<xsl:text>END&#10;</xsl:text>
+				</xsl:message>
+				-->
+
+				<c:enterpath>
 					<xsl:call-template name="genStateTree">
 						<xsl:with-param name="current" select="$targetState"/>
 						<xsl:with-param name="end" select="$lca"/>
 					</xsl:call-template>
-				</c:exitpath>
+				</c:enterpath>
 				<c:lca>
 					<xsl:value-of select="$lca/@id"/>
 				</c:lca>



Mime
View raw message