harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r730659 [2/4] - in /harmony/enhanced/classlib/trunk/modules/prefs/src: main/java/java/util/prefs/ test/java/org/apache/harmony/prefs/tests/ test/java/org/apache/harmony/prefs/tests/java/util/prefs/
Date Fri, 02 Jan 2009 02:52:35 GMT
Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/RegistryPreferencesImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/RegistryPreferencesImpl.java?rev=730659&r1=730658&r2=730659&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/RegistryPreferencesImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/RegistryPreferencesImpl.java
Thu Jan  1 18:52:34 2009
@@ -14,35 +14,29 @@
  * limitations under the License.
  */
 
-
 package java.util.prefs;
 
 import org.apache.harmony.prefs.internal.nls.Messages;
 
 /**
- * Default implementation of <code>AbstractPreferences</code> for windows platform,
- * using windows registry as back end. 
+ * Default implementation of <code>AbstractPreferences</code> for windows platform,
using windows
+ * registry as back end.
  * 
  * @since 1.4
  */
 class RegistryPreferencesImpl extends AbstractPreferences {
-    
+
     static {
-		System.loadLibrary("hyprefs"); //$NON-NLS-1$
-	}
+        System.loadLibrary("hyprefs"); //$NON-NLS-1$
+    }
 
-    /*
-	 * -------------------------------------------------------------- 
-     * Class fields
-	 * --------------------------------------------------------------
-	 */
-    //registry path for root preferences 
+    // registry path for root preferences
     private static final String ROOT_PATH = "SOFTWARE\\JavaSoft\\Prefs"; //$NON-NLS-1$
 
-    //index for returned error code
+    // index for returned error code
     private static final int ERROR_CODE = 0;
 
-    //error code for registry access    
+    // error code for registry access
     private static final int RETURN_SUCCESS = 0;
 
     @SuppressWarnings("unused")
@@ -53,22 +47,11 @@
     @SuppressWarnings("unused")
     private static final int RETURN_UNKNOWN_ERROR = 3;
 
-    /*
-     * --------------------------------------------------------------
-     * Instance fields
-     * --------------------------------------------------------------
-     */
-    //registry path for this preferences, default value is the root path
+    // registry path for this preferences, default value is the root path
     private byte[] path = ROOT_PATH.getBytes();
 
