@Override public void putBoolean(String key, boolean value) { put(key, String.valueOf(value)); }
@Override public void sync() throws BackingStoreException { synchronized (lock) { checkState(); syncSpi(); } for (AbstractPreferences child : cachedChildren()) { child.sync(); } }
@Override public String toString() { return (isUserNode() ? "User" : "System") + " Preference Node: " + absolutePath(); }
@Override public void flush() throws BackingStoreException { synchronized (lock) { flushSpi(); } AbstractPreferences[] cc = cachedChildren(); int i; for (i = 0; i < cc.length; i++) { cc[i].flush(); } }
@Override public void remove(String key) { synchronized (lock) { checkState(); removeSpi(key); } notifyPreferenceChange(key, null); }
private void removeNodeImpl() throws BackingStoreException { synchronized (lock) { checkState(); String[] childrenNames = childrenNamesSpi(); for (String childrenName : childrenNames) { if (cachedNode.get(childrenName) == null) { AbstractPreferences child = childSpi(childrenName); cachedNode.put(childrenName, child); } } final Collection<AbstractPreferences> values = cachedNode.values(); final AbstractPreferences[] children = values.toArray(new AbstractPreferences[values.size()]); for (AbstractPreferences child : children) { child.removeNodeImpl(); } removeNodeSpi(); isRemoved = true; parentPref.cachedNode.remove(nodeName); } if (parentPref.nodeChangeListeners.size() > 0) { parentPref.notifyChildRemoved(this); } }
private AbstractPreferences getNodeFromBackend(boolean createNew, AbstractPreferences currentNode, String name) throws BackingStoreException { if (name.length() > MAX_NAME_LENGTH) { throw new IllegalArgumentException("Name '" + name + "' too long"); } AbstractPreferences temp; if (createNew) { temp = currentNode.childSpi(name); currentNode.cachedNode.put(name, temp); if (temp.newNode && currentNode.nodeChangeListeners.size() > 0) { currentNode.notifyChildAdded(temp); } } else { temp = currentNode.getChild(name); } return temp; }
/** * Returns the child node with the specified name or {@code null} if it * doesn't exist. Implementers can assume that the name supplied to this * method will be a valid node name string (conforming to the node naming * format) and will not correspond to a node that has been cached or * removed. * * @param name * the name of the desired child node. * @return the child node with the given name or {@code null} if it doesn't * exist. * @throws BackingStoreException * if the backing store is unavailable or causes an operation * failure. */ protected AbstractPreferences getChild(String name) throws BackingStoreException { synchronized (lock) { checkState(); AbstractPreferences result = null; String[] childrenNames = childrenNames(); for (String childrenName : childrenNames) { if (childrenName.equals(name)) { result = childSpi(name); break; } } return result; } }
@Override public String[] childrenNames() throws BackingStoreException { synchronized (lock) { checkState(); TreeSet<String> result = new TreeSet<String>(cachedNode.keySet()); String[] names = childrenNamesSpi(); for (int i = 0; i < names.length; i++) { result.add(names[i]); } return result.toArray(new String[result.size()]); } }
if (isRemoved()) { if (name.isEmpty()) { return false; validateName(name); if (name.isEmpty() || "/".equals(name)) { return true; Preferences result = startNode.nodeImpl(name, false); return (result != null); } catch(IllegalArgumentException e) {
private void checkState() { if (isRemoved()) { throw new IllegalStateException("This node has been removed"); } }
@Override public void put(String key, String value) { if (key == null) { throw new NullPointerException("key == null"); } else if (value == null) { throw new NullPointerException("value == null"); } if (key.length() > MAX_KEY_LENGTH || value.length() > MAX_VALUE_LENGTH) { throw new IllegalArgumentException(); } synchronized (lock) { checkState(); putSpi(key, value); } notifyPreferenceChange(key, value); }
@Override public String absolutePath() { if (parentPref == null) { return "/"; } else if (parentPref == root) { return "/" + nodeName; } return parentPref.absolutePath() + "/" + nodeName; }
@Override public String[] keys() throws BackingStoreException { synchronized (lock) { checkState(); return keysSpi(); } }
@Override public Preferences parent() { checkState(); return parentPref; }
@Override public String get(String key, String deflt) { if (key == null) { throw new NullPointerException("key == null"); } String result = null; synchronized (lock) { checkState(); try { result = getSpi(key); } catch (Exception e) { // ignored } } return (result == null ? deflt : result); }
public @Override final void sync() throws BackingStoreException { flushTask.waitFinished(); super.sync(); }
private void removeNodeImpl() throws BackingStoreException { synchronized (lock) { checkState(); String[] childrenNames = childrenNamesSpi(); for (String childrenName : childrenNames) { if (cachedNode.get(childrenName) == null) { AbstractPreferences child = childSpi(childrenName); cachedNode.put(childrenName, child); } } final Collection<AbstractPreferences> values = cachedNode.values(); final AbstractPreferences[] children = values.toArray(new AbstractPreferences[values.size()]); for (AbstractPreferences child : children) { child.removeNodeImpl(); } removeNodeSpi(); isRemoved = true; parentPref.cachedNode.remove(nodeName); } if (parentPref.nodeChangeListeners.size() > 0) { parentPref.notifyChildRemoved(this); } }
@Override public void flush() throws BackingStoreException { synchronized (lock) { flushSpi(); } AbstractPreferences[] cc = cachedChildren(); int i; for (i = 0; i < cc.length; i++) { cc[i].flush(); } }
private AbstractPreferences getNodeFromBackend(boolean createNew, AbstractPreferences currentNode, String name) throws BackingStoreException { if (name.length() > MAX_NAME_LENGTH) { throw new IllegalArgumentException("Name '" + name + "' too long"); } AbstractPreferences temp; if (createNew) { temp = currentNode.childSpi(name); currentNode.cachedNode.put(name, temp); if (temp.newNode && currentNode.nodeChangeListeners.size() > 0) { currentNode.notifyChildAdded(temp); } } else { temp = currentNode.getChild(name); } return temp; }