src/java.prefs/macosx/classes/java/util/prefs/MacOSXPreferences.java
author stefank
Mon, 25 Nov 2019 12:32:40 +0100
changeset 59251 4cbfa5077d68
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234739: Harmonize parameter order in Atomic - xchg Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 14186
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
package java.util.prefs;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents: 12047
diff changeset
    28
import java.util.Objects;
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents: 12047
diff changeset
    29
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
class MacOSXPreferences extends AbstractPreferences {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
    // fixme need security checks?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
    // CF preferences file name for Java nodes with short names
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
    // This value is also in MacOSXPreferencesFile.c
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
    private static final String defaultAppName = "com.apple.java.util.prefs";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
    // true if this node is a child of userRoot or is userRoot
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    38
    private final boolean isUser;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
    // CF's storage location for this node and its keys
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    41
    private final MacOSXPreferencesFile file;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
    // absolutePath() + "/"
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    44
    private final String path;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
    // User root and system root nodes
38887
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    47
    private static volatile MacOSXPreferences userRoot;
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    48
    private static volatile MacOSXPreferences systemRoot;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    // Returns user root node, creating it if necessary.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
    // Called by MacOSXPreferencesFactory
38887
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    53
    static Preferences getUserRoot() {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    54
        MacOSXPreferences root = userRoot;
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    55
        if (root == null) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    56
            synchronized (MacOSXPreferences.class) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    57
                root = userRoot;
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    58
                if (root == null) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    59
                    userRoot = root = new MacOSXPreferences(true);
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    60
                }
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    61
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
        }
38887
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    63
        return root;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
    // Returns system root node, creating it if necessary.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    // Called by MacOSXPreferencesFactory
38887
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    69
    static Preferences getSystemRoot() {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    70
        MacOSXPreferences root = systemRoot;
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    71
        if (root == null) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    72
            synchronized (MacOSXPreferences.class) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    73
                root = systemRoot;
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    74
                if (root == null) {
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    75
                    systemRoot = root = new MacOSXPreferences(false);
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    76
                }
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    77
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
        }
