Coverage Report - org.jaudiotagger.audio.generic.ModificationHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ModificationHandler
27%
11/40
25%
3/12
2.667
 
 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  
 import java.util.Iterator;
 28  
 
 29  
 /**
 30  
  * This class multicasts the events to multiple listener instances.<br>
 31  
  * Additionally the Vetos are handled. (other listeners are notified).
 32  
  *
 33  
  * @author Christian Laireiter
 34  
  */
 35  4
 public class ModificationHandler implements AudioFileModificationListener
 36  
 {
 37  
 
 38  
     /**
 39  
      * The listeners to wich events are broadcasted are stored here.
 40  
      */
 41  4
     private Vector<AudioFileModificationListener> listeners = new Vector<AudioFileModificationListener>();
 42  
 
 43  
     /**
 44  
      * This method adds an {@link AudioFileModificationListener}
 45  
      *
 46  
      * @param l Listener to add.
 47  
      */
 48  
     public void addAudioFileModificationListener(AudioFileModificationListener l)
 49  
     {
 50  0
         if (!this.listeners.contains(l))
 51  
         {
 52  0
             this.listeners.add(l);
 53  
         }
 54  0
     }
 55  
 
 56  
     /**
 57  
      * (overridden)
 58  
      *
 59  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileModified(org.jaudiotagger.audio.AudioFile,
 60  
      *File)
 61  
      */
 62  
     public void fileModified(AudioFile original, File temporary) throws ModifyVetoException
 63  
     {
 64  442
         Iterator<AudioFileModificationListener> iterator = this.listeners.iterator();
 65  442
         while (iterator.hasNext())
 66  
         {
 67  0
             AudioFileModificationListener current = iterator.next();
 68  
             try
 69  
             {
 70  0
                 current.fileModified(original, temporary);
 71  
             }
 72  0
             catch (ModifyVetoException e)
 73  
             {
 74  0
                 vetoThrown(current, original, e);
 75  0
                 throw e;
 76  0
             }
 77  0
         }
 78  442
     }
 79  
 
 80  
     /**
 81  
      * (overridden)
 82  
      *
 83  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileOperationFinished(File)
 84  
      */
 85  
     public void fileOperationFinished(File result)
 86  
     {
 87  442
         Iterator<AudioFileModificationListener> iterator = this.listeners.iterator();
 88  442
         while (iterator.hasNext())
 89  
         {
 90  0
             AudioFileModificationListener current = iterator.next();
 91  0
             current.fileOperationFinished(result);
 92  0
         }
 93  442
     }
 94  
 
 95  
     /**
 96  
      * (overridden)
 97  
      *
 98  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileWillBeModified(org.jaudiotagger.audio.AudioFile,
 99  
      *boolean)
 100  
      */
 101  
     public void fileWillBeModified(AudioFile file, boolean delete) throws ModifyVetoException
 102  
     {
 103  443
         Iterator<AudioFileModificationListener> iterator = this.listeners.iterator();
 104  443
         while (iterator.hasNext())
 105  
         {
 106  0
             AudioFileModificationListener current = iterator.next();
 107  
             try
 108  
             {
 109  0
                 current.fileWillBeModified(file, delete);
 110  
             }
 111  0
             catch (ModifyVetoException e)
 112  
             {
 113  0
                 vetoThrown(current, file, e);
 114  0
                 throw e;
 115  0
             }
 116  0
         }
 117  443
     }
 118  
 
 119  
     /**
 120  
      * This method removes an {@link AudioFileModificationListener}
 121  
      *
 122  
      * @param l Listener to remove.
 123  
      */
 124  
     public void removeAudioFileModificationListener(AudioFileModificationListener l)
 125  
     {
 126  0
         if (this.listeners.contains(l))
 127  
         {
 128  0
             this.listeners.remove(l);
 129  
         }
 130  0
     }
 131  
 
 132  
     /**
 133  
      * (overridden)
 134  
      *
 135  
      * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#vetoThrown(org.jaudiotagger.audio.generic.AudioFileModificationListener,
 136  
      *org.jaudiotagger.audio.AudioFile,
 137  
      *org.jaudiotagger.audio.exceptions.ModifyVetoException)
 138  
      */
 139  
     public void vetoThrown(AudioFileModificationListener cause, AudioFile original, ModifyVetoException veto)
 140  
     {
 141  0
         Iterator<AudioFileModificationListener> iterator = this.listeners.iterator();
 142  0
         while (iterator.hasNext())
 143  
         {
 144  0
             AudioFileModificationListener current = iterator.next();
 145  0
             current.vetoThrown(cause, original, veto);
 146  0
         }
 147  0
     }
 148  
 }