ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/event DefaultTaskEventManager.java
Date Tue, 23 Apr 2002 07:21:40 GMT
donaldp     02/04/23 00:21:40

  Added:       container/src/java/org/apache/myrmidon/components/event
                        DefaultTaskEventManager.java
  Log:
  Basic implementation of TaskEventManager added. Needs to be enhanced to make it more usable
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/event/DefaultTaskEventManager.java
  
  Index: DefaultTaskEventManager.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.myrmidon.components.event;
  
  import org.apache.myrmidon.api.event.TaskEvent;
  import org.apache.myrmidon.api.event.TaskListener;
  import org.apache.myrmidon.interfaces.event.TaskEventManager;
  
  /**
   * Support for the task listener event dispatching.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/23 07:21:39 $
   */
  public class DefaultTaskEventManager
      implements TaskEventManager
  {
      private TaskListener[] m_listeners = new TaskListener[ 0 ];
  
      /**
       * Add an extra project listener that wants to receive notification of listener events.
       *
       * @param listener the listener
       */
      public void addTaskListener( final TaskListener listener )
      {
          final TaskListener[] listeners = new TaskListener[ m_listeners.length + 1 ];
          System.arraycopy( m_listeners, 0, listeners, 0, m_listeners.length );
          listeners[ m_listeners.length ] = listener;
          m_listeners = listeners;
      }
  
      /**
       * Remove a project listener that wants to receive notification of listener events.
       *
       * @param listener the listener
       */
      public void removeTaskListener( final TaskListener listener )
      {
          int found = -1;
  
          for( int i = 0; i < m_listeners.length; i++ )
          {
              if( listener == m_listeners[ i ] )
              {
                  found = i;
                  break;
              }
          }
  
          if( -1 == found )
          {
              return;
          }
  
          final TaskListener[] listeners = new TaskListener[ m_listeners.length - 1 ];
          System.arraycopy( m_listeners, 0, listeners, 0, found );
  
          final int count = m_listeners.length - found - 1;
          System.arraycopy( m_listeners, found, listeners, found + 1, count );
  
          m_listeners = listeners;
      }
  
      /**
       * Fire a taskStarting event.
       */
      public void fireTaskStarting( final String path,
                                    final String name,
                                    final String location )
      {
          final TaskEvent event =
              new TaskEvent( path, name, location, getCurrentProcessID() );
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].taskStarting( event );
          }
      }
  
      /**
       * Fire a taskFinished event.
       */
      public void fireTaskFinished( final String path,
                                    final String name,
                                    final String location )
      {
          final TaskEvent event =
              new TaskEvent( path, name, location, getCurrentProcessID() );
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].taskFinished( event );
          }
      }
  
      /**
       * Fire a taskMessage event.
       */
      public void fireTaskMessage( final TaskEvent event )
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].taskMessage( event );
          }
      }
  
      /**
       * Retrieve current processID.
       *
       * @return the current processID.
       * @todo Actually implement
       */
      private int getCurrentProcessID()
      {
          return 0;
      }
  }
  
  
  

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


Mime
View raw message