src/java.prefs/share/classes/java/util/prefs/Preferences.java
author stefank
Thu, 22 Feb 2018 18:35:04 +0100
changeset 49045 9b556b613a07
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198509: Move satisfy_failed_metadata_allocation out from CollectorPolicy Reviewed-by: sjohanss, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29397
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.prefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
    35
import java.util.ServiceLoader;
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
    36
import java.util.ServiceConfigurationError;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// These imports needed only as a workaround for a JavaDoc bug
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.RuntimePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.Long;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.Float;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.lang.Double;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A node in a hierarchical collection of preference data.  This class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * allows applications to store and retrieve user and system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * preference and configuration data.  This data is stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * persistently in an implementation-dependent backing store.  Typical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * implementations include flat files, OS-specific registries,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * directory servers and SQL databases.  The user of this class needn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * be concerned with details of the backing store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>There are two separate trees of preference nodes, one for user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * preferences and one for system preferences.  Each user has a separate user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * preference tree, and all users in a given system share the same system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * preference tree.  The precise description of "user" and "system" will vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * from implementation to implementation.  Typical information stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * user preference tree might include font choice, color choice, or preferred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * window location and size for a particular application.  Typical information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * stored in the system preference tree might include installation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * configuration data for an application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>Nodes in a preference tree are named in a similar fashion to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * directories in a hierarchical file system.   Every node in a preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * tree has a <i>node name</i> (which is not necessarily unique),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * a unique <i>absolute path name</i>, and a path name <i>relative</i> to each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * ancestor including itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>The root node has a node name of the empty string ("").  Every other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * node has an arbitrary node name, specified at the time it is created.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * only restrictions on this name are that it cannot be the empty string, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * it cannot contain the slash character ('/').
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
    75
 * <p>The root node has an absolute path name of {@code "/"}.  Children of
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
    76
 * the root node have absolute path names of {@code "/" + }<i>&lt;node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * name&gt;</i>.  All other nodes have absolute path names of <i>&lt;parent's
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
    78
 * absolute path name&gt;</i>{@code  + "/" + }<i>&lt;node name&gt;</i>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Note that all absolute path names begin with the slash character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>A node <i>n</i>'s path name relative to its ancestor <i>a</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * is simply the string that must be appended to <i>a</i>'s absolute path name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * in order to form <i>n</i>'s absolute path name, with the initial slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * character (if present) removed.  Note that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <li>No relative path names begin with the slash character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <li>Every node's path name relative to itself is the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <li>Every node's path name relative to its parent is its node name (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * for the root node, which does not have a parent).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <li>Every node's path name relative to the root is its absolute path name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * with the initial slash character removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>Note finally that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <li>No path name contains multiple consecutive slash characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <li>No path name with the exception of the root's absolute path name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * ends in the slash character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <li>Any string that conforms to these two rules is a valid path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <p>All of the methods that modify preferences data are permitted to operate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * asynchronously; they may return immediately, and changes will eventually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * propagate to the persistent backing store with an implementation-dependent
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   105
 * delay.  The {@code flush} method may be used to synchronously force
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * updates to the backing store.  Normal termination of the Java Virtual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * Machine will <i>not</i> result in the loss of pending updates -- an explicit
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   108
 * {@code flush} invocation is <i>not</i> required upon termination to ensure
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * that pending updates are made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   111
 * <p>All of the methods that read preferences from a {@code Preferences}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * object require the invoker to provide a default value.  The default value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * returned if no value has been previously set <i>or if the backing store is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * unavailable</i>.  The intent is to allow applications to operate, albeit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * with slightly degraded functionality, even if the backing store becomes
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   116
 * unavailable.  Several methods, like {@code flush}, have semantics that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * prevent them from operating if the backing store is unavailable.  Ordinary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * applications should have no need to invoke any of these methods, which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * be identified by the fact that they are declared to throw {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * BackingStoreException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <p>The methods in this class may be invoked concurrently by multiple threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * in a single JVM without the need for external synchronization, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * results will be equivalent to some serial execution.  If this class is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * concurrently <i>by multiple JVMs</i> that store their preference data in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * the same backing store, the data store will not be corrupted, but no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * other guarantees are made concerning the consistency of the preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * <p>This class contains an export/import facility, allowing preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * to be "exported" to an XML document, and XML documents representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * preferences to be "imported" back into the system.  This facility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * may be used to back up all or part of a preference tree, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * subsequently restore from the backup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <p>The XML document has the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   137
 * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   138
 * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   139
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Note that the system URI (http://java.sun.com/dtd/preferences.dtd) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <i>not</i> accessed when exporting or importing preferences; it merely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * serves as a string to uniquely identify the DTD, which is:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   143
 * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   144
 *    <?xml version="1.0" encoding="UTF-8"?>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   146
 *    <!-- DTD for a Preferences tree. -->
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   148
 *    <!-- The preferences element is at the root of an XML document
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   149
 *         representing a Preferences tree. -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   150
 *    <!ELEMENT preferences (root)>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   152
 *    <!-- The preferences element contains an optional version attribute,
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   153
 *          which specifies version of DTD. -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   154
 *    <!ATTLIST preferences EXTERNAL_XML_VERSION CDATA "0.0" >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   156
 *    <!-- The root element has a map representing the root's preferences
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   157
 *         (if any), and one node for each child of the root (if any). -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   158
 *    <!ELEMENT root (map, node*) >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   160
 *    <!-- Additionally, the root contains a type attribute, which
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   161
 *         specifies whether it's the system or user root. -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   162
 *    <!ATTLIST root
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   163
 *              type (system|user) #REQUIRED >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   165
 *    <!-- Each node has a map representing its preferences (if any),
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   166
 *         and one node for each child (if any). -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   167
 *    <!ELEMENT node (map, node*) >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   169
 *    <!-- Additionally, each node has a name attribute -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   170
 *    <!ATTLIST node
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   171
 *              name CDATA #REQUIRED >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   173
 *    <!-- A map represents the preferences stored at a node (if any). -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   174
 *    <!ELEMENT map (entry*) >
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   176
 *    <!-- An entry represents a single preference, which is simply
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   177
 *          a key-value pair. -->
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   178
 *    <!ELEMENT entry EMPTY >
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   179
 *    <!ATTLIST entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *              key   CDATA #REQUIRED
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   181
 *              value CDATA #REQUIRED >
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
   182
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   184
 * Every {@code Preferences} implementation must have an associated {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * PreferencesFactory} implementation.  Every Java(TM) SE implementation must provide
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   186
 * some means of specifying which {@code PreferencesFactory} implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * is used to generate the root preferences nodes.  This allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * administrator to replace the default preferences implementation with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * alternative implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *
44247
b128e61f230e 8176221: Preferences docs contain reference to Sun's JRE
bpb
parents: 37782
diff changeset
   191
 * @implNote
b128e61f230e 8176221: Preferences docs contain reference to Sun's JRE
bpb
parents: 37782
diff changeset
   192
 * The {@code PreferencesFactory} implementation is located as follows:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * <li><p>If the system property
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   197
 * {@code java.util.prefs.PreferencesFactory} is defined, then it is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * taken to be the fully-qualified name of a class implementing the
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   199
 * {@code PreferencesFactory} interface.  The class is loaded and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * instantiated; if this process fails then an unspecified error is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * thrown.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   203
 * <li><p> If a {@code PreferencesFactory} implementation class file
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * has been installed in a jar file that is visible to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * {@link java.lang.ClassLoader#getSystemClassLoader system class loader},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * and that jar file contains a provider-configuration file named
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   207
 * {@code java.util.prefs.PreferencesFactory} in the resource
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   208
 * directory {@code META-INF/services}, then the first class name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * specified in that file is taken.  If more than one such jar file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * provided, the first one found will be used.  The class is loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * and instantiated; if this process fails then an unspecified error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * is thrown.  </p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * <li><p>Finally, if neither the above-mentioned system property nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * an extension jar file is provided, then the system-wide default
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   216
 * {@code PreferencesFactory} implementation for the underlying
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * platform is loaded and instantiated.</p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
public abstract class Preferences {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    private static final PreferencesFactory factory = factory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private static PreferencesFactory factory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // 1. Try user-specified system property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        String factoryName = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    return System.getProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                        "java.util.prefs.PreferencesFactory");}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (factoryName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            // FIXME: This code should be run in a doPrivileged and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            // not use the context classloader, to avoid being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            // dependent on the invoking thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            // Checking AllPermission also seems wrong.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            try {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   241
                @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   242
                Object result =Class.forName(factoryName, false,
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   243
                                             ClassLoader.getSystemClassLoader())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    .newInstance();
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   245
                return (PreferencesFactory)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    // workaround for javaws, plugin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    // load factory class using non-system classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        sm.checkPermission(new java.security.AllPermission());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    }
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   254
                    @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   255
                    Object result = Class.forName(factoryName, false,
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   256
                                                  Thread.currentThread()
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   257
                                                  .getContextClassLoader())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        .newInstance();
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   259
                    return (PreferencesFactory) result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                } catch (Exception e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   261
                    throw new InternalError(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                        "Can't instantiate Preferences factory "
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   263
                        + factoryName, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            new PrivilegedAction<PreferencesFactory>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                public PreferencesFactory run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    return factory1();}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private static PreferencesFactory factory1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // 2. Try service provider interface
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   276
        Iterator<PreferencesFactory> itr = ServiceLoader
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   277
            .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   278
            .iterator();
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   279
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        // choose first provider instance
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   281
        while (itr.hasNext()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            try {
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   283
                return itr.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            } catch (ServiceConfigurationError sce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                if (sce.getCause() instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    // Ignore the security exception, try the next provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                throw sce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // 3. Use platform-specific system-wide default
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   294
        String osName = System.getProperty("os.name");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   295
        String platformFactory;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   296
        if (osName.startsWith("Windows")) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   297
            platformFactory = "java.util.prefs.WindowsPreferencesFactory";
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12047
diff changeset
   298
        } else if (osName.contains("OS X")) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   299
            platformFactory = "java.util.prefs.MacOSXPreferencesFactory";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   300
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   301
            platformFactory = "java.util.prefs.FileSystemPreferencesFactory";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   302
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        try {
37782
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   304
            @SuppressWarnings("deprecation")
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   305
            Object result = Class.forName(platformFactory, false,
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   306
                                          Preferences.class.getClassLoader()).newInstance();
ad8fe7507ecc 6850612: Deprecate Class.newInstance since it violates the checked exception language contract
darcy
parents: 32037
diff changeset
   307
            return (PreferencesFactory) result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } catch (Exception e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   309
            throw new InternalError(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                "Can't instantiate platform default Preferences factory "
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   311
                + platformFactory, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Maximum length of string allowed as a key (80 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public static final int MAX_KEY_LENGTH = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * Maximum length of string allowed as a value (8192 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public static final int MAX_VALUE_LENGTH = 8*1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Maximum length of a node name (80 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public static final int MAX_NAME_LENGTH = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the preference node from the calling user's preference tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * that is associated (by convention) with the specified class's package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * The convention is as follows: the absolute path name of the node is the
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   334
     * fully qualified package name, preceded by a slash ({@code '/'}), and
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   335
     * with each period ({@code '.'}) replaced by a slash.  For example the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * absolute path name of the node associated with the class
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   337
     * {@code com.acme.widget.Foo} is {@code /com/acme/widget}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <p>This convention does not apply to the unnamed package, whose
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   340
     * associated preference node is {@code <unnamed>}.  This node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * is not intended for long term use, but for convenience in the early
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * development of programs that do not yet belong to a package, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * for "throwaway" programs.  <i>Valuable data should not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * at this node as it is shared by all programs that use it.</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   346
     * <p>A class {@code Foo} wishing to access preferences pertaining to its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * package can obtain a preference node as follows: <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *    static Preferences prefs = Preferences.userNodeForPackage(Foo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * This idiom obviates the need for using a string to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * preferences node and decreases the likelihood of a run-time failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * (If the class name is misspelled, it will typically result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * compile-time error.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <p>Invoking this method will result in the creation of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * node and its ancestors if they do not already exist.  If the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * node did not exist prior to this call, this node and any ancestors that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * were created by this call are not guaranteed to become permanent until
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   359
     * the {@code flush} method is called on the returned node (or one of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param c the class for whose package a user preference node is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @return the user preference node associated with the package of which
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   364
     *         {@code c} is a member.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   365
     * @throws NullPointerException if {@code c} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @throws SecurityException if a security manager is present and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   367
     *         it denies {@code RuntimePermission("preferences")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public static Preferences userNodeForPackage(Class<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return userRoot().node(nodeName(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Returns the preference node from the system preference tree that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * associated (by convention) with the specified class's package.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * convention is as follows: the absolute path name of the node is the
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   378
     * fully qualified package name, preceded by a slash ({@code '/'}), and
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   379
     * with each period ({@code '.'}) replaced by a slash.  For example the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * absolute path name of the node associated with the class
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   381
     * {@code com.acme.widget.Foo} is {@code /com/acme/widget}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <p>This convention does not apply to the unnamed package, whose
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   384
     * associated preference node is {@code <unnamed>}.  This node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * is not intended for long term use, but for convenience in the early
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * development of programs that do not yet belong to a package, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * for "throwaway" programs.  <i>Valuable data should not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * at this node as it is shared by all programs that use it.</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   390
     * <p>A class {@code Foo} wishing to access preferences pertaining to its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * package can obtain a preference node as follows: <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *  static Preferences prefs = Preferences.systemNodeForPackage(Foo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * This idiom obviates the need for using a string to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * preferences node and decreases the likelihood of a run-time failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * (If the class name is misspelled, it will typically result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * compile-time error.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>Invoking this method will result in the creation of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * node and its ancestors if they do not already exist.  If the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * node did not exist prior to this call, this node and any ancestors that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * were created by this call are not guaranteed to become permanent until
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   403
     * the {@code flush} method is called on the returned node (or one of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param c the class for whose package a system preference node is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @return the system preference node associated with the package of which
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   408
     *         {@code c} is a member.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   409
     * @throws NullPointerException if {@code c} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @throws SecurityException if a security manager is present and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   411
     *         it denies {@code RuntimePermission("preferences")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public static Preferences systemNodeForPackage(Class<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return systemRoot().node(nodeName(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Returns the absolute path name of the node corresponding to the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @throws IllegalArgumentException if the package has node preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *         node associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 10355
diff changeset
   425
    private static String nodeName(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (c.isArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                "Arrays have no associated preferences node.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        String className = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int pkgEndIndex = className.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if (pkgEndIndex < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            return "/<unnamed>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        String packageName = className.substring(0, pkgEndIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        return "/" + packageName.replace('.', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * This permission object represents the permission required to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * access to the user or system root (which in turn allows for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * other operations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    private static Permission prefsPerm = new RuntimePermission("preferences");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Returns the root preference node for the calling user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return the root preference node for the calling user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @throws SecurityException If a security manager is present and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   449
     *         it denies {@code RuntimePermission("preferences")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public static Preferences userRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            security.checkPermission(prefsPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return factory.userRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Returns the root preference node for the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @return the root preference node for the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @throws SecurityException If a security manager is present and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   465
     *         it denies {@code RuntimePermission("preferences")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public static Preferences systemRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            security.checkPermission(prefsPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return factory.systemRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Sole constructor. (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    protected Preferences() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Associates the specified value with the specified key in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @param key key with which the specified value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param value value to be associated with the specified key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   489
     * @throws NullPointerException if key or value is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   490
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   491
     *       {@code MAX_KEY_LENGTH} or if {@code value.length} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   492
     *       {@code MAX_VALUE_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   495
     * @throws IllegalArgumentException if either key or value contain
29397
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents: 25859
diff changeset
   496
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public abstract void put(String key, String value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Returns the value associated with the specified key in this preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * node.  Returns the specified default if there is no value associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * with the key, or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * <p>Some implementations may store default values in their backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * stores.  If there is no value associated with the specified key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * but there is such a <i>stored default</i>, it is returned in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * preference to the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @param key key whose associated value is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   512
     *        preference node has no value associated with {@code key}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   513
     * @return the value associated with {@code key}, or {@code def}
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   514
     *         if no value is associated with {@code key}, or the backing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *         store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   518
     * @throws NullPointerException if {@code key} is {@code null}.  (A
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   519
     *         {@code null} value for {@code def} <i>is</i> permitted.)
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   520
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   521
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public abstract String get(String key, String def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Removes the value associated with the specified key in this preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * node, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <p>If this implementation supports <i>stored defaults</i>, and there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * such a default for the specified preference, the stored default will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * "exposed" by this call, in the sense that it will be returned
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   532
     * by a succeeding call to {@code get}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @param key key whose mapping is to be removed from the preference node.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   535
     * @throws NullPointerException if {@code key} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   538
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   539
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public abstract void remove(String key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Removes all of the preferences (key-value associations) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * preference node.  This call has no effect on any descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * of this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * <p>If this implementation supports <i>stored defaults</i>, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * node in the preferences hierarchy contains any such defaults,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * the stored defaults will be "exposed" by this call, in the sense that
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   551
     * they will be returned by succeeding calls to {@code get}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #removeNode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public abstract void clear() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Associates a string representing the specified int value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * one that would be returned if the int value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * {@link Integer#toString(int)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * conjunction with {@link #getInt}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   571
     * @throws NullPointerException if {@code key} is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   572
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   573
     *         {@code MAX_KEY_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   576
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   577
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @see #getInt(String,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public abstract void putInt(String key, int value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Returns the int value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * specified key in this preference node.  The string is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * an integer as by {@link Integer#parseInt(String)}.  Returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * specified default if there is no value associated with the key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * the backing store is inaccessible, or if
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   588
     * {@code Integer.parseInt(String)} would throw a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * NumberFormatException} if the associated value were passed.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * method is intended for use in conjunction with {@link #putInt}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * default exists, is accessible, and could be converted to an int
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   594
     * with {@code Integer.parseInt}, this int is returned in preference to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param key key whose associated value is to be returned as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   599
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *        or the associated value cannot be interpreted as an int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @return the int value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   603
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *         an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   608
     * @throws NullPointerException if {@code key} is {@code null}.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   609
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   610
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see #putInt(String,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    public abstract int getInt(String key, int def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Associates a string representing the specified long value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * one that would be returned if the long value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * {@link Long#toString(long)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * conjunction with {@link #getLong}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   625
     * @throws NullPointerException if {@code key} is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   626
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   627
     *         {@code MAX_KEY_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   630
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   631
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @see #getLong(String,long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public abstract void putLong(String key, long value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Returns the long value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * specified key in this preference node.  The string is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * a long as by {@link Long#parseLong(String)}.  Returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * specified default if there is no value associated with the key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * the backing store is inaccessible, or if
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   642
     * {@code Long.parseLong(String)} would throw a {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * NumberFormatException} if the associated value were passed.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * method is intended for use in conjunction with {@link #putLong}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * default exists, is accessible, and could be converted to a long
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   648
     * with {@code Long.parseLong}, this long is returned in preference to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @param key key whose associated value is to be returned as a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   653
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *        or the associated value cannot be interpreted as a long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @return the long value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   657
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *         a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   662
     * @throws NullPointerException if {@code key} is {@code null}.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   663
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   664
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @see #putLong(String,long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    public abstract long getLong(String key, long def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Associates a string representing the specified boolean value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * specified key in this preference node.  The associated string is
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   673
     * {@code "true"} if the value is true, and {@code "false"} if it is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * false.  This method is intended for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * {@link #getBoolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   679
     * @throws NullPointerException if {@code key} is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   680
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   681
     *         {@code MAX_KEY_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   684
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   685
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see #getBoolean(String,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    public abstract void putBoolean(String key, boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * Returns the boolean value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * specified key in this preference node.  Valid strings
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   694
     * are {@code "true"}, which represents true, and {@code "false"}, which
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   695
     * represents false.  Case is ignored, so, for example, {@code "TRUE"}
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   696
     * and {@code "False"} are also valid.  This method is intended for use in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * conjunction with {@link #putBoolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <p>Returns the specified default if there is no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * associated with the key, the backing store is inaccessible, or if the
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   701
     * associated value is something other than {@code "true"} or
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   702
     * {@code "false"}, ignoring case.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * default exists and is accessible, it is used in preference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * specified default, unless the stored default is something other than
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   707
     * {@code "true"} or {@code "false"}, ignoring case, in which case the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * specified default is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @param key key whose associated value is to be returned as a boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   712
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *        or the associated value cannot be interpreted as a boolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @return the boolean value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   716
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *         a boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   721
     * @throws NullPointerException if {@code key} is {@code null}.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   722
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   723
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @see #putBoolean(String,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public abstract boolean getBoolean(String key, boolean def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * Associates a string representing the specified float value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * one that would be returned if the float value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * {@link Float#toString(float)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * conjunction with {@link #getFloat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   738
     * @throws NullPointerException if {@code key} is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   739
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   740
     *         {@code MAX_KEY_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   743
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   744
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @see #getFloat(String,float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public abstract void putFloat(String key, float value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * Returns the float value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * specified key in this preference node.  The string is converted to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * integer as by {@link Float#parseFloat(String)}.  Returns the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * default if there is no value associated with the key, the backing store
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   754
     * is inaccessible, or if {@code Float.parseFloat(String)} would throw a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * {@link NumberFormatException} if the associated value were passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * This method is intended for use in conjunction with {@link #putFloat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * default exists, is accessible, and could be converted to a float
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   760
     * with {@code Float.parseFloat}, this float is returned in preference to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @param key key whose associated value is to be returned as a float.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   765
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *        or the associated value cannot be interpreted as a float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @return the float value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   769
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *         a float.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   774
     * @throws NullPointerException if {@code key} is {@code null}.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   775
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   776
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @see #putFloat(String,float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    public abstract float getFloat(String key, float def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * Associates a string representing the specified double value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * one that would be returned if the double value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * {@link Double#toString(double)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * conjunction with {@link #getDouble}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   791
     * @throws NullPointerException if {@code key} is {@code null}.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   792
     * @throws IllegalArgumentException if {@code key.length()} exceeds
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   793
     *         {@code MAX_KEY_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   796
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   797
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see #getDouble(String,double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public abstract void putDouble(String key, double value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Returns the double value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * specified key in this preference node.  The string is converted to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * integer as by {@link Double#parseDouble(String)}.  Returns the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * default if there is no value associated with the key, the backing store
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   807
     * is inaccessible, or if {@code Double.parseDouble(String)} would throw a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * {@link NumberFormatException} if the associated value were passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * This method is intended for use in conjunction with {@link #putDouble}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * default exists, is accessible, and could be converted to a double
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   813
     * with {@code Double.parseDouble}, this double is returned in preference
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * to the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @param key key whose associated value is to be returned as a double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   818
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *        or the associated value cannot be interpreted as a double,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @return the double value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   822
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *         a double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   827
     * @throws NullPointerException if {@code key} is {@code null}.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   828
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   829
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * @see #putDouble(String,double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    public abstract double getDouble(String key, double def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Associates a string representing the specified byte array with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * specified key in this preference node.  The associated string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * the <i>Base64</i> encoding of the byte array, as defined in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * href=http://www.ietf.org/rfc/rfc2045.txt>RFC 2045</a>, Section 6.8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * with one minor change: the string will consist solely of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * from the <i>Base64 Alphabet</i>; it will not contain any newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * characters.  Note that the maximum length of the byte array is limited
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   843
     * to three quarters of {@code MAX_VALUE_LENGTH} so that the length
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   844
     * of the Base64 encoded String does not exceed {@code MAX_VALUE_LENGTH}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * This method is intended for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * {@link #getByteArray}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param value value whose string form is to be associated with key.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   850
     * @throws NullPointerException if key or value is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @throws IllegalArgumentException if key.length() exceeds MAX_KEY_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *         or if value.length exceeds MAX_VALUE_LENGTH*3/4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *         removed with the {@link #removeNode()} method.
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   855
     * @throws IllegalArgumentException if key contains
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   856
     *         the null control character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @see #getByteArray(String,byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public abstract void putByteArray(String key, byte[] value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Returns the byte array value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * the specified key in this preference node.  Valid strings are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * <i>Base64</i> encoded binary data, as defined in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * href=http://www.ietf.org/rfc/rfc2045.txt>RFC 2045</a>, Section 6.8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * with one minor change: the string must consist solely of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * from the <i>Base64 Alphabet</i>; no newline characters or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * extraneous characters are permitted.  This method is intended for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * in conjunction with {@link #putByteArray}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * <p>Returns the specified default if there is no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * associated with the key, the backing store is inaccessible, or if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * associated value is not a valid Base64 encoded byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * (as defined above).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * default exists and is accessible, it is used in preference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * specified default, unless the stored default is not a valid Base64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * encoded byte array (as defined above), in which case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * specified default is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @param key key whose associated value is to be returned as a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @param def the value to be returned in the event that this
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   885
     *        preference node has no value associated with {@code key}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *        or the associated value cannot be interpreted as a byte array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @return the byte array value represented by the string associated with
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   889
     *         {@code key} in this preference node, or {@code def} if the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *         a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     *         removed with the {@link #removeNode()} method.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   894
     * @throws NullPointerException if {@code key} is {@code null}.  (A
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   895
     *         {@code null} value for {@code def} <i>is</i> permitted.)
30043
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   896
     * @throws IllegalArgumentException if key contains the null control
b0dd05ec3db1 8075156: (prefs) get*() and remove() should disallow the use of the null control character '\u0000' as key
bpb
parents: 29397
diff changeset
   897
     *         character, code point U+0000.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @see #putByteArray(String,byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    public abstract byte[] getByteArray(String key, byte[] def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * Returns all of the keys that have an associated value in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * preference node.  (The returned array will be of size zero if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * this node has no preferences.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <p>If the implementation supports <i>stored defaults</i> and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * are any such defaults at this node that have not been overridden,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * by explicit preferences, the defaults are returned in the array in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * addition to any explicit preferences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @return an array of the keys that have an associated value in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *         preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    public abstract String[] keys() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * Returns the names of the children of this preference node, relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * this node.  (The returned array will be of size zero if this node has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * no children.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @return the names of the children of this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    public abstract String[] childrenNames() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   938
     * Returns the parent of this preference node, or {@code null} if this is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @return the parent of this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    public abstract Preferences parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Returns the named preference node in the same tree as this node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * creating it and any of its ancestors if they do not already exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Accepts a relative or absolute path name.  Relative path names
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   951
     * (which do not begin with the slash character {@code ('/')}) are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * interpreted relative to this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * <p>If the returned node did not exist prior to this call, this node and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * any ancestors that were created by this call are not guaranteed
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   956
     * to become permanent until the {@code flush} method is called on
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * the returned node (or one of its ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @param pathName the path name of the preference node to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @return the specified preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @throws IllegalArgumentException if the path name is invalid (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *         it contains multiple consecutive slash characters, or ends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *         with a slash character and is more than one character long).
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   964
     * @throws NullPointerException if path name is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    public abstract Preferences node(String pathName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * Returns true if the named preference node exists in the same tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * as this node.  Relative path names (which do not begin with the slash
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   974
     * character {@code ('/')}) are interpreted relative to this preference
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * <p>If this node (or an ancestor) has already been removed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * {@link #removeNode()} method, it <i>is</i> legal to invoke this method,
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   979
     * but only with the path name {@code ""}; the invocation will return
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   980
     * {@code false}.  Thus, the idiom {@code p.nodeExists("")} may be
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   981
     * used to test whether {@code p} has been removed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @param pathName the path name of the node whose existence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     *        is to be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @return true if the specified node exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @throws IllegalArgumentException if the path name is invalid (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     *         it contains multiple consecutive slash characters, or ends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     *         with a slash character and is more than one character long).
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   992
     * @throws NullPointerException if path name is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     *         removed with the {@link #removeNode()} method and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
   995
     *         {@code pathName} is not the empty string ({@code ""}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public abstract boolean nodeExists(String pathName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * Removes this preference node and all of its descendants, invalidating
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * any preferences contained in the removed nodes.  Once a node has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * removed, attempting any method other than {@link #name()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * {@link #absolutePath()}, {@link #isUserNode()}, {@link #flush()} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * {@link #node(String) nodeExists("")} on the corresponding
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1006
     * {@code Preferences} instance will fail with an
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1007
     * {@code IllegalStateException}.  (The methods defined on {@link Object}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * can still be invoked on a node after it has been removed; they will not
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1009
     * throw {@code IllegalStateException}.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * <p>The removal is not guaranteed to be persistent until the
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1012
     * {@code flush} method is called on this node (or an ancestor).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * <p>If this implementation supports <i>stored defaults</i>, removing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * node exposes any stored defaults at or below this node.  Thus, a
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1016
     * subsequent call to {@code nodeExists} on this node's path name may
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1017
     * return {@code true}, and a subsequent call to {@code node} on this
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1018
     * path name may return a (different) {@code Preferences} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * representing a non-empty collection of preferences and/or children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * @throws IllegalStateException if this node (or an ancestor) has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *         been removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @throws UnsupportedOperationException if this method is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     *         the root node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public abstract void removeNode() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * Returns this preference node's name, relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * @return this preference node's name, relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    public abstract String name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * Returns this preference node's absolute path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * @return this preference node's absolute path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    public abstract String absolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1047
     * Returns {@code true} if this preference node is in the user
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1048
     * preference tree, {@code false} if it's in the system preference tree.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1050
     * @return {@code true} if this preference node is in the user
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1051
     *         preference tree, {@code false} if it's in the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *         preference tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    public abstract boolean isUserNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * Returns a string representation of this preferences node,
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1058
     * as if computed by the expression:{@code (this.isUserNode() ? "User" :
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1059
     * "System") + " Preference Node: " + this.absolutePath()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * Forces any changes in the contents of this preference node and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * descendants to the persistent store.  Once this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * successfully, it is safe to assume that all changes made in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * subtree rooted at this node prior to the method invocation have become
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * permanent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * <p>Implementations are free to flush changes into the persistent store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * at any time.  They do not need to wait for this method to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * <p>When a flush occurs on a newly created node, it is made persistent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * as are any ancestors (and descendants) that have yet to be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * persistent.  Note however that any preference value changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * ancestors are <i>not</i> guaranteed to be made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * <p> If this method is invoked on a node that has been removed with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * the {@link #removeNode()} method, flushSpi() is invoked on this node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * but not on others.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @see    #sync()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    public abstract void flush() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * Ensures that future reads from this preference node and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * descendants reflect any changes that were committed to the persistent
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1092
     * store (from any VM) prior to the {@code sync} invocation.  As a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * side-effect, forces any changes in the contents of this preference node
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1094
     * and its descendants to the persistent store, as if the {@code flush}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * method had been invoked on this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @see    #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    public abstract void sync() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * Registers the specified listener to receive <i>preference change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * events</i> for this preference node.  A preference change event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * generated when a preference is added to this node, removed from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * node, or when the value associated with a preference is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * (Preference change events are <i>not</i> generated by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * #removeNode()} method, which generates a <i>node change event</i>.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1113
     * Preference change events <i>are</i> generated by the {@code clear}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * method.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * <p>Events are only guaranteed for changes made within the same JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * as the registered listener, though some implementations may generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * events for changes made outside this JVM.  Events may be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * before the changes have been made persistent.  Events are not generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * when preferences are modified in descendants of this node; a caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * desiring such events must register with each descendant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * @param pcl The preference change listener to add.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1124
     * @throws NullPointerException if {@code pcl} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @see #removePreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @see #addNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    public abstract void addPreferenceChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        PreferenceChangeListener pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * Removes the specified preference change listener, so it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * receives preference change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @param pcl The preference change listener to remove.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1138
     * @throws IllegalArgumentException if {@code pcl} was not a registered
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *         preference change listener on this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @see #addPreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    public abstract void removePreferenceChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        PreferenceChangeListener pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * Registers the specified listener to receive <i>node change events</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * for this node.  A node change event is generated when a child node is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * added to or removed from this node.  (A single {@link #removeNode()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * invocation results in multiple <i>node change events</i>, one for every
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * node in the subtree rooted at the removed node.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * <p>Events are only guaranteed for changes made within the same JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * as the registered listener, though some implementations may generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * events for changes made outside this JVM.  Events may be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * before the changes have become permanent.  Events are not generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * when indirect descendants of this node are added or removed; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * caller desiring such events must register with each descendant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * <p>Few guarantees can be made regarding node creation.  Because nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * are created implicitly upon access, it may not be feasible for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * implementation to determine whether a child node existed in the backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * store prior to access (for example, because the backing store is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * unreachable or cached information is out of date).  Under these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * circumstances, implementations are neither required to generate node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * change events nor prohibited from doing so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1169
     * @param ncl The {@code NodeChangeListener} to add.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1170
     * @throws NullPointerException if {@code ncl} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @see #removeNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see #addPreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    public abstract void addNodeChangeListener(NodeChangeListener ncl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1179
     * Removes the specified {@code NodeChangeListener}, so it no longer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * receives change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1182
     * @param ncl The {@code NodeChangeListener} to remove.
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1183
     * @throws IllegalArgumentException if {@code ncl} was not a registered
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1184
     *         {@code NodeChangeListener} on this node.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @see #addNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    public abstract void removeNodeChangeListener(NodeChangeListener ncl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Emits on the specified output stream an XML document representing all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * of the preferences contained in this node (but not its descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * This XML document is, in effect, an offline backup of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * <p>The XML document will have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1197
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1198
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1199
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * The UTF-8 character encoding will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * results equivalent to some serial execution.  If the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * at this node are modified concurrently with an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * method, the exported preferences comprise a "fuzzy snapshot" of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * preferences contained in the node; some of the concurrent modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * may be reflected in the exported data while others may not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @param os the output stream on which to emit the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @throws IOException if writing to the specified output stream
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1212
     *         results in an {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @throws BackingStoreException if preference data cannot be read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *         backing store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @see    #importPreferences(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    public abstract void exportNode(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        throws IOException, BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * Emits an XML document representing all of the preferences contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * in this node and all of its descendants.  This XML document is, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * effect, an offline backup of the subtree rooted at the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * <p>The XML document will have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1228
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1229
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1230
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * The UTF-8 character encoding will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * results equivalent to some serial execution.  If the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * or nodes in the subtree rooted at this node are modified concurrently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * with an invocation of this method, the exported preferences comprise a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * "fuzzy snapshot" of the subtree; some of the concurrent modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * may be reflected in the exported data while others may not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @param os the output stream on which to emit the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @throws IOException if writing to the specified output stream
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1243
     *         results in an {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @throws BackingStoreException if preference data cannot be read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *         backing store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * @see    #importPreferences(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @see    #exportNode(OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    public abstract void exportSubtree(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        throws IOException, BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * Imports all of the preferences represented by the XML document on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * specified input stream.  The document may represent user preferences or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * system preferences.  If it represents user preferences, the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * will be imported into the calling user's preference tree (even if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * originally came from a different user's preference tree).  If any of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * the preferences described by the document inhabit preference nodes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * do not exist, the nodes will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * <p>The XML document must have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1264
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1265
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1266
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * (This method is designed for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * {@link #exportNode(OutputStream)} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * {@link #exportSubtree(OutputStream)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * results equivalent to some serial execution.  The method behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * as if implemented on top of the other public methods in this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * notably {@link #node(String)} and {@link #put(String, String)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * @param is the input stream from which to read the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * @throws IOException if reading from the specified input stream
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1279
     *         results in an {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * @throws InvalidPreferencesFormatException Data on input stream does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     *         constitute a valid XML document with the mandated document type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * @throws SecurityException If a security manager is present and
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 30043
diff changeset
  1283
     *         it denies {@code RuntimePermission("preferences")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    public static void importPreferences(InputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        throws IOException, InvalidPreferencesFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        XmlSupport.importPreferences(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
}