rbpm 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,147 @@
1
+ GNU Lesser General Public License
2
+
3
+ Version 2.1, February 1999
4
+
5
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
6
+
7
+ [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.]
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
12
+
13
+ This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
14
+
15
+ When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
16
+
17
+ To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
18
+
19
+ For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
20
+
21
+ We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
22
+
23
+ To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
24
+
25
+ Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
26
+
27
+ Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
28
+
29
+ When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
30
+
31
+ We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
32
+
33
+ For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
34
+
35
+ In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
36
+
37
+ Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
38
+
39
+ The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
40
+
41
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
42
+
43
+ 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
44
+
45
+ A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
46
+
47
+ The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
48
+
49
+ "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
50
+
51
+ Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
52
+
53
+ 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
54
+
55
+ You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
56
+
57
+ 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
58
+
59
+ a) The modified work must itself be a software library.
60
+
61
+ b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
62
+
63
+ c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
64
+
65
+ d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
66
+
67
+ (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
68
+
69
+ These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
70
+
71
+ Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
72
+
73
+ In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
74
+
75
+ 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
76
+
77
+ Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
78
+
79
+ This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
80
+
81
+ 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
82
+
83
+ If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
84
+
85
+ 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
86
+
87
+ However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
88
+
89
+ When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
90
+
91
+ If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
92
+
93
+ Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
94
+
95
+ 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
96
+
97
+ You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
98
+
99
+ a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
100
+
101
+ b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
102
+
103
+ c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
104
+
105
+ d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
106
+
107
+ e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
108
+
109
+ For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
110
+
111
+ It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
112
+
113
+ 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
114
+
115
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
116
+
117
+ b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
118
+
119
+ 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
120
+
121
+ 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
122
+
123
+ 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
124
+
125
+ 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
126
+
127
+ If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
128
+
129
+ It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
130
+
131
+ This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
132
+
133
+ 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
134
+
135
+ 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
136
+
137
+ Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
138
+
139
+ 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
140
+
141
+ NO WARRANTY
142
+
143
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
144
+
145
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
146
+
147
+ END OF TERMS AND CONDITIONS
data/README CHANGED
@@ -1,18 +1,43 @@
1
- what is rBPM?
1
+ = What is rBPM? =
2
2
 
3
3
  rbpm is a (JBoss-)jBPM-like lightweight workflow framework. it helps you to
4
4
  develop asynchronous programs. developers describe their process definitions
5
5
  (workflows) using extended ruby class definition syntax - no use of xml
6
6
  files is planned.
7
7
 
8
- license terms?
8
+ = License terms? =
9
9
 
10
10
  LGPL
11
11
 
12
- author?
12
+ = Author? =
13
13
 
14
14
  (c) 2005 by Christian Tschenett
15
15
 
16
- getting startet...
16
+ = Getting started... =
17
+
18
+ 1st step:
19
+ gem install rbpm
20
+ #...Successfully installed rbpm-0.0.x... :-)
21
+
22
+ 2nd step:
23
+ download hello_world.rb and rbpm_tutorial.rb (rbpm project: files tab)
24
+
25
+ 3rd step:
26
+ ruby hello_world.rb
27
+ ruby rbpm_tutorial.rb
28
+
29
+ 4th step:
30
+ open the demo sources in a text file exitor and study these very simple workflows
31
+
32
+ 5th step:
33
+ visit the rbpm project's wiki (no more doco yet)
34
+
35
+ 6th step:
36
+ browse the svn repository. workflow instance persistence is on the way.... and more important: there are a lot of unit test cases and a few more complex (realistic) workflows. unit test are better than doco (imho).
37
+
38
+ but keep in mind that rbpm is pre-alpha in the moment. and the rails demo - unfortunately - is somewhat out of date (uses rbpm 0.0.1).
39
+
40
+ last bot not least: if you wanna get familiar with graph oriented programming the jboss jbpm docos are worth reading.
41
+
42
+ hope it helps :)
17
43
 
