leif        02/04/21 23:39:22

  Modified:    instrument/src/java/org/apache/avalon/excalibur/instrument
                        AbstractInstrumentable.java
                        AbstractLogEnabledInstrumentable.java
  Log:
  Modified Abstract Insturmentable utility classes so that integration is 
simpler.
  The change is not backwards compatible.
  
  Revision  Changes    Path
  1.3       +98 -8     
jakarta-avalon-excalibur/instrument/src/java/org/apache/avalon/excalibur/instrument/AbstractInstrumentable.java
  
  Index: AbstractInstrumentable.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/instrument/src/java/org/apache/avalon/excalibur/instrument/AbstractInstrumentable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractInstrumentable.java       22 Apr 2002 03:45:49 -0000      1.2
  +++ AbstractInstrumentable.java       22 Apr 2002 06:39:22 -0000      1.3
  @@ -7,12 +7,17 @@
    */
   package org.apache.avalon.excalibur.instrument;
   
  +import java.util.ArrayList;
  +
   /**
    * Utility class to ease the construction of components that can be 
instrumented.
  - * Subclasses must override either <code>getChildInstrumentables</code> or
  - * <code>getInstruments</code>, or both, to be of any use.
  + * <p>
  + * Subclasses should call <code>addInstrument</code> or
  + *  <code>addChildInstrumentable</code> as part of the component's
  + *  initialization.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
    */
   public abstract class AbstractInstrumentable
       implements Instrumentable
  @@ -20,12 +25,77 @@
       /** Name of the instrumentable. */
       private String m_instrumentableName; 
       
  +    /** Stores the instruments during initialization. */
  +    private ArrayList m_instrumentList;
  +    
  +    /** Stores the child instrumentables during initialization. */
  +    private ArrayList m_childList;
  +    
  +    /** Flag which is to used to keep track of when the Instrumentable has 
been registered. */
  +    private boolean m_registered;
  +    
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Creates a new AbstractInstrumentable.
  +     */
  +    protected AbstractInstrumentable()
  +    {
  +        m_registered = false;
  +        m_instrumentList = new ArrayList();
  +        m_childList = new ArrayList();
  +    }
  +    
  +    /*---------------------------------------------------------------
  +     * Methods
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Adds an Instrument to the list of Instruments published by the 
component.
  +     *  This method may not be called after the Instrumentable has been
  +     *  registered with the InstrumentManager.
  +     *
  +     * @param instrument Instrument to publish.
  +     */
  +    protected void addInstrument( Instrument instrument )
  +    {
  +        if ( m_registered )
  +        {
  +            throw new IllegalStateException( "Instruments can not be added 
after the " +
  +                "Instrumentable is registered with the InstrumentManager." );
  +        }
  +        m_instrumentList.add( instrument );
  +    }
  +    
  +    /**
  +     * Adds a child Instrumentable to the list of child Instrumentables
  +     *  published by the component.  This method may not be called after the
  +     *  Instrumentable has been registered with the InstrumentManager.
  +     * <p>
  +     * Note that Child Instrumentables must be named by the caller using the
  +     *  setInstrumentableName method.
  +     *
  +     * @param child Child Instrumentable to publish.
  +     */
  +    protected void addChildInstrumentable( Instrumentable child )
  +    {
  +        if ( m_registered )
  +        {
  +            throw new IllegalStateException( "Child Instrumentables can not 
be added after the " +
  +                "Instrumentable is registered with the InstrumentManager." );
  +        }
  +        m_childList.add( child );
  +    }
  +    
  +    /*---------------------------------------------------------------
  +     * Instrumentable Methods
  +     *-------------------------------------------------------------*/
       /**
        * Gets the name of the Instrumentable.
        *
        * @return The name used to identify a Instrumentable.
        */
  -    public String getInstrumentableName() 
  +    public final String getInstrumentableName() 
       {
           return m_instrumentableName;
       }
  @@ -43,7 +113,7 @@
        *
        * @param name The name used to identify a Instrumentable.
        */
  -    public void setInstrumentableName(String name) 
  +    public final void setInstrumentableName(String name) 
       {
           m_instrumentableName = name;
       }
  @@ -57,9 +127,19 @@
        *         return null.  If there are no child Instrumentables, then
        *         EMPTY_INSTRUMENTABLE_ARRAY can be returned.
        */
  -    public Instrumentable[] getChildInstrumentables() 
  +    public final Instrumentable[] getChildInstrumentables() 
       {
  -        return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
  +        m_registered = true;
  +        if ( m_childList.size() == 0 )
  +        {
  +            return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
  +        }
  +        else
  +        {
  +            Instrumentable[] children = new Instrumentable[ 
m_childList.size() ];
  +            m_childList.toArray( children );
  +            return children;
  +        }
       }
       
       /**
  @@ -73,8 +153,18 @@
        *         the case though unless there are child Instrumentables with
        *         Instruments.
        */
  -    public Instrument[] getInstruments() 
  +    public final Instrument[] getInstruments() 
       {
  -        return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
  +        m_registered = true;
  +        if ( m_instrumentList.size() == 0 )
  +        {
  +            return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
  +        }
  +        else
  +        {
  +            Instrument[] instruments = new Instrument[ 
m_instrumentList.size() ];
  +            m_instrumentList.toArray( instruments );
  +            return instruments;
  +        }
       }
   }
  
  
  
  1.2       +96 -8     
