jdk/src/share/classes/java/util/prefs/Preferences.java
author alanb
Mon, 10 Jun 2013 12:58:32 +0100
changeset 18156 edb590d448c5
parent 13589 da4cb574f4a6
child 23010 6dadb192ad81
permissions -rw-r--r--
8016217: More javadoc warnings Reviewed-by: lancea, chegar, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
12538
211d6e82fe51 7130404: [macosx] "os.arch" value should be "x86_64" for compatibility with Apple JDK6
jmelvin
parents: 12047
diff changeset
     2
 * Copyright (c) 2000, 2012, 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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>The root node has an absolute path name of <tt>"/"</tt>.  Children of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the root node have absolute path names of <tt>"/" + </tt><i>&lt;node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * name&gt;</i>.  All other nodes have absolute path names of <i>&lt;parent's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * absolute path name&gt;</i><tt> + "/" + </tt><i>&lt;node name&gt;</i>.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * delay.  The <tt>flush</tt> method may be used to synchronously force
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <tt>flush</tt> invocation is <i>not</i> required upon termination to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * that pending updates are made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>All of the methods that read preferences from a <tt>Preferences</tt>
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * unavailable.  Several methods, like <tt>flush</tt>, have semantics that
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * Every <tt>Preferences</tt> implementation must have an associated {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * PreferencesFactory} implementation.  Every Java(TM) SE implementation must provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * some means of specifying which <tt>PreferencesFactory</tt> implementation
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * <p>Implementation note: In Sun's JRE, the <tt>PreferencesFactory</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * implementation is located as follows:
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * <tt>java.util.prefs.PreferencesFactory</tt> is defined, then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * taken to be the fully-qualified name of a class implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * <tt>PreferencesFactory</tt> interface.  The class is loaded and
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * <li><p> If a <tt>PreferencesFactory</tt> implementation class file
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * <tt>java.util.prefs.PreferencesFactory</tt> in the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * directory <tt>META-INF/services</tt>, then the first class name
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * <tt>PreferencesFactory</tt> implementation for the underlying
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 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                return (PreferencesFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    Class.forName(factoryName, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                  ClassLoader.getSystemClassLoader())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    .newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    // workaround for javaws, plugin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    // load factory class using non-system classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        sm.checkPermission(new java.security.AllPermission());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    return (PreferencesFactory)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        Class.forName(factoryName, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                                      Thread.currentThread()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                      .getContextClassLoader())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        .newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                } catch (Exception e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   259
                    throw new InternalError(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        "Can't instantiate Preferences factory "
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   261
                        + factoryName, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            new PrivilegedAction<PreferencesFactory>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                public PreferencesFactory run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    return factory1();}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    private static PreferencesFactory factory1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        // 2. Try service provider interface
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   274
        Iterator<PreferencesFactory> itr = ServiceLoader
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   275
            .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   276
            .iterator();
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   277
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // choose first provider instance
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   279
        while (itr.hasNext()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            try {
70
01cbfebae878 6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
sherman
parents: 2
diff changeset
   281
                return itr.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            } catch (ServiceConfigurationError sce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                if (sce.getCause() instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    // Ignore the security exception, try the next provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                throw sce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // 3. Use platform-specific system-wide default
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   292
        String osName = System.getProperty("os.name");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   293
        String platformFactory;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   294
        if (osName.startsWith("Windows")) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   295
            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
   296
        } else if (osName.contains("OS X")) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   297
            platformFactory = "java.util.prefs.MacOSXPreferencesFactory";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   298
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   299
            platformFactory = "java.util.prefs.FileSystemPreferencesFactory";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11274
diff changeset
   300
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return (PreferencesFactory)
13589
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 12538
diff changeset
   303
                Class.forName(platformFactory, false,
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 12538
diff changeset
   304
                              Preferences.class.getClassLoader()).newInstance();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        } catch (Exception e) {
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   306
            throw new InternalError(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                "Can't instantiate platform default Preferences factory "
10355
a976ff46116b 7080020: Add conventional constructors to InternalError and VirtualMachineError
darcy
parents: 5506
diff changeset
   308
                + platformFactory, e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Maximum length of string allowed as a key (80 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public static final int MAX_KEY_LENGTH = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Maximum length of string allowed as a value (8192 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public static final int MAX_VALUE_LENGTH = 8*1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Maximum length of a node name (80 characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public static final int MAX_NAME_LENGTH = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Returns the preference node from the calling user's preference tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * that is associated (by convention) with the specified class's package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * The convention is as follows: the absolute path name of the node is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * fully qualified package name, preceded by a slash (<tt>'/'</tt>), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * with each period (<tt>'.'</tt>) replaced by a slash.  For example the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * absolute path name of the node associated with the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <tt>com.acme.widget.Foo</tt> is <tt>/com/acme/widget</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p>This convention does not apply to the unnamed package, whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * associated preference node is <tt>&lt;unnamed&gt;</tt>.  This node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * is not intended for long term use, but for convenience in the early
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * development of programs that do not yet belong to a package, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * for "throwaway" programs.  <i>Valuable data should not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * at this node as it is shared by all programs that use it.</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>A class <tt>Foo</tt> wishing to access preferences pertaining to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * package can obtain a preference node as follows: <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *    static Preferences prefs = Preferences.userNodeForPackage(Foo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * This idiom obviates the need for using a string to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * preferences node and decreases the likelihood of a run-time failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * (If the class name is misspelled, it will typically result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * compile-time error.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <p>Invoking this method will result in the creation of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * node and its ancestors if they do not already exist.  If the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * node did not exist prior to this call, this node and any ancestors that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * were created by this call are not guaranteed to become permanent until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * the <tt>flush</tt> method is called on the returned node (or one of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param c the class for whose package a user preference node is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @return the user preference node associated with the package of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *         <tt>c</tt> is a member.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @throws NullPointerException if <tt>c</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @throws SecurityException if a security manager is present and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *         it denies <tt>RuntimePermission("preferences")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public static Preferences userNodeForPackage(Class<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return userRoot().node(nodeName(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Returns the preference node from the system preference tree that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * associated (by convention) with the specified class's package.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * convention is as follows: the absolute path name of the node is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * fully qualified package name, preceded by a slash (<tt>'/'</tt>), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * with each period (<tt>'.'</tt>) replaced by a slash.  For example the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * absolute path name of the node associated with the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <tt>com.acme.widget.Foo</tt> is <tt>/com/acme/widget</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <p>This convention does not apply to the unnamed package, whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * associated preference node is <tt>&lt;unnamed&gt;</tt>.  This node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * is not intended for long term use, but for convenience in the early
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * development of programs that do not yet belong to a package, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * for "throwaway" programs.  <i>Valuable data should not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * at this node as it is shared by all programs that use it.</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <p>A class <tt>Foo</tt> wishing to access preferences pertaining to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * package can obtain a preference node as follows: <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *  static Preferences prefs = Preferences.systemNodeForPackage(Foo.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * This idiom obviates the need for using a string to describe the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * preferences node and decreases the likelihood of a run-time failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * (If the class name is misspelled, it will typically result in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * compile-time error.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <p>Invoking this method will result in the creation of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * node and its ancestors if they do not already exist.  If the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * node did not exist prior to this call, this node and any ancestors that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * were created by this call are not guaranteed to become permanent until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * the <tt>flush</tt> method is called on the returned node (or one of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param c the class for whose package a system preference node is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @return the system preference node associated with the package of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *         <tt>c</tt> is a member.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @throws NullPointerException if <tt>c</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @throws SecurityException if a security manager is present and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *         it denies <tt>RuntimePermission("preferences")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public static Preferences systemNodeForPackage(Class<?> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return systemRoot().node(nodeName(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Returns the absolute path name of the node corresponding to the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @throws IllegalArgumentException if the package has node preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *         node associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
11274
7e7196757acd 7117249: fix warnings in java.util.jar, .logging, .prefs, .zip
smarks
parents: 10355
diff changeset
   422
    private static String nodeName(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (c.isArray())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                "Arrays have no associated preferences node.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        String className = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        int pkgEndIndex = className.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (pkgEndIndex < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return "/<unnamed>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        String packageName = className.substring(0, pkgEndIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return "/" + packageName.replace('.', '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * This permission object represents the permission required to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * access to the user or system root (which in turn allows for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * other operations).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    private static Permission prefsPerm = new RuntimePermission("preferences");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Returns the root preference node for the calling user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @return the root preference node for the calling user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @throws SecurityException If a security manager is present and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *         it denies <tt>RuntimePermission("preferences")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public static Preferences userRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            security.checkPermission(prefsPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return factory.userRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * Returns the root preference node for the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @return the root preference node for the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @throws SecurityException If a security manager is present and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *         it denies <tt>RuntimePermission("preferences")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public static Preferences systemRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if (security != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            security.checkPermission(prefsPerm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        return factory.systemRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Sole constructor. (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    protected Preferences() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Associates the specified value with the specified key in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param key key with which the specified value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @param value value to be associated with the specified key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @throws NullPointerException if key or value is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *       <tt>MAX_KEY_LENGTH</tt> or if <tt>value.length</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *       <tt>MAX_VALUE_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public abstract void put(String key, String value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Returns the value associated with the specified key in this preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * node.  Returns the specified default if there is no value associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * with the key, or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * <p>Some implementations may store default values in their backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * stores.  If there is no value associated with the specified key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * but there is such a <i>stored default</i>, it is returned in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * preference to the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param key key whose associated value is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *        preference node has no value associated with <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @return the value associated with <tt>key</tt>, or <tt>def</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *         if no value is associated with <tt>key</tt>, or the backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *         store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.  (A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *         <tt>null</tt> value for <tt>def</tt> <i>is</i> permitted.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    public abstract String get(String key, String def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Removes the value associated with the specified key in this preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * node, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <p>If this implementation supports <i>stored defaults</i>, and there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * such a default for the specified preference, the stored default will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * "exposed" by this call, in the sense that it will be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * by a succeeding call to <tt>get</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @param key key whose mapping is to be removed from the preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public abstract void remove(String key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Removes all of the preferences (key-value associations) in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * preference node.  This call has no effect on any descendants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * of this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <p>If this implementation supports <i>stored defaults</i>, and this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * node in the preferences hierarchy contains any such defaults,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * the stored defaults will be "exposed" by this call, in the sense that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * they will be returned by succeeding calls to <tt>get</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @see #removeNode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public abstract void clear() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Associates a string representing the specified int value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * one that would be returned if the int value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * {@link Integer#toString(int)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * conjunction with {@link #getInt}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *         <tt>MAX_KEY_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @see #getInt(String,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    public abstract void putInt(String key, int value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Returns the int value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * specified key in this preference node.  The string is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * an integer as by {@link Integer#parseInt(String)}.  Returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * specified default if there is no value associated with the key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * the backing store is inaccessible, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <tt>Integer.parseInt(String)</tt> would throw a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * NumberFormatException} if the associated value were passed.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * method is intended for use in conjunction with {@link #putInt}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * default exists, is accessible, and could be converted to an int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * with <tt>Integer.parseInt</tt>, this int is returned in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @param key key whose associated value is to be returned as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *        or the associated value cannot be interpreted as an int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @return the int value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *         an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see #putInt(String,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public abstract int getInt(String key, int def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Associates a string representing the specified long value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * one that would be returned if the long value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * {@link Long#toString(long)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * conjunction with {@link #getLong}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *         <tt>MAX_KEY_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see #getLong(String,long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public abstract void putLong(String key, long value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Returns the long value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * specified key in this preference node.  The string is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * a long as by {@link Long#parseLong(String)}.  Returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * specified default if there is no value associated with the key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * the backing store is inaccessible, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * <tt>Long.parseLong(String)</tt> would throw a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * NumberFormatException} if the associated value were passed.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * method is intended for use in conjunction with {@link #putLong}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * default exists, is accessible, and could be converted to a long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * with <tt>Long.parseLong</tt>, this long is returned in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @param key key whose associated value is to be returned as a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *        or the associated value cannot be interpreted as a long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @return the long value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *         a long.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see #putLong(String,long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    public abstract long getLong(String key, long def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Associates a string representing the specified boolean value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * specified key in this preference node.  The associated string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * <tt>"true"</tt> if the value is true, and <tt>"false"</tt> if it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * false.  This method is intended for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * {@link #getBoolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *         <tt>MAX_KEY_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @see #getBoolean(String,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public abstract void putBoolean(String key, boolean value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Returns the boolean value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * specified key in this preference node.  Valid strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * are <tt>"true"</tt>, which represents true, and <tt>"false"</tt>, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * represents false.  Case is ignored, so, for example, <tt>"TRUE"</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * and <tt>"False"</tt> are also valid.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * conjunction with {@link #putBoolean}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <p>Returns the specified default if there is no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * associated with the key, the backing store is inaccessible, or if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * associated value is something other than <tt>"true"</tt> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * <tt>"false"</tt>, ignoring case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * default exists and is accessible, it is used in preference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * specified default, unless the stored default is something other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <tt>"true"</tt> or <tt>"false"</tt>, ignoring case, in which case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * specified default is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * @param key key whose associated value is to be returned as a boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *        or the associated value cannot be interpreted as a boolean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @return the boolean value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *         a boolean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @see #putBoolean(String,boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    public abstract boolean getBoolean(String key, boolean def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Associates a string representing the specified float value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * one that would be returned if the float value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * {@link Float#toString(float)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * conjunction with {@link #getFloat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *         <tt>MAX_KEY_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @see #getFloat(String,float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public abstract void putFloat(String key, float value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * Returns the float value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * specified key in this preference node.  The string is converted to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * integer as by {@link Float#parseFloat(String)}.  Returns the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * default if there is no value associated with the key, the backing store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * is inaccessible, or if <tt>Float.parseFloat(String)</tt> would throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * {@link NumberFormatException} if the associated value were passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * This method is intended for use in conjunction with {@link #putFloat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * default exists, is accessible, and could be converted to a float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * with <tt>Float.parseFloat</tt>, this float is returned in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param key key whose associated value is to be returned as a float.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *        or the associated value cannot be interpreted as a float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @return the float value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *         a float.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see #putFloat(String,float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public abstract float getFloat(String key, float def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Associates a string representing the specified double value with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * specified key in this preference node.  The associated string is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * one that would be returned if the double value were passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * {@link Double#toString(double)}.  This method is intended for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * conjunction with {@link #getDouble}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @throws IllegalArgumentException if <tt>key.length()</tt> exceeds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *         <tt>MAX_KEY_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @see #getDouble(String,double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public abstract void putDouble(String key, double value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Returns the double value represented by the string associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * specified key in this preference node.  The string is converted to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * integer as by {@link Double#parseDouble(String)}.  Returns the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * default if there is no value associated with the key, the backing store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * is inaccessible, or if <tt>Double.parseDouble(String)</tt> would throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * {@link NumberFormatException} if the associated value were passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * This method is intended for use in conjunction with {@link #putDouble}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * default exists, is accessible, and could be converted to a double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * with <tt>Double.parseDouble</tt>, this double is returned in preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * to the specified default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @param key key whose associated value is to be returned as a double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *        or the associated value cannot be interpreted as a double,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @return the double value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     *         a double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @see #putDouble(String,double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public abstract double getDouble(String key, double def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Associates a string representing the specified byte array with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * specified key in this preference node.  The associated string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * the <i>Base64</i> encoding of the byte array, as defined in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * href=http://www.ietf.org/rfc/rfc2045.txt>RFC 2045</a>, Section 6.8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * with one minor change: the string will consist solely of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * from the <i>Base64 Alphabet</i>; it will not contain any newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * characters.  Note that the maximum length of the byte array is limited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * to three quarters of <tt>MAX_VALUE_LENGTH</tt> so that the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * of the Base64 encoded String does not exceed <tt>MAX_VALUE_LENGTH</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * This method is intended for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * {@link #getByteArray}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @param key key with which the string form of value is to be associated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @param value value whose string form is to be associated with key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @throws NullPointerException if key or value is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @throws IllegalArgumentException if key.length() exceeds MAX_KEY_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *         or if value.length exceeds MAX_VALUE_LENGTH*3/4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @see #getByteArray(String,byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    public abstract void putByteArray(String key, byte[] value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * Returns the byte array value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * the specified key in this preference node.  Valid strings are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <i>Base64</i> encoded binary data, as defined in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * href=http://www.ietf.org/rfc/rfc2045.txt>RFC 2045</a>, Section 6.8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * with one minor change: the string must consist solely of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * from the <i>Base64 Alphabet</i>; no newline characters or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * extraneous characters are permitted.  This method is intended for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * in conjunction with {@link #putByteArray}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * <p>Returns the specified default if there is no value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * associated with the key, the backing store is inaccessible, or if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * associated value is not a valid Base64 encoded byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * (as defined above).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <p>If the implementation supports <i>stored defaults</i> and such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * default exists and is accessible, it is used in preference to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * specified default, unless the stored default is not a valid Base64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * encoded byte array (as defined above), in which case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * specified default is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @param key key whose associated value is to be returned as a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @param def the value to be returned in the event that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *        preference node has no value associated with <tt>key</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *        or the associated value cannot be interpreted as a byte array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *        or the backing store is inaccessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return the byte array value represented by the string associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *         <tt>key</tt> in this preference node, or <tt>def</tt> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *         associated value does not exist or cannot be interpreted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *         a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>.  (A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *         <tt>null</tt> value for <tt>def</tt> <i>is</i> permitted.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @see #get(String,String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @see #putByteArray(String,byte[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public abstract byte[] getByteArray(String key, byte[] def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * Returns all of the keys that have an associated value in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * preference node.  (The returned array will be of size zero if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * this node has no preferences.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * <p>If the implementation supports <i>stored defaults</i> and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * are any such defaults at this node that have not been overridden,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * by explicit preferences, the defaults are returned in the array in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * addition to any explicit preferences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @return an array of the keys that have an associated value in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *         preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public abstract String[] keys() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Returns the names of the children of this preference node, relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * this node.  (The returned array will be of size zero if this node has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * no children.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @return the names of the children of this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    public abstract String[] childrenNames() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * Returns the parent of this preference node, or <tt>null</tt> if this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * the root.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @return the parent of this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public abstract Preferences parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Returns the named preference node in the same tree as this node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * creating it and any of its ancestors if they do not already exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Accepts a relative or absolute path name.  Relative path names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * (which do not begin with the slash character <tt>('/')</tt>) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * interpreted relative to this preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * <p>If the returned node did not exist prior to this call, this node and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * any ancestors that were created by this call are not guaranteed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * to become permanent until the <tt>flush</tt> method is called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * the returned node (or one of its ancestors or descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @param pathName the path name of the preference node to return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @return the specified preference node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @throws IllegalArgumentException if the path name is invalid (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *         it contains multiple consecutive slash characters, or ends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *         with a slash character and is more than one character long).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @throws NullPointerException if path name is <tt>null</tt>.
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
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    public abstract Preferences node(String pathName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * Returns true if the named preference node exists in the same tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * as this node.  Relative path names (which do not begin with the slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * character <tt>('/')</tt>) are interpreted relative to this preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * <p>If this node (or an ancestor) has already been removed with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * {@link #removeNode()} method, it <i>is</i> legal to invoke this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * but only with the path name <tt>""</tt>; the invocation will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * <tt>false</tt>.  Thus, the idiom <tt>p.nodeExists("")</tt> may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * used to test whether <tt>p</tt> has been removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @param pathName the path name of the node whose existence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *        is to be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @return true if the specified node exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * @throws IllegalArgumentException if the path name is invalid (i.e.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     *         it contains multiple consecutive slash characters, or ends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *         with a slash character and is more than one character long).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @throws NullPointerException if path name is <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     *         removed with the {@link #removeNode()} method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *         <tt>pathName</tt> is not the empty string (<tt>""</tt>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    public abstract boolean nodeExists(String pathName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * Removes this preference node and all of its descendants, invalidating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * any preferences contained in the removed nodes.  Once a node has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * removed, attempting any method other than {@link #name()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * {@link #absolutePath()}, {@link #isUserNode()}, {@link #flush()} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * {@link #node(String) nodeExists("")} on the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * <tt>Preferences</tt> instance will fail with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * <tt>IllegalStateException</tt>.  (The methods defined on {@link Object}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * can still be invoked on a node after it has been removed; they will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * throw <tt>IllegalStateException</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <p>The removal is not guaranteed to be persistent until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <tt>flush</tt> method is called on this node (or an ancestor).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <p>If this implementation supports <i>stored defaults</i>, removing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * node exposes any stored defaults at or below this node.  Thus, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * subsequent call to <tt>nodeExists</tt> on this node's path name may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * return <tt>true</tt>, and a subsequent call to <tt>node</tt> on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * path name may return a (different) <tt>Preferences</tt> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * representing a non-empty collection of preferences and/or children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * @throws IllegalStateException if this node (or an ancestor) has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *         been removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @throws UnsupportedOperationException if this method is invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     *         the root node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * @see #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    public abstract void removeNode() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * Returns this preference node's name, relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @return this preference node's name, relative to its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public abstract String name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * Returns this preference node's absolute path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * @return this preference node's absolute path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    public abstract String absolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * Returns <tt>true</tt> if this preference node is in the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * preference tree, <tt>false</tt> if it's in the system preference tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @return <tt>true</tt> if this preference node is in the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     *         preference tree, <tt>false</tt> if it's in the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *         preference tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public abstract boolean isUserNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * Returns a string representation of this preferences node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * as if computed by the expression:<tt>(this.isUserNode() ? "User" :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * "System") + " Preference Node: " + this.absolutePath()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * Forces any changes in the contents of this preference node and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * descendants to the persistent store.  Once this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * successfully, it is safe to assume that all changes made in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * subtree rooted at this node prior to the method invocation have become
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * permanent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * <p>Implementations are free to flush changes into the persistent store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * at any time.  They do not need to wait for this method to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * <p>When a flush occurs on a newly created node, it is made persistent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * as are any ancestors (and descendants) that have yet to be made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * persistent.  Note however that any preference value changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * ancestors are <i>not</i> guaranteed to be made persistent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * <p> If this method is invoked on a node that has been removed with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * the {@link #removeNode()} method, flushSpi() is invoked on this node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * but not on others.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @see    #sync()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    public abstract void flush() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * Ensures that future reads from this preference node and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * descendants reflect any changes that were committed to the persistent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * store (from any VM) prior to the <tt>sync</tt> invocation.  As a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * side-effect, forces any changes in the contents of this preference node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * and its descendants to the persistent store, as if the <tt>flush</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * method had been invoked on this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @throws BackingStoreException if this operation cannot be completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *         due to a failure in the backing store, or inability to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *         communicate with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @see    #flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public abstract void sync() throws BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * Registers the specified listener to receive <i>preference change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * events</i> for this preference node.  A preference change event is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * generated when a preference is added to this node, removed from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * node, or when the value associated with a preference is changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * (Preference change events are <i>not</i> generated by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * #removeNode()} method, which generates a <i>node change event</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * Preference change events <i>are</i> generated by the <tt>clear</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * method.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * <p>Events are only guaranteed for changes made within the same JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * as the registered listener, though some implementations may generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * events for changes made outside this JVM.  Events may be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * before the changes have been made persistent.  Events are not generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * when preferences are modified in descendants of this node; a caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * desiring such events must register with each descendant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @param pcl The preference change listener to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * @throws NullPointerException if <tt>pcl</tt> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * @see #removePreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * @see #addNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    public abstract void addPreferenceChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        PreferenceChangeListener pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Removes the specified preference change listener, so it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * receives preference change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @param pcl The preference change listener to remove.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @throws IllegalArgumentException if <tt>pcl</tt> was not a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *         preference change listener on this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @see #addPreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    public abstract void removePreferenceChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        PreferenceChangeListener pcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * Registers the specified listener to receive <i>node change events</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * for this node.  A node change event is generated when a child node is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * added to or removed from this node.  (A single {@link #removeNode()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * invocation results in multiple <i>node change events</i>, one for every
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * node in the subtree rooted at the removed node.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * <p>Events are only guaranteed for changes made within the same JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * as the registered listener, though some implementations may generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * events for changes made outside this JVM.  Events may be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * before the changes have become permanent.  Events are not generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * when indirect descendants of this node are added or removed; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * caller desiring such events must register with each descendant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * <p>Few guarantees can be made regarding node creation.  Because nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * are created implicitly upon access, it may not be feasible for an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * implementation to determine whether a child node existed in the backing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * store prior to access (for example, because the backing store is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * unreachable or cached information is out of date).  Under these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * circumstances, implementations are neither required to generate node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * change events nor prohibited from doing so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @param ncl The <tt>NodeChangeListener</tt> to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @throws NullPointerException if <tt>ncl</tt> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @see #removeNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * @see #addPreferenceChangeListener(PreferenceChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    public abstract void addNodeChangeListener(NodeChangeListener ncl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * Removes the specified <tt>NodeChangeListener</tt>, so it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * receives change events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @param ncl The <tt>NodeChangeListener</tt> to remove.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @throws IllegalArgumentException if <tt>ncl</tt> was not a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     *         <tt>NodeChangeListener</tt> on this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @see #addNodeChangeListener(NodeChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    public abstract void removeNodeChangeListener(NodeChangeListener ncl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * Emits on the specified output stream an XML document representing all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * of the preferences contained in this node (but not its descendants).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * This XML document is, in effect, an offline backup of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * <p>The XML document will have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1164
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1165
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1166
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * The UTF-8 character encoding will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * results equivalent to some serial execution.  If the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * at this node are modified concurrently with an invocation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * method, the exported preferences comprise a "fuzzy snapshot" of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * preferences contained in the node; some of the concurrent modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * may be reflected in the exported data while others may not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @param os the output stream on which to emit the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @throws IOException if writing to the specified output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @throws BackingStoreException if preference data cannot be read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *         backing store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * @see    #importPreferences(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public abstract void exportNode(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        throws IOException, BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * Emits an XML document representing all of the preferences contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * in this node and all of its descendants.  This XML document is, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * effect, an offline backup of the subtree rooted at the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * <p>The XML document will have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1195
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1196
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1197
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * The UTF-8 character encoding will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * results equivalent to some serial execution.  If the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * or nodes in the subtree rooted at this node are modified concurrently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * with an invocation of this method, the exported preferences comprise a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * "fuzzy snapshot" of the subtree; some of the concurrent modifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * may be reflected in the exported data while others may not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @param os the output stream on which to emit the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @throws IOException if writing to the specified output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @throws BackingStoreException if preference data cannot be read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *         backing store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @throws IllegalStateException if this node (or an ancestor) has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *         removed with the {@link #removeNode()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @see    #importPreferences(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @see    #exportNode(OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    public abstract void exportSubtree(OutputStream os)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        throws IOException, BackingStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * Imports all of the preferences represented by the XML document on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * specified input stream.  The document may represent user preferences or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * system preferences.  If it represents user preferences, the preferences
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * will be imported into the calling user's preference tree (even if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * originally came from a different user's preference tree).  If any of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * the preferences described by the document inhabit preference nodes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * do not exist, the nodes will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * <p>The XML document must have the following DOCTYPE declaration:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1231
     * <pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1232
     * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 13589
diff changeset
  1233
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * (This method is designed for use in conjunction with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * {@link #exportNode(OutputStream)} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * {@link #exportSubtree(OutputStream)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * <p>This method is an exception to the general rule that the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * concurrently executing multiple methods in this class yields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * results equivalent to some serial execution.  The method behaves
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * as if implemented on top of the other public methods in this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * notably {@link #node(String)} and {@link #put(String, String)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @param is the input stream from which to read the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * @throws IOException if reading from the specified input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *         results in an <tt>IOException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     * @throws InvalidPreferencesFormatException Data on input stream does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *         constitute a valid XML document with the mandated document type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @throws SecurityException If a security manager is present and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     *         it denies <tt>RuntimePermission("preferences")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * @see    RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    public static void importPreferences(InputStream is)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        throws IOException, InvalidPreferencesFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        XmlSupport.importPreferences(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
}