- Barging in with bargein
- Multiple Document Applications
- Multidocument Transitions
- Throwing and Catching Events
- Application-Specific Events
- Event Names and Prefix Matching
- Summary
Event Names and Prefix Matching
Using periods in an event name such as com.zorkon.bossProblem does more than make an event readable. The dots in the name actually define a hierarchy that can be used to provide handlers for a wide variety of events.
For example, a prefix match occurs when the catch element event attribute specifies a token prefix of the full name of the event being thrown. For example, the following will match zorkon.disconnect.transfer, zorkon.disconnect.drop, or any event that begins with zorkon.disconnect:
<catch event="zorkon.disconnect"> <prompt>Caught a connection dot disconnect event</prompt> </catch>
The ultimate shorthand is to simply specify ".", as in the following, which matches all events (as does <catch> without an event attribute):
<catch event="."> <prompt>Caught an event</prompt> </catch>
When using event prefixes to catch events, it’s significant to note that the catch element selection gives priority to catch elements that occur earlier in a document over those that occur later, but does not give priority to catch elements that are more specific over those that are less specific.
Therefore, it is advisable to specify catch elements in order from more specific to less specific. For example, one should specify catch elements for "error.foo" and "error" in that order, as follows:
<catch event="error.foo"> <prompt>Caught an error dot foo event</prompt> </catch> <catch event="error"> <prompt>Caught an error event</prompt> </catch>
If the catch elements are specified in the reverse order, the catch element for "error.foo" will never be executed since event="error" will always match any event beginning with the word event.