Hi all,

Here's another patch for Configuration : it adds location information to
every ConfigurationException thrown, and also erroneous values for parse
failures. This is really usefull for debugging.

Thanks,
Sylvain.
-- 
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
? config-msg.txt
Index: AbstractConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/AbstractConfiguration.java,v
retrieving revision 1.5
diff -u -r1.5 AbstractConfiguration.java
--- AbstractConfiguration.java  2001/10/02 16:24:55     1.5
+++ AbstractConfiguration.java  2001/10/29 17:37:12
@@ -54,9 +54,10 @@
         }
         catch( final Exception nfe )
         {
-            throw
-                new ConfigurationException( "Cannot parse the value of the 
configuration " +
-                                            "element \"" + getName() + "\" as 
an integer" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the configuration element 
\"" +
+                                              getName() + "\" as an integer, 
at " +
+                                              getLocation() );
         }
     }
 
@@ -115,9 +116,10 @@
         }
         catch( final Exception nfe )
         {
-            throw new ConfigurationException( "Cannot parse the value of the " 
+
-                                              "configuration element \"" + 
getName() +
-                                              "\" as a long" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the configuration element 
\"" +
+                                              getName() + "\" as a long, at " +
+                                              getLocation() );
         }
     }
 
@@ -158,9 +160,10 @@
         }
         catch( final Exception nfe )
         {
-            throw new ConfigurationException( "Cannot parse the value of the " 
+
-                                              "configuration element \"" + 
getName() +
-                                              "\" as a float" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the configuration element 
\"" +
+                                              getName() + "\" as a float, at " 
+
+                                              getLocation() );
         }
     }
 
@@ -202,9 +205,10 @@
         }
         else
         {
-            throw new ConfigurationException( "Cannot parse the value of the " 
+
-                                              "configuration element \"" +
-                                              getName() + "\" as a boolean" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the configuration element 
\"" +
+                                              getName() + "\" as a boolean, at 
" +
+                                              getLocation() );
         }
     }
 
@@ -280,9 +284,9 @@
         }
         catch( final Exception nfe )
         {
-            throw new ConfigurationException( "Cannot parse the value of the 
attribute \"" +
-                                              name + "\" of the configuration 
element \"" +
-                                              getName() + "\" as an integer" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the attribute \"" + name +
+                                              "\" as an integer, at " + 
getLocation() );
         }
     }
 
@@ -346,9 +350,9 @@
         }
         catch( final Exception nfe )
         {
-            throw new ConfigurationException( "Cannot parse the value of the 
attribute \"" +
-                                              name + "\" of the configuration 
element \"" +
-                                              getName() + "\" as a long" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the attribute \"" + name +
+                                              "\" as a long, at " + 
getLocation() );
         }
     }
 
@@ -393,9 +397,9 @@
         }
         catch( final Exception e )
         {
-            throw new ConfigurationException( "Cannot parse the value of the 
attribute \"" +
-                                              name + "\" of the configuration 
element \"" +
-                                              getName() + "\" as a float" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the attribute \"" + name +
+                                              "\" as a float, at " + 
getLocation() );
         }
     }
 
@@ -442,9 +446,9 @@
         }
         else
         {
-            throw new ConfigurationException( "Cannot parse the value of the 
attribute \"" +
-                                              name + "\" of the configuration 
element \"" +
-                                              getName() + "\" as a boolean" );
+            throw new ConfigurationException( "Cannot parse the value \"" + 
value +
+                                              "\" of the attribute \"" + name +
+                                              "\" as a boolean, at " + 
getLocation() );
         }
     }
 
Index: DefaultConfiguration.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/DefaultConfiguration.java,v
retrieving revision 1.6
diff -u -r1.6 DefaultConfiguration.java
--- DefaultConfiguration.java   2001/10/02 16:24:55     1.6
+++ DefaultConfiguration.java   2001/10/29 17:37:15
@@ -89,7 +89,8 @@
         else
         {
             throw new ConfigurationException( "No value is associated with the 
"+
-                                              "configuration element \"" + 
getName() + "\"" );
+                                              "configuration element \"" + 
getName() +
+                                              "\", at " + getLocation() );
         }
     }
 
@@ -146,7 +147,7 @@
         {
             throw new ConfigurationException( "No attribute named \"" + name + 
"\" is " +
                                               "associated with the 
configuration element \"" +
-                                              getName() + "\"" );
+                                              getName() + "\", at " + 
getLocation() );
         }
     }
 

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

Reply via email to