Coverage Report - org.jaudiotagger.audio.generic.ModificationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ModificationHandler
28%
11/40
25%
3/12
0
 
 1  
 /*
 2  
  * Entagged Audio Tag library
 3  
  * Copyright (c) 2003-2005 Christian Laireiter <liree@web.de>
 4  
  * 
 5  
  * This library is free software; you can redistribute it and/or
 6  
  * modify it under the terms of the GNU Lesser General Public
 7  
  * License as published by the Free Software Foundation; either
 8  
  * version 2.1 of the License, or (at your option) any later version.
 9  
  *  
 10  
  * This library is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  * Lesser General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU Lesser General Public
 16  
  * License along with this library; if not, write to the Free Software
 17  
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 18  
  */
 19  
 package org.jaudiotagger.audio.generic;
 20  
 
 21  
 import org.jaudiotagger.audio.AudioFile;
 22  
 import org.jaudiotagger.audio.exceptions.ModifyVetoException;
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.Enumeration;
 26  
 import java.util.Vector;
 27  
 
 28  
 /**
 29  
  * This class multicasts the events to multiple listener instances.<br>
 30  
  * Additionally the Vetos are handled. (other listeners are notified).
 31  
  *
 32  
  * @author Christian Laireiter
 33  
  */
 34  42
 public class ModificationHandler implements AudioFileModificationListener
 35  
 {
 36  
 
 37  
     /**
 38  
      * The listeners to wich events are broadcasted are stored here.
 39  
      */
 40  42
     private Vector<AudioFileModificationListener> listeners = new Vector<AudioFileModificationListener>();
 41  
 
 42  
     /**
 43  
      * This method adds an {@link AudioFileModificationListener}
 44  
      *
 45  
      * @param l Listener to add.
 46  
      */
 47  
     public void addAudioFileModificationListener(AudioFileModificationListener l)
 48  
     {
 49  0
         if (!this.listeners.contains(l))
 50  
         {
 51  0
             this.listeners.add(l);
 52  
         }
 53  0
     }
 54  
 
 55  
     /**
 56  
      * (overridden)
 57  
      *
 58  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileModified(org.jaudiotagger.audio.AudioFile,
 59  
      *File)
 60  
      */
 61  
     public void fileModified(AudioFile original, File temporary) throws ModifyVetoException
 62  
     {
 63  109
         Enumeration<AudioFileModificationListener> enumer = this.listeners.elements();
 64  109
         while (enumer.hasMoreElements())
 65  
         {
 66  0
             AudioFileModificationListener current = enumer.nextElement();
 67  
             try
 68  
             {
 69  0
                 current.fileModified(original, temporary);
 70  
             }
 71  0
             catch (ModifyVetoException e)
 72  
             {
 73  0
                 vetoThrown(current, original, e);
 74  0
                 throw e;
 75  0
             }
 76  0
         }
 77  109
     }
 78  
 
 79  
     /**
 80  
      * (overridden)
 81  
      *
 82  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileOperationFinished(File)
 83  
      */
 84  
     public void fileOperationFinished(File result)
 85  
     {
 86  109
         Enumeration<AudioFileModificationListener> enumer = this.listeners.elements();
 87  109
         while (enumer.hasMoreElements())
 88  
         {
 89  0
             AudioFileModificationListener current = enumer.nextElement();
 90  0
             current.fileOperationFinished(result);
 91  0
         }
 92  109
     }
 93  
 
 94  
     /**
 95  
      * (overridden)
 96  
      *
 97  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileWillBeModified(org.jaudiotagger.audio.AudioFile,
 98  
      *boolean)
 99  
      */
 100  
     public void fileWillBeModified(AudioFile file, boolean delete) throws ModifyVetoException
 101  
     {
 102  109
         Enumeration<AudioFileModificationListener> enumer = this.listeners.elements();
 103  109
         while (enumer.hasMoreElements())
 104  
         {
 105  0
             AudioFileModificationListener current = enumer.nextElement();
 106  
             try
 107  
             {
 108  0
                 current.fileWillBeModified(file, delete);
 109  
             }
 110  0
             catch (ModifyVetoException e)
 111  
             {
 112  0
                 vetoThrown(current, file, e);
 113  0
                 throw e;
 114  0
             }
 115  0
         }
 116  109
     }
 117  
 
 118  
     /**
 119  
      * This method removes an {@link AudioFileModificationListener}
 120  
      *
 121  
      * @param l Listener to remove.
 122  
      */
 123  
     public void removeAudioFileModificationListener(AudioFileModificationListener l)
 124  
     {
 125  0
         if (this.listeners.contains(l))
 126  
         {
 127  0
             this.listeners.remove(l);
 128  
         }
 129  0
     }
 130  
 
 131  
     /**
 132  
      * (overridden)
 133  
      *
 134  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#vetoThrown(org.jaudiotagger.audio.generic.AudioFileModificationListener,
 135  
      *org.jaudiotagger.audio.AudioFile,
 136  
      *org.jaudiotagger.audio.exceptions.ModifyVetoException)
 137  
      */
 138  
     public void vetoThrown(AudioFileModificationListener cause, AudioFile original, ModifyVetoException veto)
 139  
     {
 140  0
         Enumeration<AudioFileModificationListener> enumer = this.listeners.elements();
 141  0
         while (enumer.hasMoreElements())
 142  
         {
 143  0
             AudioFileModificationListener current = enumer.nextElement();
 144  0
             current.vetoThrown(cause, original, veto);
 145  0
         }
 146  0
     }
 147  
 }