-    /*
-     * --------------------------------------------------------------
-     * Constructors
-     * --------------------------------------------------------------
-     */
     /**
-     * Construct <code>RegistryPreferencesImpl</code> instance using given parent

-     * and given name 
+     * Construct <code>RegistryPreferencesImpl</code> instance using given parent
and given name
      */
     public RegistryPreferencesImpl(AbstractPreferences parent, String name) {
         super(parent, name);
@@ -77,8 +60,8 @@
     }
 
     /**
-     * Construct root <code>RegistryPreferencesImpl</code> instance, construct

-     * user root if userNode is true, system root otherwise
+     * Construct root <code>RegistryPreferencesImpl</code> instance, construct
user root if userNode
+     * is true, system root otherwise
      */
     public RegistryPreferencesImpl(boolean userNode) {
         super(null, ""); //$NON-NLS-1$
@@ -91,7 +74,7 @@
         byte[][] names = getChildNames(path, userNode, error);
         if (error[ERROR_CODE] != RETURN_SUCCESS) {
             // prefs.B=Enumerate child nodes error\!
-            throw new BackingStoreException(Messages.getString("prefs.B"));  //$NON-NLS-1$
+            throw new BackingStoreException(Messages.getString("prefs.B")); //$NON-NLS-1$
         }
         String[] result = new String[names.length];
         for (int i = 0; i < result.length; i++) {
@@ -104,7 +87,7 @@
     protected AbstractPreferences childSpi(String name) {
         int[] error = new int[1];
         RegistryPreferencesImpl result = new RegistryPreferencesImpl(this, name);
-        //FIXME: is it right thing to set newNode here?
+        // FIXME: is it right thing to set newNode here?
         result.newNode = getNode(path, encodeWindowsStr(name).getBytes(), result.userNode,
error);
         if (error[ERROR_CODE] == RETURN_ACCESS_DENIED) {
             throw new SecurityException();
@@ -118,7 +101,7 @@
         flushPrefs(path, userNode, error);
         if (error[ERROR_CODE] != RETURN_SUCCESS) {
             // prefs.C=Flush error\!
-            throw new BackingStoreException(Messages.getString("prefs.C"));  //$NON-NLS-1$
+            throw new BackingStoreException(Messages.getString("prefs.C")); //$NON-NLS-1$
         }
     }
 
@@ -138,7 +121,7 @@
         byte[][] keys = keys(path, userNode, errorCode);
         if (errorCode[ERROR_CODE] != RETURN_SUCCESS) {
             // prefs.D=Enumerate keys error\!
-            throw new BackingStoreException(Messages.getString("prefs.D"));  //$NON-NLS-1$
+            throw new BackingStoreException(Messages.getString("prefs.D")); //$NON-NLS-1$
         }
         String[] result = new String[keys.length];
         for (int i = 0; i < result.length; i++) {
@@ -153,18 +136,18 @@
         putValue(path, encodeWindowsStr(name).getBytes(), value.getBytes(), userNode, errorCode);
         if (errorCode[ERROR_CODE] == RETURN_ACCESS_DENIED) {
             // prefs.E=Access denied\!
-            throw new SecurityException(Messages.getString("prefs.E"));  //$NON-NLS-1$
+            throw new SecurityException(Messages.getString("prefs.E")); //$NON-NLS-1$
         }
     }
 
     @Override
     protected void removeNodeSpi() throws BackingStoreException {
         int[] error = new int[1];
-        removeNode(((RegistryPreferencesImpl) parent()).path,
-                encodeWindowsStr(name()).getBytes(), userNode, error);
+        removeNode(((RegistryPreferencesImpl) parent()).path, encodeWindowsStr(name()).getBytes(),
+                userNode, error);
         if (error[ERROR_CODE] != RETURN_SUCCESS) {
             // prefs.F=Remove node error\!
-            throw new BackingStoreException(Messages.getString("prefs.F"));  //$NON-NLS-1$
+            throw new BackingStoreException(Messages.getString("prefs.F")); //$NON-NLS-1$
         }
     }
 
@@ -174,7 +157,7 @@
         removeKey(path, encodeWindowsStr(key).getBytes(), userNode, errorCode);
         if (errorCode[ERROR_CODE] == RETURN_ACCESS_DENIED) {
             // prefs.E=Access denied\!
-            throw new SecurityException(Messages.getString("prefs.E"));  //$NON-NLS-1$
+            throw new SecurityException(Messages.getString("prefs.E")); //$NON-NLS-1$
         }
     }
 
@@ -183,71 +166,70 @@
         flushSpi();
     }
 
-    //handle the lower/upper case pitfall
-    private static String encodeWindowsStr(String str){
+    // handle the lower/upper case pitfall
+    private static String encodeWindowsStr(String str) {
         char[] chars = str.toCharArray();
         StringBuffer buffer = new StringBuffer();
         for (int i = 0; i < chars.length; i++) {
             char c = chars[i];
-            if(c == '/'){
+            if (c == '/') {
                 buffer.append("\\"); //$NON-NLS-1$
-            }else if(c == '\\'){
+            } else if (c == '\\') {
                 buffer.append("//"); //$NON-NLS-1$
-            }else if((c >= 'A') && (c <= 'Z')){
+            } else if ((c >= 'A') && (c <= 'Z')) {
                 buffer.append('/').append(c);
-            }else{
+            } else {
                 buffer.append(c);
             }
         }
         return buffer.toString();
     }
-    
-    private static String decodeWindowsStr(String str){
+
+    private static String decodeWindowsStr(String str) {
         StringBuffer buffer = new StringBuffer();
         char[] chars = str.toCharArray();
         for (int i = 0; i < chars.length; i++) {
-            char c= chars[i];
-            if(c == '\\'){
+            char c = chars[i];
+            if (c == '\\') {
                 buffer.append('/');
-            }else if(c == '/'){
-                if((c = chars[++i]) == '/'){
+            } else if (c == '/') {
+                if ((c = chars[++i]) == '/') {
                     buffer.append('\\');
-                }else{
+                } else {
                     buffer.append(c);
                 }
-            }else{
+            } else {
                 buffer.append(c);
             }
         }
         return buffer.toString();
     }
-    
+
     /*
-     * --------------------------------------------------------------
-     * Native methods declaration
+     * -------------------------------------------------------------- 
+     * Native method declarations
      * --------------------------------------------------------------
      */
-    private native byte[] getValue(byte[] registryPath, byte[] key,
-            boolean isUserNode, int[] errorCode);
 
-    private native void putValue(byte[] registryPath, byte[] key, byte[] value,
-            boolean isUserNode, int[] errorCode);
+    private native byte[] getValue(byte[] registryPath, byte[] key, boolean isUserNode,
+            int[] errorCode);
 
-    private native void removeKey(byte[] registryPath, byte[] key,
-            boolean isUserNode, int[] errorCode);
+    private native void putValue(byte[] registryPath, byte[] key, byte[] value, boolean isUserNode,
+            int[] errorCode);
 
-    private native byte[][] keys(byte[] registryPath, boolean isUserNode,
+    private native void removeKey(byte[] registryPath, byte[] key, boolean isUserNode,
             int[] errorCode);
 
-    private native void removeNode(byte[] registryPath, byte[] name,
-            boolean isUserNode, int[] errorCode);
+    private native byte[][] keys(byte[] registryPath, boolean isUserNode, int[] errorCode);
 
-    private native boolean getNode(byte[] registryPath, byte[] name,
-            boolean isUserNode, int[] errorCode);
+    private native void removeNode(byte[] registryPath, byte[] name, boolean isUserNode,
+            int[] errorCode);
+
+    private native boolean getNode(byte[] registryPath, byte[] name, boolean isUserNode,
+            int[] errorCode);
 
-    private native byte[][] getChildNames(byte[] registryPath,
-            boolean isUserNode, int[] errorCode);
+    private native byte[][] getChildNames(byte[] registryPath, boolean isUserNode, int[]
errorCode);
 
-    private native void flushPrefs(byte[] registryPath, boolean isUserNode,
-            int[] errorCode) throws SecurityException;
+    private native void flushPrefs(byte[] registryPath, boolean isUserNode, int[] errorCode)
+            throws SecurityException;
 }

Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java?rev=730659&r1=730658&r2=730659&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java
Thu Jan  1 18:52:34 2009
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-
 package java.util.prefs;
 
 import java.io.BufferedInputStream;
@@ -55,7 +54,6 @@
 
 /**
  * Utility class for the Preferences import/export from XML file.
- * 
  */
 class XMLParser {
 
@@ -68,15 +66,15 @@
      * 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$
-            + "    <!ATTLIST preferences EXTERNAL_XML_VERSION CDATA \"0.0\" >" //$NON-NLS-1$
-            + "    <!ELEMENT root (map, node*) >" //$NON-NLS-1$
-            + "    <!ATTLIST root type (system|user) #REQUIRED >" //$NON-NLS-1$
-            + "    <!ELEMENT node (map, node*) >" //$NON-NLS-1$
-            + "    <!ATTLIST node name CDATA #REQUIRED >" //$NON-NLS-1$
-            + "    <!ELEMENT map (entry*) >" //$NON-NLS-1$
-            + "    <!ELEMENT entry EMPTY >" //$NON-NLS-1$
-            + "    <!ATTLIST entry key   CDATA #REQUIRED value CDATA #REQUIRED >";
//$NON-NLS-1$
+        + "    <!ELEMENT preferences (root)>" //$NON-NLS-1$
+        + "    <!ATTLIST preferences EXTERNAL_XML_VERSION CDATA \"0.0\" >" //$NON-NLS-1$
+        + "    <!ELEMENT root (map, node*) >" //$NON-NLS-1$
+        + "    <!ATTLIST root type (system|user) #REQUIRED >" //$NON-NLS-1$
+        + "    <!ELEMENT node (map, node*) >" //$NON-NLS-1$
+        + "    <!ATTLIST node name CDATA #REQUIRED >" //$NON-NLS-1$
+        + "    <!ELEMENT map (entry*) >" //$NON-NLS-1$
+        + "    <!ELEMENT entry EMPTY >" //$NON-NLS-1$
+        + "    <!ATTLIST entry key   CDATA #REQUIRED value CDATA #REQUIRED >"; //$NON-NLS-1$
 
     /*
      * Constant - the specified header
@@ -92,7 +90,7 @@
      * empty string array constant
      */
     private static final String[] EMPTY_SARRAY = new String[0];
-    
+
     /*
      * Constant - used by FilePreferencesImpl, which is default implementation of Linux platform

      */
@@ -102,7 +100,7 @@
      * Constant - specify the DTD version
      */
     private static final float XML_VERSION = 1.0f;    
-    
+
     /*
      * DOM builder
      */
@@ -126,7 +124,7 @@
         }
         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));
@@ -181,7 +179,7 @@
         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$
@@ -192,7 +190,7 @@
 
     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(
@@ -211,7 +209,7 @@
     }
 
     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++) {
@@ -226,7 +224,7 @@
     }
 
     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++) {
@@ -252,7 +250,7 @@
     }
 
     private static void flushEndTag(String tagName, BufferedWriter out)
-            throws IOException {
+    throws IOException {
         flushIndent(indent--, out);
         out.write("</"); //$NON-NLS-1$
         out.write(tagName);
@@ -261,7 +259,7 @@
     }
 
     private static void flushEmptyElement(String tagName, BufferedWriter out)
-            throws IOException {
+    throws IOException {
         flushIndent(++indent, out);
         out.write("<"); //$NON-NLS-1$
         out.write(tagName);
@@ -293,7 +291,7 @@
     }
 
     private static void flushIndent(int ind, BufferedWriter out)
-            throws IOException {
+    throws IOException {
         for (int i = 0; i < ind; i++) {
             out.write("  "); //$NON-NLS-1$
         }
@@ -310,7 +308,7 @@
     }
 
     private static void flushStartTag(String tagName, BufferedWriter out)
-            throws IOException {
+    throws IOException {
         flushIndent(++indent, out);
         out.write("<"); //$NON-NLS-1$
         out.write(tagName);
@@ -350,7 +348,7 @@
      * utilities for Preferences import
      **************************************************************************/
     static void importPrefs(InputStream in) throws IOException,
-            InvalidPreferencesFormatException {
+    InvalidPreferencesFormatException {
         try {
             // load XML document
             Document doc = builder.parse(new InputSource(in));
@@ -367,7 +365,7 @@
 
             // 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$
@@ -388,7 +386,7 @@
     }
 
     private static void loadNode(Preferences prefs, Element node)
-            throws TransformerException {
+    throws TransformerException {
         // load preferences
         NodeList children = XPathAPI.selectNodeList(node, "node"); //$NON-NLS-1$
         NodeList entries = XPathAPI.selectNodeList(node, "map/entry"); //$NON-NLS-1$
@@ -501,7 +499,7 @@
             }
         });
     }
-    
+
     static void flushFilePrefsImpl(File file, Properties prefs) throws IOException {
         BufferedWriter out = null;
         FileLock lock = null;
@@ -540,5 +538,3 @@
         }
     }
 }
-
-

Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/AllTests.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/AllTests.java?rev=730659&r1=730658&r2=730659&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/AllTests.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/test/java/org/apache/harmony/prefs/tests/AllTests.java
Thu Jan  1 18:52:34 2009
@@ -25,15 +25,15 @@
  */
 public class AllTests {
 
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(AllTests.suite());
-	}
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(AllTests.suite());
+    }
 
-	public static Test suite() {
-		TestSuite suite = new TestSuite("All Prefs test suites");
-		// $JUnit-BEGIN$
-		suite.addTest(org.apache.harmony.prefs.tests.java.util.prefs.AllTests.suite());
-		// $JUnit-END$
-		return suite;
-	}
+    public static Test suite() {
+        TestSuite suite = new TestSuite("All Prefs test suites");
+        // $JUnit-BEGIN$
+        suite.addTest(org.apache.harmony.prefs.tests.java.util.prefs.AllTests.suite());
+        // $JUnit-END$
+        return suite;
+    }
 }



Mime
View raw message