View Javadoc
1   package org.apache.maven.plugins.checkstyle;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
26  import com.puppycrawl.tools.checkstyle.api.AuditListener;
27  
28  /**
29   * AuditListener that forwards events to a list of other AuditListeners
30   */
31  public class CompositeAuditListener
32      implements AuditListener
33  {
34  
35      private final List<AuditListener> delegates = new ArrayList<>();
36  
37      public void addListener( AuditListener listener )
38      {
39          delegates.add( listener );
40      }
41  
42      @Override
43      public void auditStarted( AuditEvent event )
44      {
45          for ( AuditListener listener : delegates )
46          {
47              listener.auditStarted( event );
48          }
49      }
50  
51      @Override
52      public void auditFinished( AuditEvent event )
53      {
54          for ( AuditListener listener : delegates )
55          {
56              listener.auditFinished( event );
57          }
58      }
59  
60      @Override
61      public void fileStarted( AuditEvent event )
62      {
63          for ( AuditListener listener : delegates )
64          {
65              listener.fileStarted( event );
66          }
67      }
68  
69      @Override
70      public void fileFinished( AuditEvent event )
71      {
72          for ( AuditListener listener : delegates )
73          {
74              listener.fileFinished( event );
75          }
76      }
77  
78      @Override
79      public void addError( AuditEvent event )
80      {
81          for ( AuditListener listener : delegates )
82          {
83              listener.addError( event );
84          }
85      }
86  
87      @Override
88      public void addException( AuditEvent event, Throwable throwable )
89      {
90          for ( AuditListener listener : delegates )
91          {
92              listener.addException( event, throwable );
93          }
94      }
95  
96  }