public
Description: Shade is a state machine (or workflow) engine for ColdFusion business objects.
Homepage:
Clone URL: git://github.com/ryanwood/shade.git
shade / Event.cfc
50b21454 » ryanwood 2008-07-17 Initial Commit part 2 1 <cfcomponent displayname="Event" output="false">
2
3 <cfset instance = structNew() />
4
5 <cffunction name="init" access="public" output="false">
6 <cfargument name="name" type="string" required="true" />
7 <cfargument name="transitionTable" type="struct" required="true" />
8 <cfscript>
9 instance.name = arguments.name;
b336ed32 » ryanwood 2008-07-18 Updated project name to sha... 10 arguments.transitionTable[arguments.name] = createObject("component", "shade.StateTransitionCollection").init();
50b21454 » ryanwood 2008-07-17 Initial Commit part 2 11 instance.transitions = arguments.transitionTable[arguments.name];
12 </cfscript>
13 <cfreturn this />
14 </cffunction>
15
16 <cffunction name="addTransitions" access="public" output="false">
17 <cfargument name="from" type="string" required="true" />
18 <cfargument name="to" type="string" required="true" />
19 <cfargument name="guard" type="string" required="false" default="" />
20 <cfset var local = structNew() />
21
22 <cfloop list="#arguments.from#" index="local.from">
b336ed32 » ryanwood 2008-07-18 Updated project name to sha... 23 <cfset local.transition = createObject("component", "shade.StateTransition").init(local.from, arguments.to, arguments.guard) />
50b21454 » ryanwood 2008-07-17 Initial Commit part 2 24 <cfset instance.transitions.add(local.transition) />
25 </cfloop>
26
27 <cfreturn this />
28 </cffunction>
29
30 <cffunction name="fire" access="public" output="false">
31 <cfargument name="obj" type="any" required="true" />
32 <cfset var i = 1 />
33 <cfset var transitions = instance.transitions.getTransitionsFromState(arguments.obj.getCurrentState()) />
34 <cfset transition = 0 />
35
36 <cfset transitions.reset() />
37 <cfloop condition="transitions.hasNext()">
38 <cfset transition = transitions.next() />
39 <cfif transition.perform(obj)>
94ee712c » ryanwood 2008-07-18 Added License. Changed 'ent... 40 <cfreturn true />
50b21454 » ryanwood 2008-07-17 Initial Commit part 2 41 </cfif>
94ee712c » ryanwood 2008-07-18 Added License. Changed 'ent... 42 </cfloop>
43 <cfreturn false />
50b21454 » ryanwood 2008-07-17 Initial Commit part 2 44 </cffunction>
45
46 <cffunction name="transitions" access="public" output="false">
47 <cfargument name="record" required="true" />
48 </cffunction>
49
50
51 <cffunction name="getName" access="public" returntype="string" output="false">
52 <cfreturn instance.name />
53 </cffunction>
54
55 <cffunction name="getTransitions" access="public" returntype="string" output="false">
56 <cfreturn instance.name />
57 </cffunction>
58
59 </cfcomponent>