Module: OpenWFE

Defined in:
lib/openwfe/version.rb,
lib/openwfe/utils.rb,
lib/openwfe/logging.rb,
lib/openwfe/omixins.rb,
lib/openwfe/service.rb,
lib/openwfe/util/irb.rb,
lib/openwfe/workitem.rb,
lib/openwfe/filterdef.rb,
lib/openwfe/contextual.rb,
lib/openwfe/exceptions.rb,
lib/openwfe/util/ometa.rb,
lib/openwfe/util/dollar.rb,
lib/openwfe/engine/engine.rb,
lib/openwfe/expool/parser.rb,
lib/openwfe/orest/osocket.rb,
lib/openwfe/rudefinitions.rb,
lib/openwfe/expool/history.rb,
lib/openwfe/expool/journal.rb,
lib/openwfe/expool/wfidgen.rb,
lib/openwfe/orest/workitem.rb,
lib/openwfe/orest/xmlcodec.rb,
lib/openwfe/util/workqueue.rb,
lib/openwfe/expressions/raw.rb,
lib/openwfe/orest/exception.rb,
lib/openwfe/util/observable.rb,
lib/openwfe/expressions/time.rb,
lib/openwfe/flowexpressionid.rb,
lib/openwfe/orest/restclient.rb,
lib/openwfe/tools/flowtracer.rb,
lib/openwfe/worklist/oldrest.rb,
lib/openwfe/expool/expstorage.rb,
lib/openwfe/expressions/fe_do.rb,
lib/openwfe/expressions/fe_if.rb,
lib/openwfe/expressions/merge.rb,
lib/openwfe/expressions/value.rb,
lib/openwfe/orest/definitions.rb,
lib/openwfe/worklist/worklist.rb,
lib/openwfe/expressions/fe_fqv.rb,
lib/openwfe/expressions/fe_set.rb,
lib/openwfe/expressions/filter.rb,
lib/openwfe/listeners/listener.rb,
lib/openwfe/storage/yamlcustom.rb,
lib/openwfe/expool/errorjournal.rb,
lib/openwfe/expressions/fe_cron.rb,
lib/openwfe/expressions/fe_misc.rb,
lib/openwfe/expressions/fe_save.rb,
lib/openwfe/expressions/fe_wait.rb,
lib/openwfe/expressions/fe_when.rb,
lib/openwfe/expressions/timeout.rb,
lib/openwfe/listeners/listeners.rb,
lib/openwfe/orest/controlclient.rb,
lib/openwfe/worklist/storelocks.rb,
lib/openwfe/expressions/fe_sleep.rb,
lib/openwfe/expressions/rprocdef.rb,
lib/openwfe/orest/oldrestservlet.rb,
lib/openwfe/orest/worklistclient.rb,
lib/openwfe/engine/process_status.rb,
lib/openwfe/expool/expressionpool.rb,
lib/openwfe/expool/journal_replay.rb,
lib/openwfe/expool/yamlexpstorage.rb,
lib/openwfe/expressions/condition.rb,
lib/openwfe/expressions/fe_cancel.rb,
lib/openwfe/expressions/fe_cursor.rb,
lib/openwfe/expressions/fe_define.rb,
lib/openwfe/expressions/fe_equals.rb,
lib/openwfe/expressions/fe_filter.rb,
lib/openwfe/expressions/fe_listen.rb,
lib/openwfe/expressions/fe_losfor.rb,
lib/openwfe/expressions/wtemplate.rb,
lib/openwfe/expressions/fe_command.rb,
lib/openwfe/expressions/fe_reserve.rb,
lib/openwfe/expressions/fe_timeout.rb,
lib/openwfe/expressions/environment.rb,
lib/openwfe/expressions/fe_iterator.rb,
lib/openwfe/expressions/fe_sequence.rb,
lib/openwfe/storage/yamlfilestorage.rb,
lib/openwfe/participants/participant.rb,
lib/openwfe/expool/threadedexpstorage.rb,
lib/openwfe/expressions/expressionmap.rb,
lib/openwfe/expressions/fe_subprocess.rb,
lib/openwfe/listeners/socketlisteners.rb,
lib/openwfe/participants/participants.rb,
lib/openwfe/worklist/storeparticipant.rb,
lib/openwfe/expressions/fe_concurrence.rb,
lib/openwfe/expressions/fe_participant.rb,
lib/openwfe/expressions/flowexpression.rb,
lib/openwfe/participants/participantmap.rb,
lib/openwfe/engine/file_persisted_engine.rb,
lib/openwfe/participants/enoparticipants.rb,
lib/openwfe/participants/soapparticipants.rb,
lib/openwfe/participants/socketparticipants.rb,
lib/openwfe/expressions/fe_filter_definition.rb

