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