View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2015 the original author or authors.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  package com.puppycrawl.tools.checkstyle.api;
20  
21  import java.util.EventObject;
22  
23  
24  /**
25   * Raw event for audit.
26   * <p>
27   * <i>
28   * I'm not very satisfied about the design of this event since there are
29   * optional methods that will return null in most of the case. This will
30   * need some work to clean it up especially if we want to introduce
31   * a more sequential reporting action rather than a packet error
32   * reporting. This will allow for example to follow the process quickly
33   * in an interface or a servlet (yep, that's cool to run a check via
34   * a web interface in a source repository ;-)
35   * </i>
36   * </p>
37   *
38   * @author <a href="mailto:stephane.bailliez@wanadoo.fr">Stephane Bailliez</a>
39   * @see AuditListener
40   */
41  public final class AuditEvent
42      extends EventObject
43  {
44      /** Record a version. */
45      private static final long serialVersionUID = -3774725606973812736L;
46      /** filename event associated with **/
47      private final String fileName;
48      /** message associated with the event **/
49      private final transient LocalizedMessage message;
50  
51      /**
52       * Creates a new instance.
53       * @param source the object that created the event
54       */
55      public AuditEvent(Object source)
56      {
57          this(source, null);
58      }
59  
60      /**
61       * Creates a new <code>AuditEvent</code> instance.
62       * @param src source of the event
63       * @param fileName file associated with the event
64       */
65      public AuditEvent(Object src, String fileName)
66      {
67          this(src, fileName, null);
68      }
69  
70      /**
71       * Creates a new <code>AuditEvent</code> instance.
72       *
73       * @param src source of the event
74       * @param fileName file associated with the event
75       * @param message the actual message
76       */
77      public AuditEvent(Object src, String fileName, LocalizedMessage message)
78      {
79          super(src);
80          this.fileName = fileName;
81          this.message = message;
82      }
83  
84      /**
85       * @return the file name currently being audited or null if there is
86       * no relation to a file.
87       */
88      public String getFileName()
89      {
90          return fileName;
91      }
92  
93      /**
94       * return the line number on the source file where the event occurred.
95       * This may be 0 if there is no relation to a file content.
96       * @return an integer representing the line number in the file source code.
97       */
98      public int getLine()
99      {
100         return message.getLineNo();
101     }
102 
103     /**
104      * return the message associated to the event.
105      * @return the event message
106      */
107     public String getMessage()
108     {
109         return message.getMessage();
110     }
111 
112     /** @return the column associated with the message **/
113     public int getColumn()
114     {
115         return message.getColumnNo();
116     }
117 
118     /** @return the audit event severity level **/
119     public SeverityLevel getSeverityLevel()
120     {
121         return message == null
122             ? SeverityLevel.INFO
123             : message.getSeverityLevel();
124     }
125 
126     /**
127      * @return the identifier of the module that generated the event. Can return
128      *         null.
129      */
130     public String getModuleId()
131     {
132         return message.getModuleId();
133     }
134 
135     /** @return the name of the source for the message **/
136     public String getSourceName()
137     {
138         return message.getSourceName();
139     }
140 
141     /** @return the localized message **/
142     public LocalizedMessage getLocalizedMessage()
143     {
144         return message;
145     }
146 }