PropertyChangeEvent.java revision 6b811c5daec1b28e6f63b57f98a032236f2c3cf7
1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package java.beans;
19
20import java.util.EventObject;
21
22/**
23 * An event that indicates that a constraint or a boundary of a property has
24 * changed.
25 */
26public class PropertyChangeEvent extends EventObject {
27
28    private static final long serialVersionUID = 7042693688939648123L;
29
30    String propertyName;
31
32    Object oldValue;
33
34    Object newValue;
35
36    Object propagationId;
37
38    /**
39     * The constructor used to create a new {@code PropertyChangeEvent}.
40     *
41     * @param source
42     *            the changed bean.
43     * @param propertyName
44     *            the changed property, or <code>null</code> to indicate an
45     *            unspecified set of the properties has changed.
46     * @param oldValue
47     *            the previous value of the property, or <code>null</code> if
48     *            the <code>propertyName</code> is <code>null</code> or the
49     *            previous value is unknown.
50     * @param newValue
51     *            the new value of the property, or <code>null</code> if the
52     *            <code>propertyName</code> is <code>null</code> or the new
53     *            value is unknown.
54     */
55    public PropertyChangeEvent(Object source, String propertyName,
56            Object oldValue, Object newValue) {
57        super(source);
58
59        this.propertyName = propertyName;
60        this.oldValue = oldValue;
61        this.newValue = newValue;
62    }
63
64    /**
65     * Returns the name of the property that has changed. If an unspecified set
66     * of properties has changed it returns null.
67     *
68     * @return the name of the property that has changed, or null.
69     */
70    public String getPropertyName() {
71        return propertyName;
72    }
73
74    /**
75     * Sets the propagationId object.
76     *
77     * @see #getPropagationId()
78     */
79    public void setPropagationId(Object propagationId) {
80        this.propagationId = propagationId;
81    }
82
83    /**
84     * Returns the propagationId object. This is reserved for future use. Beans
85     * 1.0 demands that a listener receiving this property and then sending its
86     * own PropertyChangeEvent sets the received propagationId on the new
87     * PropertyChangeEvent's propagationId field.
88     *
89     * @return the propagationId object.
90     */
91    public Object getPropagationId() {
92        return propagationId;
93    }
94
95    /**
96     * Returns the old value that the property had. If the old value is unknown
97     * this method returns null.
98     *
99     * @return the old property value or null.
100     */
101    public Object getOldValue() {
102        return oldValue;
103    }
104
105    /**
106     * Returns the new value that the property now has. If the new value is
107     * unknown this method returns null.
108     *
109     * @return the old property value or null.
110     */
111    public Object getNewValue() {
112        return newValue;
113    }
114}
115