Datasheet

<!ATTLIST root
type (system|user) #REQUIRED >
<!-- Each node has a map representing its preferences (if any),
and one node for each child (if any). -->
<!ELEMENT node (map, node*) >
<!-- Additionally, each node has a name attribute -->
<!ATTLIST node
name CDATA #REQUIRED >
<!-- A map represents the preferences stored at a node (if any). -->
<!ELEMENT map (entry*) >
<!-- An entry represents a single preference, which is simply
a key-value pair. -->
<!ELEMENT entry EMPTY >
<!ATTLIST entry
key CDATA #REQUIRED
value CDATA #REQUIRED >
Using Preferences
The following example sets a few properties in a node in the user tree, prints out information about the
node, and then exports the information to an XML file:
import java.util.*;
import java.util.prefs.*;
import java.io.*;
public class PreferenceExample {
public void printInformation(Preferences p)
throws BackingStoreException
{
System.out.println(“Node’s absolute path: “ + p.absolutePath());
System.out.print(“Node’s children: “);
for(String s : p.childrenNames()) {
System.out.print(s + “ “);
}
System.out.println(“”);
System.out.print(“Node’s keys: “);
for(String s : p.keys()) {
System.out.print(s + “ “);
}
System.out.println(“”);
System.out.println(“Node’s name: “ + p.name());
System.out.println(“Node’s parent: “ + p.parent());
System.out.println(“NODE: “ + p);
System.out.println(“userNodeForPackage: “ +
Preferences.userNodeForPackage(PreferenceExample.class));
System.out.println(“All information in node”);
75
Chapter 1: Key Java Language Features and Libraries
05_777106 ch01.qxp 11/28/06 10:43 PM Page 75