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
17package java.util.prefs;
18
19import java.io.Serializable;
20import java.util.EventObject;
21import java.io.ObjectOutputStream;
22import java.io.ObjectInputStream;
23import java.io.NotSerializableException;
24import java.io.IOException;
25
26/**
27 * This is the event class to indicate that one child of the preference node has
28 * been added or deleted.
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.NodeChangeListener
36 *
37 * @since 1.4
38 */
39public class NodeChangeEvent extends EventObject implements Serializable {
40
41    private static final long serialVersionUID = 8068949086596572957L;
42
43    private final Preferences parent;
44    private final Preferences child;
45
46    /**
47     * Constructs a new {@code NodeChangeEvent} instance.
48     *
49     * @param p
50     *            the {@code Preferences} instance that fired this event; this object is
51     *            considered as the event source.
52     * @param c
53     *            the child {@code Preferences} instance that was added or deleted.
54     */
55    public NodeChangeEvent (Preferences p, Preferences c) {
56        super(p);
57        parent = p;
58        child = c;
59    }
60
61    /**
62     * Gets the {@code Preferences} instance that fired this event.
63     *
64     * @return the {@code Preferences} instance that fired this event.
65     */
66    public Preferences getParent() {
67        return parent;
68    }
69
70    /**
71     * Gets the child {@code Preferences} node that was added or removed.
72     *
73     * @return the added or removed child {@code Preferences} node.
74     */
75    public Preferences getChild() {
76        return child;
77    }
78
79    /**
80     * This method always throws a <code>NotSerializableException</code>,
81     * because this object cannot be serialized,
82     */
83    private void writeObject (ObjectOutputStream out) throws IOException {
84        throw new NotSerializableException();
85    }
86
87    /**
88     * This method always throws a <code>NotSerializableException</code>,
89     * because this object cannot be serialized,
90     */
91    private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
92        throw new NotSerializableException();
93    }
94}
95