section ‹Abstract Syntax of BPEL v2.0 language›
theory bpel_ast
imports Main
begin
type_synonym QName = string
type_synonym NCName = string
type_synonym Time = nat
record ('s,'l) State =
vars :: 's
links :: "'l ⇒ bool"
tick :: nat
record ('s,'l) Flow_Ele =
targets :: "((('s,'l) State ⇒ bool) × 'l list) option"
sources :: "('l × (('s,'l) State ⇒ bool)) list option"
text ‹We only permit Flow Element for basic activities.
Although it is allowed in BPEL standard for structured activities, we did not find examples in the standard.
The important thing is that flow element for structured activities
can be transformed into flow element only in basic activities.›
datatype ('s,'l) Activity =
Invoke (se:"('s,'l) Flow_Ele") (ptlink:NCName) (pttype:QName) (op:NCName)
"('s,'l) State ⇒ ('s,'l) State"
(catches:"(QName × (('s,'l) Activity)) list") (catchall:"('s,'l) Activity option")
| Receive (se:"('s,'l) Flow_Ele") (ptlink:NCName) (pttype:QName) (op:NCName)
(spec:"('s,'l) State ⇒ ('s,'l) State")
| Reply (se:"('s,'l) Flow_Ele") (ptlink:NCName) (pttype:QName) (op:NCName)
| Assign (se:"('s,'l) Flow_Ele") "('s,'l) State ⇒ ('s,'l) State"
| Wait (se:"('s,'l) Flow_Ele") Time
| Empty (se:"('s,'l) Flow_Ele")
| Seqb "('s,'l) Activity" "('s,'l) Activity"
| If (cond:"('s,'l) State set") "('s,'l) Activity" "('s,'l) Activity"
| While (cond:"('s,'l) State set") "('s,'l) Activity"
| Pick "(('s,'l) EventHandler)" "(('s,'l) EventHandler)"
| Flow "('s,'l) Activity" "('s,'l) Activity"
| ActTerminator
and ('s,'l) EventHandler =
OnMessage (ptlink:NCName) (pttype:QName) (op:NCName)
(spec:"('s,'l) State ⇒ ('s,'l) State") "('s,'l) Activity"
| OnAlarm Time "('s,'l) Activity"
definition "repeatUntil c P ≡ Seqb P (While c P)"
function forEach :: "nat ⇒ nat ⇒ ('s,'l) Activity ⇒ ('s,'l) Activity"
where "forEach m n P = (if m = n then P
else if m > n then ActTerminator
else Seqb P (forEach (m + 1) n P))"
by auto
termination forEach
apply(relation "measure (λ(m,n,P). n - m)")
by auto
primrec seqs :: "nat ⇒ ('s,'l) Activity ⇒ ('s,'l) Activity"
where "seqs 0 P = P" |
"seqs (Suc n) P = Seqb P (seqs n P)"
type_synonym ('s,'l) BPELProc = "('s,'l) Activity"
definition targets_sat ::
"((('s,'l) State ⇒ bool) × 'l list) option ⇒ ('s,'l) State ⇒ bool"
where "targets_sat tgs s ≡
tgs ≠ None ⟶
(fst (the tgs) s ⟶
(∀i<length (snd (the tgs)). links s ((snd (the tgs))!i)))
∧ (¬ fst (the tgs) s ⟶
(∃i<length (snd (the tgs)). links s ((snd (the tgs))!i)))"
definition fire_sources ::
"('l × (('s,'l) State ⇒ bool)) list option
⇒ ('s,'l) State ⇒ ('s,'l) State"
where "fire_sources srcs s ≡
(if srcs ≠ None then
s⦇links := foldl (λf l. f(fst l := snd l s)) (links s) (the srcs)⦈
else s)"
end