OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / main / java / java / util / prefs / PreferenceChangeEvent.java
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package java.util.prefs;
18
19 import java.io.IOException;
20 import java.io.NotSerializableException;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23 import java.io.Serializable;
24 import java.util.EventObject;
25
26 /**
27  * This is the event class to indicate that a preference has been added, deleted
28  * or updated.
29  * <p>
30  * Please note that although the class is marked as {@code Serializable} by
31  * inheritance from {@code EventObject}, this type is not intended to be serialized
32  * so the serialization methods do nothing but throw a {@code NotSerializableException}.
33  *
34  * @see java.util.prefs.Preferences
35  * @see java.util.prefs.PreferenceChangeListener
36  *
37  * @since 1.4
38  */
39 public class PreferenceChangeEvent extends EventObject implements Serializable {
40
41     private static final long serialVersionUID = 793724513368024975L;
42
43     private final Preferences node;
44
45     private final String key;
46
47     private final String value;
48
49     /**
50      * Construct a new {@code PreferenceChangeEvent} instance.
51      *
52      * @param p
53      *            the {@code Preferences} instance that fired this event; this object is
54      *            considered as the event's source.
55      * @param k
56      *            the changed preference key.
57      * @param v
58      *            the new value of the changed preference, this value can be
59      *            {@code null}, which means the preference has been removed.
60      */
61     public PreferenceChangeEvent(Preferences p, String k, String v) {
62         super(p);
63         node = p;
64         key = k;
65         value = v;
66     }
67
68     /**
69      * Gets the key of the changed preference.
70      *
71      * @return the changed preference's key.
72      */
73     public String getKey() {
74         return key;
75     }
76
77     /**
78      * Gets the new value of the changed preference or {@code null} if the
79      * preference has been removed.
80      *
81      * @return the new value of the changed preference or {@code null} if the
82      *         preference has been removed.
83      */
84     public String getNewValue() {
85         return value;
86     }
87
88     /**
89      * Gets the {@code Preferences} instance that fired this event.
90      *
91      * @return the {@code Preferences} instance that fired this event.
92      */
93     public Preferences getNode() {
94         return node;
95     }
96
97     /**
98      * This method always throws a <code>NotSerializableException</code>,
99      * because this object cannot be serialized,
100      */
101     private void writeObject(ObjectOutputStream out) throws IOException {
102         throw new NotSerializableException();
103     }
104
105     /**
106      * This method always throws a <code>NotSerializableException</code>,
107      * because this object cannot be serialized,
108      */
109     private void readObject(ObjectInputStream in) throws IOException{
110         throw new NotSerializableException();
111     }
112 }