Overview

The participant expression, in its own file

Defined Under Namespace

Modules: CommandConstants, CommandMixin, ConditionMixin, Contextual, DefParser, ExpressionStorageBase, ExpressionTree, FeiMixin, FilterMixin, HistoryMixin, JournalReplay, LocalParticipant, Logging, LookupMixin, MergeMixin, OwfeObservable, OwfeServiceLocator, Participant, ServiceMixin, StatusMixin, StoreParticipantMixin, TemplateMixin, ThreadedStorageMixin, TimeoutMixin, ValueMixin, WorkItemListener, WorkqueueMixin, XmlCodec Classes: AliasParticipant, AttributeExpression, Base64Attribute, BaseHistory, BlockParticipant, CacheExpressionStorage, CachedFilePersistedEngine, CancelItem, CancelProcessExpression, CaseExpression, ComparisonExpression, ConcurrenceExpression, ConcurrentIteratorExpression, ControlClient, CronExpression, CursorCommandExpression, CursorExpression, DefaultAuthSystem, DefaultWfidGenerator, DefineExpression, DefinedExpression, EmailNotificationParticipant, Engine, Environment, EqualsExpression, ErrorJournal, EvalExpression, ExpExpression, Expression, ExpressionMap, ExpressionPool, FieldWfidGenerator, FileHistory, FileListener, FileParticipant, FilePersistedEngine, FilterDefinition, FilterDefinitionExpression, FilterExpression, FlowDict, FlowExpression, FlowExpressionId, FlowMutex, ForgetExpression, FqvExpression, GenericSyncExpression, HashParticipant, Header, HistoryItem, IfExpression, InFlowItem, InFlowWorkItem, InMemoryErrorJournal, InMemoryExpressionStorage, InMemoryHistory, Iterator, IteratorExpression, Journal, KotobaWfidGenerator, LaunchItem, Launchable, ListenExpression, LogExpression, LoopExpression, LoseExpression, MailParticipant, MonitorProvider, NoOperationParticipant, NullParticipant, ObjectWithMeta, OldRestServlet, OldRestWorklistServlet, OldSocketListener, OwfeException, ParameterException, ParticipantExpression, ParticipantMap, PausedError, PrintExpression, PrintParticipant, ProcessDefinition, ProcessError, ProcessParticipant, ProcessStatus, ProgRawExpression, RawExpression, RedoExpression, ReserveExpression, RestClient, RestoreWorkItemExpression, RevalExpression, SaveWorkItemExpression, SequenceExpression, Service, SetValueExpression, SimpleExpRepresentation, SleepExpression, SoapParticipant, SocketListener, SocketParticipant, Store, StoreWithLocks, SubProcessRefExpression, SymbolHash, SyncExpression, ThreadedYamlFileExpressionStorage, TimeExpression, TimeoutExpression, Timer, UndoExpression, UnsetValueExpression, UuidWfidGenerator, WaitExpression, WaitingExpression, WhenExpression, WithTemplateExpression, WorkItem, Worklist, WorklistClient, XmlRawExpression, XmlSocketParticipant, YamlErrorJournal, YamlFileExpressionStorage, YamlFileStorage, YamlParticipant

Constant Summary collapse

OPENWFERU_VERSION =
'0.9.17'
FIELD_RESULT =

The convention for the result of some expressions is to store their result in a workitem field named “__result__”.

"__result__"
DSUB_SAFETY_LEVEL =
4
S_LOGGER =

service names

