1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import java.util.ArrayList ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 43 import org.jdom.Element; 44 45 import net.sourceforge.cruisecontrol.CruiseControlException; 46 import net.sourceforge.cruisecontrol.Publisher; 47 import net.sourceforge.cruisecontrol.util.ValidationHelper; 48 49 53 public abstract class ConditionalPublisher implements Publisher { 54 55 private List publishers = new ArrayList (); 56 57 public void publish(Element log) throws CruiseControlException { 58 if (shouldPublish(log)) { 59 for (Iterator iterator = publishers.iterator(); iterator.hasNext();) { 60 Publisher publisher = (Publisher) iterator.next(); 61 publisher.publish(log); 62 } 63 } 64 } 65 66 public void validate() throws CruiseControlException { 67 ValidationHelper.assertTrue(publishers.size() > 0, 68 "conditional publishers should have at least one nested publisher"); 69 70 for (Iterator iterator = publishers.iterator(); iterator.hasNext();) { 71 Publisher publisher = (Publisher) iterator.next(); 72 publisher.validate(); 73 } 74 } 75 76 81 public void add(Publisher publisher) { 82 publishers.add(publisher); 83 } 84 85 94 public abstract boolean shouldPublish(Element log); 95 } | Popular Tags |