author | darcy |
Tue, 24 Sep 2019 18:25:54 -0700 | |
changeset 58309 | c6f8b2c3dc66 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.beans; |
|
27 |
||
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
28 |
import java.util.EventObject; |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
29 |
|
2 | 30 |
/** |
31 |
* A "PropertyChange" event gets delivered whenever a bean changes a "bound" |
|
32 |
* or "constrained" property. A PropertyChangeEvent object is sent as an |
|
33 |
* argument to the PropertyChangeListener and VetoableChangeListener methods. |
|
34 |
* <P> |
|
35 |
* Normally PropertyChangeEvents are accompanied by the name and the old |
|
36 |
* and new value of the changed property. If the new value is a primitive |
|
37 |
* type (such as int or boolean) it must be wrapped as the |
|
38 |
* corresponding java.lang.* Object type (such as Integer or Boolean). |
|
39 |
* <P> |
|
40 |
* Null values may be provided for the old and the new values if their |
|
41 |
* true values are not known. |
|
42 |
* <P> |
|
43 |
* An event source may send a null object as the name to indicate that an |
|
44 |
* arbitrary set of if its properties have changed. In this case the |
|
45 |
* old and new values should also be null. |
|
25130
adfaa02ea516
8044855: Add missing @since tag under java.beans.*
henryjen
parents:
11089
diff
changeset
|
46 |
* |
adfaa02ea516
8044855: Add missing @since tag under java.beans.*
henryjen
parents:
11089
diff
changeset
|
47 |
* @since 1.1 |
2 | 48 |
*/ |
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
49 |
public class PropertyChangeEvent extends EventObject { |
2482
77898184e343
4769844: classes in java.beans that are serializable but don't define serialVersionUID
malenkov
parents:
2
diff
changeset
|
50 |
private static final long serialVersionUID = 7042693688939648123L; |
2 | 51 |
|
52 |
/** |
|
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
53 |
* Constructs a new {@code PropertyChangeEvent}. |
2 | 54 |
* |
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
55 |
* @param source the bean that fired the event |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
56 |
* @param propertyName the programmatic name of the property that was changed |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
57 |
* @param oldValue the old value of the property |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
58 |
* @param newValue the new value of the property |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
59 |
* |
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
60 |
* @throws IllegalArgumentException if {@code source} is {@code null} |
2 | 61 |
*/ |
62 |
public PropertyChangeEvent(Object source, String propertyName, |
|
11089
e23e7a5faad5
7087429: Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source
malenkov
parents:
5506
diff
changeset
|
63 |
Object oldValue, Object newValue) { |
2 | 64 |
super(source); |
65 |
this.propertyName = propertyName; |
|
66 |
this.newValue = newValue; |
|
67 |
this.oldValue = oldValue; |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Gets the programmatic name of the property that was changed. |
|
72 |
* |
|
73 |
* @return The programmatic name of the property that was changed. |
|
74 |
* May be null if multiple properties have changed. |
|
75 |
*/ |
|
76 |
public String getPropertyName() { |
|
77 |
return propertyName; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Gets the new value for the property, expressed as an Object. |
|
82 |
* |
|
83 |
* @return The new value for the property, expressed as an Object. |
|
84 |
* May be null if multiple properties have changed. |
|
85 |
*/ |
|
86 |
public Object getNewValue() { |
|
87 |
return newValue; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Gets the old value for the property, expressed as an Object. |
|
92 |
* |
|
93 |
* @return The old value for the property, expressed as an Object. |
|
94 |
* May be null if multiple properties have changed. |
|
95 |
*/ |
|
96 |
public Object getOldValue() { |
|
97 |
return oldValue; |
|
98 |
} |
|
99 |
||
100 |
/** |
|
101 |
* Sets the propagationId object for the event. |
|
102 |
* |
|
103 |
* @param propagationId The propagationId object for the event. |
|
104 |
*/ |
|
105 |
public void setPropagationId(Object propagationId) { |
|
106 |
this.propagationId = propagationId; |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* The "propagationId" field is reserved for future use. In Beans 1.0 |
|
111 |
* the sole requirement is that if a listener catches a PropertyChangeEvent |
|
112 |
* and then fires a PropertyChangeEvent of its own, then it should |
|
113 |
* make sure that it propagates the propagationId field from its |
|
114 |
* incoming event to its outgoing event. |
|
115 |
* |
|
116 |
* @return the propagationId object associated with a bound/constrained |
|
117 |
* property update. |
|
118 |
*/ |
|
119 |
public Object getPropagationId() { |
|
120 |
return propagationId; |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* name of the property that changed. May be null, if not known. |
|
125 |
* @serial |
|
126 |
*/ |
|
127 |
private String propertyName; |
|
128 |
||
129 |
/** |
|
130 |
* New value for property. May be null if not known. |
|
131 |
* @serial |
|
132 |
*/ |
|
58309
c6f8b2c3dc66
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents:
47216
diff
changeset
|
133 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 134 |
private Object newValue; |
135 |
||
136 |
/** |
|
137 |
* Previous value for property. May be null if not known. |
|
138 |
* @serial |
|
139 |
*/ |
|
58309
c6f8b2c3dc66
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents:
47216
diff
changeset
|
140 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 141 |
private Object oldValue; |
142 |
||
143 |
/** |
|
144 |
* Propagation ID. May be null. |
|
145 |
* @serial |
|
146 |
* @see #getPropagationId |
|
147 |
*/ |
|
58309
c6f8b2c3dc66
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents:
47216
diff
changeset
|
148 |
@SuppressWarnings("serial") // Not statically typed as Serializable |
2 | 149 |
private Object propagationId; |
4960
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
150 |
|
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
151 |
/** |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
152 |
* Returns a string representation of the object. |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
153 |
* |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
154 |
* @return a string representation of the object |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
155 |
* |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
156 |
* @since 1.7 |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
157 |
*/ |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
158 |
public String toString() { |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
159 |
StringBuilder sb = new StringBuilder(getClass().getName()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
160 |
sb.append("[propertyName=").append(getPropertyName()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
161 |
appendTo(sb); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
162 |
sb.append("; oldValue=").append(getOldValue()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
163 |
sb.append("; newValue=").append(getNewValue()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
164 |
sb.append("; propagationId=").append(getPropagationId()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
165 |
sb.append("; source=").append(getSource()); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
166 |
return sb.append("]").toString(); |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
167 |
} |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
168 |
|
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
169 |
void appendTo(StringBuilder sb) { |
99ac74ca2f2f
4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents:
2482
diff
changeset
|
170 |
} |
2 | 171 |
} |