1 /*
2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package java.util.prefs;
27 
28 import java.io.NotSerializableException;
29 
30 /**
31  * An event emitted by a {@code Preferences} node to indicate that
32  * a child of that node has been added or removed.<p>
33  *
34  * Note, that although NodeChangeEvent inherits Serializable interface from
35  * java.util.EventObject, it is not intended to be Serializable. Appropriate
36  * serialization methods are implemented to throw NotSerializableException.
37  *
38  * @author  Josh Bloch
39  * @see     Preferences
40  * @see     NodeChangeListener
41  * @see     PreferenceChangeEvent
42  * @since   1.4
43  * @serial  exclude
44  */
45 
46 public class NodeChangeEvent extends java.util.EventObject {
47     /**
48      * The node that was added or removed.
49      */
50     private transient Preferences child;
51 
52     /**
53      * Constructs a new {@code NodeChangeEvent} instance.
54      *
55      * @param parent  The parent of the node that was added or removed.
56      * @param child   The node that was added or removed.
57      */
NodeChangeEvent(Preferences parent, Preferences child)58     public NodeChangeEvent(Preferences parent, Preferences child) {
59         super(parent);
60         this.child = child;
61     }
62 
63     /**
64      * Returns the parent of the node that was added or removed.
65      *
66      * @return  The parent Preferences node whose child was added or removed
67      */
getParent()68     public Preferences getParent() {
69         return (Preferences) getSource();
70     }
71 
72     /**
73      * Returns the node that was added or removed.
74      *
75      * @return  The node that was added or removed.
76      */
getChild()77     public Preferences getChild() {
78         return child;
79     }
80 
81     /**
82      * Throws NotSerializableException, since NodeChangeEvent objects are not
83      * intended to be serializable.
84      */
writeObject(java.io.ObjectOutputStream out)85      private void writeObject(java.io.ObjectOutputStream out)
86                                                throws NotSerializableException {
87          throw new NotSerializableException("Not serializable.");
88      }
89 
90     /**
91      * Throws NotSerializableException, since NodeChangeEvent objects are not
92      * intended to be serializable.
93      */
readObject(java.io.ObjectInputStream in)94      private void readObject(java.io.ObjectInputStream in)
95                                                throws NotSerializableException {
96          throw new NotSerializableException("Not serializable.");
97      }
98 
99     // Defined so that this class isn't flagged as a potential problem when
100     // searches for missing serialVersionUID fields are done.
101     private static final long serialVersionUID = 8068949086596572957L;
102 }
103