common code with Query
authorClaus Gittinger <cg@exept.de>
Fri, 01 Mar 2002 15:33:58 +0100
changeset 6431 584b4b6e231c
parent 6430 9a1580465dd2
child 6432 5a3c5155237e
common code with Query
Notification.st
--- a/Notification.st	Fri Mar 01 14:46:44 2002 +0100
+++ b/Notification.st	Fri Mar 01 15:33:58 2002 +0100
@@ -54,14 +54,14 @@
 
 examples 
 "
-  an up-query from a deeply nested operation to a higher level:
+  an up-notification from a deeply nested operation to a higher level:
                                                                         [exBegin]
     |zero|
 
     zero := 0.
-    Notification handle:[:ex |
-        Transcript showCR:'query'.
-        ex proceedWith:true
+    Notification handle:[:n |
+        Transcript showCR:'Please note that: ' , n description.
+        n proceedWith:true
     ] do:[
         'nesting'.
         [
@@ -72,119 +72,14 @@
                 ] do:[
                     [
                         1 // zero.  'an error which is caught in the handler'.
-                        (Notification query) == true ifTrue:[
-                            Transcript showCR:'query says: ok'.
-                        ] ifFalse:[
-                            Transcript showCR:'query says: no'
-                        ]
+                        Notification notify:'hello world'
                     ] value
                 ]
             ] value
         ] value
     ]
                                                                         [exEnd]
-  for lazy typists, a more compact interface is also provided
-  (which is also easier to read):
-                                                                        [exBegin]
-    Notification answer:true do:[
-        'nesting'.
-        [
-            [
-                (Notification query) == true ifTrue:[
-                    Transcript showCR:'query says: ok'.
-                ] ifFalse:[
-                    Transcript showCR:'query says: no'
-                ]
-            ] value
-        ] value
-    ]
-                                                                        [exEnd]
-  an up-query from a deeply nested operation, for which there
-  is no handler:
-  (notice, this would not work with normal signals, which would raise
-   another unhandled exception-exception;
-   also notice the == check #raise's return value being true,
-   instead of a simple ifTrue; this handles a nil-value from
-   the unhandled query)
-                                                                        [exBegin]
-    |zero|
-
-    zero := 0.
-    [
-        'nesting'.
-        [
-            [
-                Object errorSignal handle:[:ex |
-                    Transcript showCR:'some error: ' , ex errorString.
-                    ex proceed
-                ] do:[
-                    [
-                        1 // zero.  'an error which is caught in the handler'.
-                        (Notification raise) == true ifTrue:[
-                            Transcript showCR:'query says: ok'.
-                        ] ifFalse:[
-                            Transcript showCR:'query says: no'
-                        ]
-                    ] value
-                ]
-            ] value
-        ] value
-    ] value
-                                                                         [exEnd]
-  counter-example, just to show that things would not work this way
-  with regular signals:
-                                                                        [exBegin]
-    |signal|
-
-    signal := Signal new.
-    'nesting deeply'.
-    [
-        [
-            [
-                [
-                    [
-                        (signal raise) == true ifTrue:[
-                            Transcript showCR:'query says: ok'.
-                        ] ifFalse:[
-                            Transcript showCR:'query says: no'
-                        ]
-                    ] value
-                ] value
-            ] value
-        ] value
-    ] value
-                                                                         [exEnd]
-
-   except, by handling the unhandled exception
-   (but we think, that querySignals are easier to use and
-    better document the intent):
-                                                                        [exBegin]
-    |signal|
-
-    signal := Signal new.
-    'nesting deeply'.
-    [
-        [
-            [
-                [
-                    [
-                        Signal noHandlerSignal handle:[:ex |
-                            ex proceedWith:nil
-                        ] do:[
-                            (signal raise) == true ifTrue:[
-                                Transcript showCR:'query says: ok'.
-                            ] ifFalse:[
-                                Transcript showCR:'query says: no'
-                            ]
-                        ]
-                    ] value
-                ] value
-            ] value
-        ] value
-    ] value
-                                                                         [exEnd]
 "
-
 ! !
 
 !Notification class methodsFor:'initialization'!
@@ -290,6 +185,13 @@
     "Created: / 23.7.1999 / 14:59:50 / stefan"
 !
 
+notify:aMessageString
+    "raise the query - return the handlers value, or the default
+     value, if there is no handler."
+
+    ^ self raiseRequestErrorString:aMessageString
+!
+
 query
     "raise the query - return the handlers value, or the default
      value, if there is no handler.
@@ -342,14 +244,20 @@
     "the default action is to return the default value.
      Subclasses may redefine this"
 
-    ^ nil
+    ^ self defaultValue
 
     "Modified: / 23.7.1999 / 15:13:34 / stefan"
+!
+
+defaultValue
+    "the default actions default return value."
+
+    ^ nil
 ! !
 
 !Notification class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Notification.st,v 1.10 2001-11-17 10:01:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Notification.st,v 1.11 2002-03-01 14:33:58 cg Exp $'
 ! !
 Notification initialize!