18
- take a look at the unit tests
@@ -0,0 +1,6 @@
1
+ if [ -f ../lib/rbpm/persistence2_standalone.rb ]
2
+ then
3
+ ruby -r $1 ../lib/rbpm/persistence2_standalone.rb signal $2
4
+ else
5
+ ruby -r $1 -e "require 'rubygems' ; require_gem 'rbpm' ; require 'rbpm/persistence2_standalone'" signal $2
6
+ fi
@@ -0,0 +1,6 @@
1
+ if [ -f ../lib/rbpm/persistence2_standalone.rb ]
2
+ then
3
+ ruby -r $1 ../lib/rbpm/persistence2_standalone.rb create $2
4
+ else
5
+ ruby -r $1 -e "require 'rubygems' ; require_gem 'rbpm' ; require 'rbpm/persistence2_standalone'" create $2
6
+ fi
@@ -1,4 +1,5 @@
1
- [ok] workflow instance persistence
1
+ [~ok] workflow instance persistence (filesystem based)
2
+ [pending] workflow instance persistence (RDBMS based)
2
3
  [ok] states
3
4
  [ok] context variables
4
5
  [ok] versioning
@@ -11,7 +12,9 @@
11
12
  [later] rpbm server java/web service interface
12
13
  [ok] workflow support for exception handling
13
14
  [later] tasks, roles and swimlanes
14
- [pending] throw away prototype and re-implement *
15
- [pending] improve test infrastructure (tests must be runnable from IDE, using rake, using gem installer)
15
+ [later] throw away prototype and re-implement *
16
+ [ok] improve test infrastructure (tests must be runnable from IDE, using rake, using gem installer)
16
17
  [pending] workflow validation
