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