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