avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon/src/java/org/apache/avalon AbstractConfiguration.java Configurable.java Configuration.java ConfigurationBuilder.java ConfigurationException.java DefaultConfiguration.java DefaultConfigurationBuilder.java
Date Thu, 15 Mar 2001 05:09:18 GMT
donaldp     01/03/14 21:09:18

  Added:       src/compat/org/apache/avalon AbstractConfiguration.java
                        Configurable.java Configuration.java
                        ConfigurationBuilder.java
                        ConfigurationException.java
                        DefaultConfiguration.java
                        DefaultConfigurationBuilder.java
  Removed:     src/java/org/apache/avalon AbstractConfiguration.java
                        Configurable.java Configuration.java
                        ConfigurationBuilder.java
                        ConfigurationException.java
                        DefaultConfiguration.java
                        DefaultConfigurationBuilder.java
  Log:
  Moved deprecated code that required for backwards compatability to compat sub-directory.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/AbstractConfiguration.java
  
  Index: AbstractConfiguration.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  import java.util.Iterator;
  
  /**
   * This is an abstract <code>Configuration</code> implementation that deals
   * with methods that can be abstracted away from underlying implementations.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/03/15 05:09:16 $
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public abstract class AbstractConfiguration
      implements Configuration
  {
      private static int PREFIX = 2;
  
      /**
       * Returns the value of the configuration element as an <code>int</code>.
       */
      public int getValueAsInt()
          throws ConfigurationException
      {
          final String value = getValue();
          try
          {
              if( value.startsWith("0x") )
              {
                  return Integer.parseInt( value.substring(AbstractConfiguration.PREFIX),
16 );
              }
              else if( value.startsWith("0o") )
              {
                  return Integer.parseInt( value.substring(AbstractConfiguration.PREFIX),
8 );
              }
              else if( value.startsWith("0b") )
              {
                  return Integer.parseInt( value.substring(AbstractConfiguration.PREFIX),
2 );
              }
              else
              {
                  return Integer.parseInt( value );
              }
          }
          catch( final Exception nfe )
          {
              throw
                  new ConfigurationException( "Cannot parse the value of the configuration
" +
                                              "element \"" + getName() + "\" as an integer"
);
          }
      }
  
      /**
       * Returns the value of the configuration element as an <code>int</code>.
       */
      public int getValueAsInt( final int defaultValue )
      {
          try
          {
              return getValueAsInt();
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>long</code>.
       */
      public long getValueAsLong()
          throws ConfigurationException
      {
          final String value = getValue();
          try
          {
              if( value.startsWith("0x") )
              {
                  return Long.parseLong( value.substring(2), 16 );
              }
              else if( value.startsWith("0o") )
              {
                  return Long.parseLong( value.substring(2), 8);
              }
              else if( value.startsWith("0b") )
              {
                  return Long.parseLong(value.substring(2),2);
              }
              else return Integer.parseInt(value);
          }
          catch( final Exception nfe )
          {
              throw new ConfigurationException( "Cannot parse the value of the " +
                                                "configuration element \"" + getName() +
                                                "\" as a long" );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>long</code>.
       */
      public long getValueAsLong( final long defaultValue )
      {
          try
          {
              return getValueAsLong();
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>float</code>.
       */
      public float getValueAsFloat()
          throws ConfigurationException
      {
          final String value = getValue();
          try
          {
              return Float.parseFloat( value );
          }
          catch( final Exception nfe )
          {
              throw new ConfigurationException( "Cannot parse the value of the " +
                                                "configuration element \"" + getName() +
                                                "\" as a float" );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>float</code>.
       */
      public float getValueAsFloat( final float defaultValue )
      {
          try
          {
              return getValueAsFloat();
          }
          catch( final ConfigurationException ce )
          {
              return(defaultValue);
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>boolean</code>.
       */
      public boolean getValueAsBoolean()
          throws ConfigurationException
      {
          final String value = getValue();
          if( value.equals("true") ) return true;
          else if( value.equals("false") ) return false;
          else
          {
              throw new ConfigurationException( "Cannot parse the value of the " +
                                                "configuration element \"" +
                                                getName() + "\" as a boolean" );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>boolean</code>.
       */
      public boolean getValueAsBoolean( final boolean defaultValue )
      {
          try
          {
              return getValueAsBoolean();
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>String</code>.
       */
      public String getValue( final String defaultValue )
      {
          try
          {
              return getValue();
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as an
       * <code>int</code>.
       */
      public int getAttributeAsInt( final String name )
          throws ConfigurationException
      {
          final String value = getAttribute( name );
          try
          {
              if( value.startsWith("0x") )
              {
                  return Integer.parseInt( value.substring(2), 16 );
              }
              else if( value.startsWith("0o") )
              {
                  return Integer.parseInt( value.substring(2), 8);
              }
              else if( value.startsWith("0b") )
              {
                  return Integer.parseInt(value.substring(2),2);
              }
              else
              {
                  return Integer.parseInt(value);
              }
          }
          catch( final Exception nfe )
          {
              throw new ConfigurationException( "Cannot parse the value of the attribute \""
+
                                                name + "\" of the configuration element \""
+
                                                getName() + "\" as an integer" );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as an
       * <code>int</code>.
       */
      public int getAttributeAsInt( final String name, final int defaultValue )
      {
          try
          {
              return getAttributeAsInt( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>.
       */
      public long getAttributeAsLong( final String name )
          throws ConfigurationException
      {
          final String value = getAttribute( name );
  
          try
          {
              if( value.startsWith("0x") )
              {
                  return Long.parseLong( value.substring(2), 16 );
              }
              else if( value.startsWith("0o") )
              {
                  return Long.parseLong( value.substring(2), 8 );
              }
              else if( value.startsWith("0b") )
              {
                  return Long.parseLong( value.substring(2), 2);
              }
              else
              {
                  return Integer.parseInt( value );
              }
          }
          catch( final Exception nfe )
          {
              throw new ConfigurationException( "Cannot parse the value of the attribute \""
+
                                                name + "\" of the configuration element \""
+
                                                getName() + "\" as a long" );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>.
       */
      public long getAttributeAsLong( final String name, final long defaultValue )
      {
          try
          {
              return getAttributeAsLong( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>float</code>.
       */
      public float getAttributeAsFloat( final String name )
          throws ConfigurationException
      {
          final String value = getAttribute( name );
          try
          {
              return Float.parseFloat( value );
          }
          catch( final Exception e )
          {
              throw new ConfigurationException( "Cannot parse the value of the attribute \""
+
                                                name + "\" of the configuration element \""
+
                                                getName() + "\" as a float" );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>float</code>.
       */
      public float getAttributeAsFloat( final String name, final float defaultValue )
      {
          try
          {
              return getAttributeAsFloat( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>boolean</code>.
       */
      public boolean getAttributeAsBoolean( final String name )
          throws ConfigurationException
      {
          final String value = getAttribute( name );
  
          if( value.equals("true") ) return true;
          else if( value.equals("false") ) return false;
          else
          {
              throw new ConfigurationException( "Cannot parse the value of the attribute \""
+
                                                name + "\" of the configuration element \""
+
                                                getName() + "\" as a boolean" );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>boolean</code>.
       */
      public boolean getAttributeAsBoolean( final String name, final boolean defaultValue
)
      {
          try
          {
              return getAttributeAsBoolean( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>String</code>.
       */
      public String getAttribute( final String name, final String defaultValue )
      {
          try
          {
              return getAttribute( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Return the first <code>Configuration</code> object child of this
       * associated with the given name.
       */
      public Configuration getChild( final String name )
      {
          final Iterator iterator = getChildren( name );
          if( iterator.hasNext() )
          {
              return (Configuration)iterator.next();
          }
          else
          {
              return new DefaultConfiguration( name, "-" );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/Configurable.java
  
  Index: Configurable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  /**
   * This interface should be implemented by classes that need to be
   * configured with custom parameters before initialization.
   * <br />
   *
   * The contract surrounding a <code>Configurable</code> is that the
   * instantiating entity must call the <code>configure</code>
   * method before it is valid.  The <code>configure</code> method
   * must be called after the constructor, and before any other method.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public interface Configurable
  {
      /**
       * Pass the <code>Configuration</code> to the <code>Configurable</code>
       * class. This method must always be called after the constructor
       * and before any other method.
       *
       * @param configuration the class configurations.
       */
      void configure( Configuration configuration ) 
          throws ConfigurationException;
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  import java.util.Iterator;
  
  /**
   * <code>Configuration</code> is a interface encapsulating a configuration node
   * used to retrieve configuration values. This is a "read only" interface
   * preventing applications from modifying their own configurations.
   * <br />
   *
   * The contract surrounding the <code>Configuration</code> is that once
   * it is created, information never changes.  The <code>Configuration</code>
   * is built by the <code>SAXConfigurationBuilder</code> and the
   * <code>ConfigurationImpl</code> helper classes.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public interface Configuration
  {
      /**
       * Return the name of the node.
       *
       * @post getName() != null
       *
       * @return name of the <code>Configuration</code> node.
       */
      String getName();
  
      /**
       * Return a string describing location of Configuration.
       * Location can be different for different mediums (ie "file:line" for normal XML files
or
       * "table:primary-key" for DB based configurations);
       *
       * @return a string describing location of Configuration
       */
      String getLocation();
  
      /**
       * Return a new <code>Configuration</code> instance encapsulating the
       * specified child node.
       *
       * @pre child != null
       * @post getConfiguration() != null
       *
       * @param child The name of the child node.
       * @return Configuration
       */
      Configuration getChild( String child );
  
      /**
       * Return an <code>Iterator</code> of <code>Configuration<code>
       * elements containing all node children with the specified name.
       *
       * @pre name != null
       * @post getConfigurations() != null
       *
       * @param name The name of the children to get.
       * @return The child nodes with name
       */
      Iterator getChildren( String name );
  
      /**
       * Return the value of specified attribute.
       *
       * @pre paramName != null
       * @post getAttribute != null
       *
       * @param paramName The name of the parameter you ask the value of.
       * @return String value of attribute.
       * @exception ConfigurationException If no attribute with that name exists.
       */
      String getAttribute( String paramName ) throws ConfigurationException;
  
      /**
       * Return the <code>int</code> value of the specified attribute contained
       * in this node.
       *
       * @pre paramName != null
       * @post getAttributeAsInt() != null
       *
       * @param paramName The name of the parameter you ask the value of.
       * @return int value of attribute
       * @exception ConfigurationException If no parameter with that name exists.
       *                                   or if conversion to <code>int</code>
fails.
       */
      int getAttributeAsInt( String paramName ) throws ConfigurationException;
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>.
       *
       * @pre paramName != null
       * @post getAttributeAsLong() != null
       *
       * @param paramName The name of the parameter you ask the value of.
       * @return long value of attribute
       * @exception ConfigurationException If no parameter with that name exists.
       *                                   or if conversion to <code>long</code>
fails.
       */
      long getAttributeAsLong( String name ) throws ConfigurationException;
  
      /**
       * Return the <code>float</code> value of the specified parameter contained
       * in this node.
       *
       * @pre paramName != null
       * @post getAttributeAsFloat() != null
       *
       * @param paramName The name of the parameter you ask the value of.
       * @return float value of attribute
       * @exception ConfigurationException If no parameter with that name exists.
       *                                   or if conversion to <code>float</code>
fails.
       */
      float getAttributeAsFloat( String paramName ) throws ConfigurationException;
  
      /**
       * Return the <code>boolean</code> value of the specified parameter contained
       * in this node.<br>
       *
       * @pre paramName != null
       * @post getAttributeAsBoolean() != null
       *
       * @param paramName The name of the parameter you ask the value of.
       * @return boolean value of attribute
       * @exception ConfigurationException If no parameter with that name exists.
       *                                   or if conversion to <code>boolean</code>
fails.
       */
      boolean getAttributeAsBoolean( String paramName ) throws ConfigurationException;
  
      /**
       * Return the <code>String</code> value of the node.
       *
       * @post getValue() != null
       *
       * @return the value of the node.
       */
      String getValue() throws ConfigurationException;
  
      /**
       * Return the <code>int</code> value of the node.
       *
       * @post getValueAsInt() != null
       *
       * @returns the value of the node.
       *
       * @exception ConfigurationException If conversion to <code>int</code> fails.
       */
      int getValueAsInt() throws ConfigurationException;
  
      /**
       * Return the <code>float</code> value of the node.
       *
       * @post getValueAsFloat() != null
       *
       * @return the value of the node.
       * @exception ConfigurationException If conversion to <code>float</code>
fails.
       */
      float getValueAsFloat() throws ConfigurationException;
  
      /**
       * Return the <code>boolean</code> value of the node.
       *
       * @post getValueAsBoolean() != null
       *
       * @return the value of the node.
       * @exception ConfigurationException If conversion to <code>boolean</code>
fails.
       */
      boolean getValueAsBoolean() throws ConfigurationException;
  
      /**
       * Return the <code>long</code> value of the node.<br>
       *
       * @post getValueAsLong() != null
       *
       * @return the value of the node.
       * @exception ConfigurationException If conversion to <code>long</code>
fails.
       */
      long getValueAsLong() throws ConfigurationException;
  
      /**
       * Returns the value of the configuration element as a <code>String</code>.
       * If the configuration value is not set, the default value will be
       * used.
       *
       * @pre defaultValue != null
       * @post getValue(defaultValue) != null
       *
       * @param defaultValue The default value desired.
       * @return String value of the <code>Configuration</code>, or default
       *          if none specified.
       */
      String getValue( String defaultValue );
  
      /**
       * Returns the value of the configuration element as an <code>int</code>.
       * If the configuration value is not set, the default value will be
       * used.
       *
       * @pre defaultValue != null
       * @post getValueAsInt(defaultValue) != null
       *
       * @param defaultValue The default value desired.
       * @return int value of the <code>Configuration</code>, or default
       *          if none specified.
       */
      int getValueAsInt( int defaultValue );
  
      /**
       * Returns the value of the configuration element as a <code>long</code>.
       * If the configuration value is not set, the default value will be
       * used.
       *
       * @pre defaultValue != null
       * @post getValueAsLong(defaultValue) != null
       *
       * @param defaultValue The default value desired.
       * @return long value of the <code>Configuration</code>, or default
       *          if none specified.
       */
      long getValueAsLong( long defaultValue );
  
      /**
       * Returns the value of the configuration element as a <code>float</code>.
       * If the configuration value is not set, the default value will be
       * used.
       *
       * @pre defaultValue != null
       * @post getValueAsFloat(defaultValue) != null
       *
       * @param defaultValue The default value desired.
       * @return float value of the <code>Configuration</code>, or default
       *          if none specified.
       */
      float getValueAsFloat( float defaultValue );
  
      /**
       * Returns the value of the configuration element as a <code>boolean</code>.
       * If the configuration value is not set, the default value will be
       * used.
       *
       * @pre defaultValue != null
       * @post getValueAsBoolean(defaultValue) != null
       *
       * @param defaultValue The default value desired.
       * @return boolean value of the <code>Configuration</code>, or default
       *          if none specified.
       */
      boolean getValueAsBoolean( boolean defaultValue );
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>String</code>, or the default value if no attribute by
       * that name exists or is empty.
       *
       * @pre name != null
       * @pre defaultValue != null
       * @post getAttribute(name, defaultValue) != null
       *
       * @param name The name of the attribute you ask the value of.
       * @param defaultValue The default value desired.
       * @return String value of attribute. It will return the default
       *         value if the named attribute does not exist, or if
       *         the value is not set.
       */
      String getAttribute( String name, String defaultValue );
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>int</code>, or the default value if no attribute by
       * that name exists or is empty.
       *
       * @pre name != null
       * @pre defaultValue != null
       * @post getAttributeAsInt(name, defaultValue) != null
       *
       * @param name The name of the attribute you ask the value of.
       * @param defaultValue The default value desired.
       * @return int value of attribute. It will return the default
       *         value if the named attribute does not exist, or if
       *         the value is not set.
       */
      int getAttributeAsInt( String name, int defaultValue );
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>, or the default value if no attribute by
       * that name exists or is empty.
       *
       * @pre name != null
       * @pre defaultValue != null
       * @post getAttributeAsLong(name, defaultValue) != null
       *
       * @param name The name of the attribute you ask the value of.
       * @param defaultValue The default value desired.
       * @return long value of attribute. It will return the default
       *          value if the named attribute does not exist, or if
       *          the value is not set.
       */
      long getAttributeAsLong( String name, long defaultValue );
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>float</code>, or the default value if no attribute by
       * that name exists or is empty.
       *
       * @pre name != null
       * @pre defaultValue != null
       * @post getAttributeAsFloat(name, defaultValue) != null
       * 
       * @param name The name of the attribute you ask the value of.
       * @param defaultValue The default value desired.
       * @return float value of attribute. It will return the default
       *          value if the named attribute does not exist, or if
       *          the value is not set.
       */
      float getAttributeAsFloat( String name, float defaultValue );
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>boolean</code>, or the default value if no attribute by
       * that name exists or is empty.
       *
       * @pre name != null
       * @pre defaultValue != null
       * @post getAttributeAsBoolean(name, defaultValue) != null
       *
       * @param name The name of the attribute you ask the value of.
       * @param defaultValue The default value desired.
       * @return boolean value of attribute. It will return the default
       *         value if the named attribute does not exist, or if
       *         the value is not set.
       */
      boolean getAttributeAsBoolean( String name, boolean defaultValue );
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/ConfigurationBuilder.java
  
  Index: ConfigurationBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  import java.io.IOException;
  import org.xml.sax.SAXException;
  
  /**
   * The interface implemented to build configurations.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public interface ConfigurationBuilder
  {
      Configuration build( String resource )
          throws SAXException, IOException, ConfigurationException;
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/ConfigurationException.java
  
  Index: ConfigurationException.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  /**
   * Thrown when a <code>Configurable</code> component cannot be configured
   * properly, or if a value cannot be retrieved properly.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public final class ConfigurationException 
      extends CascadingException
  {
      /**
       * Construct a new <code>ConfigurationException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public ConfigurationException( final String message ) 
      {
          this( message, 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 Throwable throwable ) 
      {
          super( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/DefaultConfiguration.java
  
  Index: DefaultConfiguration.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  
  /**
   * This is the default <code>Configuration</code> implementation.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public class DefaultConfiguration 
      extends AbstractConfiguration 
  {
      protected final static Iterator          EMPTY_ITERATOR = (new ArrayList(1)).iterator();
  
      protected final String                   m_name;
      protected final String                   m_location;
      protected HashMap                        m_attributes;
      protected ArrayList                      m_children;
      protected String                         m_value;
  
      /**
       * Create a new <code>DefaultConfiguration</code> instance.
       */
      public DefaultConfiguration( final String name, final String location ) 
      {
          m_name = name;
          m_location = location;
      }
  
      /**
       * Returns the name of this configuration element.
       */
      public String getName() 
      {
          return m_name;
      }
  
      /**
       * Returns a description of location of element.
       */
      public String getLocation()
      {
          return m_location;
      }
  
      /**
       * Returns the value of the configuration element as a <code>String</code>.
       *
       * @exception ConfigurationException If the value is not present.
       */
      public String getValue() throws ConfigurationException 
      {
          if( null != m_value ) return m_value;
          else
          {
              throw new ConfigurationException( "No value is associated with the "+
                                                "configuration element \"" + getName() + "\""
);
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>String</code>.
       *
       * @exception ConfigurationException If the attribute is not present.
       */
      public String getAttribute( final String name ) 
          throws ConfigurationException 
      {
          final String value = 
              (null != m_attributes) ? (String)m_attributes.get( name ) : null;
  
          if( null != value ) return value;
          else
          {
              throw new ConfigurationException( "No attribute named \"" + name + "\" is "
+
                                                "associated with the configuration element
\"" +
                                                getName() + "\"" );
          }
      }
  
      /**
       * Return the first <code>Configuration</code> object child of this
       * associated with the given name. If none exists a new one of that name is created.
       *
       * @param name The name of the required child <code>Configuration</code>.
       */
      public Configuration getChild( final String name ) 
      {
          if( null == m_children ) 
          {
              return new DefaultConfiguration( name, "-" );
          }
          else
          {
              final int size = m_children.size();
              for( int i = 0; i < size; i++ ) 
              {
                  final Configuration configuration = (Configuration)m_children.get( i );
                  if( name.equals( configuration.getName() ) )
                  {
                      return configuration;
                  }
              }
  
              return new DefaultConfiguration( name, "-" );
          }
      }
  
      /**
       * Return an <code>Enumeration</code> of <code>Configuration</code>
objects
       * children of this associated with the given name.
       * <br>
       * The returned <code>Enumeration</code> may be empty.
       *
       * @param name The name of the required children <code>Configuration</code>.
       */
      public Iterator getChildren( final String name ) 
      {
          if( null == m_children ) return EMPTY_ITERATOR;
          else
          {
              final ArrayList children = new ArrayList();
              final int size = m_children.size();
  
              for( int i = 0; i < size; i++ ) 
              {
                  final Configuration configuration = (Configuration)m_children.get( i );
                  if( name.equals( configuration.getName() ) )
                  {
                      children.add( configuration );
                  }
              }
  
              return children.iterator();
          }
      }
  
      /**
       * Append data to the value of this configuration element.
       */
      public void appendValueData( final String value ) 
      {
          if( null == m_value ) 
          {
              m_value = value;
          }
          else 
          {
              m_value = m_value + value;
          }
      }
  
      /**
       * Add an attribute to this configuration element, returning its old
       * value or <b>null</b>.
       */
      public String addAttribute( final String name, String value ) 
      {
          if( null == m_attributes ) m_attributes = new HashMap();
  
          return (String) m_attributes.put( name, value );
      }
  
      /**
       * Add a child <code>Configuration</code> to this configuration element.
       */
      public void addChild( final Configuration configuration ) 
      {
          if( null == m_children )
          {
              m_children = new ArrayList();
          }
  
          m_children.add( configuration );
      }
  
      /**
       * Return count of children.
       */
      public int getChildCount() 
      {
          if( null == m_children )
          {
              return 0;
          }
          
          return m_children.size();
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/compat/org/apache/avalon/DefaultConfigurationBuilder.java
  
  Index: DefaultConfigurationBuilder.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon;
  
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.ArrayList;
  import org.xml.sax.Attributes;
  import org.xml.sax.InputSource;
  import org.xml.sax.Locator;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException;
  import org.xml.sax.XMLReader;
  import org.xml.sax.helpers.XMLReaderFactory;
  
  /**
   * A SAXConfigurationBuilder builds configurations via SAX2 compliant parser.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   * @deprecated This has been deprecated in favour of configuration interface in org.apache.avalon.configuration
interface
   */
  public class DefaultConfigurationBuilder
      implements ConfigurationBuilder
  {
      protected final static String                 DEFAULT_PARSER = 
          "org.apache.xerces.parsers.SAXParser";
      protected final static String                 PARSER = 
          System.getProperty("org.xml.sax.parser", DEFAULT_PARSER );
  
      protected SAXConfigurationHandler             m_handler;
      protected XMLReader                           m_parser;
  
      public DefaultConfigurationBuilder()
      {
          this( PARSER );
      }
  
      public DefaultConfigurationBuilder( final String parserClass )
      {
          //yaya the bugs with some compilers and final variables ..
          m_handler = getHandler();
          try 
          {
              m_parser = XMLReaderFactory.createXMLReader( parserClass );
              //m_parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
              m_parser.setContentHandler( m_handler );
              m_parser.setErrorHandler( m_handler );
          }
          catch( final SAXException se )
          {
              throw new Error( "Unable to setup SAX parser" + se );
          }
      }
  
      protected SAXConfigurationHandler getHandler()
      {
          return new SAXConfigurationHandler();
      }
  
      public Configuration build( final String resource )
          throws SAXException, IOException, ConfigurationException
      {
          final InputStream input = new FileInputStream( resource );
        
          try { return build( input ); }
          finally
          {
              try { input.close(); }
              catch( final IOException ioe ) {}            
          }
      }
  
      public Configuration build( final InputStream inputStream )
          throws SAXException, IOException, ConfigurationException
      {
          final InputSource inputSource = new InputSource( inputStream );
          return build( inputSource );
      }
  
      public Configuration build( final InputSource input )
          throws SAXException, IOException, ConfigurationException
      {
          m_handler.clear();
          m_parser.parse( input );
          return m_handler.getConfiguration();
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Mime
View raw message