XHandler is an AppleScript library to execute a handler with specifying its name with a text. This libary allows to change a handler to execute at run-time.
Fhutermore, followings can be made possible.
Check whther the script object has the handler or not.
If the script object don't have called handler, it is made possible that the script object can hand calling the handler over another script object.
XHandler can be used for chain of responder pattern and method forwarding.
XHandler can deal with handlers with positional parameters. But handlers which have labeld parameters are not supported.
Sample
useXHandler : script "XHandler"
scriptBScript
onsay_msg(a_msg)
return "hey " & a_msg
endsay_msg
endscript
scriptAScript
onshow_msg(a_msg)
return "hello " & a_msg
endshow_msg
-- successor object to foward calling handlers which are not implemented.
onsuccessor()
returnBScript
endsuccessor
endscript
(*== Simply calling handler ==*)
setxhandler1toXHandler'smake_with("show_msg", 1)
logxhandler1'sdo(AScript, "good morning") -- hello good morning
(*== Test whether AScript can respont to the handler "show_msg" ==*)
logxhandler1'sresponded_by(AScript) -- true
(*== If target object can't resond to the handler, try to call handler in a successr object . ==*)
setxhandler2toXHandler'smake_with("say_msg", 1)
logxhandler2'scall_to(AScript, "good evening") -- "hey good evening"