| 1 | # |
| 2 | #-- |
| 3 | # Copyright (c) 2008, John Mettraux, OpenWFE.org |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are met: |
| 8 | # |
| 9 | # . Redistributions of source code must retain the above copyright notice, this |
| 10 | # list of conditions and the following disclaimer. |
| 11 | # |
| 12 | # . Redistributions in binary form must reproduce the above copyright notice, |
| 13 | # this list of conditions and the following disclaimer in the documentation |
| 14 | # and/or other materials provided with the distribution. |
| 15 | # |
| 16 | # . Neither the name of the "OpenWFE" nor the names of its contributors may be |
| 17 | # used to endorse or promote products derived from this software without |
| 18 | # specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 24 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | # POSSIBILITY OF SUCH DAMAGE. |
| 31 | #++ |
| 32 | # |
| 33 | |
| 34 | # |
| 35 | # "made in Japan" |
| 36 | # |
| 37 | # John Mettraux at openwfe.org |
| 38 | # |
| 39 | |
| 40 | module OpenWFE |
| 41 | |
| 42 | # |
| 43 | # This module gets included into the result of the expression pool (and |
| 44 | # engine) process_stack method (if the optional parameter 'unapplied' is |
| 45 | # set to true). |
| 46 | # |
| 47 | # It adds a representation() method that returns an up-to-date |
| 48 | # representation of the executing process instance. |
| 49 | # This representation is suitable for 'fluo' rendering. |
| 50 | # |
| 51 | module RepresentationMixin |
| 52 | |
| 53 | # |
| 54 | # Computes and returns the up-to-date representation of |
| 55 | # the process definition (on the fly changes included) |
| 56 | # |
| 57 | def representation |
| 58 | |
| 59 | root_exp = find_root_expression |
| 60 | |
| 61 | update_rep root_exp |
| 62 | end |
| 63 | |
| 64 | protected |
| 65 | |
| 66 | # |
| 67 | # if a child expression is present (in the process stack) |
| 68 | # makes sure to take its current representation and include |
| 69 | # it in the parent representation. |
| 70 | # |
| 71 | def update_rep (flow_expression) |
| 72 | |
| 73 | rep = flow_expression.raw_representation.dup |
| 74 | children = flow_expression.children |
| 75 | |
| 76 | children.each { |child_fei| |
| 77 | |
| 78 | child_exp = find_expression child_fei |
| 79 | next unless child_exp |
| 80 | |
| 81 | cid = child_fei.child_id.to_i |
| 82 | |
| 83 | rep[2][cid] = update_rep(child_exp) |
| 84 | |
| 85 | } if children and children.size > 0 |
| 86 | |
| 87 | rep |
| 88 | end |
| 89 | |
| 90 | def find_root_expression |
| 91 | |
| 92 | self.find do |fexp| |
| 93 | fexp.fei.expid == "0" && |
| 94 | ( ! fexp.is_a?(OpenWFE::Environment)) && |
| 95 | fexp.fei.is_in_parent_process? |
| 96 | end |
| 97 | end |
| 98 | |
| 99 | def find_expression (fei) |
| 100 | |
| 101 | self.find { |fexp| fexp.fei == fei } |
| 102 | end |
| 103 | end |
| 104 | end |