Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/beans/PropertyChangeEvent.java
38829 views
/*1* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.beans;2627import java.util.EventObject;2829/**30* A "PropertyChange" event gets delivered whenever a bean changes a "bound"31* or "constrained" property. A PropertyChangeEvent object is sent as an32* argument to the PropertyChangeListener and VetoableChangeListener methods.33* <P>34* Normally PropertyChangeEvents are accompanied by the name and the old35* and new value of the changed property. If the new value is a primitive36* type (such as int or boolean) it must be wrapped as the37* corresponding java.lang.* Object type (such as Integer or Boolean).38* <P>39* Null values may be provided for the old and the new values if their40* true values are not known.41* <P>42* An event source may send a null object as the name to indicate that an43* arbitrary set of if its properties have changed. In this case the44* old and new values should also be null.45*/46public class PropertyChangeEvent extends EventObject {47private static final long serialVersionUID = 7042693688939648123L;4849/**50* Constructs a new {@code PropertyChangeEvent}.51*52* @param source the bean that fired the event53* @param propertyName the programmatic name of the property that was changed54* @param oldValue the old value of the property55* @param newValue the new value of the property56*57* @throws IllegalArgumentException if {@code source} is {@code null}58*/59public PropertyChangeEvent(Object source, String propertyName,60Object oldValue, Object newValue) {61super(source);62this.propertyName = propertyName;63this.newValue = newValue;64this.oldValue = oldValue;65}6667/**68* Gets the programmatic name of the property that was changed.69*70* @return The programmatic name of the property that was changed.71* May be null if multiple properties have changed.72*/73public String getPropertyName() {74return propertyName;75}7677/**78* Gets the new value for the property, expressed as an Object.79*80* @return The new value for the property, expressed as an Object.81* May be null if multiple properties have changed.82*/83public Object getNewValue() {84return newValue;85}8687/**88* Gets the old value for the property, expressed as an Object.89*90* @return The old value for the property, expressed as an Object.91* May be null if multiple properties have changed.92*/93public Object getOldValue() {94return oldValue;95}9697/**98* Sets the propagationId object for the event.99*100* @param propagationId The propagationId object for the event.101*/102public void setPropagationId(Object propagationId) {103this.propagationId = propagationId;104}105106/**107* The "propagationId" field is reserved for future use. In Beans 1.0108* the sole requirement is that if a listener catches a PropertyChangeEvent109* and then fires a PropertyChangeEvent of its own, then it should110* make sure that it propagates the propagationId field from its111* incoming event to its outgoing event.112*113* @return the propagationId object associated with a bound/constrained114* property update.115*/116public Object getPropagationId() {117return propagationId;118}119120/**121* name of the property that changed. May be null, if not known.122* @serial123*/124private String propertyName;125126/**127* New value for property. May be null if not known.128* @serial129*/130private Object newValue;131132/**133* Previous value for property. May be null if not known.134* @serial135*/136private Object oldValue;137138/**139* Propagation ID. May be null.140* @serial141* @see #getPropagationId142*/143private Object propagationId;144145/**146* Returns a string representation of the object.147*148* @return a string representation of the object149*150* @since 1.7151*/152public String toString() {153StringBuilder sb = new StringBuilder(getClass().getName());154sb.append("[propertyName=").append(getPropertyName());155appendTo(sb);156sb.append("; oldValue=").append(getOldValue());157sb.append("; newValue=").append(getNewValue());158sb.append("; propagationId=").append(getPropagationId());159sb.append("; source=").append(getSource());160return sb.append("]").toString();161}162163void appendTo(StringBuilder sb) {164}165}166167168