View Javadoc

1   package org.apache.maven.j2ee;
2   
3   /* ====================================================================
4    *   Copyright 2001-2004 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import java.util.ArrayList;
21  import java.util.Iterator;
22  import java.util.List;
23  
24  /**
25   *
26   * @version $Id: ValidationBroadcaster.java 170200 2005-05-15 06:24:19Z brett $
27   * @author  dion
28   */
29  public class ValidationBroadcaster
30  {
31      
32      /** {@link ValidationListeners} handled by this broadcaster */
33      private List listeners = new ArrayList();
34  
35      /** Creates a new instance of ValidationBroadcaster */
36      public ValidationBroadcaster() 
37      {
38      }
39      
40      /**
41       * fire a {@link ValidationListener#validationStarted(ValidationEvent) 
42       * started} event.
43       * @param event the event to broadcast
44       */
45      public void fireStartedEvent(ValidationEvent event)
46      {
47          for (Iterator listeners = getListeners().iterator(); 
48              listeners.hasNext();)
49          {
50              ((ValidationListener) listeners.next()).validationStarted(event);
51          }
52      }
53  
54      /**
55       * fire an {@link ValidationListener#validationEnded(ValidationEvent) 
56       * ended} event.
57       * @param event the event to broadcast
58       */
59      public void fireEndedEvent(ValidationEvent event)
60      {
61          for (Iterator listeners = getListeners().iterator(); 
62              listeners.hasNext();)
63          {
64              ((ValidationListener) listeners.next()).validationEnded(event);
65          }
66      }
67  
68      /**
69       * fire an {@link ValidationListener#validationError(ValidationEvent) 
70       * error} event.
71       * @param event the event to broadcast
72       */
73      public void fireErrorEvent(ValidationEvent event)
74      {
75          for (Iterator listeners = getListeners().iterator(); 
76              listeners.hasNext();)
77          {
78              ((ValidationListener) listeners.next()).validationError(event);
79          }
80      }
81  
82      /**
83       * fire a {@link ValidationListener#validationWarning(ValidationEvent) 
84       * warning} event.
85       * @param event the event to broadcast
86       */
87      public void fireWarningEvent(ValidationEvent event)
88      {
89          for (Iterator listeners = getListeners().iterator(); 
90              listeners.hasNext();)
91          {
92              ((ValidationListener) listeners.next()).validationWarning(event);
93          }
94      }
95  
96      /**
97       * fire a {@link ValidationListener#validationInformation(ValidationEvent) 
98       * information} event.
99       * @param event the event to broadcast
100      */
101     public void fireInformationEvent(ValidationEvent event)
102     {
103         for (Iterator listeners = getListeners().iterator(); 
104             listeners.hasNext();)
105         {
106             ((ValidationListener) listeners.next()).validationInformation(
107                 event);
108         }
109     }
110     
111     /** Getter for property listeners.
112      * @return Value of property listeners.
113      */
114     private List getListeners()
115     {
116         return listeners;
117     }
118     
119     /**
120      * add a listener to the list to be notified
121      * @param listener a {@link ValidationListener}
122      */
123     public void addValidationListener(ValidationListener listener)
124     {
125         getListeners().add(listener);
126     }
127     
128     /**
129      * remove a listener from the list to be notified
130      * @param listener a {@link ValidationListener}
131      */
132     public void removeValidationListener(ValidationListener listener)
133     {
134         getListeners().remove(listener);
135     }
136 
137 }