Author: psteitz
Date: Sun Mar  6 18:45:35 2005
New Revision: 156371

URL: http://svn.apache.org/viewcvs?view=rev&rev=156371
Log:
Improved exception management.
Stopped wrapping all throwables in IllegalStateExceptions in 
ReadOnlyResourceStateImpl.load.
Changed load in State interface to throw Exception instead of 
IllegalStateException (so other kinds of exceptions can be
propagated).
Eliminated NPE in finally block of ReadOnlyResourceStateImpl.load.
Reported by: John.E.Gregg 

Modified:
    
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java
    
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java
    
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/State.java
    
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImplTest.java

Modified: 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java?view=diff&r1=156370&r2=156371
==============================================================================
--- 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java
 (original)
+++ 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/NodeManagerImpl.java
 Sun Mar  6 18:45:35 2005
@@ -57,7 +57,11 @@
     /** Initialization */
     public void init() {
         nodeState = StateHelper.getStateImpl();
-        nodeState.load();
+        try {
+            nodeState.load();
+        } catch (Exception ex) {
+          throw new RuntimeException(ex);
+        }
         nodesSet = nodeState.getNodes();
         Iterator it = nodesSet.iterator();
         allNodes = new Node[nodesSet.size()];

Modified: 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java?view=diff&r1=156370&r2=156371
==============================================================================
--- 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java
 (original)
+++ 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java
 Sun Mar  6 18:45:35 2005
@@ -84,13 +84,20 @@
      * </p><p>See the documentation for further information on configuration
      * tasks.</p>
      *
+     * @throws IllegalStateException if the 
&quot;commons.uuid.configFileName&quot;
+     * system property is not set or the resource cannot be loaded.
+     * @throws SAXException if an xml parsing error occurs
+     * @throws ParserConfigurationException if the parser cannot be loaded
+     * @throws IOException if an error occurs reading the file
+     * 
      * @see org.apache.commons.id.uuid.state.State#load()
      */
-    public void load() throws IllegalStateException {
+    public void load() throws Exception {
         // Get the resource name
         String resourceName = System.getProperty(CONFIG_FILENAME_KEY);
         if (resourceName == null) {
-            throw new IllegalStateException("No value set for system property: 
" + CONFIG_FILENAME_KEY);
+            throw new IllegalStateException("No value set for system property: 
" 
+                    + CONFIG_FILENAME_KEY);
         }
 
         // Load the resource
@@ -98,18 +105,18 @@
         try {
             in = ClassLoader.getSystemResourceAsStream(resourceName);
             if (in == null) {
-                throw new IllegalStateException(resourceName + " loaded as 
system resource is null");
+                throw new IllegalStateException(resourceName + 
+                        " loaded as system resource is null");
             }
-
             //Do the XML parsing
             parse(in);
-        } catch (Throwable e) {
-            throw new IllegalStateException(e.getMessage());
         } finally {
-            try {
-                in.close();
-            } catch (IOException ioe) {
-                //Nothing to do at this point.
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ioe) {
+                    //Nothing to do at this point.
+                }
             }
         }
     }
@@ -151,17 +158,14 @@
      *
      * @param in the XML input stream to parse.
      */
-    protected void parse(InputStream in) {
+    protected void parse(InputStream in) throws Exception {
         DefaultHandler handler = new StateConfigHandler();
         SAXParserFactory saxFactory = SAXParserFactory.newInstance();
         saxFactory.setValidating(true);
-        try {
-            SAXParser parser = saxFactory.newSAXParser();
-            parser.parse(in, handler);
-        } catch (Throwable t) {
-            return;
-        }
+        SAXParser parser = saxFactory.newSAXParser();
+        parser.parse(in, handler);
     }
+   
     
//--------------------------------------------------------------------------
     /**
      * Inner class to handle document processing of the configuration file.

Modified: 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/State.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/State.java?view=diff&r1=156370&r2=156371
==============================================================================
--- 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/State.java
 (original)
+++ 
jakarta/commons/sandbox/id/trunk/src/java/org/apache/commons/id/uuid/state/State.java
 Sun Mar  6 18:45:35 2005
@@ -46,7 +46,7 @@
      *
      * @throws IllegalStateException likely the system is not configured or 
the state of the system is incorrect.
      */
-    void load(  ) throws IllegalStateException;
+    void load(  ) throws Exception;
 
     /**
      * <p>Returns the collection of <code>Nodes</code> for this uuid state

Modified: 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImplTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImplTest.java?view=diff&r1=156370&r2=156371
==============================================================================
--- 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImplTest.java
 (original)
+++ 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImplTest.java
 Sun Mar  6 18:45:35 2005
@@ -104,7 +104,7 @@
     /**
      * <p>Test the Set getNodes method.</p>
      */
-    public void testGetNodes() {
+    public void testGetNodes() throws Exception {
         System.setProperty(ReadOnlyResourceStateImpl.CONFIG_FILENAME_KEY, 
"uuid1.state");
         ReadOnlyResourceStateImpl impl = new ReadOnlyResourceStateImpl();
         impl.load();



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to