:logger
S_ENGINE =
'engine'
S_EXPRESSION_MAP =
'expressionMap'
S_WFID_GENERATOR =
'wfidGenerator'
S_EXPRESSION_POOL =
'expressionPool'
S_EXPRESSION_STORAGE =
'expressionStorage'
S_PARTICIPANT_MAP =
'participantMap'
S_SCHEDULER =
'scheduler'
S_ERROR_JOURNAL =
'errorJournal'
EN_ENVIRONMENT =

some special expression names

'environment'
DEFAULT_WORK_DIRECTORY =

some file storage default values

'work'
SPLIT_MAP =

“module methods”

{
    "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" => UuidWfidGenerator,
    "[0-9]{8}-[a-z]*" => KotobaWfidGenerator
}
NAME =
'name'
STORE =
'store'
STORES =
'stores'
WORKITEM_COUNT =
'workitem-count'
PERMISSIONS =
'permissions'
HEADER =
'header'
HEADERS =
'headers'
A_LAST_MODIFIED =
'last-modified'
A_LOCKED =
'locked'
FLOW_EXPRESSION_ID =
'flow-expression-id'
ATTRIBUTES =
'attributes'
OWFE_VERSION =
'owfe-version'
ENGINE_ID =
'engine-id'
INITIAL_ENGINE_ID =
'initial-engine-id'
WORKFLOW_DEFINITION_URL =
'workflow-definition-url'
WORKFLOW_DEFINITION_NAME =
'workflow-definition-name'
WORKFLOW_DEFINITION_REVISION =
'workflow-definition-revision'
WORKFLOW_INSTANCE_ID =
'workflow-instance-id'
EXPRESSION_NAME =
'expression-name'
EXPRESSION_ID =
'expression-id'
E_STRING =
'string'
E_INTEGER =
'integer'
E_BOOLEAN =
'boolean'
E_LONG =
'long'
E_DOUBLE =
'double'
E_RAW_XML =
'raw-xml'
E_XML_DOCUMENT =
'xml-document'
E_BASE64 =
'base64'
E_LIST =
'list'
E_MAP =
'map'
E_SMAP =
'smap'
M_ENTRY =
'entry'
M_KEY =
'key'
M_VALUE =
'value'
MAP_TYPE =
'___map_type'
FLOW_EXPRESSION_IDS =
'flow-expression-ids'
LAUNCHITEM =
'launchitem'
ENGINEID =
"engineid"
OK =
"ok"
A_FLOW_ID =
"flow-id"
IN_FLOW_WORKITEM =
'workitem'
A_DISPATCH_TIME =
'dispatch-time'
A_PARTICIPANT_NAME =
'participant-name'
E_LAST_EXPRESSION_ID =
'last-expression-id'
LAUNCHABLES =
'launchables'
LAUNCHABLE =
'launchable'
URL =
'url'
TARGETSTORE =
'targetstore'
EXPRESSIONS =
'expressions'
EXPRESSION =
'expression'
APPLY_TIME =
'apply-time'
STATE =
'state'
STATE_SINCE =
'state-since'
HISTORY =
'history'
HISTORY_ITEM =
'history-item'
A_AUTHOR =
'author'
A_DATE =
'date'
A_HOST =
'host'
GONE =
"gone"
GONE_PARENT_ID =

This special flow expression id is used by the forget() method (which is used by the forget expression and the concurrence synchronization expressions)

FlowExpressionId.new
VAR_PAUSED =

When this variable is set to true (at the process root), it means the process is paused.

'/__paused__'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call_in_thread(caller_name, caller_object = nil, &block) ⇒ Object

Some code for writing thinks like :

if async
    OpenWFE::call_in_thread "launch()", self do
        raw_expression.apply(wi)
    end
else
    raw_expression.apply(wi)
end

Returns the new thread instance.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/openwfe/utils.rb', line 291

