| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AuditEvent |
|
| 1.0909090909090908;1.091 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 Oliver Burn | |
| 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 | * @author <a href="mailto:stephane.bailliez@wanadoo.fr">Stephane Bailliez</a> | |
| 37 | * @see AuditListener | |
| 38 | */ | |
| 39 | public final class AuditEvent | |
| 40 | extends EventObject | |
| 41 | { | |
| 42 | /** Record a version. */ | |
| 43 | private static final long serialVersionUID = -3774725606973812736L; | |
| 44 | /** filename event associated with **/ | |
| 45 | private final String mFileName; | |
| 46 | /** message associated with the event **/ | |
| 47 | private final transient LocalizedMessage mMessage; | |
| 48 | ||
| 49 | /** | |
| 50 | * Creates a new instance. | |
| 51 | * @param aSource the object that created the event | |
| 52 | */ | |
| 53 | public AuditEvent(Object aSource) | |
| 54 | { | |
| 55 | 1172 | this(aSource, null); |
| 56 | 1172 | } |
| 57 | ||
| 58 | /** | |
| 59 | * Creates a new <code>AuditEvent</code> instance. | |
| 60 | * @param aSrc source of the event | |
| 61 | * @param aFileName file associated with the event | |
| 62 | */ | |
| 63 | public AuditEvent(Object aSrc, String aFileName) | |
| 64 | { | |
| 65 | 2372 | this(aSrc, aFileName, null); |
| 66 | 2372 | } |
| 67 | ||
| 68 | /** | |
| 69 | * Creates a new <code>AuditEvent</code> instance. | |
| 70 | * | |
| 71 | * @param aSrc source of the event | |
| 72 | * @param aFileName file associated with the event | |
| 73 | * @param aMessage the actual message | |
| 74 | */ | |
| 75 | public AuditEvent(Object aSrc, String aFileName, LocalizedMessage aMessage) | |
| 76 | { | |
| 77 | 5813 | super(aSrc); |
| 78 | 5813 | mFileName = aFileName; |
| 79 | 5813 | mMessage = aMessage; |
| 80 | 5813 | } |
| 81 | ||
| 82 | /** | |
| 83 | * @return the file name currently being audited or null if there is | |
| 84 | * no relation to a file. | |
| 85 | */ | |
| 86 | public String getFileName() | |
| 87 | { | |
| 88 | 3395 | return mFileName; |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * return the line number on the source file where the event occurred. | |
| 93 | * This may be 0 if there is no relation to a file content. | |
| 94 | * @return an integer representing the line number in the file source code. | |
| 95 | */ | |
| 96 | public int getLine() | |
| 97 | { | |
| 98 | 4311 | return mMessage.getLineNo(); |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * return the message associated to the event. | |
| 103 | * @return the event message | |
| 104 | */ | |
| 105 | public String getMessage() | |
| 106 | { | |
| 107 | 3384 | return mMessage.getMessage(); |
| 108 | } | |
| 109 | ||
| 110 | /** @return the column associated with the message **/ | |
| 111 | public int getColumn() | |
| 112 | { | |
| 113 | 6014 | return mMessage.getColumnNo(); |
| 114 | } | |
| 115 | ||
| 116 | /** @return the audit event severity level **/ | |
| 117 | public SeverityLevel getSeverityLevel() | |
| 118 | { | |
| 119 | 6783 | return (mMessage == null) |
| 120 | ? SeverityLevel.INFO | |
| 121 | : mMessage.getSeverityLevel(); | |
| 122 | } | |
| 123 | ||
| 124 | /** | |
| 125 | * @return the identifier of the module that generated the event. Can return | |
| 126 | * null. | |
| 127 | */ | |
| 128 | public String getModuleId() | |
| 129 | { | |
| 130 | 0 | return mMessage.getModuleId(); |
| 131 | } | |
| 132 | ||
| 133 | /** @return the name of the source for the message **/ | |
| 134 | public String getSourceName() | |
| 135 | { | |
| 136 | 240 | return mMessage.getSourceName(); |
| 137 | } | |
| 138 | ||
| 139 | /** @return the localized message **/ | |
| 140 | public LocalizedMessage getLocalizedMessage() | |
| 141 | { | |
| 142 | 302 | return mMessage; |
| 143 | } | |
| 144 | } |