Notification.st
author Stefan Vogel <sv@exept.de>
Mon, 24 Jan 2005 13:33:39 +0100
changeset 8698 948da171e6e5
parent 8692 3abb4811f5b2
child 8701 bd5034470a47
permissions -rw-r--r--
Make #handle - contexts also #return-able
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
8698
948da171e6e5 Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents: 8692
diff changeset
    99
    <context: #return>
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   100
    <exception: #handle>
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   101
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   102
    "/ thisContext markForHandle. -- same as above pragma
5227
73a2dc34cb42 #answer:do: now returns the evaluated blocks value
Claus Gittinger <cg@exept.de>
parents: 4605
diff changeset
   103
    ^ aBlock value.  "the real logic is in Exception>>doRaise"
4550
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
    "
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   106
     Notification answer:true do:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   107
        Transcript showCR:'query answers: ' , (Query query printString).
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   108
     ]
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   109
    "
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   110
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   111
    "
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   112
     Notification answer:false do:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   113
        Transcript showCR:'first query answers: ' , (Query query printString).
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   114
        Query answer:true do:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   115
            Transcript showCR:'second query answers: ' , (Query query printString).
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   116
        ]
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   117
     ]
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   118
    "
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   119
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   120
    "Created: / 10.7.1996 / 15:08:20 / cg"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   121
    "Modified: / 14.10.1996 / 16:59:18 / cg"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   122
    "Modified: / 25.7.1999 / 23:12:19 / stefan"
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   125
!Notification class methodsFor:'queries'!
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   126
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   127
accepts:aSignal
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   128
    "return true, if the receiver accepts the argument, aSignal.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   129
     (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
   130
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   131
    |s|
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   132
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   133
    self == aSignal ifTrue:[^ true].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   134
    aSignal isQuerySignal ifFalse:[^ false].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   135
8681
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   136
    s := aSignal parent.
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   137
    [s notNil] whileTrue:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   138
        self == s ifTrue:[^ true].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   139
        s := s parent
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   140
    ].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   141
    ^ false
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   142
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   143
    "Modified: / 22.3.1999 / 12:45:32 / stefan"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   144
    "Created: / 23.7.1999 / 15:18:00 / stefan"
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   147
defaultAnswer
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   148
    "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
   149
     if nobody catches the signal.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   150
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   151
     Subclasses may redefine this method."
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   152
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   153
    "Calling raiseRequest here will execute the exception's action method"    
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   154
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   155
    ^ super raiseRequest
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   156
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   157
    "Created: / 23.7.1999 / 15:16:03 / stefan"
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   160
handlerForSignal:signal context:theContext originator:originator
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   161
    "answer the handler block for the signal from originator.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   162
     The block is retrieved from aContext.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   163
     Answer nil if the signal is not handled"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   164
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   165
    |arg|
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   166
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   167
    theContext selector == #'answer:do:' ifTrue:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   168
        (self == signal or:[self accepts:signal]) ifTrue:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   169
            arg := theContext argAt:1.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   170
            ^ [:ex| ex proceedWith:arg].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   171
        ]
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   172
    ] ifFalse:[
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   173
        ^ super handlerForSignal:signal context:theContext originator:originator.
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   176
    ^ nil
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   177
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   178
    "Created: / 25.7.1999 / 23:11:55 / stefan"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   179
!
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   180
8681
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   181
handles:anException
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   182
    "return true, if the receiver handles the argument, anException.
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   183
     (i.e. the receiver is anExceptions signal or a parent of it)"
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   184
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   185
    |signal|
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   186
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   187
    signal := anException signal.
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   188
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   189
    self == signal ifTrue:[^ true].               "quick check"
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   190
    anException isNotification ifFalse:[^ false]. "speed up non-queries by not traversing the parent chain"
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   191
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   192
    [(signal := signal parent) notNil] whileTrue:[
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   193
        self == signal ifTrue:[^ true].
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   194
    ].
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   195
    ^ false
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   196
!
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   197
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   198
isQuerySignal
4605
7d5e97290c97 comment only
Claus Gittinger <cg@exept.de>
parents: 4554
diff changeset
   199
    "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
   200
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   201
    ^ true
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   202
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   203
    "Created: / 23.7.1999 / 14:59:50 / stefan"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   204
!
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   205
6431
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   206
notify:aMessageString
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   207
    "raise the query - return the handlers value, or the default
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   208
     value, if there is no handler."
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   209
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   210
    ^ self raiseRequestErrorString:aMessageString
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   211
!
584b4b6e231c common code with Query
Claus Gittinger <cg@exept.de>
parents: 6206
diff changeset
   212
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   213
query
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   214
    "raise the query - return the handlers value, or the default
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   215
     value, if there is no handler.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   216
     Invoking the handler is exactly the functionality of Signal>>raiseRequest,
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   217
     but we can do it faster here."
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   218
8683
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   219
    |con signal|
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   220
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   221
    con := Context findFirstSpecialHandle:true raise:false.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   222
    [con notNil] whileTrue:[
8692
3abb4811f5b2 When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents: 8683
diff changeset
   223
        (con selector ~~ #answer:do:) ifTrue:[
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   224
            ^ super raiseRequest
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   225
        ].
8683
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   226
        signal := con receiver.
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   227
        signal == self ifTrue:[
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   228
            ^ con argAt:1
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   229
        ].
8692
3abb4811f5b2 When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents: 8683
diff changeset
   230
        signal isNil ifTrue:[
3abb4811f5b2 When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents: 8683
diff changeset
   231
            self error:'nil receiver in #answer:do: - send'.
3abb4811f5b2 When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents: 8683
diff changeset
   232
        ].
8683
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   233
        (signal accepts:self) ifTrue:[
8692
3abb4811f5b2 When sending #query do a shortcut for #answer:do: - contexts if the
Stefan Vogel <sv@exept.de>
parents: 8683
diff changeset
   234
            ^ con argAt:1
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   235
        ].
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   236
        con := con findSpecialHandle:true raise:false.
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   239
    "/ no handler found - return the default value
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   240
    ^ self defaultAnswer
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
    "Modified: / 15.6.1998 / 21:27:37 / cg"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   243
    "Modified: / 25.7.1999 / 23:15:16 / stefan"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   244
!
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
raise
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   247
    "QuerySignals are proceedable by definition,
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   248
     so they should be raised with #query or #raiseRequest"
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
    ^ self shouldNotImplement
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   251
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   252
    "Created: / 23.7.1999 / 15:19:17 / stefan"
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
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   255
raiseRequest
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   256
    "redefined to use #query"
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   257
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   258
    ^ self query
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   259
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   260
    "Created: / 25.7.1999 / 23:25:59 / stefan"
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   261
! !
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   262
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   263
!Notification methodsFor:'default actions'!
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   264
4525
999e680a29ca Make error classes public.
Stefan Vogel <sv@exept.de>
parents: 4508
diff changeset
   265
defaultAction
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   266
    "the default action is to return the default value.
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   267
     Subclasses may redefine this"
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   268
8683
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   269
    |handlerBlock|
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   270
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   271
    "try per signal handler.
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   272
     I may have been created from a QuerySignal"
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   273
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   274
    (handlerBlock := signal handlerBlock) notNil ifTrue:[
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   275
        "... and call it"
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   276
        ^ handlerBlock value:self.
a162510a0408 QuerySignal generates Notifications instead of Exceptions.
Stefan Vogel <sv@exept.de>
parents: 8681
diff changeset
   277
    ].
6451
f22b12c0349a renamed #defaultValue -> #defaultResumeValue (vw54 compat.)
Claus Gittinger <cg@exept.de>
parents: 6431
diff changeset
   278
    ^ self defaultResumeValue
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   279
4550
66adee5e8491 Renamed from Query.st
Stefan Vogel <sv@exept.de>
parents: 4525
diff changeset
   280
    "Modified: / 23.7.1999 / 15:13:34 / stefan"
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   281
! !
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   282
8681
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   283
!Notification methodsFor:'testing'!
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   284
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   285
isNotification
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   286
    ^ true
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   287
! !
38aa963476a5 Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents: 8516
diff changeset
   288
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   289
!Notification class methodsFor:'documentation'!
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   290
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   291
version
8698
948da171e6e5 Make #handle - contexts also #return-able
Stefan Vogel <sv@exept.de>
parents: 8692
diff changeset
   292
    ^ '$Header: /cvs/stx/stx/libbasic/Notification.st,v 1.17 2005-01-24 12:33:39 stefan Exp $'
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   293
! !
8516
14ec9e1d3b39 example
Stefan Vogel <sv@exept.de>
parents: 6451
diff changeset
   294
4443
6928884b4c8a initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   295
Notification initialize!