def OpenWFE.call_in_thread (caller_name, caller_object=nil, &block)

    return unless block

    Thread.new do

        #set_current_thread_name "call_in_thread() for '#{caller_name}'"
        set_current_thread_name caller_name

        begin
            #$SAFE = safe_level
                #
                # (note)
                # doesn't work : the block inherits the safety level
                # of its surroundings, it's a closure, ne ?

            block.call

        rescue Exception => e
            msg = "#{caller_name} caught an exception\n" + exception_to_s(e)
            if caller_object and caller_object.respond_to? :lwarn
                caller_object.lwarn { msg }
            else
                puts msg
            end
        end
    end
    # returns the thread
end

.caller_to_s(start_index, max_lines = nil) ⇒ Object

Pretty printing a caller() array



256
257
258
259
260
261
262
263
# File 'lib/openwfe/utils.rb', line 256

def OpenWFE.caller_to_s (start_index, max_lines=nil)
    s = ""
    caller(start_index + 1).each_with_index do |line, index|
        break if max_lines and index >= max_lines
        s << "   #{line}\n"
    end
    s
end

.clean_path(s) ⇒ Object

“my//path” -> “my/path”



381
382
383
# File 'lib/openwfe/utils.rb', line 381

def OpenWFE.clean_path (s)
    s.gsub(/\/+/, "/")
end

.deep_clone(object) ⇒ Object

see wiki.rubygarden.org/Ruby/page/show/Make_A_Deep_Copy_Of_An_Object

It’s not perfect (that’s why fulldup() uses it only in certain cases).

For example :

TypeError: singleton can't be dumped
    ./lib/openwfe/utils.rb:74:in `dump'
    ./lib/openwfe/utils.rb:74:in `deep_clone'


72
73
74
75
# File 'lib/openwfe/utils.rb', line 72

def OpenWFE.deep_clone (object)

    Marshal::load(Marshal.dump(object))
end

.dispatch_workitem(host, port, workitem) ⇒ Object

Dispatches a workitem over TCP, the workitem will be encoded with XML The default encode_method is



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/openwfe/orest/osocket.rb', line 93

def OpenWFE.dispatch_workitem (host, port, workitem)

    #sXml = OpenWFE.xml_encode(workitem)
    sXml = OpenWFE::XmlCodec::encode workitem

    socket = TCPSocket.new(host, port)
    socket.puts "xmlCoder #{sXml.length}"
    socket.puts
    socket.puts sXml
    socket.puts
    socket.close_write

    reply = socket.gets

    #reply = reply + socket.gets
        #
        # a bit ridiculous, but it works
        # socket.close_write fixed it

    socket.close

    #puts "dispatch() reply is >#{reply}<"
end

.dosub(text, flow_expression, workitem) ⇒ Object

Performs ‘dollar substitution’ on a piece of text with as input a flow expression and a workitem (fields and variables).



62
63
64
65
# File 'lib/openwfe/util/dollar.rb', line 62

def OpenWFE.dosub (text, flow_expression, workitem)

    Rufus::dsub(text, FlowDict.new(flow_expression, workitem))
end

.ends_with(string, _end) ⇒ Object

Returns true if the given string ends with the ‘_end’ string.



237
238
239
240
241
# File 'lib/openwfe/utils.rb', line 237

def OpenWFE.ends_with (string, _end)
    return false unless string
    return false if string.length < _end.length
    string[-_end.length..-1] == _end
end

.ensure_for_filename(s) ⇒ Object

