You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/07/16 00:03:36 UTC
svn commit: r422297 - in
/incubator/harmony/enhanced/classlib/trunk/modules/prefs: ./
src/main/java/java/util/prefs/
src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/
Author: ndbeyer
Date: Sat Jul 15 15:03:35 2006
New Revision: 422297
URL: http://svn.apache.org/viewvc?rev=422297&view=rev
Log:
Code cleanup.
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/prefs/build.xml
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/BackingStoreException.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/build.xml
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/build.xml?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/build.xml (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/build.xml Sat Jul 15 15:03:35 2006
@@ -150,7 +150,6 @@
<fileset dir="${hy.prefs.src.test.java}">
<include name="**/*Test.java"/>
- <exclude name="org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java"/>
<exclude name="org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java"/>
</fileset>
</batchtest>
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java Sat Jul 15 15:03:35 2006
@@ -18,10 +18,13 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.util.EventListener;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
@@ -52,13 +55,8 @@
* Constants
* -----------------------------------------------------------
*/
- /**
- * The object used to lock this node.
- */
- protected final Object lock;
-
- //the unhandled events colletion
- static final LinkedList events = new LinkedList();
+ //the unhandled events collection
+ static final List<EventObject> events = new LinkedList<EventObject>();
//the event dispatcher thread
private final static EventDispatcher dispatcher = new EventDispatcher("Preference Event Dispatcher");
@@ -68,6 +66,11 @@
* -----------------------------------------------------------
*/
/**
+ * The object used to lock this node.
+ */
+ protected final Object lock;
+
+ /**
* This field is true if this node is created while it doesn't exist in the
* 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
@@ -76,13 +79,14 @@
protected boolean newNode;
//cached child nodes
- private HashMap cachedNode;
+ private Map<String, AbstractPreferences> cachedNode;
//true if this node is in user preference hierarchy
boolean userNode;
- //the colletions of listeners
- LinkedList nodeChangeListeners, preferenceChangeListeners;
+ //the collections of listeners
+ List<EventListener> nodeChangeListeners;
+ List<EventListener> preferenceChangeListeners;
//this node's name
private String nodeName;
@@ -143,10 +147,10 @@
throw new IllegalArgumentException();
}
root = null == parent ? this : parent.root;
- nodeChangeListeners = new LinkedList();
- preferenceChangeListeners = new LinkedList();
+ nodeChangeListeners = new LinkedList<EventListener>();
+ preferenceChangeListeners = new LinkedList<EventListener>();
isRemoved = false;
- cachedNode = new HashMap();
+ cachedNode = new HashMap<String, AbstractPreferences>();
nodeName = name;
parentPref = parent;
lock = new Object();
@@ -164,8 +168,7 @@
* @return arrays of all cached children node.
*/
protected final AbstractPreferences[] cachedChildren() {
- return (AbstractPreferences[]) cachedNode.values().toArray(
- new AbstractPreferences[0]);
+ return cachedNode.values().toArray(new AbstractPreferences[cachedNode.size()]);
}
/**
@@ -238,7 +241,7 @@
* If the named node has just been removed, implementation of this method must
* create a new one instead of reactivated the removed one.
* <p>
- * The new creation is not required to be presisted immediately until the flush
+ * The new creation is not required to be persisted immediately until the flush
* method is invoked.</p>
*
* @param name
@@ -336,12 +339,12 @@
public String[] childrenNames() throws BackingStoreException {
synchronized (lock) {
checkState();
- TreeSet result = new TreeSet(cachedNode.keySet());
+ TreeSet<String> result = new TreeSet<String>(cachedNode.keySet());
String[] names = childrenNamesSpi();
for (int i = 0; i < names.length; i++) {
result.add(names[i]);
}
- return (String[]) result.toArray(new String[0]);
+ return result.toArray(new String[0]);
}
}
@@ -352,8 +355,9 @@
public void clear() throws BackingStoreException {
synchronized (lock) {
String[] keyList = keys();
- for (int i = 0; i < keyList.length; i++)
+ for (int i = 0; i < keyList.length; i++) {
remove(keyList[i]);
+ }
}
}
@@ -395,8 +399,9 @@
}
AbstractPreferences[] cc = cachedChildren();
int i;
- for (i = 0; i < cc.length; i++)
+ for (i = 0; i < cc.length; i++) {
cc[i].flush();
+ }
}
/*
@@ -404,8 +409,9 @@
* @see java.util.prefs.Preferences#get(java.lang.String, java.lang.String)
*/
public String get(String key, String deflt) {
- if (key == null)
+ if (key == null) {
throw new NullPointerException();
+ }
String result;
synchronized (lock) {
checkState();
@@ -424,14 +430,15 @@
*/
public boolean getBoolean(String key, boolean deflt) {
String result = get(key, null);
- if (result == null)
+ if (result == null) {
return deflt;
- else if (result.equalsIgnoreCase("true")) { //$NON-NLS-1$
+ } else if (result.equalsIgnoreCase("true")) { //$NON-NLS-1$
return true;
} else if (result.equalsIgnoreCase("false")) { //$NON-NLS-1$
return false;
- } else
+ } else {
return deflt;
+ }
}
/*
@@ -440,14 +447,15 @@
*/
public byte[] getByteArray(String key, byte[] deflt) {
String svalue = get(key, null);
- if (svalue == null)
+ if (svalue == null) {
return deflt;
- if ("".equals(svalue)) { //$NON-NLS-1$
+ }
+ if (svalue.length() == 0) {
return new byte[0];
}
byte[] dres;
try {
- byte[] bavalue = svalue.getBytes("ascii"); //$NON-NLS-1$
+ byte[] bavalue = svalue.getBytes("US-ASCII"); //$NON-NLS-1$
if (bavalue.length % 4 != 0) {
return deflt;
}
@@ -464,8 +472,9 @@
*/
public double getDouble(String key, double deflt) {
String result = get(key, null);
- if (result == null)
+ if (result == null) {
return deflt;
+ }
double dres;
try {
dres = Double.parseDouble(result);
@@ -481,8 +490,9 @@
*/
public float getFloat(String key, float deflt) {
String result = get(key, null);
- if (result == null)
+ if (result == null) {
return deflt;
+ }
float fres;
try {
fres = Float.parseFloat(result);
@@ -498,8 +508,9 @@
*/
public int getInt(String key, int deflt) {
String result = get(key, null);
- if (result == null)
+ if (result == null) {
return deflt;
+ }
int ires;
try {
ires = Integer.parseInt(result);
@@ -515,8 +526,9 @@
*/
public long getLong(String key, long deflt) {
String result = get(key, null);
- if (result == null)
+ if (result == null) {
return deflt;
+ }
long lres;
try {
lres = Long.parseLong(result);
@@ -601,7 +613,7 @@
while (st.hasMoreTokens() && null != currentNode) {
String name = st.nextToken();
synchronized (currentNode.lock) {
- temp = (AbstractPreferences) currentNode.cachedNode.get(name);
+ temp = currentNode.cachedNode.get(name);
if (temp == null) {
temp = getNodeFromBackend(createNew, currentNode, name);
}
@@ -623,8 +635,9 @@
if (createNew) {
temp = currentNode.childSpi(name);
currentNode.cachedNode.put(name, temp);
- if (temp.newNode && currentNode.nodeChangeListeners.size() > 0)
+ if (temp.newNode && currentNode.nodeChangeListeners.size() > 0) {
currentNode.notifyChildAdded(temp);
+ }
} else {
temp = currentNode.getChild(name);
}
@@ -707,7 +720,7 @@
*/
public void putByteArray(String key, byte[] value) {
try {
- put(key, Base64.encode(value, "ascii")); //$NON-NLS-1$
+ put(key, Base64.encode(value, "US-ASCII")); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
//should not happen
}
@@ -784,7 +797,7 @@
cachedNode.put(childrenNames[i], child);
}
}
- AbstractPreferences[] children = (AbstractPreferences[]) cachedNode
+ AbstractPreferences[] children = cachedNode
.values().toArray(new AbstractPreferences[0]);
for (int i = 0; i < children.length; i++) {
children[i].removeNodeImpl();
@@ -867,8 +880,9 @@
}
AbstractPreferences[] cc = cachedChildren();
int i;
- for (i = 0; i < cc.length; i++)
+ for (i = 0; i < cc.length; i++) {
cc[i].sync();
+ }
}
/*
@@ -946,16 +960,16 @@
if (events.isEmpty()) {
events.wait();
}
- EventObject event = (EventObject) events.get(0);
+ EventObject event = events.get(0);
events.remove(0);
return event;
}
}
private void dispatchPrefChange(PreferenceChangeEvent event,
- LinkedList preferenceChangeListeners) {
+ List<EventListener> preferenceChangeListeners) {
synchronized (preferenceChangeListeners) {
- Iterator i = preferenceChangeListeners.iterator();
+ Iterator<EventListener> i = preferenceChangeListeners.iterator();
while (i.hasNext()) {
PreferenceChangeListener pcl = (PreferenceChangeListener) i
.next();
@@ -965,9 +979,9 @@
}
private void dispatchNodeRemove(NodeChangeEvent event,
- LinkedList nodeChangeListeners) {
+ List<EventListener> nodeChangeListeners) {
synchronized (nodeChangeListeners) {
- Iterator i = nodeChangeListeners.iterator();
+ Iterator<EventListener> i = nodeChangeListeners.iterator();
while (i.hasNext()) {
NodeChangeListener ncl = (NodeChangeListener) i.next();
ncl.childRemoved(event);
@@ -976,9 +990,9 @@
}
private void dispatchNodeAdd(NodeChangeEvent event,
- LinkedList nodeChangeListeners) {
+ List<EventListener> nodeChangeListeners) {
synchronized (nodeChangeListeners) {
- Iterator i = nodeChangeListeners.iterator();
+ Iterator<EventListener> i = nodeChangeListeners.iterator();
while (i.hasNext()) {
NodeChangeListener ncl = (NodeChangeListener) i.next();
ncl.childAdded(event);
@@ -988,25 +1002,20 @@
}
private static class NodeAddEvent extends NodeChangeEvent {
- /**
- * @param p
- * @param c
- */
+ //The base class is NOT serializable, so this class isn't either.
+ private static final long serialVersionUID = 1L;
+
public NodeAddEvent(Preferences p, Preferences c) {
super(p, c);
}
}
private static class NodeRemoveEvent extends NodeChangeEvent {
- /**
- * @param p
- * @param c
- */
+ //The base class is NOT serializable, so this class isn't either.
+ private static final long serialVersionUID = 1L;
+
public NodeRemoveEvent(Preferences p, Preferences c) {
super(p, c);
}
}
}
-
-
-
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/BackingStoreException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/BackingStoreException.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/BackingStoreException.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/BackingStoreException.java Sat Jul 15 15:03:35 2006
@@ -21,7 +21,7 @@
import java.io.ObjectOutputStream;
/**
- * An exception to indicate that some eror was encountered while accessing
+ * An exception to indicate that some error was encountered while accessing
* the backing store.
* <p>
* Please note that this class cannot be serialized actually, so relevant
@@ -31,6 +31,8 @@
* @since 1.4
*/
public class BackingStoreException extends Exception {
+
+ private static final long serialVersionUID = 859796500401108469L;
/**
* Constructs a new <code>BackingStoreException</code> instance using an
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesFactoryImpl.java Sat Jul 15 15:03:35 2006
@@ -16,7 +16,7 @@
package java.util.prefs;
-/*
+/**
* Default implementation of <code>PreferencesFactory</code> for Linux
* platform, using file system as back end.
*
@@ -24,29 +24,19 @@
*/
class FilePreferencesFactoryImpl implements PreferencesFactory {
- /*
+ /**
* Default constructor
*/
public FilePreferencesFactoryImpl() {
super();
}
- /* (non-Javadoc)
- * @see java.util.prefs.PreferencesFactory#userRoot()
- */
public Preferences userRoot() {
return FilePreferencesImpl.userRoot;
}
- /* (non-Javadoc)
- * @see java.util.prefs.PreferencesFactory#systemRoot()
- */
public Preferences systemRoot() {
return FilePreferencesImpl.systemRoot;
}
}
-
-
-
-
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java Sat Jul 15 15:03:35 2006
@@ -62,7 +62,7 @@
* --------------------------------------------------------------
*/
static {
- AccessController.doPrivileged(new PrivilegedAction() {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
USER_HOME = System.getProperty("user.home") + "/.java/.userPrefs";//$NON-NLS-1$ //$NON-NLS-2$
SYSTEM_HOME = System.getProperty("java.home") + "/.systemPrefs";//$NON-NLS-1$//$NON-NLS-2$
@@ -93,10 +93,10 @@
File dir;
//cache for removed prefs key-value pair
- private Set removed = new HashSet();
+ private Set<String> removed = new HashSet<String>();
//cache for updated prefs key-value pair
- private Set updated = new HashSet();
+ private Set<String> updated = new HashSet<String>();
/*
* --------------------------------------------------------------
@@ -114,12 +114,11 @@
private void initPrefs() {
dir = new File(path);
- newNode = ((Boolean) AccessController
- .doPrivileged(new PrivilegedAction() {
- public Object run() {
- return Boolean.valueOf(!dir.exists());
- }
- })).booleanValue();
+ newNode = (AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return Boolean.valueOf(!dir.exists());
+ }
+ })).booleanValue();
prefsFile = new File(path + File.separator + prefsFileName);
prefs = XMLParser.loadFilePrefs(prefsFile);
}
@@ -146,13 +145,12 @@
* @see java.util.prefs.AbstractPreferences#chilrenNamesSpi()
*/
protected String[] childrenNamesSpi() throws BackingStoreException {
- String[] names = (String[]) AccessController
- .doPrivileged(new PrivilegedAction() {
- public Object run() {
+ String[] names = AccessController
+ .doPrivileged(new PrivilegedAction<String[]>() {
+ public String[] run() {
return dir.list(new FilenameFilter() {
public boolean accept(File parent, String name) {
- return new File(path + File.separator + name)
- .isDirectory(); //$NON-NLS-1$
+ return new File(path + File.separator + name).isDirectory();
}
});
@@ -189,7 +187,7 @@
// reload
Properties currentPrefs = XMLParser.loadFilePrefs(prefsFile);
// merge
- Iterator it = removed.iterator();
+ Iterator<String> it = removed.iterator();
while (it.hasNext()) {
currentPrefs.remove(it.next());
}
@@ -230,7 +228,7 @@
* @see java.util.prefs.AbstractPreferences#keysSpi()
*/
protected String[] keysSpi() throws BackingStoreException {
- return (String[]) prefs.keySet().toArray(new String[0]);
+ return prefs.keySet().toArray(new String[0]);
}
/*
@@ -250,15 +248,15 @@
* @see java.util.prefs.AbstractPreferences#removeNodeSpi()
*/
protected void removeNodeSpi() throws BackingStoreException {
- boolean removeSucceed = ((Boolean) AccessController
- .doPrivileged(new PrivilegedAction() {
- public Object run() {
- prefsFile.delete();
- return Boolean.valueOf(dir.delete());
- }
- })).booleanValue();
- if (!removeSucceed)
+ boolean removeSucceed = (AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ prefsFile.delete();
+ return Boolean.valueOf(dir.delete());
+ }
+ })).booleanValue();
+ if (!removeSucceed) {
throw new BackingStoreException("Cannot remove " + toString() + "!"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
}
/*
@@ -282,5 +280,3 @@
}
}
-
-
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/InvalidPreferencesFormatException.java Sat Jul 15 15:03:35 2006
@@ -34,6 +34,8 @@
*/
public class InvalidPreferencesFormatException extends Exception {
+ private static final long serialVersionUID = -791715184232119669L;
+
/**
* Constructs a new <code>InvalidPreferencesFormatException</code> instance using an
* exception message.
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/NodeChangeEvent.java Sat Jul 15 15:03:35 2006
@@ -37,7 +37,10 @@
*/
public class NodeChangeEvent extends EventObject implements Serializable {
- static final long serialVersionUID = 8068949086596572957L;
+ private static final long serialVersionUID = 8068949086596572957L;
+
+ private final Preferences parent;
+ private final Preferences child;
/**
* Construct a new <code>NodeChangeEvent</code> instance.
@@ -86,8 +89,6 @@
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
throw new NotSerializableException();
}
-
- private Preferences parent, child;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeEvent.java Sat Jul 15 15:03:35 2006
@@ -38,7 +38,13 @@
*/
public class PreferenceChangeEvent extends EventObject implements Serializable {
- static final long serialVersionUID = 793724513368024975L;
+ private static final long serialVersionUID = 793724513368024975L;
+
+ private final Preferences node;
+
+ private final String key;
+
+ private final String value;
/**
* Construct a new <code>PreferenceChangeEvent</code> instance.
@@ -100,12 +106,6 @@
private void readObject(ObjectInputStream in) throws IOException{
throw new NotSerializableException();
}
-
- private Preferences node;
-
- private String key;
-
- private String value;
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferenceChangeListener.java Sat Jul 15 15:03:35 2006
@@ -19,7 +19,7 @@
import java.util.EventListener;
/**
- * This interface is used to handle preferences change event. Implmenetation
+ * This interface is used to handle preferences change event. Implementation
* of this interface can be installed by <code>Preferences</code> instance.
*
* @see Preferences
@@ -31,7 +31,7 @@
public interface PreferenceChangeListener extends EventListener {
/**
- * This method gets invoked whenener some preference is added, deleted or
+ * This method gets invoked whenever some preference is added, deleted or
* updated.
*
* @param pce the event instance which describes the changed Preferences
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java Sat Jul 15 15:03:35 2006
@@ -34,7 +34,7 @@
* persistly in implementation-dependent backend, and user doesn't need to care
* about the details.
* <p>
- * Every node has one name and one unique absolute path in a similiar way with
+ * Every node has one name and one unique absolute path in a similar way with
* directories in file system. The root node's name is "", and other nodes' name
* string cannot contains slash and cannot be empty. The root node's absolute
* path is "/", and other nodes' absolute path equals <parent's absolute
@@ -44,7 +44,7 @@
* ancestor's absolute path and a slash.
* </p>
* <p>
- * The modification to preferences data may be asynchronized, which means they
+ * The modification to preferences data may be asynchronous, which means they
* may don't block and may returns immediately, implementation can feel free to
* the modifications to the backend in any time until the flush() or sync()
* method is invoked, these two methods force synchronized updates to backend.
@@ -58,7 +58,7 @@
* when backend is unavailable.
* </p>
* <p>
- * Preferences can be export to/import from xml files, the XML document must
+ * Preferences can be export to/import from XML files, the XML document must
* have the following DOCTYPE declaration:
* </p>
* <p>
@@ -120,17 +120,17 @@
* ---------------------------------------------------------
*/
static{
- String factoryClassName = (String)AccessController.doPrivileged(new PrivilegedAction(){
- public Object run() {
+ String factoryClassName = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
return System.getProperty("java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
}
- });
+ });
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null){
loader = ClassLoader.getSystemClassLoader();
}
- Class factoryClass = loader.loadClass(factoryClassName);
+ Class<?> factoryClass = loader.loadClass(factoryClassName);
factory = (PreferencesFactory) factoryClass.newInstance();
} catch (Exception e) {
throw new InternalError("Cannot initiate PreferencesFactory: "+factoryClassName+". Caused by "+ e); //$NON-NLS-1$//$NON-NLS-2$
@@ -190,7 +190,7 @@
* This XML document has the following DOCTYPE declaration:
* <pre>
* <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"></pre>
- * And the utf-8 encoding will be used. Please note that this node is not
+ * And the UTF-8 encoding will be used. Please note that this node is not
* thread-safe, which is an exception of this class.
* </p>
* @param ostream
@@ -211,7 +211,7 @@
* This XML document has the following DOCTYPE declaration:
* <pre>
* <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"></pre> *
- * And the utf-8 encoding will be used. Please note that this node is not
+ * And the UTF-8 encoding will be used. Please note that this node is not
* thread-safe, which is an exception of this class.
* </p>
* @param ostream
@@ -445,10 +445,10 @@
/**
* Return true if this is a user preferences, false if this is a system
- * perferences
+ * preferences
*
* @return true if this is a user preferences, false if this is a
- * system perferences
+ * system preferences
*/
public abstract boolean isUserNode();
@@ -570,7 +570,7 @@
* @throws IllegalArgumentException
* if the given key's length is bigger than
* <code>MAX_KEY_LENGTH</code> or value's length is bigger than
- * three quaters of <code>MAX_KEY_LENGTH</code>
+ * three quarters of <code>MAX_KEY_LENGTH</code>
* @throws IllegalStateException
* if this node has been removed
*/
@@ -810,7 +810,7 @@
}
//parse node's absolute path from class instance
- private static String getNodeName(Class c){
+ private static String getNodeName(Class<?> c){
Package p = c.getPackage();
if(null == p){
return "/<unnamed>"; //$NON-NLS-1$
@@ -840,7 +840,3 @@
*/
public abstract String toString();
}
-
-
-
-
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferencesFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferencesFactory.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferencesFactory.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/PreferencesFactory.java Sat Jul 15 15:03:35 2006
@@ -17,7 +17,7 @@
package java.util.prefs;
/**
- * This interfaceis used by {@link java.util.prefs.Preferences Preferences} class
+ * This interface is used by {@link Preferences} class
* as factory class to create Preferences instance. This interface can be implemented
* and installed to replace the default preferences implementation.
*
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java Sat Jul 15 15:03:35 2006
@@ -52,18 +52,18 @@
import org.xml.sax.SAXParseException;
/**
- * Utility class for the Preferences import/export from xml file.
+ * Utility class for the Preferences import/export from XML file.
*
*/
class XMLParser {
/*
- * const - the specified dtd URL
+ * Constant - the specified DTD URL
*/
static final String PREFS_DTD_NAME = "http://java.sun.com/dtd/preferences.dtd"; //$NON-NLS-1$
/*
- * const - the dtd string
+ * Constant - the DTD string
*/
static final String PREFS_DTD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" //$NON-NLS-1$
+ " <!ELEMENT preferences (root)>" //$NON-NLS-1$
@@ -77,12 +77,12 @@
+ " <!ATTLIST entry key CDATA #REQUIRED value CDATA #REQUIRED >"; //$NON-NLS-1$
/*
- * const - the specified header
+ * Constant - the specified header
*/
static final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
/*
- * const - the specified doctype
+ * Constant - the specified DOCTYPE
*/
static final String DOCTYPE = "<!DOCTYPE preferences SYSTEM"; //$NON-NLS-1$
@@ -92,17 +92,17 @@
private static final String[] EMPTY_SARRAY = new String[0];
/*
- * const - 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 = "<!DOCTYPE map SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>"; //$NON-NLS-1$
/*
- * const - specify the dtd version
+ * Constant - specify the DTD version
*/
private static final float XML_VERSION = 1.0f;
/*
- * dom builder
+ * DOM builder
*/
private static final DocumentBuilder builder;
@@ -112,7 +112,7 @@
private static int indent = -1;
/*
- * init dom builder
+ * init DOM builder
*/
static {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -136,16 +136,16 @@
}
});
builder.setErrorHandler(new ErrorHandler() {
- public void warning(SAXParseException arg0) throws SAXException {
- throw arg0;
+ public void warning(SAXParseException e) throws SAXException {
+ throw e;
}
- public void error(SAXParseException arg0) throws SAXException {
- throw arg0;
+ public void error(SAXParseException e) throws SAXException {
+ throw e;
}
- public void fatalError(SAXParseException arg0) throws SAXException {
- throw arg0;
+ public void fatalError(SAXParseException e) throws SAXException {
+ throw e;
}
});
}
@@ -159,8 +159,7 @@
static void exportPrefs(Preferences prefs, OutputStream stream,
boolean withSubTree) throws IOException, BackingStoreException {
indent = -1;
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(stream,
- "utf-8")); //$NON-NLS-1$
+ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(stream, "UTF-8")); //$NON-NLS-1$
out.write(HEADER);
out.newLine();
out.newLine();
@@ -350,7 +349,7 @@
static void importPrefs(InputStream in) throws IOException,
InvalidPreferencesFormatException {
try {
- // load xml document
+ // load XML document
Document doc = builder.parse(new InputSource(in));
// check preferences' export version
@@ -423,27 +422,26 @@
* 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) {
- return (Properties) AccessController
- .doPrivileged(new PrivilegedAction() {
- public Object run() {
- return loadFilePrefsImpl(file);
- }
- });
+ return AccessController.doPrivileged(new PrivilegedAction<Properties>() {
+ public Properties run() {
+ return loadFilePrefsImpl(file);
+ }
+ });
// try {
// //FIXME: lines below can be deleted, because it is not required to
- // persistent at the very begining
+ // persistent at the very beginning
// flushFilePrefs(file, result);
// } catch (IOException e) {
// e.printStackTrace();
// }
}
- static Object loadFilePrefsImpl(final File file) {
+ static Properties loadFilePrefsImpl(final File file) {
Properties result = new Properties();
if (!file.exists()) {
file.getParentFile().mkdirs();
@@ -492,13 +490,12 @@
* @throws PrivilegedActionException
*/
static void flushFilePrefs(final File file, final Properties prefs) throws PrivilegedActionException {
- AccessController
- .doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws IOException {
- flushFilePrefsImpl(file, prefs);
- return null;
- }
- });
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws IOException {
+ flushFilePrefsImpl(file, prefs);
+ return null;
+ }
+ });
}
static void flushFilePrefsImpl(File file, Properties prefs) throws IOException {
@@ -506,7 +503,7 @@
FileLock lock = null;
try {
FileOutputStream ostream = new FileOutputStream(file);
- out = new BufferedWriter(new OutputStreamWriter(ostream, "utf-8")); //$NON-NLS-1$
+ out = new BufferedWriter(new OutputStreamWriter(ostream, "UTF-8")); //$NON-NLS-1$
FileChannel channel = ostream.getChannel();
lock = channel.lock();
out.write(HEADER);
@@ -516,7 +513,7 @@
if (prefs.size() == 0) {
exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, out);
} else {
- String[] keys = (String[]) prefs.keySet().toArray(EMPTY_SARRAY);
+ String[] keys = prefs.keySet().toArray(new String[prefs.size()]);
int length = keys.length;
String[] values = new String[length];
for (int i = 0; i < length; i++) {
@@ -531,8 +528,9 @@
} catch (Exception e) {//ignore
}
try {
- if (null != out)
+ if (null != out) {
out.close();
+ }
} catch (Exception e) {//ignore
}
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java Sat Jul 15 15:03:35 2006
@@ -23,29 +23,31 @@
import junit.framework.TestCase;
-/**
- * TODO Type description
- *
- */
public class FilePreferencesImplTest extends TestCase {
- Preferences uroot = Preferences.userRoot();
-
- Preferences sroot = Preferences.systemRoot();
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+ private String prevFactory;
+ private Preferences uroot;
+ private Preferences sroot;
+
+ public FilePreferencesImplTest() {
+ super();
+ }
+
+ protected void setUp() throws Exception {
+ prevFactory = System.getProperty("java.util.prefs.PreferencesFactory");
+ System.setProperty("java.util.prefs.PreferencesFactory", "java.util.prefs.FilePreferencesFactoryImpl");
+
+ uroot = Preferences.userRoot();
+ sroot = Preferences.systemRoot();
+ }
+
+ protected void tearDown() throws Exception {
+ if (prevFactory != null)
+ System.setProperty("java.util.prefs.PreferencesFactory", prevFactory);
+
+ uroot = null;
+ sroot = null;
+ }
public void testPutGet() throws IOException, BackingStoreException {
uroot.put("ukey1", "value1");
@@ -75,6 +77,7 @@
Preferences child1 = uroot.node("child1");
Preferences child2 = uroot.node("\u4e2d child2");
Preferences grandchild = child1.node("grand");
+ assertNotNull(grandchild);
String[] childNames = uroot.childrenNames();
assertEquals(2, childNames.length);
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java Sat Jul 15 15:03:35 2006
@@ -16,6 +16,7 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.prefs.AbstractPreferences;
@@ -34,7 +35,7 @@
Properties attr = new Properties();
- HashMap childs = new HashMap();
+ Map<String, MockAbstractPreferences> childs = new HashMap<String, MockAbstractPreferences>();
private int flushedTimes;
@@ -113,7 +114,7 @@
}
if (result == returnNull)
return null;
- AbstractPreferences r = (AbstractPreferences) childs.get(name);
+ AbstractPreferences r = childs.get(name);
if (r == null) {
r = new MockAbstractPreferences(this, name, true);
@@ -139,7 +140,7 @@
protected String[] keysSpi() throws BackingStoreException {
checkException();
- Set keys = attr.keySet();
+ Set<Object> keys = attr.keySet();
String[] results = new String[keys.size()];
keys.toArray(results);
return result == returnNull ? null : results;
Modified: incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java?rev=422297&r1=422296&r2=422297&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java Sat Jul 15 15:03:35 2006
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.StringBufferInputStream;
import java.net.MalformedURLException;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
@@ -46,8 +45,7 @@
*/
protected void setUp() throws Exception {
super.setUp();
- in = new StringBufferInputStream(
- "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>");
+ in = new ByteArrayInputStream("<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>".getBytes("UTF-8"));
stream = new MockInputStream(in);
}