001: /* Licensed to the Apache Software Foundation (ASF) under one or more
002: * contributor license agreements. See the NOTICE file distributed with
003: * this work for additional information regarding copyright ownership.
004: * The ASF licenses this file to You under the Apache License, Version 2.0
005: * (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package java.util.prefs;
018:
019: import java.io.IOException;
020: import java.io.NotSerializableException;
021: import java.io.ObjectInputStream;
022: import java.io.ObjectOutputStream;
023: import java.io.Serializable;
024: import java.util.EventObject;
025:
026: /**
027: * This is the event class to indicate some preferences has been added,
028: * deleted or updated.
029: * <p>
030: * Please note that this class cannot be serialized actually, so relevant
031: * serialization methods only throw <code>NotSerializableException</code>.
032: * </p>
033: *
034: * @see java.util.prefs.Preferences
035: * @see java.util.prefs.PreferenceChangeListener
036: *
037: * @since 1.4
038: */
039: public class PreferenceChangeEvent extends EventObject implements
040: Serializable {
041:
042: private static final long serialVersionUID = 793724513368024975L;
043:
044: private final Preferences node;
045:
046: private final String key;
047:
048: private final String value;
049:
050: /**
051: * Construct a new <code>PreferenceChangeEvent</code> instance.
052: *
053: * @param p the <code>Preferences</code> instance that this event happened,
054: * this object is considered as event's source.
055: * @param k the changed preference's key
056: * @param v the new value of the changed preference, this value can be null,
057: * which means the preference is removed.
058: */
059: public PreferenceChangeEvent(Preferences p, String k, String v) {
060: super (p);
061: node = p;
062: key = k;
063: value = v;
064: }
065:
066: /**
067: * Get the changed preference's key.
068: *
069: * @return the changed preference's key
070: */
071: public String getKey() {
072: return key;
073: }
074:
075: /**
076: * Get the new value of the changed preference, or null if this preference
077: * is removed.
078: *
079: * @return the new value of the changed preference, or null if this preference
080: * is removed.
081: */
082: public String getNewValue() {
083: return value;
084: }
085:
086: /**
087: * Get the <code>Preferences</code> instance that this event happened.
088: *
089: * @return the <code>Preferences</code> instance that this event happened.
090: */
091: public Preferences getNode() {
092: return node;
093: }
094:
095: /*
096: * This method always throws a <code>NotSerializableException</code>, because
097: * this object cannot be serialized,
098: */
099: private void writeObject(ObjectOutputStream out) throws IOException {
100: throw new NotSerializableException();
101: }
102:
103: /*
104: * This method always throws a <code>NotSerializableException</code>, because
105: * this object cannot be serialized,
106: */
107: private void readObject(ObjectInputStream in) throws IOException {
108: throw new NotSerializableException();
109: }
110: }
|