Returns a version of s that is usable as or within a filename (removes for examples things like ‘/’ or ‘'…)



364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/openwfe/utils.rb', line 364

def OpenWFE.ensure_for_filename (s)

    s = s.gsub(" ", "_")
    s = s.gsub("/", "_")
    s = s.gsub(":", "_")
    s = s.gsub(";", "_")
    s = s.gsub("\*", "_")
    s = s.gsub("\\", "_")
    s = s.gsub("\+", "_")
    s = s.gsub("\?", "_")

    s
end

.exception_to_s(exception) ⇒ Object

Attempts at displaying a nice stack trace



246
247
248
249
250
251
# File 'lib/openwfe/utils.rb', line 246

def OpenWFE.exception_to_s (exception)
    s = "exception : "
    s << "#{exception}\n"
    s << exception.backtrace.join("\n")
    s
end

.first_element(xmlElt, elementName = nil) ⇒ Object

Returns the first subelt of xmlElt that matches the given xpath. If xpath is null, the first elt will be returned.



51
52
53
54
55
56
57
58
# File 'lib/openwfe/utils.rb', line 51

def OpenWFE.first_element (xmlElt, elementName=nil)

    return nil if not xmlElt

    return xmlElt.elements[1] if not elementName

    xmlElt.elements.detect { |elt| elt.name == elementName }
end

.fulldup(object) ⇒ Object

an automatic dup implementation attempt



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/openwfe/utils.rb', line 80

def OpenWFE.fulldup (object)

    return nil if object == nil

    return object.fulldup if object.respond_to?("fulldup")
        # trusting client objects providing a fulldup() implementation
        # Tomaso Tosolini 2007.12.11

    return object if object.kind_of?(Float)
    return object if object.kind_of?(Fixnum)
    return object if object.kind_of?(TrueClass)
    return object if object.kind_of?(FalseClass)
    return object if object.kind_of?(Symbol)

    return object.dup if object.kind_of?(String)

    #return deep_clone(object) if object.kind_of? REXML::Document
    
    #return REXML::Document.new(object.to_s)      #    if object.kind_of? REXML::Document

    if object.kind_of?(REXML::Element)
        d = REXML::Document.new object.to_s
        return d if object.kind_of?(REXML::Document)
        return d.root
    end

    return Rational(object.denominator, object.numerator) \
        if object.kind_of?(Rational)

    o = nil

    begin
        o = object.class.new
    rescue ArgumentError => ae
        return deep_clone(object)
    end

    #
    # some kind of collection ?

    if object.kind_of?(Array)
        object.each do |i|
            o << fulldup(i)
        end
    elsif object.kind_of?(Hash)
        object.each do |k, v|
            o[fulldup(k)] = fulldup(v)
        end
    end

    #
    # duplicate the attributes of the object

    object.instance_variables.each do |v|

        #puts "v is #{v}"

        value = object.instance_variable_get(v)

        #puts "value is '#{value}'"

        value = fulldup(value)

        begin
            o.instance_variable_set(v, value)
        rescue
            # ignore, must be readonly
        end
    end

    o
end

.get_class(h) ⇒ Object



481
482
483
484
485
486
487
# File 'lib/openwfe/workitem.rb', line 481

def OpenWFE.get_class (h)

    cl = h[:type]
    return nil if cl.index(";")
    return nil if cl.index(" ")
    eval(cl)
end

.grep(pattern, filepath, &block) ⇒ Object

Returns a list of lines matching the pattern in the given file.

This is also possible :

OpenWFE::grep "^..) ", "path/to/file.txt" do |line|
    puts " - '#{line.downcase}'"
end

TODO : find a ruby library and use it instead of that code



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/openwfe/utils.rb', line 441

def OpenWFE.grep (pattern, filepath, &block)

    result = []
    r = Regexp.new pattern

    File.open filepath do |file|
        file.readlines.each do |l|
            if r.match l
                if block
                    block.call l
                else
                    result << l
                end
            end
        end
    end
    result unless block
end

.has_attribute?(container, key) ⇒ Boolean

This method is used within the InFlowWorkItem and the CsvTable classes.



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/openwfe/utils.rb', line 410

def OpenWFE.has_attribute? (container, key)

    key, last_key = pop_last_key(key)

    container = lookup_attribute(container, key) if key

    if container.respond_to?(:has_key?)

        (container.has_key?(last_key) or container.has_key?(last_key.to_s))

    elsif container.is_a?(Array) and last_key.is_a?(Fixnum)

        (last_key < container.length)

    else

        false
    end
end

.lookup_attribute(container, key) ⇒ Object

This method is used within the InFlowWorkItem and the CsvTable classes.



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/openwfe/utils.rb', line 388

def OpenWFE.lookup_attribute (container, key)

    key, rest = pop_key(key)

    #value = nil
    #begin
    #    value = container[key]
    #rescue Exception => e
    #end

    value = flex_lookup(container, key)

    return value unless rest

    return nil unless value

    lookup_attribute(value, rest)
end

.name_to_symbol(name) ⇒ Object



169
170
171
172
173
# File 'lib/openwfe/utils.rb', line 169

def OpenWFE.name_to_symbol (name)

    return name if name.is_a?(Symbol)
    to_underscore(name).intern
end

.parse_known_uri(ref) ⇒ Object

Returns a URI instance if the given ref is a http, https, file or ftp URI. Returns nil else. The sister method parse_uri() is OK with things like mailto:, gopher:, …



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/openwfe/utils.rb', line 205

def OpenWFE.parse_known_uri (ref)

    uri = OpenWFE::parse_uri(ref.to_s)

    return nil unless uri

    return uri if uri.scheme == "file"
    return uri if uri.scheme == "http"
    return uri if uri.scheme == "https"
    return uri if uri.scheme == "ftp"
        # what else ...

    nil
end

.parse_uri(string) ⇒ Object

Returns an URI if the string is one, else returns nil. No exception is thrown by this method.



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/openwfe/utils.rb', line 188

def OpenWFE.parse_uri (string)

    return nil if string.split("\n").size > 1

    begin
        return URI::parse(string)
    rescue Exception => e
    end

    nil
end

.pretty_print_process_status(ps) ⇒ Object

Renders a nice, terminal oriented, representation of an Engine.get_process_status() result.

You usually directly benefit from this when doing

puts engine.get_process_status.to_s


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/openwfe/engine/process_status.rb', line 241

def OpenWFE.pretty_print_process_status (ps)

    # TODO : include launch_time and why is process_id so long ?

    s = ""
    s << "process_id          | name              | rev     | brn | err | paused? \n"
    s << "--------------------+-------------------+---------+-----+-----+---------\n"

    ps.keys.sort.each do |wfid|

        status = ps[wfid]
        fexp = status.expressions.first
        ffei = fexp.fei

        s << "%-19s" % wfid[0, 19]
        s << " | "
        s << "%-17s" % ffei.workflow_definition_name[0, 17]
        s << " | "
        s << "%-7s" % ffei.workflow_definition_revision[0, 7]
        s << " | "
        s << "%3s" % status.expressions.size.to_s[0, 3]
        s << " | "
        s << "%3s" % status.errors.size.to_s[0, 3]
        s << " | "
        s << "%5s" % status.paused?.to_s
        s << "\n"
    end
    s
end

.set_attribute(container, key, value) ⇒ Object

This method is used within the InFlowWorkItem and the CsvTable classes.



463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/openwfe/utils.rb', line 463

def OpenWFE.set_attribute (container, key, value)

    i = key.rindex(".")

    if not i
        container[key] = value
        return
    end

    container = lookup_attribute(container, key[0..i-1])
    container[key[i+1..-1]] = value
end

.set_current_thread_name(name) ⇒ Object

Sets the name of the current thread (the attribute :name if it is a ruby thread, the java thread name if we’re in JRuby)



269
270
271
272
273
274
275
276
# File 'lib/openwfe/utils.rb', line 269

def OpenWFE.set_current_thread_name (name)
   if defined?(JRUBY_VERSION)
       require 'java'
       java.lang.Thread.current_thread.name = "#{name} (Ruby Thread)"
   else
       Thread.current[:name] = name
   end
end

.split_wfid(wfid) ⇒ Object

This method should be able to split any wfid whose scheme is implemented here.



376
377
378
379
380
381
382
383
384
385
# File 'lib/openwfe/expool/wfidgen.rb', line 376

def OpenWFE.split_wfid (wfid)

    SPLIT_MAP.each do |regex, clazz|
        return clazz.split_wfid(wfid) if wfid.match(regex) 
    end
    #
    # else
    #
    DefaultWfidGenerator.split_wfid(wfid)
end

.starts_with(string, start) ⇒ Object

Returns true if the given string starts with the ‘start’ string.



223
224
225
226
227
228
229
230
231
232
# File 'lib/openwfe/utils.rb', line 223

def OpenWFE.starts_with (string, start)
    #
    # my favourite way of doing that would be by adding this 
    # method to the String class, but that could be intrusive
    # (as OpenWFE is meant at first as an embeddable workflow engine).
    #
    return false unless string
    return false if string.length < start.length
    string[0, start.length] == start
end

.stu(s) ⇒ Object

Turns all the spaces in string into underscores. Returns the new String.



179
180
181
182
# File 'lib/openwfe/utils.rb', line 179

def OpenWFE.stu (s)

    s.gsub("\s", "_")
end

.symbol_to_name(symbol) ⇒ Object



164
165
166
167
# File 'lib/openwfe/utils.rb', line 164

def OpenWFE.symbol_to_name (symbol)

    to_dash(symbol.to_s)
end

.to_dash(string) ⇒ Object



159
160
161
162
# File 'lib/openwfe/utils.rb', line 159

def OpenWFE.to_dash (string)

    string.gsub("_", "-")
end

.to_underscore(string) ⇒ Object



154
155
156
157
# File 'lib/openwfe/utils.rb', line 154

def OpenWFE.to_underscore (string)

    string.gsub("-", "_")
end

.trap_int_irb(*args) ⇒ Object

Binds the SIGINT signal so that a console is opened with the bindings specified in ‘args’.



57
58
59
60
61
62
63
# File 'lib/openwfe/util/irb.rb', line 57

def OpenWFE.trap_int_irb (*args)
    trap 'INT' do
        OpenWFE.start_irb_session(*args)
        #OpenWFE.trap_int_irb(*args) if $openwfe_irb
        OpenWFE.trap_int_irb(*args)
    end
end

.unset_attribute(container, key) ⇒ Object

This method is used within the InFlowWorkItem and the CsvTable classes.



479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/openwfe/utils.rb', line 479

def OpenWFE.unset_attribute (container, key)

    i = key.rindex(".")

    if not i
        container.delete key
        return
    end

    container = lookup_attribute container, key[0..i-1]

    if container.is_a?(Array)

        container.delete_at key[i+1..-1].to_i
    else

        container.delete key[i+1..-1]
    end
end

.workitem_from_h(h) ⇒ Object

Turns a hash into its corresponding workitem (InFlowWorkItem, CancelItem, LaunchItem).



474
475
476
477
478
479
# File 'lib/openwfe/workitem.rb', line 474

def OpenWFE.workitem_from_h (h)

    #wi_class = eval(h[:type])
    wi_class = get_class(h)
    wi_class.from_h(h)
end

.xml_to_s(xml, decl = true) ⇒ Object

An alias for OpenWFE::xmldoc_to_string()



649
650
651
652
# File 'lib/openwfe/orest/xmlcodec.rb', line 649

def OpenWFE.xml_to_s (xml, decl=true)

    OpenWFE::xmldoc_to_string(xml, decl)
end

.xmldoc_to_string(xml, decl = true) ⇒ Object

Just turns some XML to a String (if decl is set to false, no XML declaration will be printed).



633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/openwfe/orest/xmlcodec.rb', line 633

def OpenWFE.xmldoc_to_string (xml, decl=true)

    #return xml if xml.is_a?(String)

    xml << REXML::XMLDecl.new \
        if decl and (not xml[0].is_a?(REXML::XMLDecl))

    #s = ""
    #xml.write(s, 0)
    #return s
    xml.to_s
end

Instance Method Details

#online?Boolean

Returns true if this host is currently online (has access to the web / internet).



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/openwfe/utils.rb', line 503

def online?

    require 'open-uri'

    begin
        open("http://www.openwfe.org")
        true
    rescue SocketError => se
        false
    end
end

#trace_flow(process_definition) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/openwfe/tools/flowtracer.rb', line 50

def trace_flow (process_definition)

    li = LaunchItem.new process_definition

    engine = Engine.new

    i = 0

    engine.register_participant(".*") do |workitem|

        puts "-- #{i} ------------------------------------------------------------------------"
        puts
        puts " participant '#{workitem.participant_name}' received workitem :"
        puts 
        puts workitem.to_s
        puts
        puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" 
        puts
        puts " expression pool state :"
        #puts 
        puts engine.get_expression_storage.to_s
        puts
        #puts

        i = i + 1
    end

    engine.launch li
end