author | Stefan Vogel <sv@exept.de> |
Mon, 24 Jan 2005 13:33:39 +0100 | |
changeset 8698 | 948da171e6e5 |
parent 8692 | 3abb4811f5b2 |
child 8701 | bd5034470a47 |
permissions | -rw-r--r-- |
4466
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
1 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
3 |
All Rights Reserved |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
4 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
5 |
This software is furnished under a license and may be used |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
10 |
hereby transferred. |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
11 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
12 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
13 |
|
6206 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
4443 | 16 |
Exception subclass:#Notification |
17 |
instanceVariableNames:'' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Kernel-Exceptions' |
|
21 |
! |
|
22 |
||
23 |
!Notification class methodsFor:'documentation'! |
|
24 |
||
4466
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
25 |
copyright |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
26 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
27 |
COPYRIGHT (c) 1999 by eXept Software AG |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
28 |
All Rights Reserved |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
29 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
30 |
This software is furnished under a license and may be used |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
31 |
only in accordance with the terms of that license and with the |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
32 |
inclusion of the above copyright notice. This software may not |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
33 |
be provided or otherwise made available to, or used by, any |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
34 |
other person. No title to or ownership of the software is |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
35 |
hereby transferred. |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
36 |
" |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
37 |
|
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
38 |
! |
9cba6f4ecec4
copyrights added; typo in docu
Claus Gittinger <cg@exept.de>
parents:
4443
diff
changeset
|
39 |
|
4443 | 40 |
documentation |
41 |
" |
|
4550 | 42 |
Notification is the superclass of all notification exceptions in the system. |
43 |
These notifications are ignored, if no handler is present. |
|
44 |
In this case a default value is returned. |
|
4443 | 45 |
|
46 |
[author:] |
|
47 |
Stefan Vogel |
|
48 |
||
49 |
[see also:] |
|
4550 | 50 |
Signal QuerySignal |
4443 | 51 |
" |
4550 | 52 |
|
4443 | 53 |
! |
54 |
||
4550 | 55 |
examples |
4443 | 56 |
" |
6431 | 57 |
an up-notification from a deeply nested operation to a higher level: |
4550 | 58 |
[exBegin] |
59 |
|zero| |
|
60 |
||
61 |
zero := 0. |
|
6431 | 62 |
Notification handle:[:n | |
63 |
Transcript showCR:'Please note that: ' , n description. |
|
64 |
n proceedWith:true |
|
4550 | 65 |
] do:[ |
66 |
'nesting'. |
|
67 |
[ |
|
68 |
[ |
|
8516 | 69 |
Error handle:[:ex | |
4550 | 70 |
Transcript showCR:'some error: ' , ex errorString. |
71 |
ex proceed |
|
72 |
] do:[ |
|
73 |
[ |
|
74 |
1 // zero. 'an error which is caught in the handler'. |
|
6431 | 75 |
Notification notify:'hello world' |
4550 | 76 |
] value |
77 |
] |
|
78 |
] value |
|
79 |
] value |
|
80 |
] |
|
81 |
[exEnd] |
|
4443 | 82 |
" |
83 |
! ! |
|
84 |
||
85 |
!Notification class methodsFor:'initialization'! |
|
86 |
||
87 |
initialize |
|
88 |
||
4550 | 89 |
NotifierString := 'Notification:' |
90 |
! ! |
|
91 |
||
92 |
!Notification class methodsFor:'answering queries'! |
|
93 |
||
94 |
answer:someAnswer do:aBlock |
|
95 |
"evaluate the argument, aBlock. |
|
96 |
If the receiver is queried during evaluation, answer with someAnswer. |
|
97 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
|
98 |
||
8698
948da171e6e5
Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents:
8692
diff
changeset
|
99 |
<context: #return> |
4550 | 100 |
<exception: #handle> |
101 |
||
102 |
"/ thisContext markForHandle. -- same as above pragma |
|
5227
73a2dc34cb42
#answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents:
4605
diff
changeset
|
103 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
4550 | 104 |
|
105 |
" |
|
106 |
Notification answer:true do:[ |
|
107 |
Transcript showCR:'query answers: ' , (Query query printString). |
|
108 |
] |
|
109 |
" |
|
4443 | 110 |
|
111 |
" |
|
4550 | 112 |
Notification answer:false do:[ |
113 |
Transcript showCR:'first query answers: ' , (Query query printString). |
|
114 |
Query answer:true do:[ |
|
115 |
Transcript showCR:'second query answers: ' , (Query query printString). |
|
116 |
] |
|
117 |
] |
|
4443 | 118 |
" |
119 |
||
4550 | 120 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
121 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
|
122 |
"Modified: / 25.7.1999 / 23:12:19 / stefan" |
|
123 |
! ! |
|
124 |
||
125 |
!Notification class methodsFor:'queries'! |
|
126 |
||
127 |
accepts:aSignal |
|
128 |
"return true, if the receiver accepts the argument, aSignal. |
|
129 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
130 |
||
131 |
|s| |
|
132 |
||
133 |
self == aSignal ifTrue:[^ true]. |
|
134 |
aSignal isQuerySignal ifFalse:[^ false]. |
|
135 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
136 |
s := aSignal parent. |
4550 | 137 |
[s notNil] whileTrue:[ |
138 |
self == s ifTrue:[^ true]. |
|
139 |
s := s parent |
|
140 |
]. |
|
141 |
^ false |
|
142 |
||
143 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
|
144 |
"Created: / 23.7.1999 / 15:18:00 / stefan" |
|
145 |
! |
|
146 |
||
147 |
defaultAnswer |
|
148 |
"Return the default answer to the Query. This method is called, |
|
149 |
if nobody catches the signal. |
|
150 |
||
151 |
Subclasses may redefine this method." |
|
152 |
||
153 |
"Calling raiseRequest here will execute the exception's action method" |
|
154 |
||
155 |
^ super raiseRequest |
|
156 |
||
157 |
"Created: / 23.7.1999 / 15:16:03 / stefan" |
|
158 |
! |
|
159 |
||
160 |
handlerForSignal:signal context:theContext originator:originator |
|
161 |
"answer the handler block for the signal from originator. |
|
162 |
The block is retrieved from aContext. |
|
163 |
Answer nil if the signal is not handled" |
|
164 |
||
165 |
|arg| |
|
166 |
||
167 |
theContext selector == #'answer:do:' ifTrue:[ |
|
168 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
|
169 |
arg := theContext argAt:1. |
|
170 |
^ [:ex| ex proceedWith:arg]. |
|
171 |
] |
|
172 |
] ifFalse:[ |
|
173 |
^ super handlerForSignal:signal context:theContext originator:originator. |
|
174 |
]. |
|
175 |
||
176 |
^ nil |
|
177 |
||
178 |
"Created: / 25.7.1999 / 23:11:55 / stefan" |
|
179 |
! |
|
180 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
181 |
handles:anException |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
182 |
"return true, if the receiver handles the argument, anException. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
183 |
(i.e. the receiver is anExceptions signal or a parent of it)" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
184 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
185 |
|signal| |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
186 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
187 |
signal := anException signal. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
188 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
189 |
self == signal ifTrue:[^ true]. "quick check" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
190 |
anException isNotification ifFalse:[^ false]. "speed up non-queries by not traversing the parent chain" |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
191 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
192 |
[(signal := signal parent) notNil] whileTrue:[ |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
193 |
self == signal ifTrue:[^ true]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
194 |
]. |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
195 |
^ false |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
196 |
! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
197 |
|
4550 | 198 |
isQuerySignal |
4605 | 199 |
"return true, if this is a querySignal - always return true here" |
4550 | 200 |
|
201 |
^ true |
|
202 |
||
203 |
"Created: / 23.7.1999 / 14:59:50 / stefan" |
|
204 |
! |
|
205 |
||
6431 | 206 |
notify:aMessageString |
207 |
"raise the query - return the handlers value, or the default |
|
208 |
value, if there is no handler." |
|
209 |
||
210 |
^ self raiseRequestErrorString:aMessageString |
|
211 |
! |
|
212 |
||
4550 | 213 |
query |
214 |
"raise the query - return the handlers value, or the default |
|
215 |
value, if there is no handler. |
|
216 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
|
217 |
but we can do it faster here." |
|
218 |
||
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
219 |
|con signal| |
4550 | 220 |
|
221 |
con := Context findFirstSpecialHandle:true raise:false. |
|
222 |
[con notNil] whileTrue:[ |
|
8692
3abb4811f5b2
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8683
diff
changeset
|
223 |
(con selector ~~ #answer:do:) ifTrue:[ |
4550 | 224 |
^ super raiseRequest |
225 |
]. |
|
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
226 |
signal := con receiver. |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
227 |
signal == self ifTrue:[ |
4550 | 228 |
^ con argAt:1 |
229 |
]. |
|
8692
3abb4811f5b2
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8683
diff
changeset
|
230 |
signal isNil ifTrue:[ |
3abb4811f5b2
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8683
diff
changeset
|
231 |
self error:'nil receiver in #answer:do: - send'. |
3abb4811f5b2
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8683
diff
changeset
|
232 |
]. |
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
233 |
(signal accepts:self) ifTrue:[ |
8692
3abb4811f5b2
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8683
diff
changeset
|
234 |
^ con argAt:1 |
4550 | 235 |
]. |
236 |
con := con findSpecialHandle:true raise:false. |
|
237 |
]. |
|
238 |
||
239 |
"/ no handler found - return the default value |
|
240 |
^ self defaultAnswer |
|
241 |
||
242 |
"Modified: / 15.6.1998 / 21:27:37 / cg" |
|
243 |
"Modified: / 25.7.1999 / 23:15:16 / stefan" |
|
244 |
! |
|
245 |
||
246 |
raise |
|
247 |
"QuerySignals are proceedable by definition, |
|
248 |
so they should be raised with #query or #raiseRequest" |
|
249 |
||
250 |
^ self shouldNotImplement |
|
251 |
||
252 |
"Created: / 23.7.1999 / 15:19:17 / stefan" |
|
253 |
! |
|
254 |
||
255 |
raiseRequest |
|
256 |
"redefined to use #query" |
|
257 |
||
258 |
^ self query |
|
259 |
||
260 |
"Created: / 25.7.1999 / 23:25:59 / stefan" |
|
4443 | 261 |
! ! |
262 |
||
263 |
!Notification methodsFor:'default actions'! |
|
264 |
||
4525 | 265 |
defaultAction |
4550 | 266 |
"the default action is to return the default value. |
267 |
Subclasses may redefine this" |
|
4443 | 268 |
|
8683
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
269 |
|handlerBlock| |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
270 |
|
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
271 |
"try per signal handler. |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
272 |
I may have been created from a QuerySignal" |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
273 |
|
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
274 |
(handlerBlock := signal handlerBlock) notNil ifTrue:[ |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
275 |
"... and call it" |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
276 |
^ handlerBlock value:self. |
a162510a0408
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
8681
diff
changeset
|
277 |
]. |
6451
f22b12c0349a
renamed #defaultValue -> #defaultResumeValue (vw54 compat.)
Claus Gittinger <cg@exept.de>
parents:
6431
diff
changeset
|
278 |
^ self defaultResumeValue |
4443 | 279 |
|
4550 | 280 |
"Modified: / 23.7.1999 / 15:13:34 / stefan" |
4443 | 281 |
! ! |
282 |
||
8681
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
283 |
!Notification methodsFor:'testing'! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
284 |
|
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
285 |
isNotification |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
286 |
^ true |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
287 |
! ! |
38aa963476a5
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8516
diff
changeset
|
288 |
|
4443 | 289 |
!Notification class methodsFor:'documentation'! |
290 |
||
291 |
version |
|
8698
948da171e6e5
Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents:
8692
diff
changeset
|
292 |
^ '$Header: /cvs/stx/stx/libbasic/Notification.st,v 1.17 2005-01-24 12:33:39 stefan Exp $' |
4443 | 293 |
! ! |
8516 | 294 |
|
4443 | 295 |
Notification initialize! |