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