jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java
changeset 13248 8f0767748f15
parent 12695 06bbe7432ade
child 13367 0cc1e08af793
--- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Wed Jul 11 17:10:34 2012 +0800
+++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java	Fri Jul 13 16:02:26 2012 -0700
@@ -35,16 +35,16 @@
     private static final String defaultAppName = "com.apple.java.util.prefs";
 
     // true if this node is a child of userRoot or is userRoot
-    private boolean isUser;
+    private final boolean isUser;
 
     // true if this node is userRoot or systemRoot
-    private boolean isRoot;
+    private final boolean isRoot;
 
     // CF's storage location for this node and its keys
-    private MacOSXPreferencesFile file;
+    private final MacOSXPreferencesFile file;
 
     // absolutePath() + "/"
-    private String path;
+    private final String path;
 
     // User root and system root nodes
     private static MacOSXPreferences userRoot = null;
@@ -73,36 +73,40 @@
 
     // Create a new root node. Called by getUserRoot() and getSystemRoot()
     // Synchronization is provided by the caller.
-    private MacOSXPreferences(boolean newIsUser)
-    {
-        super(null, "");
-        isUser = newIsUser;
-        isRoot = true;
-
-        initFields();
+    private MacOSXPreferences(boolean newIsUser) {
+        this(null, "", false, true, newIsUser);
     }
 
 
     // Create a new non-root node with the given parent.
     // Called by childSpi().
-    private MacOSXPreferences(MacOSXPreferences parent, String name)
+    private MacOSXPreferences(MacOSXPreferences parent, String name) {
+        this(parent, name, false, false, false);
+    }
+
+    private MacOSXPreferences(MacOSXPreferences parent, String name,
+                              boolean isNew)
     {
-        super(parent, name);
-        isUser = isUserNode();
-        isRoot = false;
-
-        initFields();
+        this(parent, name, isNew, false, false);
     }
 
-
-    private void initFields()
+    private MacOSXPreferences(MacOSXPreferences parent, String name,
+                              boolean isNew, boolean isRoot, boolean isUser)
     {
+        super(parent, name);
+        this.isRoot = isRoot;
+        if (isRoot)
+            this.isUser = isUser;
+        else
+            this.isUser = isUserNode();
         path = isRoot ? absolutePath() : absolutePath() + "/";
         file = cfFileForNode(isUser);
-        newNode = file.addNode(path);
+        if (isNew)
+            newNode = isNew;
+        else
+            newNode = file.addNode(path);
     }
 
-
     // Create and return the MacOSXPreferencesFile for this node.
     // Does not write anything to the file.
     private MacOSXPreferencesFile cfFileForNode(boolean isUser)
@@ -160,7 +164,7 @@
     // AbstractPreferences implementation
     @Override
     protected void removeNodeSpi()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         // Disallow flush or sync between these two operations
         // (they may be manipulating two different files)
@@ -180,7 +184,7 @@
     // AbstractPreferences implementation
     @Override
     protected String[] childrenNamesSpi()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         String[] result = file.getChildrenForNode(path);
         if (result == null) throw new BackingStoreException("Couldn't get list of children for node '" + path + "'");
@@ -190,7 +194,7 @@
     // AbstractPreferences implementation
     @Override
     protected String[] keysSpi()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         String[] result = file.getKeysForNode(path);
         if (result == null) throw new BackingStoreException("Couldn't get list of keys for node '" + path + "'");
@@ -204,15 +208,15 @@
         // Add to parent's child list here and disallow sync
         // because parent and child might be in different files.
         synchronized(MacOSXPreferencesFile.class) {
-            file.addChildToNode(path, name);
-            return new MacOSXPreferences(this, name);
+            boolean isNew = file.addChildToNode(path, name);
+            return new MacOSXPreferences(this, name, isNew);
         }
     }
 
     // AbstractPreferences override
     @Override
     public void flush()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         // Flush should *not* check for removal, unlike sync, but should
         // prevent simultaneous removal.
@@ -227,7 +231,7 @@
     // AbstractPreferences implementation
     @Override
     protected void flushSpi()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         // nothing here - overridden flush() doesn't call this
     }
@@ -235,7 +239,7 @@
     // AbstractPreferences override
     @Override
     public void sync()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         synchronized(lock) {
             if (isRemoved())
@@ -256,7 +260,7 @@
     // AbstractPreferences implementation
     @Override
     protected void syncSpi()
-        throws BackingStoreException
+    throws BackingStoreException
     {
         // nothing here - overridden sync() doesn't call this
     }