📄 preferences.java
字号:
* Removes this preference node and all of its descendants, invalidating * any preferences contained in the removed nodes. Once a node has been * removed, attempting any method other than {@link #name()}, * {@link #absolutePath()}, {@link #isUserNode()}, {@link #flush()} or * {@link #node(String) nodeExists("")} on the corresponding * <tt>Preferences</tt> instance will fail with an * <tt>IllegalStateException</tt>. (The methods defined on {@link Object} * can still be invoked on a node after it has been removed; they will not * throw <tt>IllegalStateException</tt>.) * * <p>The removal is not guaranteed to be persistent until the * <tt>flush</tt> method is called on this node (or an ancestor). * * <p>If this implementation supports <i>stored defaults</i>, removing a * node exposes any stored defaults at or below this node. Thus, a * subsequent call to <tt>nodeExists</tt> on this node's path name may * return <tt>true</tt>, and a subsequent call to <tt>node</tt> on this * path name may may return a (different) <tt>Preferences</tt> instance * representing a non-empty collection of preferences and/or children. * * @throws BackingStoreException if this operation cannot be completed * due to a failure in the backing store, or inability to * communicate with it. * @throws IllegalStateException if this node (or an ancestor) has already * been removed with the {@link #removeNode()} method. * @throws UnsupportedOperationException if this method is invoked on * the root node. * @see #flush() */ public abstract void removeNode() throws BackingStoreException; /** * Returns this preference node's name, relative to its parent. * * @return this preference node's name, relative to its parent. */ public abstract String name(); /** * Returns this preference node's absolute path name. * * @return this preference node's absolute path name. */ public abstract String absolutePath(); /** * Returns <tt>true</tt> if this preference node is in the user * preference tree, <tt>false</tt> if it's in the system preference tree. * * @return <tt>true</tt> if this preference node is in the user * preference tree, <tt>false</tt> if it's in the system * preference tree. */ public abstract boolean isUserNode(); /** * Returns a string representation of this preferences node, * as if computed by the expression:<tt>(this.isUserNode() ? "User" : * "System") + " Preference Node: " + this.absolutePath()</tt>. */ public abstract String toString(); /** * Forces any changes in the contents of this preference node and its * descendants to the persistent store. Once this method returns * successfully, it is safe to assume that all changes made in the * subtree rooted at this node prior to the method invocation have become * permanent. * * <p>Implementations are free to flush changes into the persistent store * at any time. They do not need to wait for this method to be called. * * <p>When a flush occurs on a newly created node, it is made persistent, * as are any ancestors (and descendants) that have yet to be made * persistent. Note however that any preference value changes in * ancestors are <i>not</i> guaranteed to be made persistent. * * <p> If this method is invoked on a node that has been removed with * the {@link #removeNode()} method, flushSpi() is invoked on this node, * but not on others. * * @throws BackingStoreException if this operation cannot be completed * due to a failure in the backing store, or inability to * communicate with it. * @see #sync() */ public abstract void flush() throws BackingStoreException; /** * Ensures that future reads from this preference node and its * descendants reflect any changes that were committed to the persistent * store (from any VM) prior to the <tt>sync</tt> invocation. As a * side-effect, forces any changes in the contents of this preference node * and its descendants to the persistent store, as if the <tt>flush</tt> * method had been invoked on this node. * * @throws BackingStoreException if this operation cannot be completed * due to a failure in the backing store, or inability to * communicate with it. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #flush() */ public abstract void sync() throws BackingStoreException; /** * Registers the specified listener to receive <i>preference change * events</i> for this preference node. A preference change event is * generated when a preference is added to this node, removed from this * node, or when the value associated with a preference is changed. * (Preference change events are <i>not</i> generated by the {@link * #removeNode()} method, which generates a <i>node change event</i>. * Preference change events <i>are</i> generated by the <tt>clear</tt> * method.) * * <p>Events are only guaranteed for changes made within the same JVM * as the registered listener, though some implementations may generate * events for changes made outside this JVM. Events may be generated * before the changes have been made persistent. Events are not generated * when preferences are modified in descendants of this node; a caller * desiring such events must register with each descendant. * * @param pcl The preference change listener to add. * @throws NullPointerException if <tt>pcl</tt> is null. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #removePreferenceChangeListener(PreferenceChangeListener) * @see #addNodeChangeListener(NodeChangeListener) */ public abstract void addPreferenceChangeListener( PreferenceChangeListener pcl); /** * Removes the specified preference change listener, so it no longer * receives preference change events. * * @param pcl The preference change listener to remove. * @throws IllegalArgumentException if <tt>pcl</tt> was not a registered * preference change listener on this node. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #addPreferenceChangeListener(PreferenceChangeListener) */ public abstract void removePreferenceChangeListener( PreferenceChangeListener pcl); /** * Registers the specified listener to receive <i>node change events</i> * for this node. A node change event is generated when a child node is * added to or removed from this node. (A single {@link #removeNode()} * invocation results in multiple <i>node change events</i>, one for every * node in the subtree rooted at the removed node.) * * <p>Events are only guaranteed for changes made within the same JVM * as the registered listener, though some implementations may generate * events for changes made outside this JVM. Events may be generated * before the changes have become permanent. Events are not generated * when indirect descendants of this node are added or removed; a * caller desiring such events must register with each descendant. * * <p>Few guarantees can be made regarding node creation. Because nodes * are created implicitly upon access, it may not be feasible for an * implementation to determine whether a child node existed in the backing * store prior to access (for example, because the backing store is * unreachable or cached information is out of date). Under these * circumstances, implementations are neither required to generate node * change events nor prohibited from doing so. * * @param ncl The <tt>NodeChangeListener</tt> to add. * @throws NullPointerException if <tt>ncl</tt> is null. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #removeNodeChangeListener(NodeChangeListener) * @see #addPreferenceChangeListener(PreferenceChangeListener) */ public abstract void addNodeChangeListener(NodeChangeListener ncl); /** * Removes the specified <tt>NodeChangeListener</tt>, so it no longer * receives change events. * * @param ncl The <tt>NodeChangeListener</tt> to remove. * @throws IllegalArgumentException if <tt>ncl</tt> was not a registered * <tt>NodeChangeListener</tt> on this node. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #addNodeChangeListener(NodeChangeListener) */ public abstract void removeNodeChangeListener(NodeChangeListener ncl); /** * Emits on the specified output stream an XML document representing all * of the preferences contained in this node (but not its descendants). * This XML document is, in effect, an offline backup of the node. * * <p>The XML document will have the following DOCTYPE declaration: * <pre> * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"> * </pre> * The UTF-8 character encoding will be used. * * <p>This method is an exception to the general rule that the results of * concurrently executing multiple methods in this class yields * results equivalent to some serial execution. If the preferences * at this node are modified concurrently with an invocation of this * method, the exported preferences comprise a "fuzzy snapshot" of the * preferences contained in the node; some of the concurrent modifications * may be reflected in the exported data while others may not. * * @param os the output stream on which to emit the XML document. * @throws IOException if writing to the specified output stream * results in an <tt>IOException</tt>. * @throws BackingStoreException if preference data cannot be read from * backing store. * @see #importPreferences(InputStream) * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. */ public abstract void exportNode(OutputStream os) throws IOException, BackingStoreException; /** * Emits an XML document representing all of the preferences contained * in this node and all of its descendants. This XML document is, in * effect, an offline backup of the subtree rooted at the node. * * <p>The XML document will have the following DOCTYPE declaration: * <pre> * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"> * </pre> * The UTF-8 character encoding will be used. * * <p>This method is an exception to the general rule that the results of * concurrently executing multiple methods in this class yields * results equivalent to some serial execution. If the preferences * or nodes in the subtree rooted at this node are modified concurrently * with an invocation of this method, the exported preferences comprise a * "fuzzy snapshot" of the subtree; some of the concurrent modifications * may be reflected in the exported data while others may not. * * @param os the output stream on which to emit the XML document. * @throws IOException if writing to the specified output stream * results in an <tt>IOException</tt>. * @throws BackingStoreException if preference data cannot be read from * backing store. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @see #importPreferences(InputStream) * @see #exportNode(OutputStream) */ public abstract void exportSubtree(OutputStream os) throws IOException, BackingStoreException; /** * Imports all of the preferences represented by the XML document on the * specified input stream. The document may represent user preferences or * system preferences. If it represents user preferences, the preferences * will be imported into the calling user's preference tree (even if they * originally came from a different user's preference tree). If any of * the preferences described by the document inhabit preference nodes that * do not exist, the nodes will be created. * * <p>The XML document must have the following DOCTYPE declaration: * <pre> * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"> * </pre> * (This method is designed for use in conjunction with * {@link #exportNode(OutputStream)} and * {@link #exportSubtree(OutputStream)}. * * <p>This method is an exception to the general rule that the results of * concurrently executing multiple methods in this class yields * results equivalent to some serial execution. The method behaves * as if implemented on top of the other public methods in this class, * notably {@link #node(String)} and {@link #put(String, String)}. * * @param is the input stream from which to read the XML document. * @throws IOException if reading from the specified output stream * results in an <tt>IOException</tt>. * @throws InvalidPreferencesFormatException Data on input stream does not * constitute a valid XML document with the mandated document type. * @throws SecurityException If a security manager is present and * it denies <tt>RuntimePermission("preferences")</tt>. * @see RuntimePermission */ public static void importPreferences(InputStream is) throws IOException, InvalidPreferencesFormatException { XmlSupport.importPreferences(is); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -