1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
Wotonomy: OpenStep design patterns for pure Java applications.
Copyright (C) 2000 Blacksmith, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see http://www.gnu.org
*/
package net.wotonomy.foundation;
import java.util.Map;
/**
* An NSNotification is a generic message that can be
* dispatched by the NSNotificationCenter.
*
* @author michael@mpowers.net
* @author $Author: cgruber $
* @version $Revision: 893 $
*/
public class NSNotification
{
public static boolean showStack = false;
protected String name;
protected Object object;
protected Map userInfo;
// for debugging only
private Throwable stackTrace;
/**
* Default constructor creates a new notification
* with no name, object, or info dictionary.
*/
public NSNotification ()
{
this( null, null, null );
}
/**
* Constructor specifying name and object.
*/
public NSNotification ( String aName, Object anObject )
{
this( aName, anObject, null );
}
/**
* Constructor specifying name, object, and a Map
* containing application specific information.
*/
public NSNotification (
String aName, Object anObject, Map aUserInfo )
{
name = aName;
object = anObject;
if ( showStack ) stackTrace = new RuntimeException();
userInfo = aUserInfo;
}
/**
* Returns the name of this notification.
*/
public String name ()
{
return name;
}
/**
* Returns the object of this notification.
*/
public Object object ()
{
return object;
}
/**
* Returns an NSDictionary that is a copy of
* the map containing application specific
* information relating to this notification,
* or null if no such data exists.
*/
public NSDictionary userInfo ()
{
if ( userInfo == null ) return null;
return new NSDictionary( userInfo );
}
/**
* Returns a Map containing application specific
* information relating to this notification,
* or null if no such data exists.
* Note: this method is not in the spec.
*/
public Map userInfoMap ()
{
return userInfo;
}
/**
* Returns the stack trace when this notification was generated,
* or null if showStack is false, which is the default.
* NOTE: This method is not part of the specification.
*/
public Throwable stackTrace()
{
return stackTrace;
}
/**
* Returns a human-readable string representation.
*/
public String toString()
{
return "[ " + name() + " : " + object() + " : " + userInfo() + " ]";
}
}
/*
* $Log$
* Revision 1.2 2006/02/16 13:15:00 cgruber
* Check in all sources in eclipse-friendly maven-enabled packages.
*
* Revision 1.7 2002/10/24 18:16:04 mpowers
* No longer generating stack trace by default.
*
* Revision 1.6 2002/06/21 22:02:47 mpowers
* Oops: Fixed NPE.
*
* Revision 1.5 2002/06/21 21:50:41 mpowers
* Added a method to get the map directly from the notification.
* Changed the internal representation to a map not a dictionary.
* We had been creating a new dictionary with each creation.
* This also allows people to modify the contents of the userInfo.
*
* Revision 1.4 2001/04/09 21:41:49 mpowers
* Better debugging.
*
* Revision 1.3 2001/02/21 18:31:07 mpowers
* Finished and tested implementation of NSNotificationCenter.
*
* Revision 1.2 2001/02/20 23:57:03 mpowers
* Implemented NSNotificationCenter.
*
* Revision 1.1.1.1 2000/12/21 15:47:36 mpowers
* Contributing wotonomy.
*
* Revision 1.3 2000/12/20 16:25:38 michael
* Added log to all files.
*
*
*/
|