From 5cc8cb84ac4a3474cfb666c9b94fd721e4615ca0 Mon Sep 17 00:00:00 2001
From: Jesse Wilson
Date: Mon, 31 Aug 2009 10:52:23 -0700
Subject: Update prefs to Harmony r772995.
Notable changes:
- exception handling has changed to cleanup more reliably
- calls to Collection.toArray() size the array properly
- lots of style tweaks (rewrapping Javadoc, reintending wrapped code, whitespace)
- new PrefsTester class ensures tests store prefs in the tmp directory
Squashed commit of the following:
commit 2157269d8ed39ccb8a71d735c12bbabcfd548243
Merge: d287282 97818bf
Author: Jesse Wilson
Date: Wed Aug 5 11:14:26 2009 -0700
Merge branch 'prefs_772995' into prefs_dalvik
Conflicts:
libcore/prefs/.classpath
libcore/prefs/.settings/org.eclipse.jdt.core.prefs
libcore/prefs/build.xml
libcore/prefs/make/exclude.linux.x86_64.drl
libcore/prefs/make/exclude.windows.x86.drl
libcore/prefs/make/exclude.windows.x86_64.drl
libcore/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
libcore/prefs/src/main/java/java/util/prefs/BackingStoreException.java
libcore/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
libcore/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
libcore/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java
libcore/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java
libcore/prefs/src/main/java/java/util/prefs/NodeChangeListener.java
libcore/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java
libcore/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java
libcore/prefs/src/main/java/java/util/prefs/Preferences.java
libcore/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
libcore/prefs/src/main/java/java/util/prefs/RegistryPreferencesFactoryImpl.java
libcore/prefs/src/main/java/java/util/prefs/RegistryPreferencesImpl.java
libcore/prefs/src/main/java/java/util/prefs/XMLParser.java
libcore/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/Messages.java
libcore/prefs/src/main/native/prefs/windows/PreferencesImpl.c
libcore/prefs/src/main/native/prefs/windows/hyprefs.rc
libcore/prefs/src/main/native/prefs/windows/makefile
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferencesFactory.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockSecurityManager.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
libcore/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
libcore/prefs/src/test/java/tests/prefs/AllTests.java
commit d287282b550d4a5d262f1d1703344ed61bdc6d15
Author: Jesse Wilson
Date: Tue Aug 4 14:36:36 2009 -0700
Dalvik Prefs
commit 97818bf21cfde744eeb5fbf1f9c31d9bd66f5a2e
Author: Jesse Wilson
Date: Tue Aug 4 14:35:52 2009 -0700
Prefs 772995
commit 9a506f93947938dad3b41e1393f53b766ba0319f
Author: Jesse Wilson
Date: Tue Aug 4 14:22:40 2009 -0700
Prefs 527399
---
.../java/java/util/prefs/AbstractPreferences.java | 199 ++++----
.../java/util/prefs/BackingStoreException.java | 23 +-
.../util/prefs/FilePreferencesFactoryImpl.java | 6 +-
.../java/java/util/prefs/FilePreferencesImpl.java | 41 +-
.../prefs/InvalidPreferencesFormatException.java | 26 +-
.../main/java/java/util/prefs/NodeChangeEvent.java | 37 +-
.../java/java/util/prefs/NodeChangeListener.java | 17 +-
.../java/util/prefs/PreferenceChangeEvent.java | 28 +-
.../java/util/prefs/PreferenceChangeListener.java | 16 +-
.../src/main/java/java/util/prefs/Preferences.java | 499 ++++++++++-----------
.../java/java/util/prefs/PreferencesFactory.java | 18 +-
prefs/src/main/java/java/util/prefs/XMLParser.java | 147 +++---
.../harmony/prefs/internal/nls/Messages.java | 14 +-
.../java/util/prefs/AbstractPreferencesTest.java | 42 +-
.../java/util/prefs/FilePreferencesImplTest.java | 20 +-
.../InvalidPreferencesFormatExceptionTest.java | 4 +-
.../java/util/prefs/MockAbstractPreferences.java | 9 +
.../tests/java/util/prefs/MockSecurityManager.java | 2 +
.../tests/java/util/prefs/NodeChangeEventTest.java | 18 +-
.../java/util/prefs/NodeChangeListenerTest.java | 7 +
.../java/util/prefs/PreferenceChangeEventTest.java | 4 +-
.../util/prefs/PreferenceChangeListenerTest.java | 1 +
.../java/util/prefs/PreferencesFactoryTest.java | 5 +-
.../tests/java/util/prefs/PreferencesTest.java | 69 +--
prefs/src/test/java/tests/prefs/AllTests.java | 3 +-
.../prefs/java/util/prefs/preferences.dtd | 56 ---
26 files changed, 605 insertions(+), 706 deletions(-)
delete mode 100644 prefs/src/test/resources/prefs/java/util/prefs/preferences.dtd
(limited to 'prefs')
diff --git a/prefs/src/main/java/java/util/prefs/AbstractPreferences.java b/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
index 711cc01..3264569 100644
--- a/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
+++ b/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
@@ -20,6 +20,7 @@ package java.util.prefs;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.util.Collection;
import java.util.EventListener;
import java.util.EventObject;
import java.util.HashMap;
@@ -27,7 +28,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.harmony.luni.util.Base64;
@@ -38,8 +38,9 @@ import org.apache.harmony.prefs.internal.nls.Messages;
* Preferences, which can be used to simplify {@code Preferences} provider's
* implementation. This class defines nine abstract SPI methods, which must be
* implemented by a preference provider.
- *
- * @since Android 1.0
+ *
+ * @since 1.4
+ * @see Preferences
*/
public abstract class AbstractPreferences extends Preferences {
/*
@@ -47,14 +48,9 @@ public abstract class AbstractPreferences extends Preferences {
* Class fields
* -----------------------------------------------------------
*/
- /**
- * The unhandled events collection.
- */
+ /** the unhandled events collection */
private static final List events = new LinkedList();
-
- /**
- * The event dispatcher thread.
- */
+ /** the event dispatcher thread */
private static final EventDispatcher dispatcher = new EventDispatcher("Preference Event Dispatcher"); //$NON-NLS-1$
/*
@@ -72,11 +68,13 @@ public abstract class AbstractPreferences extends Preferences {
Preferences sroot = Preferences.systemRoot();
try {
uroot.flush();
- } catch (BackingStoreException e) {//ignore
+ } catch (BackingStoreException e) {
+ // ignore
}
try {
sroot.flush();
- } catch (BackingStoreException e) {//ignore
+ } catch (BackingStoreException e) {
+ // ignore
}
}
});
@@ -87,9 +85,7 @@ public abstract class AbstractPreferences extends Preferences {
* Instance fields (package-private)
* -----------------------------------------------------------
*/
- /**
- * True, if this node is in user preference hierarchy.
- */
+ /** true if this node is in user preference hierarchy */
boolean userNode;
/*
@@ -97,16 +93,11 @@ public abstract class AbstractPreferences extends Preferences {
* Instance fields (private)
* -----------------------------------------------------------
*/
- /**
- * Marker class for 'lock' field.
- */
- private static class Lock {
- }
+ /** Marker class for 'lock' field. */
+ private static class Lock {}
/**
* The object used to lock this node.
- *
- * @since Android 1.0
*/
protected final Object lock;
@@ -115,14 +106,10 @@ public abstract class AbstractPreferences extends Preferences {
* backing store. This field's default value is false, and it is checked
* when the node creation is completed, and if it is true, the node change
* event will be fired for this node's parent.
- *
- * @since Android 1.0
*/
protected boolean newNode;
- /**
- * Cached child nodes
- */
+ /** cached child nodes */
private Map cachedNode;
//the collections of listeners
@@ -147,9 +134,9 @@ public abstract class AbstractPreferences extends Preferences {
* -----------------------------------------------------------
*/
/**
- * Constructs a new {@code AbstractPreferences} instance using the given parent node
- * and node name.
- *
+ * Constructs a new {@code AbstractPreferences} instance using the given
+ * parent node and node name.
+ *
* @param parent
* the parent node of the new node or {@code null} to indicate
* that the new node is a root node.
@@ -159,7 +146,6 @@ public abstract class AbstractPreferences extends Preferences {
* @throws IllegalArgumentException
* if the name contains a slash character or is empty if {@code
* parent} is not {@code null}.
- * @since Android 1.0
*/
protected AbstractPreferences(AbstractPreferences parent, String name) {
if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) { //$NON-NLS-1$
@@ -185,7 +171,6 @@ public abstract class AbstractPreferences extends Preferences {
* Returns an array of all cached child nodes.
*
* @return the array of cached child nodes.
- * @since Android 1.0
*/
protected final AbstractPreferences[] cachedChildren() {
return cachedNode.values().toArray(new AbstractPreferences[cachedNode.size()]);
@@ -193,9 +178,10 @@ public abstract class AbstractPreferences extends Preferences {
/**
* 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.
+ * 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.
@@ -204,7 +190,6 @@ public abstract class AbstractPreferences extends Preferences {
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected AbstractPreferences getChild(String name)
throws BackingStoreException {
@@ -226,10 +211,9 @@ public abstract class AbstractPreferences extends Preferences {
/**
* Returns whether this node has been removed by invoking the method {@code
* removeNode()}.
- *
+ *
* @return {@code true}, if this node has been removed, {@code false}
* otherwise.
- * @since Android 1.0
*/
protected boolean isRemoved() {
synchronized (lock) {
@@ -240,33 +224,31 @@ public abstract class AbstractPreferences extends Preferences {
/**
* Flushes changes of this node to the backing store. This method should
* only flush this node and should not include the descendant nodes. Any
- * implementation that wants to provide functionality to flush all nodes
+ * implementation that wants to provide functionality to flush all nodes
* at once should override the method {@link #flush() flush()}.
- *
+ *
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected abstract void flushSpi() throws BackingStoreException;
/**
- * Returns the names of all of the child nodes of this node or an empty array if
- * this node has no children. The names of cached children are not required to be
- * returned.
- *
+ * Returns the names of all of the child nodes of this node or an empty
+ * array if this node has no children. The names of cached children are not
+ * required to be returned.
+ *
* @return the names of this node's children.
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected abstract String[] childrenNamesSpi() throws BackingStoreException;
/**
* Returns the child preference node with the given name, creating it
* if it does not exist. The caller of this method should ensure that the
- * given name is valid and that this node has not been removed or cached.
+ * given name is valid and that this node has not been removed or cached.
* If the named node has just been removed, the implementation
* of this method must create a new one instead of reactivating the removed
* one.
@@ -278,7 +260,6 @@ public abstract class AbstractPreferences extends Preferences {
* @param name
* the name of the child preference to be returned.
* @return the child preference node.
- * @since Android 1.0
*/
protected abstract AbstractPreferences childSpi(String name);
@@ -287,39 +268,37 @@ public abstract class AbstractPreferences extends Preferences {
* Puts the given key-value pair into this node. Caller of this method
* should ensure that both of the given values are valid and that this
* node has not been removed.
- *
+ *
* @param name
* the given preference key.
* @param value
* the given preference value.
- * @since Android 1.0
*/
protected abstract void putSpi(String name, String value);
/**
- * Gets the preference value mapped to the given key. The caller of this method
- * should ensure that the given key is valid and that this node has not been
- * removed. This method should not throw any exceptions but if it does, the
- * caller will ignore the exception, regarding it as a {@code null} return value.
- *
+ * Gets the preference value mapped to the given key. The caller of this
+ * method should ensure that the given key is valid and that this node has
+ * not been removed. This method should not throw any exceptions but if it
+ * does, the caller will ignore the exception, regarding it as a {@code
+ * null} return value.
+ *
* @param key
* the given key to be searched for.
* @return the preference value mapped to the given key.
- * @since Android 1.0
*/
protected abstract String getSpi(String key);
/**
* Returns an array of all preference keys of this node or an empty array if
- * no preferences have been found. The caller of this method should ensure that
- * this node has not been removed.
- *
+ * no preferences have been found. The caller of this method should ensure
+ * that this node has not been removed.
+ *
* @return the array of all preference keys.
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected abstract String[] keysSpi() throws BackingStoreException;
@@ -329,11 +308,10 @@ public abstract class AbstractPreferences extends Preferences {
* method {@link Preferences#removeNode() Preferences.removeNode()} should
* invoke this method multiple-times in bottom-up pattern. The removal is
* not required to be persisted until after it is flushed.
- *
+ *
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected abstract void removeNodeSpi() throws BackingStoreException;
@@ -344,20 +322,18 @@ public abstract class AbstractPreferences extends Preferences {
*
* @param key
* the key of the preference that is to be removed.
- * @since Android 1.0
*/
protected abstract void removeSpi(String key);
/**
* Synchronizes this node with the backing store. This method should only
* synchronize this node and should not include the descendant nodes. An
- * implementation that wants to provide functionality to synchronize all nodes at once should
- * override the method {@link #sync() sync()}.
+ * implementation that wants to provide functionality to synchronize all
+ * nodes at once should override the method {@link #sync() sync()}.
*
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
protected abstract void syncSpi() throws BackingStoreException;
@@ -385,7 +361,7 @@ public abstract class AbstractPreferences extends Preferences {
for (int i = 0; i < names.length; i++) {
result.add(names[i]);
}
- return result.toArray(new String[0]);
+ return result.toArray(new String[result.size()]);
}
}
@@ -439,13 +415,13 @@ public abstract class AbstractPreferences extends Preferences {
if (key == null) {
throw new NullPointerException();
}
- String result;
+ String result = null;
synchronized (lock) {
checkState();
try {
result = getSpi(key);
} catch (Exception e) {
- result = null;
+ // ignored
}
}
return (result == null ? deflt : result);
@@ -456,9 +432,10 @@ public abstract class AbstractPreferences extends Preferences {
String result = get(key, null);
if (result == null) {
return deflt;
- } else if (result.equalsIgnoreCase("true")) { //$NON-NLS-1$
+ }
+ if ("true".equalsIgnoreCase(result)) { //$NON-NLS-1$
return true;
- } else if (result.equalsIgnoreCase("false")) { //$NON-NLS-1$
+ } else if ("false".equalsIgnoreCase(result)) { //$NON-NLS-1$
return false;
} else {
return deflt;
@@ -474,17 +451,15 @@ public abstract class AbstractPreferences extends Preferences {
if (svalue.length() == 0) {
return new byte[0];
}
- byte[] dres;
try {
byte[] bavalue = svalue.getBytes("US-ASCII"); //$NON-NLS-1$
if (bavalue.length % 4 != 0) {
return deflt;
}
- dres = Base64.decode(bavalue);
+ return Base64.decode(bavalue);
} catch (Exception e) {
- dres = deflt;
+ return deflt;
}
- return dres;
}
@Override
@@ -493,13 +468,11 @@ public abstract class AbstractPreferences extends Preferences {
if (result == null) {
return deflt;
}
- double dres;
try {
- dres = Double.parseDouble(result);
+ return Double.parseDouble(result);
} catch (NumberFormatException e) {
- dres = deflt;
+ return deflt;
}
- return dres;
}
@Override
@@ -508,13 +481,11 @@ public abstract class AbstractPreferences extends Preferences {
if (result == null) {
return deflt;
}
- float fres;
try {
- fres = Float.parseFloat(result);
+ return Float.parseFloat(result);
} catch (NumberFormatException e) {
- fres = deflt;
+ return deflt;
}
- return fres;
}
@Override
@@ -523,13 +494,11 @@ public abstract class AbstractPreferences extends Preferences {
if (result == null) {
return deflt;
}
- int ires;
try {
- ires = Integer.parseInt(result);
+ return Integer.parseInt(result);
} catch (NumberFormatException e) {
- ires = deflt;
+ return deflt;
}
- return ires;
}
@Override
@@ -538,13 +507,11 @@ public abstract class AbstractPreferences extends Preferences {
if (result == null) {
return deflt;
}
- long lres;
try {
- lres = Long.parseLong(result);
+ return Long.parseLong(result);
} catch (NumberFormatException e) {
- lres = deflt;
+ return deflt;
}
- return lres;
}
@Override
@@ -583,42 +550,44 @@ public abstract class AbstractPreferences extends Preferences {
startNode = this;
}
}
- Preferences result = null;
try {
- result = startNode.nodeImpl(name, true);
+ return startNode.nodeImpl(name, true);
} catch (BackingStoreException e) {
- //should not happen
+ // should not happen
+ return null;
}
- return result;
}
private void validateName(String name) {
if (name.endsWith("/") && name.length() > 1) { //$NON-NLS-1$
// prefs.6=Name cannot end with '/'\!
- throw new IllegalArgumentException(Messages.getString("prefs.6")); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("prefs.6")); //$NON-NLS-1$
}
if (name.indexOf("//") >= 0) { //$NON-NLS-1$
// prefs.7=Name cannot contains consecutive '/'\!
- throw new IllegalArgumentException(
- Messages.getString("prefs.7")); //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("prefs.7")); //$NON-NLS-1$
}
}
private AbstractPreferences nodeImpl(String path, boolean createNew)
throws BackingStoreException {
- StringTokenizer st = new StringTokenizer(path, "/"); //$NON-NLS-1$
+ String[] names = path.split("/");//$NON-NLS-1$
AbstractPreferences currentNode = this;
AbstractPreferences temp = null;
- while (st.hasMoreTokens() && null != currentNode) {
- String name = st.nextToken();
- synchronized (currentNode.lock) {
- temp = currentNode.cachedNode.get(name);
- if (temp == null) {
- temp = getNodeFromBackend(createNew, currentNode, name);
+ if (null != currentNode) {
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ synchronized (currentNode.lock) {
+ temp = currentNode.cachedNode.get(name);
+ if (temp == null) {
+ temp = getNodeFromBackend(createNew, currentNode, name);
+ }
+ }
+ currentNode = temp;
+ if (null == currentNode) {
+ break;
}
}
-
- currentNode = temp;
}
return currentNode;
}
@@ -626,12 +595,12 @@ public abstract class AbstractPreferences extends Preferences {
private AbstractPreferences getNodeFromBackend(boolean createNew,
AbstractPreferences currentNode, String name)
throws BackingStoreException {
- AbstractPreferences temp;
if (name.length() > MAX_NAME_LENGTH) {
// prefs.8=Name length is too long: {0}
- throw new IllegalArgumentException(Messages.getString("prefs.8", //$NON-NLS-1$
+ throw new IllegalArgumentException(Messages.getString("prefs.8", //$NON-NLS-1$
name));
}
+ AbstractPreferences temp;
if (createNew) {
temp = currentNode.childSpi(name);
currentNode.cachedNode.put(name, temp);
@@ -646,6 +615,9 @@ public abstract class AbstractPreferences extends Preferences {
@Override
public boolean nodeExists(String name) throws BackingStoreException {
+ if (null == name) {
+ throw new NullPointerException();
+ }
AbstractPreferences startNode = null;
synchronized (lock) {
if (isRemoved()) {
@@ -771,10 +743,11 @@ public abstract class AbstractPreferences extends Preferences {
cachedNode.put(childrenNames[i], child);
}
}
- AbstractPreferences[] children = cachedNode
- .values().toArray(new AbstractPreferences[0]);
- for (int i = 0; i < children.length; i++) {
- children[i].removeNodeImpl();
+
+ final Collection values = cachedNode.values();
+ final AbstractPreferences[] children = values.toArray(new AbstractPreferences[values.size()]);
+ for (AbstractPreferences child : children) {
+ child.removeNodeImpl();
}
removeNodeSpi();
isRemoved = true;
diff --git a/prefs/src/main/java/java/util/prefs/BackingStoreException.java b/prefs/src/main/java/java/util/prefs/BackingStoreException.java
index e8a805c..553d7ab 100644
--- a/prefs/src/main/java/java/util/prefs/BackingStoreException.java
+++ b/prefs/src/main/java/java/util/prefs/BackingStoreException.java
@@ -17,40 +17,35 @@
package java.util.prefs;
-
/**
* An exception to indicate that an error was encountered while accessing the
* backing store.
- *
- * @since Android 1.0
+ *
+ * @since 1.4
*/
public class BackingStoreException extends Exception {
-
+
private static final long serialVersionUID = 859796500401108469L;
-
+
/**
- * Constructs a new {@code BackingStoreException} instance with a detailed exception
- * message.
+ * Constructs a new {@code BackingStoreException} instance with a detailed
+ * exception message.
*
* @param s
* the detailed exception message.
- * @since Android 1.0
*/
public BackingStoreException (String s) {
super(s);
}
/**
- * Constructs a new {@code BackingStoreException} instance with a nested {@code Throwable}.
- *
+ * Constructs a new {@code BackingStoreException} instance with a nested
+ * {@code Throwable}.
+ *
* @param t
* the nested {@code Throwable}.
- * @since Android 1.0
*/
public BackingStoreException (Throwable t) {
super(t);
}
}
-
-
-
diff --git a/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java b/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
index cc68e62..69eaa01 100644
--- a/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
+++ b/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
@@ -17,10 +17,10 @@
package java.util.prefs;
/**
- * The default implementation of PreferencesFactory for the Linux
+ * The default implementation of PreferencesFactory for the Linux
* platform, using the file system as its back end.
- *
- * @since Android 1.0
+ *
+ * @since 1.4
*/
class FilePreferencesFactoryImpl implements PreferencesFactory {
// user root preferences
diff --git a/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java b/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
index cf85fa0..f6e5e8f 100644
--- a/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
+++ b/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
@@ -28,12 +28,12 @@ import java.util.Set;
import org.apache.harmony.prefs.internal.nls.Messages;
/**
- * The default implementation of AbstractPreferences for the Linux platform,
- * using the file system as its back end.
- *
+ * The default implementation of AbstractPreferences for the Linux
+ * platform, using the file system as its back end.
+ *
* TODO some sync mechanism with backend, Performance - check file edit date
- *
- * @since Android 1.0
+ *
+ * @since 1.4
*/
class FilePreferencesImpl extends AbstractPreferences {
@@ -64,7 +64,6 @@ class FilePreferencesImpl extends AbstractPreferences {
SYSTEM_HOME = System.getProperty("java.home") + "/.systemPrefs";//$NON-NLS-1$//$NON-NLS-2$
return null;
}
-
});
}
@@ -97,9 +96,9 @@ class FilePreferencesImpl extends AbstractPreferences {
* Constructors
* --------------------------------------------------------------
*/
-
+
/**
- * Construct root FilePreferencesImpl instance, construct
+ * Construct root FilePreferencesImpl instance, construct
* user root if userNode is true, system root otherwise
*/
FilePreferencesImpl(boolean userNode) {
@@ -108,9 +107,9 @@ class FilePreferencesImpl extends AbstractPreferences {
path = userNode ? USER_HOME : SYSTEM_HOME;
initPrefs();
}
-
+
/**
- * Construct a prefs using given parent and given name
+ * Construct a prefs using given parent and given name
*/
private FilePreferencesImpl(AbstractPreferences parent, String name) {
super(parent, name);
@@ -132,16 +131,16 @@ class FilePreferencesImpl extends AbstractPreferences {
@Override
protected String[] childrenNamesSpi() throws BackingStoreException {
String[] names = AccessController
- .doPrivileged(new PrivilegedAction() {
- public String[] run() {
- return dir.list(new FilenameFilter() {
- public boolean accept(File parent, String name) {
- return new File(path + File.separator + name).isDirectory();
- }
- });
-
+ .doPrivileged(new PrivilegedAction() {
+ public String[] run() {
+ return dir.list(new FilenameFilter() {
+ public boolean accept(File parent, String name) {
+ return new File(path + File.separator + name).isDirectory();
}
});
+
+ }
+ });
if (null == names) {// file is not a directory, exception case
// prefs.3=Cannot get children names for {0}!
throw new BackingStoreException(
@@ -192,14 +191,16 @@ class FilePreferencesImpl extends AbstractPreferences {
prefs = XMLParser.loadFilePrefs(prefsFile);
}
return prefs.getProperty(key);
- } catch (Exception e) {// if Exception happened, return null
+ } catch (Exception e) {
+ // if Exception happened, return null
return null;
}
}
@Override
protected String[] keysSpi() throws BackingStoreException {
- return prefs.keySet().toArray(new String[0]);
+ final Set
*
* @param istream
@@ -565,7 +554,6 @@ public abstract class Preferences {
* @throws SecurityException
* if {@code RuntimePermission("preferences")} is denied by a
* SecurityManager.
- * @since Android 1.0
*/
public static void importPreferences (InputStream istream) throws InvalidPreferencesFormatException, IOException {
checkSecurity();
@@ -575,16 +563,15 @@ public abstract class Preferences {
}
XMLParser.importPrefs(istream);
}
-
+
/**
* Returns whether this is a user preference node.
*
* @return {@code true}, if this is a user preference node, {@code false} if
* this is a system preference node.
- * @since Android 1.0
*/
public abstract boolean isUserNode();
-
+
/**
* Returns all preference keys stored in this node or an empty array if no
* key was found.
@@ -595,18 +582,16 @@ public abstract class Preferences {
* failure.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract String[] keys() throws BackingStoreException;
-
+
/**
* Returns the name of this node.
*
* @return the name of this node.
- * @since Android 1.0
*/
public abstract String name();
-
+
/**
* Returns the preference node with the given path name. The path name can
* be relative or absolute. The requested node and its ancestors will
@@ -625,10 +610,9 @@ public abstract class Preferences {
* if the path name is invalid.
* @throws NullPointerException
* if the given path is {@code null}.
- * @since Android 1.0
*/
- public abstract Preferences node (String path);
-
+ public abstract Preferences node(String path);
+
/**
* Returns whether the preference node with the given path name exists. The
* path is treated as relative to this node if it doesn't start with a slash,
@@ -653,10 +637,9 @@ public abstract class Preferences {
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
- * @since Android 1.0
*/
- public abstract boolean nodeExists (String path) throws BackingStoreException;
-
+ public abstract boolean nodeExists(String path) throws BackingStoreException;
+
/**
* Returns the parent preference node of this node or {@code null} if this
* node is the root node.
@@ -664,10 +647,9 @@ public abstract class Preferences {
* @return the parent preference node of this node.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract Preferences parent();
-
+
/**
* Adds a new preference to this node using the given key and value or
* updates the value if a preference with the given key already exists.
@@ -684,14 +666,13 @@ public abstract class Preferences {
* MAX_VALUE_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void put (String key, String value);
-
+ public abstract void put(String key, String value);
+
/**
- * Adds a new preference with a {@code boolean} value to this node using the given
- * key and value or updates the value if a preference with the given key
- * already exists.
+ * Adds a new preference with a {@code boolean} value to this node using the
+ * given key and value or updates the value if a preference with the given
+ * key already exists.
*
* @param key
* the preference key to be added or updated.
@@ -704,10 +685,9 @@ public abstract class Preferences {
* MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putBoolean (String key, boolean value);
-
+ public abstract void putBoolean(String key, boolean value);
+
/**
* Adds a new preference to this node using the given key and the string
* form of the given value or updates the value if a preference with the
@@ -730,10 +710,9 @@ public abstract class Preferences {
* quarters of {@code MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putByteArray (String key, byte[] value);
-
+ public abstract void putByteArray(String key, byte[] value);
+
/**
* Adds a new preference to this node using the given key and {@code double}
* value or updates the value if a preference with the
@@ -754,12 +733,11 @@ public abstract class Preferences {
* MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putDouble (String key, double value);
-
+ public abstract void putDouble(String key, double value);
+
/**
- * Adds a new preference to this node using the given key and {@code float}
+ * Adds a new preference to this node using the given key and {@code float}
* value or updates the value if a preference with the
* given key already exists.
*
@@ -778,12 +756,11 @@ public abstract class Preferences {
* MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putFloat (String key, float value);
-
+ public abstract void putFloat(String key, float value);
+
/**
- * Adds a new preference to this node using the given key and {@code int}
+ * Adds a new preference to this node using the given key and {@code int}
* value or updates the value if a preference with the
* given key already exists.
*
@@ -802,12 +779,11 @@ public abstract class Preferences {
* MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putInt (String key, int value);
-
+ public abstract void putInt(String key, int value);
+
/**
- * Adds a new preference to this node using the given key and {@code long}
+ * Adds a new preference to this node using the given key and {@code long}
* value or updates the value if a preference with the
* given key already exists.
*
@@ -826,9 +802,8 @@ public abstract class Preferences {
* MAX_KEY_LENGTH}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void putLong (String key, long value);
+ public abstract void putLong(String key, long value);
/**
* Removes the preference mapped to the given key from this node.
@@ -839,13 +814,12 @@ public abstract class Preferences {
* if the given key is {@code null}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void remove (String key);
-
+ public abstract void remove(String key);
+
/**
- * Removes this preference node with all its descendants. The removal
- * won't necessarily be persisted until the method {@code flush()} is invoked.
+ * Removes this preference node with all its descendants. The removal won't
+ * necessarily be persisted until the method {@code flush()} is invoked.
*
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
@@ -854,14 +828,13 @@ public abstract class Preferences {
* if this node has been removed.
* @throws UnsupportedOperationException
* if this is a root node.
- * @since Android 1.0
*/
public abstract void removeNode() throws BackingStoreException;
-
+
/**
- * Registers a {@code NodeChangeListener} instance for this node, which will handle
- * {@code NodeChangeEvent}s. {@code NodeChangeEvent}s will be fired when a child node has
- * been added to or removed from this node.
+ * Registers a {@code NodeChangeListener} instance for this node, which will
+ * handle {@code NodeChangeEvent}s. {@code NodeChangeEvent}s will be fired
+ * when a child node has been added to or removed from this node.
*
* @param ncl
* the listener to be registered.
@@ -869,25 +842,24 @@ public abstract class Preferences {
* if the given listener is {@code null}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
- public abstract void addNodeChangeListener (NodeChangeListener ncl);
-
+ public abstract void addNodeChangeListener(NodeChangeListener ncl);
+
/**
- * Registers a {@code PreferenceChangeListener} instance for this node, which will
- * handle {@code PreferenceChangeEvent}s. {@code PreferenceChangeEvent}s will be fired when
- * a preference has been added to, removed from, or updated for this node.
- *
+ * Registers a {@code PreferenceChangeListener} instance for this node,
+ * which will handle {@code PreferenceChangeEvent}s. {@code
+ * PreferenceChangeEvent}s will be fired when a preference has been added
+ * to, removed from, or updated for this node.
+ *
* @param pcl
* the listener to be registered.
* @throws NullPointerException
* if the given listener is {@code null}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract void addPreferenceChangeListener (PreferenceChangeListener pcl);
-
+
/**
* Removes the given {@code NodeChangeListener} instance from this node.
*
@@ -897,12 +869,12 @@ public abstract class Preferences {
* if the given listener is {@code null}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract void removeNodeChangeListener (NodeChangeListener ncl);
-
+
/**
- * Removes the given {@code PreferenceChangeListener} instance from this node.
+ * Removes the given {@code PreferenceChangeListener} instance from this
+ * node.
*
* @param pcl
* the listener to be removed.
@@ -910,36 +882,34 @@ public abstract class Preferences {
* if the given listener is {@code null}.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract void removePreferenceChangeListener (PreferenceChangeListener pcl);
-
+
/**
* Synchronizes the data of this preference node and its descendants with
- * the back-end preference store. Any changes found in the back-end data should be reflected
- * in this node and its descendants, and at the same time any local changes to this node and
- * descendants should be persisted.
+ * the back-end preference store. Any changes found in the back-end data
+ * should be reflected in this node and its descendants, and at the same
+ * time any local changes to this node and descendants should be persisted.
*
* @throws BackingStoreException
* if the backing store is unavailable or causes an operation
* failure.
* @throws IllegalStateException
* if this node has been removed.
- * @since Android 1.0
*/
public abstract void sync() throws BackingStoreException;
-
+
/**
* Returns the system preference node for the package of the given class.
* The absolute path of the returned node is one slash followed by the given
* class's full package name, replacing each period character ('.') with
- * a slash. For example, the absolute path of the preference associated with
+ * a slash. For example, the absolute path of the preference associated with
* the class Object would be "/java/lang". As a special case, the unnamed
* package is associated with a preference node "/<unnamed>". This
* method will create the node and its ancestors as needed. Any nodes created
- * by this method won't necessarily be persisted until the method {@code flush()} is
- * invoked.
- *
+ * by this method won't necessarily be persisted until the method {@code
+ * flush()} is invoked.
+ *
* @param c
* the given class.
* @return the system preference node for the package of the given class.
@@ -948,13 +918,12 @@ public abstract class Preferences {
* @throws SecurityException
* if the {@code RuntimePermission("preferences")} is denied by
* a SecurityManager.
- * @since Android 1.0
*/
public static Preferences systemNodeForPackage (Class> c) {
checkSecurity();
return factory.systemRoot().node(getNodeName(c));
}
-
+
/**
* Returns the root node of the system preference hierarchy.
*
@@ -962,33 +931,32 @@ public abstract class Preferences {
* @throws SecurityException
* if the {@code RuntimePermission("preferences")} is denied by
* a SecurityManager.
- * @since Android 1.0
*/
public static Preferences systemRoot() {
checkSecurity();
return factory.systemRoot();
}
-
+
//check the RuntimePermission("preferences")
private static void checkSecurity() {
SecurityManager manager = System.getSecurityManager();
if(null != manager){
manager.checkPermission(PREFS_PERM);
}
-
+
}
/**
* Returns the user preference node for the package of the given class.
* The absolute path of the returned node is one slash followed by the given
* class's full package name, replacing each period character ('.') with
- * a slash. For example, the absolute path of the preference associated with
+ * a slash. For example, the absolute path of the preference associated with
* the class Object would be "/java/lang". As a special case, the unnamed
* package is associated with a preference node "/<unnamed>". This
* method will create the node and its ancestors as needed. Any nodes created
- * by this method won't necessarily be persisted until the method {@code flush()} is
- * invoked.
- *
+ * by this method won't necessarily be persisted until the method {@code
+ * flush()} is invoked.
+ *
* @param c
* the given class.
* @return the user preference node for the package of the given class.
@@ -997,13 +965,12 @@ public abstract class Preferences {
* @throws SecurityException
* if the {@code RuntimePermission("preferences")} is denied by
* a SecurityManager.
- * @since Android 1.0
*/
public static Preferences userNodeForPackage (Class> c) {
checkSecurity();
return factory.userRoot().node(getNodeName(c));
}
-
+
//parse node's absolute path from class instance
private static String getNodeName(Class> c){
Package p = c.getPackage();
@@ -1020,7 +987,6 @@ public abstract class Preferences {
* @throws SecurityException
* if the {@code RuntimePermission("preferences")} is denied by
* a SecurityManager.
- * @since Android 1.0
*/
public static Preferences userRoot() {
checkSecurity();
@@ -1032,7 +998,6 @@ public abstract class Preferences {
* Preference Node: " followed by this node's absolute path.
*
* @return the string representation of this node.
- * @since Android 1.0
*/
@Override
public abstract String toString();
diff --git a/prefs/src/main/java/java/util/prefs/PreferencesFactory.java b/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
index e56dd95..3ac13e4 100644
--- a/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
+++ b/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
@@ -14,36 +14,30 @@
* limitations under the License.
*/
-
package java.util.prefs;
/**
* This interface is used by the {@link Preferences} class as factory class to
- * create {@code Preferences} instances. This interface can be implemented and installed
- * to replace the default preferences implementation.
+ * create {@code Preferences} instances. This interface can be implemented and
+ * installed to replace the default preferences implementation.
+ *
+ * @see java.util.prefs.Preferences
*
- * @since Android 1.0
+ * @since 1.4
*/
public interface PreferencesFactory {
-
/**
* Returns the root node of the preferences hierarchy for the calling user
* context.
*
* @return the user preferences hierarchy root node.
- * @since Android 1.0
*/
Preferences userRoot();
-
+
/**
* Returns the root node of the system preferences hierarchy.
*
* @return the system preferences hierarchy root node.
- * @since Android 1.0
*/
Preferences systemRoot();
}
-
-
-
-
diff --git a/prefs/src/main/java/java/util/prefs/XMLParser.java b/prefs/src/main/java/java/util/prefs/XMLParser.java
index 2edfc71..c5a234c 100644
--- a/prefs/src/main/java/java/util/prefs/XMLParser.java
+++ b/prefs/src/main/java/java/util/prefs/XMLParser.java
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-
package java.util.prefs;
import java.io.BufferedInputStream;
@@ -27,6 +26,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;
+import java.io.Writer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.security.AccessController;
@@ -64,9 +64,7 @@ import org.w3c.dom.Node;
// END android-added
/**
- * Utility class for importing and exporting {@code Preferences} data from an XML file.
- *
- * @since Android 1.0
+ * Utility class for the Preferences import/export from XML file.
*/
class XMLParser {
@@ -79,15 +77,15 @@ class XMLParser {
* Constant - the DTD string
*/
static final String PREFS_DTD = "" //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " " //$NON-NLS-1$
- + " "; //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " " //$NON-NLS-1$
+ + " "; //$NON-NLS-1$
/*
* Constant - the specified header
@@ -103,24 +101,24 @@ class XMLParser {
* empty string array constant
*/
private static final String[] EMPTY_SARRAY = new String[0];
-
+
/*
- * Constant - used by FilePreferencesImpl, which is default implementation of Linux platform
+ * Constant - used by FilePreferencesImpl, which is default implementation of Linux platform
*/
private static final String FILE_PREFS = ""; //$NON-NLS-1$
/*
* Constant - specify the DTD version
*/
- private static final float XML_VERSION = 1.0f;
-
+ private static final float XML_VERSION = 1.0f;
+
/*
* DOM builder
*/
private static final DocumentBuilder builder;
/*
- * specify the indent level
+ * specify the indent level
*/
private static int indent = -1;
@@ -139,7 +137,7 @@ class XMLParser {
}
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
+ throws SAXException, IOException {
if (systemId.equals(PREFS_DTD_NAME)) {
InputSource result = new InputSource(new StringReader(
PREFS_DTD));
@@ -196,7 +194,7 @@ class XMLParser {
flushEmptyElement("map", out); //$NON-NLS-1$
StringTokenizer ancestors = new StringTokenizer(prefs.absolutePath(),
- "/"); //$NON-NLS-1$
+ "/"); //$NON-NLS-1$
exportNode(ancestors, prefs, withSubTree, out);
flushEndTag("root", out); //$NON-NLS-1$
@@ -207,7 +205,7 @@ class XMLParser {
private static void exportNode(StringTokenizer ancestors,
Preferences prefs, boolean withSubTree, BufferedWriter out)
- throws IOException, BackingStoreException {
+ throws IOException, BackingStoreException {
if (ancestors.hasMoreTokens()) {
String name = ancestors.nextToken();
flushStartTag(
@@ -226,7 +224,7 @@ class XMLParser {
}
private static void exportSubTree(Preferences prefs, BufferedWriter out)
- throws BackingStoreException, IOException {
+ throws BackingStoreException, IOException {
String[] names = prefs.childrenNames();
if (names.length > 0) {
for (int i = 0; i < names.length; i++) {
@@ -241,7 +239,7 @@ class XMLParser {
}
private static void exportEntries(Preferences prefs, BufferedWriter out)
- throws BackingStoreException, IOException {
+ throws BackingStoreException, IOException {
String[] keys = prefs.keys();
String[] values = new String[keys.length];
for (int i = 0; i < keys.length; i++) {
@@ -267,7 +265,7 @@ class XMLParser {
}
private static void flushEndTag(String tagName, BufferedWriter out)
- throws IOException {
+ throws IOException {
flushIndent(indent--, out);
out.write(""); //$NON-NLS-1$
out.write(tagName);
@@ -276,7 +274,7 @@ class XMLParser {
}
private static void flushEmptyElement(String tagName, BufferedWriter out)
- throws IOException {
+ throws IOException {
flushIndent(++indent, out);
out.write("<"); //$NON-NLS-1$
out.write(tagName);
@@ -308,7 +306,7 @@ class XMLParser {
}
private static void flushIndent(int ind, BufferedWriter out)
- throws IOException {
+ throws IOException {
for (int i = 0; i < ind; i++) {
out.write(" "); //$NON-NLS-1$
}
@@ -325,7 +323,7 @@ class XMLParser {
}
private static void flushStartTag(String tagName, BufferedWriter out)
- throws IOException {
+ throws IOException {
flushIndent(++indent, out);
out.write("<"); //$NON-NLS-1$
out.write(tagName);
@@ -365,7 +363,7 @@ class XMLParser {
* utilities for Preferences import
**************************************************************************/
static void importPrefs(InputStream in) throws IOException,
- InvalidPreferencesFormatException {
+ InvalidPreferencesFormatException {
try {
// load XML document
Document doc = builder.parse(new InputSource(in));
@@ -382,7 +380,7 @@ class XMLParser {
// check preferences root's type
Element root = (Element) preferences
- .getElementsByTagName("root").item(0); //$NON-NLS-1$
+ .getElementsByTagName("root").item(0); //$NON-NLS-1$
Preferences prefsRoot = null;
String type = root.getAttribute("type"); //$NON-NLS-1$
if (type.equals("user")) { //$NON-NLS-1$
@@ -445,15 +443,15 @@ class XMLParser {
// TODO dirty implementation of a method from javax.xml.xpath
// should be replaced with a call to a good impl of this method
private static NodeList selectNodeList(Element documentElement, String string) {
-
+
NodeList result = null;
-
+
ArrayList input = new ArrayList();
-
+
String[] path = string.split("/");
-
+
NodeList childNodes = documentElement.getChildNodes();
-
+
if(path[0].equals("entry") || path[0].equals("node")) {
for(int i = 0; i < childNodes.getLength(); i++) {
Object next = childNodes.item(i);
@@ -483,21 +481,21 @@ class XMLParser {
}
}
}
-
+
result = new NodeSet(input.iterator());
-
+
return result;
}
// END android-added
-
+
/***************************************************************************
* utilities for FilePreferencesImpl, which is default implementation of Linux platform
**************************************************************************/
/**
* load preferences from file, if cannot load, create a new one FIXME: need
* lock or not?
- *
- * @param file the XML file to be read
+ *
+ * @param file the XML file to be read
* @return Properties instance which indicates the preferences key-value pairs
*/
static Properties loadFilePrefs(final File file) {
@@ -506,14 +504,6 @@ class XMLParser {
return loadFilePrefsImpl(file);
}
});
-
- // try {
- // //FIXME: lines below can be deleted, because it is not required to
- // persistent at the very beginning
- // flushFilePrefs(file, result);
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
}
static Properties loadFilePrefsImpl(final File file) {
@@ -524,7 +514,6 @@ class XMLParser {
InputStream in = null;
FileLock lock = null;
try {
-
FileInputStream istream = new FileInputStream(file);
// BEGIN android-modified
in = new BufferedInputStream(istream, 8192);
@@ -544,17 +533,16 @@ class XMLParser {
result.setProperty(key, value);
}
return result;
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
+ } catch (SAXException e) {
+ // BEGIN android-removed
+ // } catch (TransformerException e) {
+ // // transform shouldn't fail for xpath call
+ // throw new AssertionError(e);
+ // END android-removed
} finally {
- try {
- lock.release();
- } catch (Exception e) {//ignore
- }
- try {
- in.close();
- } catch (Exception e) {//ignore
- }
+ releaseQuietly(lock);
+ closeQuietly(in);
}
} else {
file.delete();
@@ -563,7 +551,7 @@ class XMLParser {
}
/**
- *
+ *
* @param file
* @param prefs
* @throws PrivilegedActionException
@@ -576,7 +564,7 @@ class XMLParser {
}
});
}
-
+
static void flushFilePrefsImpl(File file, Properties prefs) throws IOException {
BufferedWriter out = null;
FileLock lock = null;
@@ -604,18 +592,35 @@ class XMLParser {
}
out.flush();
} finally {
- try {
- lock.release();
- } catch (Exception e) {//ignore
- }
- try {
- if (null != out) {
- out.close();
- }
- } catch (Exception e) {//ignore
- }
+ releaseQuietly(lock);
+ closeQuietly(out);
}
}
-}
+ private static void releaseQuietly(FileLock lock) {
+ if (lock == null) {
+ return;
+ }
+ try {
+ lock.release();
+ } catch (IOException e) {}
+ }
+ private static void closeQuietly(Writer out) {
+ if (out == null) {
+ return;
+ }
+ try {
+ out.close();
+ } catch (IOException e) {}
+ }
+
+ private static void closeQuietly(InputStream in) {
+ if (in == null) {
+ return;
+ }
+ try {
+ in.close();
+ } catch (IOException e) {}
+ }
+}
diff --git a/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/Messages.java b/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/Messages.java
index cfc7236..aaf5d8d 100644
--- a/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/Messages.java
+++ b/prefs/src/main/java/org/apache/harmony/prefs/internal/nls/Messages.java
@@ -43,7 +43,7 @@ import org.apache.harmony.luni.util.MsgHelp;
* is looked up, or resource bundle support is not available, the key itself
* will be returned as the associated message. This means that the KEY
* should a reasonable human-readable (english) string.
- *
+ *
*/
public class Messages {
@@ -54,7 +54,7 @@ public class Messages {
/**
* Retrieves a message which has no arguments.
- *
+ *
* @param msg
* String the key to look up.
* @return String the message for that key in the system message bundle.
@@ -67,7 +67,7 @@ public class Messages {
/**
* Retrieves a message which takes 1 argument.
- *
+ *
* @param msg
* String the key to look up.
* @param arg
@@ -80,7 +80,7 @@ public class Messages {
/**
* Retrieves a message which takes 1 integer argument.
- *
+ *
* @param msg
* String the key to look up.
* @param arg
@@ -93,7 +93,7 @@ public class Messages {
/**
* Retrieves a message which takes 1 character argument.
- *
+ *
* @param msg
* String the key to look up.
* @param arg
@@ -106,7 +106,7 @@ public class Messages {
/**
* Retrieves a message which takes 2 arguments.
- *
+ *
* @param msg
* String the key to look up.
* @param arg1
@@ -121,7 +121,7 @@ public class Messages {
/**
* Retrieves a message which takes several arguments.
- *
+ *
* @param msg
* String the key to look up.
* @param args
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
index 418e52d..76ef4e7 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
@@ -35,9 +35,13 @@ import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
+import tests.util.PrefsTester;
+
@TestTargetClass(AbstractPreferences.class)
public class AbstractPreferencesTest extends TestCase {
+ private final PrefsTester prefsTester = new PrefsTester();
+
AbstractPreferences pref;
static AbstractPreferences root;
@@ -51,13 +55,8 @@ public class AbstractPreferencesTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
+ prefsTester.setUp();
- System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
- System.setProperty("java.home", System.getProperty("java.io.tmpdir"));
-
- Preferences.systemRoot().clear();
- Preferences.userRoot().clear();
-
root = (AbstractPreferences) Preferences.userRoot();
parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass());
@@ -65,11 +64,7 @@ public class AbstractPreferencesTest extends TestCase {
}
protected void tearDown() throws Exception {
- parent.removeNode();
- Preferences.systemRoot().clear();
- Preferences.userRoot().clear();
- System.setProperty("user.home", oldUserHome);
- System.setProperty("java.home", oldJavaHome);
+ prefsTester.tearDown();
super.tearDown();
}
@@ -855,6 +850,31 @@ public class AbstractPreferencesTest extends TestCase {
}
@TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "nodeExists",
+ args = {String.class}
+ )
+ public void test_nodeExists() throws BackingStoreException {
+ AbstractPreferences test = (AbstractPreferences) Preferences.userRoot()
+ .node("test");
+ try {
+ test.nodeExists(null);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ test.removeNode();
+ try {
+ test.nodeExists(null);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ @TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "parent",
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
index 0c61e75..0cb1975 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
@@ -28,28 +28,22 @@ import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import junit.framework.TestCase;
+import tests.util.PrefsTester;
@TestTargetClass(java.util.prefs.Preferences.class)
public class FilePreferencesImplTest extends TestCase {
- String oldUserHome = System.getProperty("user.home");
- String oldJavaHome = System.getProperty("java.home");
+ private final PrefsTester prefsTester = new PrefsTester();
+ @Override
protected void setUp() throws Exception {
super.setUp();
-
- System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
- System.setProperty("java.home", System.getProperty("java.io.tmpdir"));
- Preferences.systemRoot().clear();
- Preferences.userRoot().clear();
+ prefsTester.setUp();
}
+ @Override
protected void tearDown() throws Exception {
- Preferences.systemRoot().clear();
- Preferences.userRoot().clear();
- System.setProperty("user.home", oldUserHome);
- System.setProperty("java.home", oldJavaHome);
-
+ prefsTester.tearDown();
super.tearDown();
}
@@ -313,6 +307,7 @@ public class FilePreferencesImplTest extends TestCase {
System.setSecurityManager(dflt);
}
+ @Override
public void checkPermission(Permission perm) {
if (perm instanceof FilePermission) {
throw new SecurityException();
@@ -321,6 +316,7 @@ public class FilePreferencesImplTest extends TestCase {
}
}
+ @Override
public void checkPermission(Permission perm, Object ctx) {
if (perm instanceof FilePermission) {
System.out.println(perm.getActions());
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
index 28c953e..c7ff946 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
@@ -44,7 +44,7 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
)
public void testInvalidPreferencesFormatExceptionString() {
InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
- "msg");
+ "msg");
assertNull(e.getCause());
assertEquals("msg", e.getMessage());
}
@@ -99,7 +99,7 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new InvalidPreferencesFormatException(
- "msg"));
+ "msg"));
}
/**
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
index 1820954..b149225 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
@@ -84,6 +84,7 @@ public class MockAbstractPreferences extends AbstractPreferences {
return lock;
}
+ @Override
public String[] childrenNamesSpi() throws BackingStoreException {
checkException();
if (result == returnNull)
@@ -108,6 +109,7 @@ public class MockAbstractPreferences extends AbstractPreferences {
return childSpi(name);
}
+ @Override
public AbstractPreferences childSpi(String name) {
try {
checkException();
@@ -123,11 +125,13 @@ public class MockAbstractPreferences extends AbstractPreferences {
return r;
}
+ @Override
public void flushSpi() throws BackingStoreException {
checkException();
flushedTimes++;
}
+ @Override
public String getSpi(String key) {
try {
checkException();
@@ -139,6 +143,7 @@ public class MockAbstractPreferences extends AbstractPreferences {
return result == returnNull ? null : attr.getProperty(key);
}
+ @Override
public String[] keysSpi() throws BackingStoreException {
checkException();
Set