bloritsch    2003/08/29 08:12:00

  Modified:    framework/src/api/org/apache/avalon/framework/configuration
                        ConfigurationException.java
               framework/src/impl/org/apache/avalon/framework/configuration
                        AbstractConfiguration.java
                        DefaultConfiguration.java
               framework project.xml
  Log:
  Update the configuration exceptions so that we can pinpoint information much better.
  
  Revision  Changes    Path
  1.12      +55 -2     
avalon/framework/src/api/org/apache/avalon/framework/configuration/ConfigurationException.java
  
  Index: ConfigurationException.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/framework/src/api/org/apache/avalon/framework/configuration/ConfigurationException.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ConfigurationException.java       11 Feb 2003 15:58:38 -0000      1.11
  +++ ConfigurationException.java       29 Aug 2003 15:12:00 -0000      1.12
  @@ -66,6 +66,18 @@
   public class ConfigurationException
       extends CascadingException
   {
  +    private final Configuration m_config;
  +
  +    /**
  +     * Construct a new <code>ConfigurationException</code> instance.
  +     *
  +     * @param config  The offending configuration object
  +     */
  +    public ConfigurationException( final Configuration config )
  +    {
  +        this( "Bad configuration: " + config.toString(), config );
  +    }
  +
       /**
        * Construct a new <code>ConfigurationException</code> instance.
        *
  @@ -73,7 +85,7 @@
        */
       public ConfigurationException( final String message )
       {
  -        this( message, null );
  +        this( message, (Configuration) null );
       }
   
       /**
  @@ -84,6 +96,47 @@
        */
       public ConfigurationException( final String message, final Throwable throwable )
       {
  +        this( message, null, throwable );
  +    }
  +
  +    /**
  +     * Construct a new <code>ConfigurationException</code> instance.
  +     *
  +     * @param message The detail message for this exception.
  +     * @param config  The configuration object
  +     */
  +    public ConfigurationException( final String message, final Configuration config 
)
  +    {
  +        this( message, config, null );
  +    }
  +
  +    /**
  +     * Construct a new <code>ConfigurationException</code> instance.
  +     *
  +     * @param message The detail message for this exception.
  +     * @param throwable the root cause of the exception
  +     */
  +    public ConfigurationException( final String message, final Configuration 
config, final Throwable throwable )
  +    {
           super( message, throwable );
  +        m_config = config;
  +    }
  +
  +    public Configuration getOffendingConfiguration()
  +    {
  +        return m_config;
  +    }
  +
  +    public String getMessage()
  +    {
  +        StringBuffer message = new StringBuffer(super.getMessage());
  +
  +        if (null != m_config)
  +        {
  +            message.append("@");
  +            message.append(m_config.getLocation());
  +        }
  +
  +        return message.toString();
       }
   }
  
  
  
  1.29      +28 -16    
