Author: jbeard Date: Wed Jun 16 03:20:05 2010 New Revision: 955120 URL: http://svn.apache.org/viewvc?rev=955120&view=rev Log: Browser front-end works in IE8.
Added: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl (with props) Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator.js commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/SCXMLCompiler.js Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator.js?rev=955120&r1=955119&r2=955120&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator.js Wed Jun 16 03:20:05 2010 @@ -5,7 +5,10 @@ require.def( [ "src/javascript/scxml/cgf/backends/js/AbstractStatechartGenerator", "xml!src/xslt/ir-compiler/appendTransitionInformation.xsl", - "xml!src/xslt/backends/js/StatePatternStatechartGenerator.xsl" ], + //stylesheet must be preprocessed with preprocess_import.xsl for IE and maybe chrome + "xml!src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl" + //"xml!src/xslt/backends/js/StatePatternStatechartGenerator.xsl" + ], function( AbstractStatechartGenerator, Added: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl?rev=955120&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl (added) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl Wed Jun 16 03:20:05 2010 @@ -0,0 +1,568 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--><stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:c="urn://scxml-js" xmlns:s="http://www.w3.org/2005/07/scxml"> + <output method="text"/> + <param name="log" select="true()"/> + <param name="noIndexOf" select="false()"/> + <param name="noMap" select="false()"/> + <param name="noForEach" select="false()"/> + <param name="name"/> + <variable name="allStates" select="//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history)]"/> + <variable name="states" select="//s:state"/> + <variable name="transitions" select="//s:transition"/> + <variable name="basicStates" select="$allStates[not(.//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history)])]"/> + <variable name="compositeStates" select="$allStates[.//*[(self::s:state or self::s:parallel or self::s:final or self::s:initial or self::s:scxml or self::s:history)]]"/> + <variable name="eventsEnum" select="/s:scxml/c:eventsEnum/c:event"/> + <template match="/s:scxml"> + <if test="$noIndexOf"> + <call-template name="genNoIndexOfArrayPrototypeExtension"/> + </if> + <if test="$noMap"> + <call-template name="genNoMapArrayPrototypeExtension"/> + </if> + <if test="$noForEach"> + <call-template name="genNoForEachArrayPrototypeExtension"/> + </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 + + <call-template name="genAbstractState"><with-param name="events" select="$eventsEnum"/></call-template> + + //states + <for-each select="$allStates"><call-template name="genState"><with-param name="state" select="."/></call-template></for-each> + + + //states enum for glass-box unit testing + <call-template name="genStatesEnum"><with-param name="states" select="$basicStates"/></call-template> + + //trigger methods for synchronous interaction + <for-each select="$eventsEnum"><call-template name="genExternalTriggerDispatcher"><with-param name="event" select="."/></call-template></for-each><call-template name="genContextHooks"/> + + //initialization script + <value-of select="s:script"/> + + //initialization method + <call-template name="genInitialization"/> + + //internal runtime functions + <call-template name="genInternalRuntimeFunctions"/> + + //start static boilerplate code + <call-template name="genBoilerplateDispatchCode"/> + + } + + </template> + <template name="genAbstractState"> + <param name="events"/> + + var AbstractState = new function(){ + //triggers are methods + + <for-each select="$events"> + this.<value-of select="./c:name"/> = function(){}; + </for-each> + + this.$default = function(){}; + } + </template> + <template name="genState"> + <param name="state"/> + <variable name="stateName" select="$state/@id"/> + <variable name="parentName"> + <choose> + <!-- FIXME: probably want to refine this query, as we may not be able to assume that all states have ids?--> + <when test="$state/../@id"> + <value-of select="$state/../@id"/> + </when> + <otherwise> + <value-of select="'AbstractState'"/> + </otherwise> + </choose> + </variable> + <variable name="historyState" select="$state/s:history"/> + <variable name="constructorFunctionName" select="concat($stateName,'Constructor')"/> + + <!-- + var stateName = sta...@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; + + this.depth = <value-of select="count($state/ancestor::*)"/>; + + this.historyState = null; + + <if test="$state/self::s:history"> + this.parent.historyState = this; //init parent's pointer to history state + </if><if test="$state/self::s: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><apply-templates select="$state/s:onentry/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/> + } + + this.exitAction = function(){ + <if test="$log"> + console.log("exiting <value-of select="$stateName"/>" ); + </if><if test="$historyState"> + this.historyState.lastConfiguration = currentConfiguration.slice(); + </if><apply-templates select="$state/s:onexit/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/> + } + + <call-template name="genStateHooks"><with-param name="state" select="$state"/></call-template> + + + } + <value-of select="$constructorFunctionName"/>.prototype = <value-of select="$parentName"/>; + return new <value-of select="$constructorFunctionName"/>(); + })(); + + </template> + <template name="genStatesEnum"> + <param name="states"/> + + this._states = { + <for-each select="$states"><value-of select="@id"/> : <value-of select="@id"/><if test="not(position() = last())">,</if></for-each> + } + + </template> + <template match="s:if"> + if (<value-of select="@cond"/>) { + <apply-templates select="c:executableContent/*"/> + } + <apply-templates select="s:elseif"/><apply-templates select="s:else"/></template> + <template match="s:elseif"> + else if (<value-of select="@cond"/>) { + <apply-templates select="c:executableContent/*"/> + } + </template> + <template match="s:else"> + else { + <apply-templates select="c:executableContent/*"/> + } + </template> + <template match="s:log"> + <if test="@label"> + console.log( ' <value-of select="@label"/> : ' ); + </if> + <if test="@expr"> + console.log( <value-of select="@expr"/> ); + + </if> + </template> + <template match="s:raise"> + <!--TODO--> + </template> + <template match="s:script"> + <value-of select="."/> + </template> + <template match="s:cancel"> + <!--TODO--> + </template> + <template match="s:invoke"> + <!--TODO--> + </template> + <template match="s:finalize"> + <!--TODO--> + </template> + <template match="s:datamodel"> + <!--TODO--> + </template> + <template match="s:data"> + <!--TODO--> + </template> + <template match="s:assign"> + <!--TODO--> + </template> + <template match="s:validate"> + <!--TODO--> + </template> + <template match="s:param"> + <!--TODO--> + </template> + <template name="genInternalRuntimeFunctions"> + function sortByDepthDeepToShallow(a,b){ + return b.depth - a.depth; + } + </template> + <template name="genBoilerplateDispatchCode"> + //static private member variables + var currentConfiguration = []; //current configuration + var innerEventQueue = []; //inner event queue + var outerEventQueue = []; //outer event queue + var isInStableState = true; + var isPreempted = false; + var hasTakenDefaultTransition = false; + var destroyed = false; + var mainLoopCallback = null; + + //static private member functions + function mainLoop() { + + if(!destroyed){ + //take an event from the current outer event queue + if (outerEventQueue.length && isInStableState) { + runToCompletion(outerEventQueue.shift()); + } + //call back + mainLoopCallback = window.setTimeout(function() { + mainLoop(); //FIXME: note that when calling mainloop this way, we won't have access to the "this" object. + //I don't think we ever use it though. Everything we need is private in function scope. + }, + 100); + } + } + + function runToCompletion(e){ + isInStableState = false; + + if(e){ + innerEventQueue.push(e); + } + + do{ + //take any available default transitions + microstep(<value-of select="$defaultEventLiteral"/>); + + if(!hasTakenDefaultTransition){ + + if(!innerEventQueue.length){ + //we have no more generated events, and no default transitions fired, so + //we are done, and have run to completion + break; + }else{ + //microstep, then dequeue next event sending in event + microstep(innerEventQueue.shift()); + } + }else{ + //he has taken a default transition, so reset the global variable to false and loop again + hasTakenDefaultTransition = false; + } + + }while(true) + + isInStableState = true; + } + + function microstep(e){ + currentConfiguration.forEach(function(state){ + if(!isPreempted) + <value-of select="$dispatchInvocation"/> + }); + + //reset the isPreempted flag + isPreempted = false; + } + + + this.destroy = function(){ + //right now, this only disables timer and sets global destroyed variable to prevent future callbacks + window.clearTimeout(mainLoopCallback); + mainLoopCallback = null; + destroyed = true; + } + + + //this is for async communication + this.GEN = function(e){ + outerEventQueue.push(e); + } + + //this may or may not be something we want to expose, but for right now, we at least need it for testing + this.getCurrentConfiguration = function(){ + //slice it to return a copy of the configuration rather than the conf itself + //this saves us all kinds of confusion involving references and stuff + return <value-of select="$currentConfigurationExpression"/>; + } + + //end static boilerplate code + </template> + <variable name="deepHistoryEnterAction"> + <text> + var topState; + while(topState = statesEntered.pop()){ + topState.enterAction(); + } + </text> + </variable> + <variable name="shallowHistoryEnterAction"> + <text> + var topState = statesEntered.pop(); + + topState.enterAction(); + + newConfiguration.push(topState.initial ? topState.initial : topState ); + </text> + </variable> + <variable name="genNonBasicTriggerDispatcherExitBlockInnerForEach"> + <text> + do{ + statesExited.push(state); + }while((state = state.parent) && + state != lca && + statesExited.indexOf(state) == -1) + </text> + </variable> + <template name="genHistoryTriggerDispatcher"> + <param name="s"/> + <param name="t"/> + <variable name="isDeep" select="$s/@type = 'deep'"/> + <variable name="historyStateReference"> + <call-template name="genHistoryTriggerDispatcherHistoryStateReference"> + <with-param name="s" select="$s"/> + </call-template> + </variable> + + + //history state semantics + if(<value-of select="$historyStateReference"/>.lastConfiguration){ + + //transition action + <if test="$log"><choose><when test="$isDeep"> + console.log("return to last deep configuration"); + </when><otherwise> + console.log("return to last shallow configuration"); + </otherwise></choose></if> + + + <!--gen executable content for t--> + <apply-templates select="$t/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/> + + + + var historyState = <value-of select="$historyStateReference"/>; + + <if test="not($isDeep)"> + var newConfiguration = []; + </if><value-of select="$historyStateReference"/>.lastConfiguration.forEach(function(state){ + <call-template name="genHistoryTriggerDispatcherInnerForEach"><with-param name="isDeep" select="$isDeep"/></call-template> + }); + + <choose><when test="$isDeep"> + currentConfiguration = <value-of select="$historyStateReference"/>.lastConfiguration.slice(); + </when><otherwise> + currentConfiguration = <value-of select="$genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS"/>; + </otherwise></choose> + + }else{ + <call-template name="genTriggerDispatcherContents"><with-param name="s" select="$s"/><with-param name="t" select="$t"/></call-template> + } + </template> + <template name="genHistoryTriggerDispatcherInnerForEach"> + <param name="isDeep"/> + + var statesEntered = [<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>]; + + for(var parent = <value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.parent; + parent != historyState.parent && parent != null; + parent = parent.parent){ + statesEntered.push(parent); + } + + + <choose><when test="$isDeep"><value-of select="$deepHistoryEnterAction"/></when><otherwise><value-of select="$shallowHistoryEnterAction"/></otherwise></choose></template> + <template name="genNonBasicTriggerDispatcherExitBlock"> + <param name="t"/> + + var statesExited = []; + var lca = <value-of select="$t/c:lca"/>; + + <value-of select="$genNonBasicTriggerDispatcherExitBlockIteratorExpression"/>.forEach(function(state){ + <value-of select="$genNonBasicTriggerDispatcherExitBlockInnerForEach"/> + }); + + //sort by depth + statesExited.sort(sortByDepthDeepToShallow); + + //execute actions for each of these states + statesExited.forEach(function(state){ + state.exitAction(); + }); + </template> + <template name="genTriggerDispatcherContents"> + <param name="s"/> + <param name="t"/> + <if test="not($t/@event)"> + hasTakenDefaultTransition = true; + </if> + + //exit states + <choose><when test="local-name($s) = 'initial' or local-name($s) = 'history' or ( $s/@c:isBasic and ( not($s/@c:isParallelSubstate) or ($s/@c:isParallelSubstate and not($t/@c:exitsParallelRegion))))"><for-each select="$t/c:exitpath/c:state"><value-of select="."/>.exitAction(); + </for-each></when><otherwise><call-template name="genNonBasicTriggerDispatcherExitBlock"><with-param name="t" select="$t"/></call-template></otherwise></choose> + + //transition action + <apply-templates select="$t/*[self::s:if or self::s:raise or self::s:log or self::s:script or self::s:send or self::s:cancel or self::s:invoke or self::s:finalize or self::s:datamodel or self::s:data or self::s:assign or self::s:validate or self::s:param]"/> + + //enter states + <for-each select="$t/c:targets/c:target/c:enterpath/c:state"> + <!-- iterate in reverse order --> + <sort data-type="number" order="descending" select="position()"/><value-of select="."/>.enterAction(); + </for-each> + + //update configuration + <choose><when test="$s/@c:isParallelSubstate and not($t/@c:exitsParallelRegion)"><call-template name="genParallelSubstateConfigurationSetString"><with-param name="s" select="$s"/><with-param name="t" select="$t"/></call-template></when><otherwise><call-template name="genNonParallelSubstateConfigurationSetString"><with-param name="s" select="$s"/><with-param name="t" select="$t"/></call-template></otherwise></choose> + + + //set whether preempted + <if test="$t/@c:isPreempted"> + isPreempted = true; + </if></template> + <template name="genNoForEachArrayPrototypeExtension"> + if(!Array.forEach){ + Array.prototype.forEach = function(fn){ + for(var i=0; i < this.length; i++){ + fn(this[i]); + } + return undefined; + } + } + </template> + <template name="genNoIndexOfArrayPrototypeExtension"> + if(!Array.indexOf){ + Array.prototype.indexOf = function(obj){ + for(var i=0; i < 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 < this.length; i++){ + toReturn[i]=fn(this[i]); + } + return toReturn; + } + } + </template> + <template name="genContextHooks"/> + <!-- these params get overridden by subclasses --> + <param name="dispatchInvocation" select="'state[e]();'"/> + <param name="defaultEventLiteral" select="'"$default"'"/> + <param name="currentConfigurationExpression" select="'currentConfiguration.slice()'"/> + <param name="genHistoryTriggerDispatcherCurrentConfigurationAssignmentRHS" select="'newConfiguration'"/> + <param name="genHistoryTriggerDispatcherInnerForEachStateReference" select="'state'"/> + <param name="genNonBasicTriggerDispatcherExitBlockIteratorExpression" select="'currentConfiguration'"/> + <template name="genStateHooks"> + <param name="state"/> + <for-each select="$state/s:transition"> + <call-template name="genTriggerDispatcherContext"> + <with-param name="s" select="$state"/> + <with-param name="t" select="."/> + </call-template> + </for-each> + </template> + <template name="genExternalTriggerDispatcher"> + <param name="event"/> + + this.<value-of select="$event/c:name"/> = function(){ + if(isInStableState){ + runToCompletion("<value-of select="$event/c:name"/>"); + }else{ + return undefined; + } + } + </template> + <template name="genParallelSubstateConfigurationSetString"> + <param name="s"/> + <param name="t"/> + + currentConfiguration.splice(currentConfiguration.indexOf(this),1, + <for-each select="$t/c:targets/c:target/c:targetState"><value-of select="."/><if test="not(position() = last())">,</if></for-each> + ); + </template> + <template name="genNonParallelSubstateConfigurationSetString"> + <param name="t"/> + <param name="s"/> + + currentConfiguration = [ + <for-each select="$t/c:targets/c:target/c:targetState"><value-of select="."/><if test="not(position() = last())">,</if></for-each> + ]; + </template> + <template name="genInitialization"> + <variable name="initialStateName"> + <value-of select="/s:scxml/s:initial/s:transition/c:targets/c:target/c:targetState"/> + </variable> + + this.initialize = function(){ + currentConfiguration = [<value-of select="$initialStateName"/>]; + runToCompletion(); + mainLoop(); + } + + </template> + <template name="genTriggerDispatcherContext"> + <param name="s"/> + <param name="t"/> + <variable name="eventName"> + <choose> + <when test="$t/@event"> + <value-of select="$t/@event"/> + </when> + <otherwise> + <value-of select="'$default'"/> + </otherwise> + </choose> + </variable> + + this.<value-of select="$eventName"/> = function(){ + <choose><when test="local-name($s) = 'history'"><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="genHistoryTriggerDispatcherHistoryStateReference"> + <param name="s"/> + <text>this</text> + </template> + <template match="s:send"> + <choose> + <when test="@delay"> + window.setTimeout(function(){ + self.GEN("<value-of select="@event"/>"); + },<value-of select="number(@delay)*1000"/>); + </when> + <otherwise> + innerEventQueue.push("<value-of select="@event"/>"); + </otherwise> + </choose> + </template> +</stylesheet> Propchange: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/xslt/backends/js/StatePatternStatechartGenerator_combined.xsl ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/SCXMLCompiler.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/SCXMLCompiler.js?rev=955120&r1=955119&r2=955120&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/SCXMLCompiler.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/SCXMLCompiler.js Wed Jun 16 03:20:05 2010 @@ -8,6 +8,38 @@ require.def( KitchenSink, StatePatternStatechartGenerator ){ + //some compatibility stuff for IE + //TODO: move out into another file + if (!Array.indexOf) { + Array.prototype.indexOf = function(obj) { + for (var i = 0; i < this.length; i++) { + if (this[i] == obj) { + return i; + } + } + return -1; + } + } + + if (!Array.map) { + Array.prototype.map = function(fn) { + var toReturn = []; + for (var i = 0; i < this.length; i++) { + toReturn[i] = fn(this[i]); + } + return toReturn; + } + } + + if (!Array.forEach) { + Array.prototype.forEach = function(fn) { + for (var i = 0; i < this.length; i++) { + fn(this[i]); + } + return undefined; + } + } + var sourceDocument = KitchenSink; var transforms = StatePatternStatechartGenerator.transformations; @@ -19,8 +51,13 @@ require.def( } function xmlToString(d){ - var s = new XMLSerializer(); - var str = s.serializeToString(d); + var str; + if(window.XMLSerializer){ + var s = new XMLSerializer(); + str = s.serializeToString(d); + }else{ + str = d.xml; + } return str; } @@ -31,38 +68,60 @@ require.def( return { compile : function(options){ - var processors = transforms.map(getProcessorFromStylesheetDocument); - - //transform to IR var docToTransform = sourceDocument; - processors.forEach(function(p){ - docToTransform = p.transformToDocument(docToTransform); - }); - - //print IR - //console.log(xmlToString(docToTransform)); - - //transform to js - var statePatternStatechartGeneratorProcessor = - getProcessorFromStylesheetDocument(StatePatternStatechartGenerator.code); + + var transformedJs; + if(window.ActiveXObject){ + //IE + + //transform to IR + transforms.forEach(function(t){ + var txt = docToTransform.transformNode(t); + + //TODO:can reuse same doc? + xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); + xmlDoc.async="false"; + xmlDoc.loadXML(txt); - //set parameters - for(optName in options){ - statePatternStatechartGeneratorProcessor.setParameter(null,optName,options[optName]); - } + docToTransform = xmlDoc; + }); - docToTransform = statePatternStatechartGeneratorProcessor.transformToDocument(docToTransform); - - //console.log(xmlToString(docToTransform)); - //console.log(getResultTextFromDoc(docToTransform)); + //transform to js + //TODO:set parameters + transformedJs = docToTransform.transformNode(StatePatternStatechartGenerator.code); + }else{ + //everything else + + //transform to IR + var processors = transforms.map(getProcessorFromStylesheetDocument); + + processors.forEach(function(p){ + docToTransform = p.transformToDocument(docToTransform); + }); + + //transform to js + var statePatternStatechartGeneratorProcessor = + getProcessorFromStylesheetDocument(StatePatternStatechartGenerator.code); + + //set parameters + for(optName in options){ + statePatternStatechartGeneratorProcessor.setParameter(null,optName,options[optName]); + } - var transformedJs = getResultTextFromDoc(docToTransform); + docToTransform = statePatternStatechartGeneratorProcessor.transformToDocument(docToTransform); + transformedJs = getResultTextFromDoc(docToTransform); + } + + + //optionally beautify it if(options.beautify){ transformedJs = js_beautify(transformedJs); } + console.log(transformedJs); + return transformedJs; } }