avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon/src/proposal/avalon5/org/apache/framework/service/impl DefaultServiceManager.java
Date Fri, 07 Jun 2002 20:04:11 GMT
bloritsch    2002/06/07 13:04:11

  Modified:    src/proposal/avalon5/org/apache/framework/configuration/impl
                        DefaultConfiguration.java
                        DefaultConfigurationSerializer.java
  Added:       src/proposal/avalon5/org/apache/framework/component
                        ComponentException.java ComponentManager.java
                        Composable.java package.html
               src/proposal/avalon5/org/apache/framework/component/impl
                        DefaultComponentManager.java
               src/proposal/avalon5/org/apache/framework/configuration/impl
                        AbstractConfiguration.java
  Removed:     src/proposal/avalon5/org/apache/framework/configuration
                        AbstractConfiguration.java
               src/proposal/avalon5/org/apache/framework/service
                        ServiceException.java ServiceManager.java
                        Serviceable.java package.html
               src/proposal/avalon5/org/apache/framework/service/impl
                        DefaultServiceManager.java
  Log:
  update avalon5 interfaces with what they should be
  
  Revision  Changes    Path
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/ComponentException.java
  
  Index: ComponentException.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.txt file.
   */
  package org.apache.framework.component;
  
  /**
   * The exception thrown to indicate a problem with service.
   * It is usually thrown by ComponentManager or ServiceSelector.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   */
  public class ComponentException
      extends RuntimeException
  {
      /**
       * The Throwable that caused this exception to be thrown.
       */
      private final Throwable m_throwable;
  
      /**
       * Construct a new <code>ComponentException</code> instance.
       *
       * @param message the exception message
       */
      public ComponentException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>ComponentException</code> instance.
       *
       * @param message the exception message
       * @param throwable the throwable
       */
      public ComponentException( final String message, final Throwable throwable )
      {
          super( message );
          m_throwable = throwable;
      }
  
      /**
       * Retrieve root cause of the exception.
       *
       * @return the root cause
       */
      public final Throwable getCause()
      {
          return m_throwable;
      }
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/ComponentManager.java
  
  Index: ComponentManager.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.txt file.
   */
  package org.apache.framework.component;
  
  /**
   * A <code>ComponentManager</code> selects <code>Object</code>s
based on a
   * role.  The contract is that all the <code>Object</code>s implement the
   * differing roles and there is one <code>Object</code> per role.  If you
   * need to select on of many <code>Object</code>s that implement the same
   * role, then you need to use a <code>ServiceSelector</code>.  Roles are
   * usually the full interface name.
   *
   * A role is better understood by the analogy of a play.  There are many
   * different roles in a script.  Any actor or actress can play any given part
   * and you get the same results (phrases said, movements made, etc.).  The exact
   * nuances of the performance is different.
   *
   * Below is a list of things that might be considered the different roles:
   *
   * <ul>
   *   <li> InputAdaptor and OutputAdaptor</li>
   *   <li> Store and Spool</li>
   * </ul>
   *
   * The <code>ComponentManager</code> does not specify the methodology of
   * getting the <code>Object</code>, merely the interface used to get it.
   * Therefore the <code>ComponentManager</code> can be implemented with a
   * factory pattern, an object pool, or a simple Hashtable.
   *
   * @author <a href="mailto:scoobie@betaversion.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:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version 1.0
   * @see org.apache.framework.component.Composable
   */
  public interface ComponentManager
  {
      /**
       * Get the <code>Object</code> associated with the given role.  For
       * instance, If the <code>ComponentManager</code> had a
       * <code>LoggerComponent</code> stored and referenced by role, I would use
       * the following call:
       * <pre>
       * try
       * {
       *     MyComponent log;
       *     myComponent = (MyComponent) manager.lookup(MyComponent.ROLE);
       * }
       * catch (...)
       * {
       *     ...
       * }
       * </pre>
       *
       * @param role The role name of the <code>Object</code> to retrieve.
       * @return an <code>Object</code> value
       * @throws ComponentException if the component is not available
       */
      Object lookup( String role );
  
      /**
       * Get the <code>Object</code> associated with the given role.  For
       * instance, If the <code>ComponentManager</code> had a
       * <code>LoggerComponent</code> stored and referenced by role, I would use
       * the following call:
       * <pre>
       * try
       * {
       *     MyComponent log;
       *     myComponent = (MyComponent) manager.lookup(MyComponent.ROLE,
       *                                                "myhint");
       * }
       * catch (...)
       * {
       *     ...
       * }
       * </pre>
       *
       * @param role The role name of the <code>Object</code> to retrieve.
       * @return an <code>Object</code> value
       * @throws ComponentException if the component is not available
       */
      Object lookup( String role, Object hint );
  
      /**
       * Check to see if a <code>Object</code> exists for a role.
       *
       * @param role  a string identifying the role to check.
       * @return True if the object exists, False if it does not.
       */
      boolean exists( String role );   
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/Composable.java
  
  Index: Composable.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.txt file.
   */
  package org.apache.framework.component;
  
  /**
   * A Composable is a class that need to connect to software components using
   * a "role" abstraction, thus not depending on particular implementations
   * but on behavioral interfaces.
   * <br />
   *
   * The contract surrounding a <code>Composable</code> is that it is a user.
   * The <code>Composable</code> is able to use <code>Object</code>s
managed
   * by the <code>ComponentManager</code> it was initialized with.  As part
   * of the contract with the system, the instantiating entity must call
   * the <code>compose</code> method before the <code>Composable</code>
   * can be considered valid.
   *
   * @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:mcconnell@apache.org">Stephen McConnell</a>
   * @version 1.0
   * @see org.apache.framework.component.ComponentManager
   *
   */
  public interface Composable
  {
      /**
       * Pass the <code>ComponentManager</code> to the <code>Composable</code>.
       * The <code>Composable</code> implementation should use the specified
       * <code>ComponentManager</code> to acquire the components it needs for
       * execution.
       *
       * @param manager The <code>ComponentManager</code> which this
       *                <code>Composable</code> uses.
       * @exception ComponentException if an error occurs
       */
      void compose( ComponentManager manager )
          throws ComponentException;
  }
  
  
  
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Interfaces and default implementation of a service management framework supporting container
based service lookup and decommissioning. 
  </body>
  
  
  
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/component/impl/DefaultComponentManager.java
  
  Index: DefaultComponentManager.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.txt file.
   */
  package org.apache.framework.component.impl;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import org.apache.framework.component.ComponentManager;
  import org.apache.framework.component.ComponentException;
  
  /**
   * This class is a static implementation of a ComponentManager. Allow ineritance
   * and extension so you can generate a tree of ComponentManager each defining
   * Object scope.
   *
   * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version 1.0
   */
  public class DefaultComponentManager
      implements ComponentManager
  {
      private final HashMap               m_objects = new HashMap();
      private final ComponentManager      m_parent;
      private boolean                     m_readOnly;
  
      /**
       * Construct ComponentManager with no parent.
       *
       */
      public DefaultComponentManager()
      {
          this( null );
      }
  
      /**
       * Construct ComponentManager with specified parent.
       *
       * @param parent the ComponentManager parent
       */
      public DefaultComponentManager( final ComponentManager parent )
      {
          m_parent = parent;
      }
  
      /**
       * Retrieve Object by role from ComponentManager.
       *
       * @param role the role
       * @return the Object
       * @exception org.apache.framework.component.ComponentException if an error occurs
       */
      public Object lookup( final String role )
      {
          return lookup( role, null );
      }
  
      /**
       * Retrieve Object by role/hint from ComponentManager.
       *
       * @param role the role
       * @return the Object
       * @exception org.apache.framework.component.ComponentException if an error occurs
       */
      public Object lookup( final String role, Object hint )
      {
          // the default version of the method ignores the hint
          final Object object = m_objects.get( role );
  
          if( null != object )
          {
              return object;
          }
          else if( null != m_parent )
          {
              return m_parent.lookup( role );
          }
          else
          {
              throw new ComponentException( "Unable to provide implementation for " + role
);
          }
      }
  
      /**
       * Check to see if a <code>Object</code> exists for a role.
       *
       * @param role  a string identifying the role to check.
       * @return True if the object exists, False if it does not.
       */
      public boolean exists( final String role )
      {
          boolean objectExists = false;
  
          try
          {
              this.lookup(role);
              objectExists = true;
          }
          catch (Throwable t)
          {
              // Ignore all throwables--we want a yes or no answer.
          }
          return objectExists;
      }
  
      /**
       * Place Object into ComponentManager.
       *
       * @param role the components role
       * @param object an <code>Object</code> value
       */
      public void put( final String role, final Object object )
      {
          checkWriteable();
          m_objects.put( role, object );
      }
  
      /**
       * Build a human readable representation of the ComponentManager.
       *
       * @return the description of the ComponentManager
       */
      public String toString()
      {
          final StringBuffer buffer = new StringBuffer();
          final Iterator objects = m_objects.keySet().iterator();
          buffer.append( "Services:" );
  
          while( objects.hasNext() )
          {
              buffer.append( "[" );
              buffer.append( objects.next() );
              buffer.append( "]" );
          }
  
          return buffer.toString();
      }
  
      /**
       * Helper method for subclasses to retrieve parent.
       *
       * @return the parent ComponentManager
       */
      protected final ComponentManager getParent()
      {
          return m_parent;
      }
  
      /**
       * Helper method for subclasses to retrieve object map.
       *
       * @return the object map
       */
      protected final Map getObjectMap()
      {
          return m_objects;
      }
  
      /**
       * Makes this service manager read-only.
       *
       */
      public void makeReadOnly()
      {
          m_readOnly = true;
      }
  
      /**
       * Checks if this service manager is writeable.
       *
       * @exception java.lang.IllegalStateException if this service manager is read-only
       */
      protected final void checkWriteable()
          throws IllegalStateException
      {
          if( m_readOnly )
          {
              throw new IllegalStateException
                  ( "ComponentManager is read only and can not be modified" );
          }
      }
  
      
  }
  
  
  
  1.2       +0 -1      jakarta-avalon/src/proposal/avalon5/org/apache/framework/configuration/impl/DefaultConfiguration.java
  
  Index: DefaultConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/proposal/avalon5/org/apache/framework/configuration/impl/DefaultConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultConfiguration.java	31 Mar 2002 13:27:56 -0000	1.1
  +++ DefaultConfiguration.java	7 Jun 2002 20:04:11 -0000	1.2
  @@ -10,7 +10,6 @@
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.HashMap;
  -import org.apache.framework.configuration.AbstractConfiguration;
   import org.apache.framework.configuration.Configuration;
   import org.apache.framework.configuration.ConfigurationException;
   
  
  
  
  1.2       +0 -1      jakarta-avalon/src/proposal/avalon5/org/apache/framework/configuration/impl/DefaultConfigurationSerializer.java
  
  Index: DefaultConfigurationSerializer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/proposal/avalon5/org/apache/framework/configuration/impl/DefaultConfigurationSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultConfigurationSerializer.java	31 Mar 2002 13:27:56 -0000	1.1
  +++ DefaultConfigurationSerializer.java	7 Jun 2002 20:04:11 -0000	1.2
  @@ -23,7 +23,6 @@
   import org.xml.sax.helpers.NamespaceSupport;
   import org.apache.framework.configuration.Configuration;
   import org.apache.framework.configuration.ConfigurationException;
  -import org.apache.framework.configuration.AbstractConfiguration;
   
   /**
    * A ConfigurationSerializer serializes configurations via SAX2 compliant parser.
  
  
  
  1.1                  jakarta-avalon/src/proposal/avalon5/org/apache/framework/configuration/impl/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.txt file.
   */
  package org.apache.framework.configuration.impl;
  
  import org.apache.framework.configuration.Configuration;
  import org.apache.framework.configuration.ConfigurationException;
  
  /**
   * 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:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/06/07 20:04:11 $
   */
  public abstract class AbstractConfiguration
      implements Configuration
  {
      /**
       * Returns the prefix of the namespace.  This is only used as a serialization
       * hint, therefore is not part of the client API.  It should be included in
       * all Configuration implementations though.
       * @return A non-null String (defaults to "")
       * @throws ConfigurationException if no prefix was defined (prefix is
       * <code>null</code>.
       */
      protected abstract String getPrefix() throws ConfigurationException;
  
      /**
       * Returns the value of the configuration element as an <code>int</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      public int getValueAsInteger()
          throws ConfigurationException
      {
          final String value = getValue();
          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 \"" + value +
                                                "\" as an integer in the configuration element
\"" +
                                                getName() + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the configuration element as an <code>int</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      public int getValueAsInteger( final int defaultValue )
      {
          try
          {
              return getValueAsInteger();
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>long</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      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 \"" + value +
                                                "\" as a long in the configuration element
\"" +
                                                getName() + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>long</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      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 \"" + value +
                                                "\" as a float in the configuration element
\"" +
                                                getName() + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>float</code>.
       *
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      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 \"" + value +
                                                "\" as a boolean in the configuration element
\"" +
                                                getName() + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the configuration element as a <code>boolean</code>.
       *
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param name the name of the attribute
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      public int getAttributeAsInteger( 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 \"" + value +
                                                "\" as an integer in the attribute \"" +
                                                name + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as an
       * <code>int</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param name the name of the attribute
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      public int getAttributeAsInteger( final String name, final int defaultValue )
      {
          try
          {
              return getAttributeAsInteger( name );
          }
          catch( final ConfigurationException ce )
          {
              return defaultValue;
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param name the name of the attribute
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      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 Long.parseLong( value );
              }
          }
          catch( final Exception nfe )
          {
              throw new ConfigurationException( "Cannot parse the value \"" + value +
                                                "\" as a long in the attribute \"" +
                                                name + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>long</code>.
       *
       * Hexadecimal numbers begin with 0x, Octal numbers begin with 0o and binary
       * numbers begin with 0b, all other values are assumed to be decimal.
       *
       * @param name the name of the attribute
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @param name the name of the attribute
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      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 \"" + value +
                                                "\" as a float in the attribute \"" +
                                                name + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>float</code>.
       *
       * @param name the name of the attribute
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @param name the name of the attribute
       * @exception ConfigurationException if an error occurs
       * @return the value
       */
      public boolean getAttributeAsBoolean( final String name )
          throws ConfigurationException
      {
          final String value = getAttribute( name );
  
          if( value.equalsIgnoreCase( "true" ) )
          {
              return true;
          }
          else if( value.equalsIgnoreCase( "false" ) )
          {
              return false;
          }
          else
          {
              throw new ConfigurationException( "Cannot parse the value \"" + value +
                                                "\" as a boolean in the attribute \"" +
                                                name + "\" at " + getLocation() );
          }
      }
  
      /**
       * Returns the value of the attribute specified by its name as a
       * <code>boolean</code>.
       *
       * @param name the name of the attribute
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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>.
       *
       * @param name the name of the attribute
       * @param defaultValue the default value to return if value malformed or empty
       * @return the value
       */
      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. If no such child exists, a new one
       * will be created.
       *
       * @param name the name of the child
       * @return the child Configuration
       */
      public Configuration getChild( final String name )
      {
          return getChild( name, true );
      }
  
      /**
       * Return the first <code>Configuration</code> object child of this
       * associated with the given name.
       *
       * @param name the name of the child
       * @param createNew true if you want to create a new Configuration object if none exists
       * @return the child Configuration
       */
      public Configuration getChild( final String name, final boolean createNew )
      {
          final Configuration[] children = getChildren( name );
          if( children.length > 0 )
          {
              return children[ 0 ];
          }
          else
          {
              if( createNew )
              {
                  return new DefaultConfiguration( name, "-" );
              }
              else
              {
                  return null;
              }
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message