avalon/framework/src/impl/org/apache/avalon/framework/configuration/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/framework/src/impl/org/apache/avalon/framework/configuration/AbstractConfiguration.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- AbstractConfiguration.java        11 Feb 2003 16:19:27 -0000      1.28
  +++ AbstractConfiguration.java        29 Aug 2003 15:12:00 -0000      1.29
  @@ -110,8 +110,8 @@
           catch( final Exception nfe )
           {
               final String message =
  -                "Cannot parse the value \"" + value 
  -                + "\" as an integer in the configuration element \"" 
  +                "Cannot parse the value \"" + value
  +                + "\" as an integer in the configuration element \""
                   + getName() + "\" at " + getLocation();
               throw new ConfigurationException( message );
           }
  @@ -173,8 +173,8 @@
           catch( final Exception nfe )
           {
               final String message =
  -                "Cannot parse the value \"" + value 
  -                + "\" as a long in the configuration element \"" 
  +                "Cannot parse the value \"" + value
  +                + "\" as a long in the configuration element \""
                   + getName() + "\" at " + getLocation();
               throw new ConfigurationException( message );
           }
  @@ -218,8 +218,8 @@
           catch( final Exception nfe )
           {
               final String message =
  -                "Cannot parse the value \"" + value 
  -                + "\" as a float in the configuration element \"" 
  +                "Cannot parse the value \"" + value
  +                + "\" as a float in the configuration element \""
                   + getName() + "\" at " + getLocation();
               throw new ConfigurationException( message );
           }
  @@ -265,7 +265,7 @@
           else
           {
               final String message =
  -                "Cannot parse the value \"" + value 
  +                "Cannot parse the value \"" + value
                   + "\" as a boolean in the configuration element \""
                   + getName() + "\" at " + getLocation();
               throw new ConfigurationException( message );
  @@ -345,8 +345,8 @@
           catch( final Exception nfe )
           {
               final String message =
  -                "Cannot parse the value \"" + value 
  -                + "\" as an integer in the attribute \"" 
  +                "Cannot parse the value \"" + value
  +                + "\" as an integer in the attribute \""
                   + name + "\" at " + getLocation();
               throw new ConfigurationException( message );
           }
  @@ -522,17 +522,17 @@
   
       private boolean isTrue( final String value )
       {
  -        return value.equalsIgnoreCase( "true" ) 
  -            || value.equalsIgnoreCase( "yes" ) 
  -            || value.equalsIgnoreCase( "on" ) 
  +        return value.equalsIgnoreCase( "true" )
  +            || value.equalsIgnoreCase( "yes" )
  +            || value.equalsIgnoreCase( "on" )
               || value.equalsIgnoreCase( "1" );
       }
   
       private boolean isFalse( final String value )
       {
  -        return value.equalsIgnoreCase( "false" ) 
  -            || value.equalsIgnoreCase( "no" ) 
  -            || value.equalsIgnoreCase( "off" ) 
  +        return value.equalsIgnoreCase( "false" )
  +            || value.equalsIgnoreCase( "no" )
  +            || value.equalsIgnoreCase( "off" )
               || value.equalsIgnoreCase( "0" );
       }
   
  @@ -615,5 +615,17 @@
                   return null;
               }
           }
  +    }
  +
  +    /**
  +     * The toString() operation is used for debugging information.  It does
  +     * not create a deep reproduction of this configuration and all child 
configurations,
  +     * instead it displays the name, value, and location.
  +     *
  +     * @return getName() + "::" + getValue() + ":@" + getLocation();
  +     */
  +    public String toString()
  +    {
  +        return getName() + "::" + getValue("<no value>") + ":@" + getLocation();
       }
   }
  
  
  
  1.35      +13 -2     
avalon/framework/src/impl/org/apache/avalon/framework/configuration/DefaultConfiguration.java
  
  Index: DefaultConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/avalon/framework/src/impl/org/apache/avalon/framework/configuration/DefaultConfiguration.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- DefaultConfiguration.java 12 Jul 2003 12:40:49 -0000      1.34
  +++ DefaultConfiguration.java 29 Aug 2003 15:12:00 -0000      1.35
  @@ -276,7 +276,7 @@
           }
           else
           {
  -            throw new ConfigurationException( 
  +            throw new ConfigurationException(
                  "No attribute named \"" + name + "\" is "
                  + "associated with the configuration element \""
                  + getName() + "\" at " + getLocation() );
  @@ -539,6 +539,12 @@
           }
       }
   
  +    /**
  +     * Compare if this configuration is equal to another.
  +     *
  +     * @param other  The other configuration
  +     * @return <code>true</code> if they are the same.
  +     */
       public boolean equals( Object other )
       {
           if( other == null ) return false;
  @@ -546,6 +552,11 @@
           return ConfigurationUtil.equals( this, (Configuration) other );
       }
   
  +    /**
  +     * Obtaine the hashcode for this configuration.
  +     *
  +     * @return the hashcode.
  +     */
       public int hashCode()
       {
           int hash = m_prefix.hashCode();
  
  
  
  1.3       +7 -2      avalon/framework/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/framework/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml       12 Jul 2003 09:01:21 -0000      1.2
  +++ project.xml       29 Aug 2003 15:12:00 -0000      1.3
  @@ -5,7 +5,7 @@
   
       <name>Avalon-Framework</name>
       <id>avalon-framework</id>
  -    <currentVersion>4.1.5-RC2</currentVersion>
  +    <currentVersion>4.1.5</currentVersion>
       <inceptionYear>1997</inceptionYear>
       <shortDescription>the core interfaces of the avalon project</shortDescription>
       <description>
  @@ -17,6 +17,11 @@
   
       <versions>
           <version>
  +            <id>4.1.5</id>
  +            <name>4.1.5</name>
  +            <tag>AVALON_4_1_5</tag>
  +        </version>
  +        <version>
               <id>4.1.4</id>
               <name>4.1.4</name>
               <tag>AVALON_4_1_4</tag>
  @@ -91,4 +96,4 @@
               </sourceModification>
           </sourceModifications>
       </build>
  -</project>
  \ No newline at end of file
  +</project>
  
  
  

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

Reply via email to