author | Claus Gittinger <cg@exept.de> |
Thu, 07 Mar 2002 08:53:07 +0100 | |
changeset 6451 | f22b12c0349a |
parent 6431 | 584b4b6e231c |
child 8516 | 14ec9e1d3b39 |
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 |
[ |
|
69 |
Object errorSignal handle:[:ex | |
|
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 |
||
99 |
<exception: #handle> |
|
100 |
||
101 |
"/ 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
|
102 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
4550 | 103 |
|
104 |
" |
|
105 |
Notification answer:true do:[ |
|
106 |
Transcript showCR:'query answers: ' , (Query query printString). |
|
107 |
] |
|
108 |
" |
|
4443 | 109 |
|
110 |
" |
|
4550 | 111 |
Notification answer:false do:[ |
112 |
Transcript showCR:'first query answers: ' , (Query query printString). |
|
113 |
Query answer:true do:[ |
|
114 |
Transcript showCR:'second query answers: ' , (Query query printString). |
|
115 |
] |
|
116 |
] |
|
4443 | 117 |
" |
118 |
||
4550 | 119 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
120 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
|
121 |
"Modified: / 25.7.1999 / 23:12:19 / stefan" |
|
122 |
! ! |
|
123 |
||
124 |
!Notification class methodsFor:'queries'! |
|
125 |
||
126 |
accepts:aSignal |
|
127 |
"return true, if the receiver accepts the argument, aSignal. |
|
128 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
129 |
||
130 |
|s| |
|
131 |
||
132 |
self == aSignal ifTrue:[^ true]. |
|
133 |
aSignal isQuerySignal ifFalse:[^ false]. |
|
134 |
||
135 |
s := aSignal. |
|
136 |
[s notNil] whileTrue:[ |
|
137 |
self == s ifTrue:[^ true]. |
|
138 |
s := s parent |
|
139 |
]. |
|
140 |
^ false |
|
141 |
||
142 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
|
143 |
"Created: / 23.7.1999 / 15:18:00 / stefan" |
|
144 |
! |
|
145 |
||
146 |
defaultAnswer |
|
147 |
"Return the default answer to the Query. This method is called, |
|
148 |
if nobody catches the signal. |
|
149 |
||
150 |
Subclasses may redefine this method." |
|
151 |
||
152 |
"Calling raiseRequest here will execute the exception's action method" |
|
153 |
||
154 |
^ super raiseRequest |
|
155 |
||
156 |
"Created: / 23.7.1999 / 15:16:03 / stefan" |
|
157 |
! |
|
158 |
||
159 |
handlerForSignal:signal context:theContext originator:originator |
|
160 |
"answer the handler block for the signal from originator. |
|
161 |
The block is retrieved from aContext. |
|
162 |
Answer nil if the signal is not handled" |
|
163 |
||
164 |
|arg| |
|
165 |
||
166 |
theContext selector == #'answer:do:' ifTrue:[ |
|
167 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
|
168 |
arg := theContext argAt:1. |
|
169 |
^ [:ex| ex proceedWith:arg]. |
|
170 |
] |
|
171 |
] ifFalse:[ |
|
172 |
^ super handlerForSignal:signal context:theContext originator:originator. |
|
173 |
]. |
|
174 |
||
175 |
^ nil |
|
176 |
||
177 |
"Created: / 25.7.1999 / 23:11:55 / stefan" |
|
178 |
! |
|
179 |
||
180 |
isQuerySignal |
|
4605 | 181 |
"return true, if this is a querySignal - always return true here" |
4550 | 182 |
|
183 |
^ true |
|
184 |
||
185 |
"Created: / 23.7.1999 / 14:59:50 / stefan" |
|
186 |
! |
|
187 |
||
6431 | 188 |
notify:aMessageString |
189 |
"raise the query - return the handlers value, or the default |
|
190 |
value, if there is no handler." |
|
191 |
||
192 |
^ self raiseRequestErrorString:aMessageString |
|
193 |
! |
|
194 |
||
4550 | 195 |
query |
196 |
"raise the query - return the handlers value, or the default |
|
197 |
value, if there is no handler. |
|
198 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
|
199 |
but we can do it faster here." |
|
200 |
||
201 |
|con s| |
|
202 |
||
203 |
con := Context findFirstSpecialHandle:true raise:false. |
|
204 |
[con notNil] whileTrue:[ |
|
205 |
(con selector == #answer:do:) ifFalse:[ |
|
206 |
^ super raiseRequest |
|
207 |
]. |
|
208 |
(s := con receiver) == self ifTrue:[ |
|
209 |
^ con argAt:1 |
|
210 |
]. |
|
211 |
(s == self or:[s accepts:self]) ifTrue:[ |
|
212 |
^ super raiseRequest |
|
213 |
]. |
|
214 |
con := con findSpecialHandle:true raise:false. |
|
215 |
]. |
|
216 |
||
217 |
"/ no handler found - return the default value |
|
218 |
^ self defaultAnswer |
|
219 |
||
220 |
"Modified: / 15.6.1998 / 21:27:37 / cg" |
|
221 |
"Modified: / 25.7.1999 / 23:15:16 / stefan" |
|
222 |
! |
|
223 |
||
224 |
raise |
|
225 |
"QuerySignals are proceedable by definition, |
|
226 |
so they should be raised with #query or #raiseRequest" |
|
227 |
||
228 |
^ self shouldNotImplement |
|
229 |
||
230 |
"Created: / 23.7.1999 / 15:19:17 / stefan" |
|
231 |
! |
|
232 |
||
233 |
raiseRequest |
|
234 |
"redefined to use #query" |
|
235 |
||
236 |
^ self query |
|
237 |
||
238 |
"Created: / 25.7.1999 / 23:25:59 / stefan" |
|
4443 | 239 |
! ! |
240 |
||
241 |
!Notification methodsFor:'default actions'! |
|
242 |
||
4525 | 243 |
defaultAction |
4550 | 244 |
"the default action is to return the default value. |
245 |
Subclasses may redefine this" |
|
4443 | 246 |
|
6451
f22b12c0349a
renamed #defaultValue -> #defaultResumeValue (vw54 compat.)
Claus Gittinger <cg@exept.de>
parents:
6431
diff
changeset
|
247 |
^ self defaultResumeValue |
4443 | 248 |
|
4550 | 249 |
"Modified: / 23.7.1999 / 15:13:34 / stefan" |
4443 | 250 |
! ! |
251 |
||
252 |
!Notification class methodsFor:'documentation'! |
|
253 |
||
254 |
version |
|
6451
f22b12c0349a
renamed #defaultValue -> #defaultResumeValue (vw54 compat.)
Claus Gittinger <cg@exept.de>
parents:
6431
diff
changeset
|
255 |
^ '$Header: /cvs/stx/stx/libbasic/Notification.st,v 1.12 2002-03-07 07:53:07 cg Exp $' |
4443 | 256 |
! ! |
257 |
Notification initialize! |