def lookup_filter(workitem)

      f = attribute(:filter)

      if f.nil? and workitem

        reply = if t = attribute(:take)
          Array(t).collect { |tt| { 'field' => tt, 'take' => true } }
        elsif d = attribute(:discard)
          if d == true
            [ { 'field' => /.+/, 'discard' => 'all' } ]
          else
            Array(d).collect { |dd| { 'field' => dd, 'discard' => true } }
          end
        else
          nil
        end

        f = { 'reply' => reply } if reply
      end

      return nil unless f
        # no filter

      if f.is_a?(Hash)
        f['in'] = [] unless f['in'] or f['apply']
        f['out'] = [] unless f['out'] or f['reply']
      end
        # empty ins and outs for a sucessful narrowing

      3.times { f = narrow_filter(f, workitem) }

      f or raise ArgumentError.new("found no filter corresponding to '#{f}'")
    end
def lookup_filter(workitem)

      f = attribute(:filter)

      if f.nil? and workitem

        reply = if t = attribute(:take)
          Array(t).collect { |tt| { 'field' => tt, 'take' => true } }
        elsif d = attribute(:discard)
          if d == true
            [ { 'field' => /.+/, 'discard' => 'all' } ]
          else
            Array(d).collect { |dd| { 'field' => dd, 'discard' => true } }
          end
        else
          nil
        end

        f = { 'reply' => reply } if reply
      end

      return nil unless f
        # no filter

      if f.is_a?(Hash)
        f['in'] = [] unless f['in'] or f['apply']
        f['out'] = [] unless f['out'] or f['reply']
      end
        # empty ins and outs for a sucessful narrowing

      3.times { f = narrow_filter(f, workitem) }

      f or raise ArgumentError.new("found no filter corresponding to '#{f}'")
    end
Used by #filter, deals with the various ways to pass filters
 (directly, via a variable, via a participant, in and out, ...)

 Returns nil, if there is no filter. Raises an ArgumentError if the
 filter is not usable. Returns the instantiated participant if the
 filter points to a participant filter.