38887
bb8ffdf4e7aa 8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs
jlahoda
parents: 31915
diff changeset
    79
        return root;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    // Create a new root node. Called by getUserRoot() and getSystemRoot()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    // Synchronization is provided by the caller.
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    85
    private MacOSXPreferences(boolean newIsUser) {
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    86
        this(null, "", false, true, newIsUser);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    // Create a new non-root node with the given parent.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
    // Called by childSpi().
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    92
    private MacOSXPreferences(MacOSXPreferences parent, String name) {
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    93
        this(parent, name, false, false, false);
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    94
    }
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    95
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    96
    private MacOSXPreferences(MacOSXPreferences parent, String name,
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    97
                              boolean isNew)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    {
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
    99
        this(parent, name, isNew, false, false);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   102
    private MacOSXPreferences(MacOSXPreferences parent, String name,
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   103
                              boolean isNew, boolean isRoot, boolean isUser)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    {
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   105
        super(parent, name);
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   106
        if (isRoot)
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   107
            this.isUser = isUser;
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   108
        else
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   109
            this.isUser = isUserNode();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
        path = isRoot ? absolutePath() : absolutePath() + "/";
14186
bfb891f72a79 7198073: (prefs) user prefs not saved [macosx]
khazra
parents: 13367
diff changeset
   111
        file = cfFileForNode(this.isUser);
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   112
        if (isNew)
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   113
            newNode = isNew;
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   114
        else
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   115
            newNode = file.addNode(path);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    // Create and return the MacOSXPreferencesFile for this node.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
    // Does not write anything to the file.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    private MacOSXPreferencesFile cfFileForNode(boolean isUser)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        String name = path;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
        // /one/two/three/four/five/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
        // The fourth slash is the end of the first three components.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
        // If there is no fourth slash, the name has fewer than 3 components
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        int pos = -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
        for (int i = 0; i < 4; i++) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
            pos = name.indexOf('/', pos+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
            if (pos == -1) break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
        if (pos == -1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
            // fewer than three components - use default name
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
            name = defaultAppName;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
            // truncate to three components, no leading or trailing '/'
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
            // replace '/' with '.' to make filesystem happy
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
            // convert to all lowercase to survive on HFS+
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
            name = name.substring(1, pos);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
            name = name.replace('/', '.');
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
            name = name.toLowerCase();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
        return MacOSXPreferencesFile.getFile(name, isUser);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   149
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
    protected void putSpi(String key, String value)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
        file.addKeyToNode(path, key, value);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   156
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
    protected String getSpi(String key)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
        return file.getKeyFromNode(path, key);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   163
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
    protected void removeSpi(String key)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
    {
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents: 12047
diff changeset
   166
        Objects.requireNonNull(key, "Specified key cannot be null");
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
        file.removeKeyFromNode(path, key);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   172
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
    protected void removeNodeSpi()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   174
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
        // Disallow flush or sync between these two operations
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
        // (they may be manipulating two different files)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
        synchronized(MacOSXPreferencesFile.class) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
            ((MacOSXPreferences)parent()).removeChild(name());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
            file.removeNode(path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
    // Erase knowledge about a child of this node. Called by removeNodeSpi.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
    private void removeChild(String child)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
        file.removeChildFromNode(path, child);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   192
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
    protected String[] childrenNamesSpi()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   194
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
        String[] result = file.getChildrenForNode(path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
        if (result == null) throw new BackingStoreException("Couldn't get list of children for node '" + path + "'");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
        return result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   202
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    protected String[] keysSpi()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   204
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
        String[] result = file.getKeysForNode(path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
        if (result == null) throw new BackingStoreException("Couldn't get list of keys for node '" + path + "'");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
        return result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   212
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    protected AbstractPreferences childSpi(String name)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
        // Add to parent's child list here and disallow sync
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
        // because parent and child might be in different files.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
        synchronized(MacOSXPreferencesFile.class) {
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   218
            boolean isNew = file.addChildToNode(path, name);
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   219
            return new MacOSXPreferences(this, name, isNew);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    // AbstractPreferences override
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   224
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    public void flush()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   226
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
        // Flush should *not* check for removal, unlike sync, but should
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
        // prevent simultaneous removal.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
        synchronized(lock) {
13367
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   231
            if (isUser) {
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   232
                if (!MacOSXPreferencesFile.flushUser()) {
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   233
                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   234
                }
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   235
            } else {
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   236
                if (!MacOSXPreferencesFile.flushWorld()) {
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   237
                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
0cc1e08af793 7184287: (prefs) BackingStoreException when calling flush on root node[macosx]
khazra
parents: 13248
diff changeset
   238
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   244
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
    protected void flushSpi()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   246
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
        // nothing here - overridden flush() doesn't call this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
    // AbstractPreferences override
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   252
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    public void sync()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   254
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
        synchronized(lock) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
            if (isRemoved())
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
                throw new IllegalStateException("Node has been removed");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
            // fixme! overkill
12553
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   260
            if (isUser) {
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   261
                if (!MacOSXPreferencesFile.syncUser()) {
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   262
                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   263
                }
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   264
            } else {
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   265
                if (!MacOSXPreferencesFile.syncWorld()) {
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   266
                    throw new BackingStoreException("Synchronization failed for node '" + path + "'");
cf79383bbfaf 7118100: (prefs) Inconsistency when using system and user preference on OSX Lion
khazra
parents: 12552
diff changeset
   267
                }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
    // AbstractPreferences implementation
12695
06bbe7432ade 7164636: (prefs) Cleanup src/macosx/classes/java/util/prefs
khazra
parents: 12553
diff changeset
   273
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
    protected void syncSpi()
13248
8f0767748f15 7160252: (prefs) NodeAddedEvent was not delivered when new node add when new Node
khazra
parents: 12695
diff changeset
   275
    throws BackingStoreException
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
        // nothing here - overridden sync() doesn't call this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280