author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 12 Jul 2010 17:20:36 +0100 | |
branch | jv |
changeset 17780 | b6e42c92eba0 |
parent 17772 | 6e0b3c06c364 |
child 17807 | 06cc6c49e291 |
permissions | -rw-r--r-- |
420 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5871 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
420 | 14 |
Signal subclass:#QuerySignal |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
15 |
instanceVariableNames:'defaultAnswer hasDefault' |
1248 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Kernel-Exceptions' |
|
420 | 19 |
! |
20 |
||
1954 | 21 |
!QuerySignal class methodsFor:'documentation'! |
420 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
11202 | 39 |
Notice: |
40 |
Signals have been replaced by class based Exceptions. |
|
41 |
They are provided for compatibility, but new code should use Exceptions |
|
42 |
(in this case: Query) |
|
43 |
||
420 | 44 |
QuerySignals are like signals, except that they are not accepted |
45 |
by handlers for ordinary signals. |
|
46 |
I.e. a signal handler for a normal signal will not handle a query |
|
580 | 47 |
signal. Thus, these bypass anySignal handlers. |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
48 |
|
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
49 |
However, if unhandled, no error is raised, instead they are simply ignored |
1954 | 50 |
and nil is returned from the raise |
1248 | 51 |
(as opposed to normal signals, which raise an unhandled signal exception). |
1363 | 52 |
QuerySignals are also ignored, if a handler exists, but rejects. |
1248 | 53 |
|
1954 | 54 |
Their main use is to implement upQueries via signals, that work even |
1363 | 55 |
if intermediate errorSignal handlers are present |
56 |
(which is not possible with ordinary signals, since errorSignal handlers |
|
57 |
would catch those signals). |
|
58 |
||
1248 | 59 |
Code deep down in the calling hierarchy can post such an up-Query to ask |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
60 |
for some information or to pass some information upward. |
580 | 61 |
|
1248 | 62 |
For example, the activityNotification mechanism is built on top of this: |
63 |
everyone can send such a notification which is either handled by someone |
|
64 |
up in the hierarchy (to show it in the windows info area) or simply |
|
65 |
ignored. |
|
66 |
||
67 |
Using QuerySignals for this (instead of regular Signals) helps in documenting |
|
68 |
the intended usage of those signals. |
|
1275 | 69 |
|
1954 | 70 |
Another use of querySignals is to provide additional information to |
71 |
deeply nested methods, which is only required in the uncommon case; |
|
72 |
or if another parameter is required by some method, which was not planned |
|
73 |
for in the beginning, and you do not want to hand this value (via an |
|
74 |
additional argument) through all intermediate levels. |
|
75 |
A highly elegant solution to this problem is to provide a handler somewhere |
|
76 |
at the top of the calling hierarchy, and raise an upQuery from whereever |
|
77 |
that value is required. |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
78 |
A concrete application can be found in the windowGroup-lastEvent |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
79 |
queries. If anyone is interested in the windowEvent which was responible for |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
80 |
being invoked, all he needs to do is to raise the lastEventQuerySignal, |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
81 |
which returns that event. |
1954 | 82 |
No intermediate methods are required to know anything about that. |
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
83 |
Another example is found in the way Metaclass asks for the nameSpace |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
84 |
when new classes are to be installed. A Browser may simply answer such |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
85 |
a query and provide a namespace (no need to pass that information down |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
86 |
the calling chain). |
1954 | 87 |
|
88 |
A final note (to C++ and Java fans): |
|
89 |
such upQueries are only possible, if the exception handling mechanism |
|
90 |
does not automatically unwind the stack for the handler invokation. |
|
91 |
Since the handler must be able to proceed the execution and return |
|
92 |
a value to the raiser .... |
|
11202 | 93 |
... another demonstration of why ST's exception mechanisms are superior. |
1954 | 94 |
|
1275 | 95 |
[see also:] |
96 |
Signal SignalSet Exception |
|
97 |
Object |
|
1363 | 98 |
(``Exception handling and signals'': programming/exceptions.html) |
1292 | 99 |
|
100 |
[author:] |
|
101 |
Claus Gittinger |
|
580 | 102 |
" |
103 |
! |
|
104 |
||
105 |
examples |
|
106 |
" |
|
1379 | 107 |
an up-query from a deeply nested operation to a higher level: |
1316 | 108 |
[exBegin] |
1379 | 109 |
|querySignal zero| |
580 | 110 |
|
1379 | 111 |
zero := 0. |
112 |
querySignal := QuerySignal new. |
|
113 |
querySignal handle:[:ex | |
|
1422 | 114 |
Transcript showCR:'query'. |
1379 | 115 |
ex proceedWith:true |
116 |
] do:[ |
|
117 |
'nesting'. |
|
118 |
[ |
|
119 |
[ |
|
120 |
Object errorSignal handle:[:ex | |
|
1422 | 121 |
Transcript showCR:'some error: ' , ex errorString. |
1379 | 122 |
ex proceed |
123 |
] do:[ |
|
124 |
[ |
|
2689 | 125 |
1 // zero. 'an error which is caught in the handler'. |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
126 |
(querySignal query) == true ifTrue:[ |
1422 | 127 |
Transcript showCR:'query says: ok'. |
1379 | 128 |
] ifFalse:[ |
1422 | 129 |
Transcript showCR:'query says: no' |
1379 | 130 |
] |
131 |
] value |
|
132 |
] |
|
133 |
] value |
|
134 |
] value |
|
135 |
] |
|
136 |
[exEnd] |
|
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
137 |
for lazy typists, a more compact interface is also provided |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
138 |
(which is also easier to read): |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
139 |
[exBegin] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
140 |
|querySignal| |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
141 |
|
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
142 |
querySignal := QuerySignal new. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
143 |
querySignal answer:true do:[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
144 |
'nesting'. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
145 |
[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
146 |
[ |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
147 |
(querySignal query) == true ifTrue:[ |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
148 |
Transcript showCR:'query says: ok'. |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
149 |
] ifFalse:[ |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
150 |
Transcript showCR:'query says: no' |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
151 |
] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
152 |
] value |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
153 |
] value |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
154 |
] |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
155 |
[exEnd] |
1379 | 156 |
an up-query from a deeply nested operation, for which there |
157 |
is no handler: |
|
158 |
(notice, this would not work with normal signals, which would raise |
|
159 |
another unhandled exception-exception; |
|
160 |
also notice the == check #raise's return value being true, |
|
161 |
instead of a simple ifTrue; this handles a nil-value from |
|
162 |
the unhandled query) |
|
163 |
[exBegin] |
|
164 |
|querySignal zero| |
|
165 |
||
166 |
zero := 0. |
|
167 |
querySignal := QuerySignal new. |
|
168 |
||
169 |
[ |
|
170 |
'nesting'. |
|
171 |
[ |
|
172 |
[ |
|
173 |
Object errorSignal handle:[:ex | |
|
1422 | 174 |
Transcript showCR:'some error: ' , ex errorString. |
1379 | 175 |
ex proceed |
176 |
] do:[ |
|
177 |
[ |
|
2689 | 178 |
1 // zero. 'an error which is caught in the handler'. |
1379 | 179 |
(querySignal raise) == true ifTrue:[ |
1422 | 180 |
Transcript showCR:'query says: ok'. |
1379 | 181 |
] ifFalse:[ |
1422 | 182 |
Transcript showCR:'query says: no' |
1379 | 183 |
] |
184 |
] value |
|
185 |
] |
|
186 |
] value |
|
187 |
] value |
|
188 |
] value |
|
189 |
[exEnd] |
|
190 |
counter-example, just to show that things would not work this way |
|
191 |
with regular signals: |
|
192 |
[exBegin] |
|
193 |
|signal| |
|
194 |
||
195 |
signal := Signal new. |
|
196 |
'nesting deeply'. |
|
197 |
[ |
|
198 |
[ |
|
1316 | 199 |
[ |
200 |
[ |
|
1379 | 201 |
[ |
202 |
(signal raise) == true ifTrue:[ |
|
1422 | 203 |
Transcript showCR:'query says: ok'. |
1379 | 204 |
] ifFalse:[ |
1422 | 205 |
Transcript showCR:'query says: no' |
1379 | 206 |
] |
207 |
] value |
|
1316 | 208 |
] value |
209 |
] value |
|
1379 | 210 |
] value |
211 |
] value |
|
212 |
[exEnd] |
|
213 |
||
214 |
except, by handling the unhandled exception |
|
215 |
(but we think, that querySignals are easier to use and |
|
216 |
better document the intent): |
|
217 |
[exBegin] |
|
218 |
|signal| |
|
219 |
||
220 |
signal := Signal new. |
|
221 |
'nesting deeply'. |
|
222 |
[ |
|
223 |
[ |
|
224 |
[ |
|
225 |
[ |
|
226 |
[ |
|
227 |
Signal noHandlerSignal handle:[:ex | |
|
228 |
ex proceedWith:nil |
|
229 |
] do:[ |
|
230 |
(signal raise) == true ifTrue:[ |
|
1422 | 231 |
Transcript showCR:'query says: ok'. |
1379 | 232 |
] ifFalse:[ |
1422 | 233 |
Transcript showCR:'query says: no' |
1379 | 234 |
] |
235 |
] |
|
236 |
] value |
|
237 |
] value |
|
238 |
] value |
|
239 |
] value |
|
240 |
] value |
|
241 |
[exEnd] |
|
420 | 242 |
" |
243 |
! ! |
|
244 |
||
2893 | 245 |
!QuerySignal methodsFor:'answering queries'! |
246 |
||
247 |
answer:someAnswer do:aBlock |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
248 |
"evaluate the argument, aBlock. |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
249 |
If the receiver is queried during evaluation, answer and proceed with someAnswer. |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
250 |
This is a wrapper for #handle:do: for lazy typists; no new functionality." |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
251 |
|
8697
05013adab7bb
Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents:
8693
diff
changeset
|
252 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
253 |
<exception: #handle> |
2893 | 254 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
255 |
"/ thisContext markForHandle. -- same as above pragma |
5227
73a2dc34cb42
#answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents:
4908
diff
changeset
|
256 |
^ aBlock value. "the real logic is in Exception>>doRaise" |
2893 | 257 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
258 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
259 |
|q| |
2893 | 260 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
261 |
q := QuerySignal new. |
2893 | 262 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
263 |
q answer:true do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
264 |
Transcript showCR:'query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
265 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
266 |
" |
2893 | 267 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
268 |
" |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
269 |
|q| |
2893 | 270 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
271 |
q := QuerySignal new. |
2893 | 272 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
273 |
q answer:false do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
274 |
Transcript showCR:'first query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
275 |
q answer:true do:[ |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
276 |
Transcript showCR:'second query answers: ' , (q query printString). |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
277 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
278 |
] |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4466
diff
changeset
|
279 |
" |
2893 | 280 |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
281 |
"Created: / 10.7.1996 / 15:08:20 / cg" |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
282 |
"Modified: / 14.10.1996 / 16:59:18 / cg" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
283 |
"Modified: / 25.7.1999 / 23:34:02 / stefan" |
2893 | 284 |
! ! |
285 |
||
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
286 |
!QuerySignal methodsFor:'exception creation'! |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
287 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
288 |
newException |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
289 |
"{ Pragma: +inlineNew }" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
290 |
"answer a new exception object for this signal" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
291 |
|
8702
bb40a9b11f11
Create a Query instead of a Notification
Stefan Vogel <sv@exept.de>
parents:
8697
diff
changeset
|
292 |
^ Query basicNew setSignal:self. |
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
293 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
294 |
" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
295 |
|querySignal| |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
296 |
querySignal := QuerySignal new. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
297 |
querySignal handle:[:ex| self halt] do:[querySignal raiseRequest]. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
298 |
" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
299 |
! ! |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
300 |
|
2037 | 301 |
!QuerySignal methodsFor:'initialization'! |
302 |
||
303 |
defaultAnswer:someValue |
|
304 |
"define the queries defaultAnswer to be someValue. |
|
305 |
This is the same as defining an appropriate handlerBlock." |
|
306 |
||
307 |
|handler| |
|
308 |
||
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
309 |
defaultAnswer := someValue. |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
310 |
hasDefault := true. |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
311 |
|
2037 | 312 |
"/ avoid creating a fullBlock, in the most common cases |
4514 | 313 |
"/ therefore, do not replace the code below by |
314 |
"/ handler := [:ex | ex proceedWith:someValue] |
|
315 |
"/ although it is semantically equivalent. |
|
316 |
||
2037 | 317 |
someValue == true ifTrue:[ |
318 |
handler := [:ex | ex proceedWith:true] |
|
319 |
] ifFalse:[ |
|
320 |
someValue == false ifTrue:[ |
|
321 |
handler := [:ex | ex proceedWith:false] |
|
322 |
] ifFalse:[ |
|
2900
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
323 |
someValue isNil ifTrue:[ |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
324 |
handler := [:ex | ex proceedWith:nil] |
2153bcddc299
faster return of defaultValue
Claus Gittinger <cg@exept.de>
parents:
2893
diff
changeset
|
325 |
] ifFalse:[ |
6790 | 326 |
handler := [:ex | ex proceedWith:someValue value]. |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
327 |
] |
2037 | 328 |
] |
329 |
]. |
|
330 |
self handlerBlock:handler. |
|
331 |
||
332 |
" |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
333 |
QuerySignal new query |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
334 |
(QuerySignal new defaultAnswer:true) query |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
335 |
(QuerySignal new defaultAnswer:false) query |
2037 | 336 |
" |
337 |
||
338 |
" |
|
339 |
|sig rslt| |
|
340 |
||
341 |
sig := QuerySignal new. |
|
342 |
sig defaultAnswer:false. |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
343 |
rslt := sig query. |
2037 | 344 |
Transcript showCR:rslt. |
345 |
" |
|
346 |
||
347 |
" |
|
348 |
|sig rslt| |
|
349 |
||
350 |
sig := QuerySignal new. |
|
351 |
sig defaultAnswer:false. |
|
352 |
sig answer:true |
|
353 |
do:[ |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
354 |
rslt := sig query |
2037 | 355 |
]. |
356 |
Transcript showCR:rslt. |
|
357 |
" |
|
358 |
||
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
359 |
"Modified: / 3.1.1997 / 15:14:40 / cg" |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
360 |
"Modified: / 2.3.1998 / 10:42:14 / stefan" |
2037 | 361 |
! ! |
362 |
||
420 | 363 |
!QuerySignal methodsFor:'queries'! |
364 |
||
365 |
accepts:aSignal |
|
366 |
"return true, if the receiver accepts the argument, aSignal. |
|
367 |
(i.e. the receiver is aSignal or a parent of it). False otherwise." |
|
368 |
||
369 |
|s| |
|
370 |
||
4527 | 371 |
self == aSignal ifTrue:[^ true]. |
421 | 372 |
aSignal isQuerySignal ifFalse:[^ false]. |
420 | 373 |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
374 |
s := aSignal parent. |
420 | 375 |
[s notNil] whileTrue:[ |
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
376 |
self == s ifTrue:[^ true]. |
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
377 |
s := s parent |
420 | 378 |
]. |
379 |
^ false |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
380 |
|
4438 | 381 |
"Modified: / 22.3.1999 / 12:45:32 / stefan" |
691 | 382 |
! |
383 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
384 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
385 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
386 |
The block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
387 |
Answer nil if the signal is not handled" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
388 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
389 |
|arg| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
390 |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
391 |
theContext selector == #answer:do: ifTrue:[ |
4514 | 392 |
(self == signal or:[self accepts:signal]) ifTrue:[ |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
393 |
arg := theContext argAt:1. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
394 |
^ [:ex| ex proceedWith:arg]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
395 |
] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
396 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
397 |
^ super handlerForSignal:signal context:theContext originator:originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
398 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
399 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
400 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
401 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
402 |
"Created: / 25.7.1999 / 23:33:05 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
403 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4442
diff
changeset
|
404 |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
405 |
handles:anException |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
406 |
"return true, if the receiver handles the argument, anException. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
407 |
(i.e. the receiver is anExceptions signal or a parent of it)" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
408 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
409 |
|signal| |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
410 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
411 |
signal := anException signal. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
412 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
413 |
self == signal ifTrue:[^ true]. "quick check" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
414 |
anException isNotification ifFalse:[^ false]. "speed up non-queries by not traversing the parent chain" |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
415 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
416 |
[(signal := signal parent) notNil] whileTrue:[ |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
417 |
self == signal ifTrue:[^ true]. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
418 |
]. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
419 |
^ false |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
420 |
! |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
421 |
|
691 | 422 |
isQuerySignal |
1249 | 423 |
"return true, if this is a querySignal - always return true here" |
424 |
||
691 | 425 |
^ true |
1249 | 426 |
|
427 |
"Modified: 22.4.1996 / 13:45:10 / cg" |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
428 |
! ! |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
429 |
|
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
430 |
!QuerySignal methodsFor:'raising'! |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
431 |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
432 |
query |
2893 | 433 |
"raise the query - return the handlers value, or the default |
4908 | 434 |
value, if there is no handler." |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
435 |
|
4514 | 436 |
^ self raiseRequest |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
437 |
! |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
438 |
|
4908 | 439 |
queryWith:aParameter |
440 |
"raise the query passing a parameter |
|
441 |
- return the handlers value, or the default value, if there is no handler." |
|
442 |
||
443 |
^ self raiseRequestWith:aParameter |
|
444 |
! |
|
445 |
||
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
446 |
raise |
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
447 |
"QuerySignals are proceedable by definition, |
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
448 |
so they should be raised with #query or #raiseRequest" |
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
449 |
|
5871 | 450 |
<resource:#obsolete> |
451 |
||
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
452 |
self obsoleteMethodWarning:'use #query or #raiseRequest'. |
4514 | 453 |
^ self raiseRequest |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
454 |
|
4061
ef62e88fd0ac
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3581
diff
changeset
|
455 |
"Modified: / 18.3.1999 / 18:33:57 / stefan" |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
456 |
! |
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
457 |
|
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
458 |
raiseRequest |
4514 | 459 |
"raise the query - return the handlers value, or the default |
460 |
value, if there is no handler. |
|
461 |
Invoking the handler is exactly the functionality of Signal>>raiseRequest, |
|
462 |
but we can do it faster here, by avoiding the creation of a full-blown |
|
463 |
exception object." |
|
464 |
||
5935
f7e334a3fdbb
chech exception/signal against nil, to avoid recursive
Claus Gittinger <cg@exept.de>
parents:
5871
diff
changeset
|
465 |
|con sel sig| |
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
466 |
|
4514 | 467 |
con := Context findFirstSpecialHandle:true raise:false. |
468 |
[con notNil] whileTrue:[ |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
469 |
sel := con selector. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
470 |
sel == #answer:do: ifTrue:[ |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
471 |
sig := con receiver. |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
472 |
sig == self ifTrue:[ |
4514 | 473 |
^ con argAt:1 |
474 |
]. |
|
5935
f7e334a3fdbb
chech exception/signal against nil, to avoid recursive
Claus Gittinger <cg@exept.de>
parents:
5871
diff
changeset
|
475 |
sig isNil ifTrue:[ |
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
476 |
self error:'nil receiver in #answer:do: - send'. |
5935
f7e334a3fdbb
chech exception/signal against nil, to avoid recursive
Claus Gittinger <cg@exept.de>
parents:
5871
diff
changeset
|
477 |
]. |
f7e334a3fdbb
chech exception/signal against nil, to avoid recursive
Claus Gittinger <cg@exept.de>
parents:
5871
diff
changeset
|
478 |
(sig accepts:self) ifTrue:[ |
8693
e9543a43bb71
When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents:
8686
diff
changeset
|
479 |
^ con argAt:1 |
4514 | 480 |
]. |
481 |
] ifFalse:[ |
|
8686
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
482 |
(sel ~~ #handle:do: |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
483 |
or:[(sig := con receiver) == self |
708fa53592f6
QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents:
6790
diff
changeset
|
484 |
or:[sig accepts:self]]) ifTrue:[ |
4514 | 485 |
^ super raiseRequest |
486 |
]. |
|
487 |
]. |
|
488 |
con := con findSpecialHandle:true raise:false. |
|
489 |
]. |
|
3307
08ad28464911
Use #raiseRequest to invoke the (inherently) proceedable QuerySignal.
Stefan Vogel <sv@exept.de>
parents:
2900
diff
changeset
|
490 |
|
4514 | 491 |
"/ no handler found - return the default value |
492 |
hasDefault == true ifTrue:[ |
|
6790 | 493 |
^ defaultAnswer value |
4514 | 494 |
]. |
495 |
handlerBlock isNil ifTrue:[ |
|
496 |
^ nil |
|
497 |
]. |
|
498 |
^ super raiseRequest |
|
499 |
||
500 |
"Modified: / 15.6.1998 / 21:27:37 / cg" |
|
501 |
"Modified: / 25.7.1999 / 23:35:11 / stefan" |
|
1534
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
502 |
! ! |
3aac2f9ef96c
added #answer:do: - easier to read
Claus Gittinger <cg@exept.de>
parents:
1422
diff
changeset
|
503 |
|
1954 | 504 |
!QuerySignal class methodsFor:'documentation'! |
691 | 505 |
|
506 |
version |
|
17780 | 507 |
^ '$Id: QuerySignal.st 10544 2010-07-12 16:20:36Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
508 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
509 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
510 |
version_CVS |
17780 | 511 |
^ 'Header: /cvs/stx/stx/libbasic/QuerySignal.st,v 1.44 2009/10/01 07:27:33 cg Exp ' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
512 |
! |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
513 |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
514 |
version_SVN |
17780 | 515 |
^ '$Id: QuerySignal.st 10544 2010-07-12 16:20:36Z vranyj1 $' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
516 |
! ! |
17767 | 517 |
|
17772
6e0b3c06c364
Method reverted to r10532
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17767
diff
changeset
|
518 |
|
17780 | 519 |