17
- [pending] persistence
18
+ [pending] timer, scheduler: timed token signaling
19
+ [pending] cleanup mess after persistence introduction :)
20
+ [pending] real concurrent workflow execution (threads, processes)
@@ -1,598 +1,24 @@
1
- module Rbpm
2
- class WorkflowVersionManager
3
- def self.find_workflow_versions(workflow_name)
4
- versions = []
5
- ObjectSpace.each_object(Module) do |m|
6
- module_name = m.to_s
7
- if module_name =~ /#{workflow_name}Version([0-9]+)$/
8
- versions << $1.to_i
9
- end
10
- end
11
- versions
12
- end
13
-
14
- def self.create_workflow_instance(workflow_name, version = :latest)
15
- workflow_name = workflow_name.to_s if workflow_name.is_a? Symbol
16
- if :latest == version
17
- versions = find_workflow_versions(workflow_name)
18
- if versions.empty?
19
- #fallback to non-versionned wf
20
- return eval("#{workflow_name}.new")
21
- else
22
- version = versions.max
23
- end
24
- end
25
- return eval("#{workflow_name}Version#{version}::#{workflow_name}.new")
26
- end
27
- end
28
-
29
- class Workflow
30
-
31
- ##WORKFLOW METADATA
32
-
33
- #@@meta will be a class attribute of a concrete Workflow
34
- def self.init_meta
35
- module_eval <<-end_eval
36
- unless defined? @@meta
37
- @@meta = {}
38
- def self.meta
39
- @@meta
40
- end
41
- end
42
- end_eval
43
- end
44
-
45
- #insert generic node helper...
46
-
47
- def self.node(node_sym, options = {})
48
- self.init_meta
49
- self.nodes[node_sym] = {} unless self.nodes[node_sym]
50
- options.each do |key,value|
51
- case key.to_s
52
- when /(.*)_trans$|trans$/
53
- trans = $1.nil? ? "default" : $1
54
- transition(node_sym, trans.to_sym, value)
55
- when /(.*)_trans_action$|trans_action$/
56
- trans = $1.nil? ? "default" : $1
57
- transition_action(node_sym, trans.to_sym, value)
58
- when /(.*)_trans_cond$|trans_cond$/
59
- trans = $1.nil? ? "default" : $1
60
- transition_condition(node_sym, trans.to_sym, value)
61
- when "exception"
62
- exception_transition(node_sym, value)
63
- when "action"
64
- node_action(node_sym, value)
65
- when "on_enter"
66
- node_enter_action(node_sym, value)
67
- when "on_leave"
68
- node_leave_action(node_sym, value)
69
- when "action_singleton"
70
- node_action_singleton(node_sym, value)
71
- end
72
- end
73
- end
74
-
75
- #insert special nodes helpers...
76
-
77
- def self.start_node(node_sym, options = {})
78
- node(node_sym, options)
79
- nodes[node_sym][:start] = true
80
- end
81
-
82
- def self.end_node(node_sym, options = {})
83
- node(node_sym, options)
84
- nodes[node_sym][:end] = true
85
- end
86
-
87
- def self.state_node(node_sym, options = {})
88
- node(node_sym, options)
89
- nodes[node_sym][:state] = true
90
- end
91
-
92
- def self.join_node(node_sym, options = {})
93
- options[:action_singleton] = JoinNode.new
94
- node(node_sym, options)
95
- end
96
-
97
- def self.fork_node(node_sym, options = {})
98
- options[:action_singleton] = ForkNode.new(options[:children_ctx])
99
- node(node_sym, options)
100
- end
101
-
102
- def self.call_node(node_sym, options = {})
103
- options[:action_singleton] = CallNode.new(options[:workflow], options[:workflow_version], options[:call_in], options[:call_out])
104
- node(node_sym, options)
105
- end
106
-
107
- #insert node action helpers...
108
-
109
- def self.enter(node_sym, &blk)
110
- node_enter_action(node_sym, blk)
111
- end
112
-
113
- def self.node_enter_action(node_sym, action)
114
- nodes[node_sym][:on_enter] = action
115
- end
116
-
117
- def self.action(node_sym, &blk)
118
- node_action(node_sym, blk)
119
- end
120
-
121
- def self.node_action(node_sym, action)
122
- nodes[node_sym][:action] = action
123
- end
124
-
125
- def self.leave(node_sym, &blk)
126
- node_leave_action(node_sym, blk)
127
- end
128
-
129
- def self.node_leave_action(node_sym, action)
130
- nodes[node_sym][:on_leave] = action
131
- end
132
-
133
- def self.node_action_singleton(node_sym, instance)
134
- nodes[node_sym][:action_singleton] = instance
135
- end
136
-
137
- #insert transition, transition action and transition condition helpers...
138
-
139
- def self.transition(node_from_sym, trans_sym, node_to_sym)
140
- transitions(node_from_sym)[trans_sym] = node_to_sym
141
- end
142
-
143
- def self.transition_action(node_from_sym, trans_sym, action)
144
- transition_actions(node_from_sym)[trans_sym] = action
145
- end
146
-
147
- def self.transit(node_from_sym, trans_sym, &blk)
148
- transition_action(node_from_sym, trans_sym, blk)
149
- end
150
-
151
- def self.transition_condition(node_from_sym, trans_sym, condition)
152
- transition_conditions(node_from_sym)[trans_sym] = condition
153
- end
154
-
155
- def self.exception_transition(node_from_sym, node_to_sym)
156
- transition(node_from_sym, :exception, node_to_sym)
157
- transition_condition(node_from_sym, :exception, "false") #only executed if "hardcoded" signalled
158
- end
159
-
160
- #metadata access helpers...
161
-
162
- def self.nodes
163
- meta[:nodes] = {} unless meta[:nodes]
164
- meta[:nodes]
165
- end
166
-
167
- def self.node_option_values(node, option)
168
- nodes[node][option] = {} unless nodes[node][option]
169
- nodes[node][option]
170
- end
171
-
172
- def self.transitions(node)
173
- node_option_values(node, :transitions)
174
- end
175
-
176
- def self.transition_actions(node)
177
- node_option_values(node, :transition_actions)
178
- end
179
-
180
- def self.transition_conditions(node)
181
- node_option_values(node, :transition_conditions)
182
- end
183
-
184
- def self.find_first_node_with_option(option)
185
- nodes.each do |node,options|
186
- return node if options[option]
187
- end
188
- nil
189
- end
190
-
191
- def self.find_nodes_with_option(option)
192
- found = nodes.collect do |node,options|
193
- options[option] ? node : nil
194
- end
195
- found.compact
196
- end
197
-
198
- def self.find_node_with_name(name)
199
- nodes[name.to_sym]
200
- end
201
-
202
- def self.find_start_node
203
- find_first_node_with_option :start
204
- end
205
-
206
- def self.find_end_nodes
207
- find_nodes_with_option :end
208
- end
209
-
210
- def self.end_node?(node)
211
- nodes[node][:end]
212
- end
213
-
214
- @@next_token_id = 1
215
-
216
- def self.generate_token_id
217
- @@next_token_id += 1
218
- end
219
-
220
- ##WORKFLOW INSTANCE
221
-
222
- attr_writer :token_id_generator
223
- attr_reader :tokens, :result, :token_id_generator
224
-
225
- def initialize
226
- @tokens = []
227
- @result = nil
228
- end
229
-
230
- def clazz
231
- self.class
232
- end
233
-
234
- #token management...
235
-
236
- def generate_token_id
237
- if token_id_generator
238
- token_id_generator.generate_token_id
239
- else
240
- clazz.generate_token_id
241
- end
242
- end
243
-
244
- def create_root_token(ctx_vars = {})
245
- create_token(nil, ctx_vars)
246
- end
247
-
248
- def create_token(parent = nil, ctx_vars = {})
249
- token = Token.new(self, parent, ctx_vars, generate_token_id)
250
- @tokens << token
251
- token
252
- end
253
-
254
- def token_done(token)
255
- unless token.parent
256
- @result = token.all_ctx_vars
257
- end
258
-
259
- @tokens.delete token
260
- end
261
-
262
- def find_root_token
263
- @tokens.each do |token|
264
- return token unless token.parent
265
- end
266
- nil?
267
- end
268
-
269
- def [](key)
270
- if @result
271
- @result[key]
272
- else
273
- find_root_token[key]
274
- end
275
- end
276
-
277
- #(metadata-driven) reflection helpers...
278
-
279
- def find_method(method_name)
280
- action = method(method_name) if methods.include? method_name
281
-
282
- unless action
283
- action = clazz.method(method_name) if clazz.methods.include? method_name
284
- end
285
-
286
- action
287
- end
288
-
289
- def find_node_event_action(node, default_method_suffix, action_option)
290
- default_method_name = "#{node.to_s}#{default_method_suffix}"
291
-
292
- action_singleton = clazz.nodes[node][:action_singleton]
293
- action = action_singleton.method(action_option) if action_singleton && action_singleton.methods.include?(action_option.to_s)
294
-
295
- unless action
296
- action = find_method(default_method_name)
297
- end
298
-
299
- unless action
300
- action_or_name = clazz.nodes[node][action_option]
301
-
302
- if action_or_name.is_a? Symbol
303
- action_name = action_or_name.to_s
304
- action = find_method(action_name)
305
-
306
- raise "unknown custom action #{action_name}" unless action
307
- else
308
- action = action_or_name
309
- end
310
- end
311
-
312
- action
313
- end
314
-
315
- def find_enter_action(node)
316
- find_node_event_action(node, "_on_enter", :on_enter)
317
- end
318
-
319
- def find_leave_action(node)
320
- find_node_event_action(node, "_on_leave", :on_leave)
321
- end
322
-
323
- def find_node_action(node)
324
- find_node_event_action(node, "_action", :action)
325
- end
326
-
327
- def find_transit_action(node, transition)
328
- default_method_name = "#{node.to_s}_#{transition.to_s}_trans_action"
329
- action = find_method(default_method_name)
330
-
331
- unless action
332
- action_or_name = clazz.transition_actions(node)[transition]
333
-
334
- if action_or_name.is_a? Symbol
335
- action_name = action_or_name.to_s
336
- action = find_method(action_name)
337
-
338
- raise "unknown custom action #{action_name}" unless action
339
- else
340
- action = action_or_name
341
- end
342
- end
343
-
344
- action
345
- end
346
-
347
- def find_transit_target(node, transition)
348
- clazz.transitions(node)[transition]
349
- end
350
-
351
- #flow management...
352
-
353
- def start(ctx_vars = {})
354
- token = create_root_token(ctx_vars)
355
- token.enter(clazz.find_start_node)
356
- token
357
- end
358
-
359
- def call_event_action(action, token, node)
360
- begin
361
- action.call(token, node)
362
- rescue Exception => exception
363
- if clazz.transitions(node)[:exception]
364
- token[:exception] = exception
365
- return :exception
366
- else
367
- raise
368
- end
369
- end
370
- return nil
371
- end
372
-
373
- def enter_node(token, node)
374
- token.entered(node)
375
-
376
- hardcoded_transition = call_event_action(find_enter_action(node), token, node) if find_enter_action(node)
377
-
378
- if hardcoded_transition || (not (clazz.end_node?(node) || clazz.nodes[node][:state]))
379
- signal_node(token, node, hardcoded_transition)
380
- end
381
- end
382
-
383
- def signal_node(token, node, hardcoded_transition = nil)
384
- if hardcoded_transition
385
- transitions = [[hardcoded_transition, token]]
386
- elsif find_node_action(node)
387
- transitions = find_node_action(node).call(token, node)
388
- else
389
- clazz.transitions(node).each do |transition,target|
390
- if (clazz.transition_conditions(node)[transition].nil? || token.eval_expr(clazz.transition_conditions(node)[transition]))
391
- transitions = [[transition, token]]
392
- break
393
- end
394
- end
395
- end
396
-
397
- if not clazz.nodes[node][:end] and transitions
398
- transitions.each do |transition_token|
399
- transition,token = transition_token
400
- token.transit(transition)
401
- end
402
- end
403
- end
404
-
405
- def leave_node(token, node)
406
- call_event_action(find_leave_action(node), token, node) if find_leave_action(node)
407
- end
408
-
409
- def transit(token, node, transition)
410
- hardcoded_transition = call_event_action(find_transit_action(node, transition), token, node) if find_transit_action(node, transition)
411
-
412
- if hardcoded_transition
413
- enter_node(token, find_transit_target(node, hardcoded_transition))
414
- else
415
- enter_node(token, find_transit_target(node, transition))
416
- end
417
- end
418
- end
419
-
420
- class Token
421
-
422
- attr_writer :sub_process, :parent_process
423
- attr_reader :workflow, :node, :parent, :sub_process, :parent_process, :ref
424
-
425
- def initialize(workflow, parent = nil, ctx_vars = {}, ref = -1)
426
- @workflow = workflow
427
- @parent = parent
428
- @ctx_vars = ctx_vars
429
- @ref = ref
430
- @childs = []
431
- @sub_process = nil
432
- @parent_process = nil
433
- @done = false
434
- if parent
435
- @node = parent.node
436
- @parent.add_child(self)
437
- else
438
- @node = nil
439
- end
440
- end
441
-
442
- def all_ctx_vars
443
- @ctx_vars
444
- end
445
-
446
- #transition condition expressions are evaluated using token's binding()
447
- #and this method is here to support expressions like "token[:var_name] == ..."
448
- def token
449
- self
450
- end
451
-
452
- def []=(key, value)
453
- @ctx_vars[key] = value
454
- end
455
-
456
- def [](key)
457
- @ctx_vars[key]
458
- end
459
-
460
- def add_child(token)
461
- @childs << token
462
- end
463
-
464
- def remove_child(token)
465
- @childs.delete(token)
466
- end
467
-
468
- def childs?
469
- not @childs.empty?
470
- end
471
-
472
- def signal
473
- @workflow.signal_node(self, node)
474
-
475
- if end? && @parent_process
476
- @parent_process.signal
477
- @parent_process = nil
478
- end
479
- end
480
-
481
- def enter(node)
482
- @workflow.enter_node(self, node)
483
- end
484
-
485
- def entered(node)
486
- @node = node
487
-
488
- if @workflow.clazz.end_node?(@node) and not @parent
489
- @workflow.token_done(self)
490
- end
491
- end
492
-
493
- def transit(transition)
494
- hardcoded_transition = @workflow.leave_node(self, @node)
495
- if hardcoded_transition
496
- @workflow.transit(self, @node, hardcoded_transition)
497
- else
498
- @workflow.transit(self, @node, transition)
499
- end
500
- end
501
-
502
- def jump(child)
503
- @node = child.node
504
- end
505
-
506
- def done
507
- @parent.remove_child(self) if @parent
508
- @parent.jump(self) if @parent
509
- @workflow.token_done(self)
510
- @done = true
511
- end
512
-
513
- def end?
514
- @done || @workflow.clazz.end_node?(@node)
515
- end
516
-
517
- def fork(ctx_vars = {})
518
- @workflow.create_token(self, ctx_vars)
519
- end
520
-
521
- def eval_expr(expr)
522
- eval(expr, binding())
523
- end
524
- end
525
-
526
- class ForkNode
527
- def initialize(children_ctx_var)
528
- @children_ctx_var = children_ctx_var
529
- end
530
-
531
- def action(token, caller)
532
- exits = []
533
- token[@children_ctx_var].each do |ctx_vars|
534
- exits << [:default, token.fork(ctx_vars)]
535
- end
536
- return exits
537
- end
538
- end
539
-
540
- class JoinNode
541
- def action(token, caller)
542
- parent_token = token.parent
543
- token.done
544
- parent_token.childs? ? nil : [[:default, parent_token]]
545
- end
546
- end
547
-
548
- class CallNode
549
- def initialize(workflow, workflow_version, call_in, call_out)
550
- @workflow = workflow
551
- @workflow_version = workflow_version
552
- @call_in = call_in
553
- @call_out = call_out
554
- end
555
-
556
- def action(token, caller)
557
- if token.sub_process
558
- #sub process has been finished...
559
-
560
- @call_out.each do |remote,local|
561
- token[local] = token.sub_process[remote]
562
- end
563
-
564
- token.sub_process = nil
565
-
566
- return [[:default, token]]
567
- else
568
- #let's start a sub process...
569
-
570
- if (@workflow.is_a? Symbol)
571
- sub_wf = WorkflowVersionManager.create_workflow_instance(@workflow, @workflow_version.nil? ? :latest : @workflow_version)
572
- else
573
- sub_wf = @workflow.new
574
- end
575
-
576
- params = {}
577
- @call_in.each do |local,remote|
578
- params[remote] = token[local]
579
- end
580
-
581
- sub_t = sub_wf.start(params)
582
-
583
- if (sub_t.end?)
584
- @call_out.each do |remote,local|
585
- token[local] = sub_t[remote]
586
- end
587
-
588
- return [[:default, token]]
589
- else
590
- sub_t.parent_process = token
591
- token.sub_process = sub_t
592
-
593
- return nil #stop wf execution... we'll be called later...
594
- end
595
- end
596
- end
597
- end
598
- end
1
+ #---------------------------------------------------------------------------------------------------------------------------------
2
+ #
3
+ # rbpm lightweight workflows, copyright (c) 2005 Christian Tschenett <furthermore@nospam@tschenett.ch>
4
+ #
5
+ # This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
6
+ # as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
7
+ # This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8
+ # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
9
+ # You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the
10
+ # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11
+ #
12
+ #---------------------------------------------------------------------------------------------------------------------------------
13
+
14
+ $RBPM_LIB_DIR = __FILE__[0 .. __FILE__.length - "/rbpm.rb".length - 1]
15
+ $LOAD_PATH << $RBPM_LIB_DIR unless $LOAD_PATH.include? $RBPM_LIB_DIR
16
+
17
+ #puts "adjusted $LOAD_PATH = #{$LOAD_PATH.join(', ')}" #TODO remove DEBUG code
18
+
19
+ require 'rbpm/workflow_managment'
20
+ require 'rbpm/workflow'
21
+ require 'rbpm/token'
22
+ require 'rbpm/nodes'
23
+
24
+ require 'rbpm/persistence2'