jakarta-avalon-excalibur/instrument/src/java/org/apache/avalon/excalibur/instrument/AbstractLogEnabledInstrumentable.java
  
  Index: AbstractLogEnabledInstrumentable.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/instrument/src/java/org/apache/avalon/excalibur/instrument/AbstractLogEnabledInstrumentable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractLogEnabledInstrumentable.java     22 Apr 2002 03:45:49 -0000      
1.1
  +++ AbstractLogEnabledInstrumentable.java     22 Apr 2002 06:39:22 -0000      
1.2
  @@ -7,13 +7,16 @@
    */
   package org.apache.avalon.excalibur.instrument;
   
  +import java.util.ArrayList;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   
   /**
    * Utility class to ease the construction of components that can be 
instrumented
    *  but must also implement LogEnabled.
  - * Subclasses must override either <code>getChildInstrumentables</code> or
  - * <code>getInstruments</code>, or both, to be of any use.
  + * <p>
  + * Subclasses should call <code>addInstrument</code> or
  + *  <code>addChildInstrumentable</code> as part of the component's
  + *  initialization.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Ryan Shaw</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Leif Mortenson</a>
  @@ -25,12 +28,77 @@
       /** Name of the instrumentable. */
       private String m_instrumentableName; 
       
  +    /** Stores the instruments during initialization. */
  +    private ArrayList m_instrumentList;
  +    
  +    /** Stores the child instrumentables during initialization. */
  +    private ArrayList m_childList;
  +    
  +    /** Flag which is to used to keep track of when the Instrumentable has 
been registered. */
  +    private boolean m_registered;
  +    
  +    /*---------------------------------------------------------------
  +     * Constructors
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Creates a new AbstractLogEnabledInstrumentable.
  +     */
  +    protected AbstractLogEnabledInstrumentable()
  +    {
  +        m_registered = false;
  +        m_instrumentList = new ArrayList();
  +        m_childList = new ArrayList();
  +    }
  +    
  +    /*---------------------------------------------------------------
  +     * Methods
  +     *-------------------------------------------------------------*/
  +    /**
  +     * Adds an Instrument to the list of Instruments published by the 
component.
  +     *  This method may not be called after the Instrumentable has been
  +     *  registered with the InstrumentManager.
  +     *
  +     * @param instrument Instrument to publish.
  +     */
  +    protected void addInstrument( Instrument instrument )
  +    {
  +        if ( m_registered )
  +        {
  +            throw new IllegalStateException( "Instruments can not be added 
after the " +
  +                "Instrumentable is registered with the InstrumentManager." );
  +        }
  +        m_instrumentList.add( instrument );
  +    }
  +    
  +    /**
  +     * Adds a child Instrumentable to the list of child Instrumentables
  +     *  published by the component.  This method may not be called after the
  +     *  Instrumentable has been registered with the InstrumentManager.
  +     * <p>
  +     * Note that Child Instrumentables must be named by the caller using the
  +     *  setInstrumentableName method.
  +     *
  +     * @param child Child Instrumentable to publish.
  +     */
  +    protected void addChildInstrumentable( Instrumentable child )
  +    {
  +        if ( m_registered )
  +        {
  +            throw new IllegalStateException( "Child Instrumentables can not 
be added after the " +
  +                "Instrumentable is registered with the InstrumentManager." );
  +        }
  +        m_childList.add( child );
  +    }
  +    
  +    /*---------------------------------------------------------------
  +     * Instrumentable Methods
  +     *-------------------------------------------------------------*/
       /**
        * Gets the name of the Instrumentable.
        *
        * @return The name used to identify a Instrumentable.
        */
  -    public String getInstrumentableName() 
  +    public final String getInstrumentableName() 
       {
           return m_instrumentableName;
       }
  @@ -48,7 +116,7 @@
        *
        * @param name The name used to identify a Instrumentable.
        */
  -    public void setInstrumentableName(String name) 
  +    public final void setInstrumentableName(String name) 
       {
           m_instrumentableName = name;
       }
  @@ -62,9 +130,19 @@
        *         return null.  If there are no child Instrumentables, then
        *         EMPTY_INSTRUMENTABLE_ARRAY can be returned.
        */
  -    public Instrumentable[] getChildInstrumentables() 
  +    public final Instrumentable[] getChildInstrumentables() 
       {
  -        return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
  +        m_registered = true;
  +        if ( m_childList.size() == 0 )
  +        {
  +            return Instrumentable.EMPTY_INSTRUMENTABLE_ARRAY;
  +        }
  +        else
  +        {
  +            Instrumentable[] children = new Instrumentable[ 
m_childList.size() ];
  +            m_childList.toArray( children );
  +            return children;
  +        }
       }
       
       /**
  @@ -78,8 +156,18 @@
        *         the case though unless there are child Instrumentables with
        *         Instruments.
        */
  -    public Instrument[] getInstruments() 
  +    public final Instrument[] getInstruments() 
       {
  -        return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
  +        m_registered = true;
  +        if ( m_instrumentList.size() == 0 )
  +        {
  +            return Instrumentable.EMPTY_INSTRUMENT_ARRAY;
  +        }
  +        else
  +        {
  +            Instrument[] instruments = new Instrument[ 
m_instrumentList.size() ];
  +            m_instrumentList.toArray( instruments );
  +            return instruments;
  +        }
       }
   }
  
  
  

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

Reply via email to