| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons; |
| 34 | | | |
| 35 | | | import org.jcoderz.commons.util.HashCodeUtil; |
| 36 | | | |
| 37 | | | /** |
| 38 | | | * This is the base class for audit log events. |
| 39 | | | * |
| 40 | | | * <p>The base class of this AuditLogEvent is Throwable but instances |
| 41 | | | * of this class are not expected to be thrown.</p> |
| 42 | | | * |
| 43 | | | * <p>Most functionality is implemented and documented by the |
| 44 | | | * {@link org.jcoderz.commons.LoggableImpl} which is used a member of |
| 45 | | | * objects of this class.</p> |
| 46 | | | * |
| 47 | | | * @see org.jcoderz.commons |
| 48 | | | * @author Andreas Mandel |
| 49 | | | * @author Michael Griffel |
| 50 | | | */ |
| 51 | | | public class AuditLogEvent |
| 52 | | | extends LogEvent |
| 53 | | | { |
| 54 | | | /** Key used for the audit principal parameter object. */ |
| 55 | | | public static final String AUDIT_PRINCIPAL_PARAMETER_NAME |
| 56 | | | = "_AUDIT_PRINCIPAL"; |
| 57 | | | |
| 58 | | | /** |
| 59 | | | * The class fingerprint that is set to indicate serialization |
| 60 | | | * compatibility with a previous version of the class. |
| 61 | | | * Corresponds to CVS revision 1.3 of the class. |
| 62 | | | */ |
| 63 | | | static final long serialVersionUID = 3L; |
| 64 | | | |
| 65 | | | /** the principal of the AuditLogEvent */ |
| 66 | | | private final AuditPrincipal mAuditPrincipal; |
| 67 | | | |
| 68 | | | /** The hashcode value, lazy initialized. */ |
| 69 | | | private transient int mLazyHashCode = 0; |
| 70 | | | |
| 71 | | | /** |
| 72 | | | * Constructor to create a AuditLogEvent instance with the minimum |
| 73 | | | * mandatory parameters. |
| 74 | | | * @param messageInfo the log message info of this audit log event. |
| 75 | | | * @param principal the audit principal that cause this audit log event. |
| 76 | | | */ |
| 77 | | | public AuditLogEvent (LogMessageInfo messageInfo, AuditPrincipal principal) |
| 78 | | | { |
| 79 | | | super(messageInfo); |
| 80 | | | mAuditPrincipal = principal; |
| 81 | | | addParameter(AUDIT_PRINCIPAL_PARAMETER_NAME, principal); |
| 82 | | | } |
| 83 | | | |
| 84 | | | /** |
| 85 | | | * Constructor to create a AuditLogEvent instance with a |
| 86 | | | * given root <tt>cause</tt>. |
| 87 | | | * @param messageInfo the log message info of this audit log event. |
| 88 | | | * @param principal the audit principal that cause this audit log event. |
| 89 | | | * @param cause the cause of this audit log event. |
| 90 | | | */ |
| 91 | | | public AuditLogEvent (LogMessageInfo messageInfo, AuditPrincipal principal, |
| 92 | | | Throwable cause) |
| 93 | | | { |
| 94 | | | super(messageInfo, cause); |
| 95 | | | mAuditPrincipal = principal; |
| 96 | | | addParameter(AUDIT_PRINCIPAL_PARAMETER_NAME, principal); |
| 97 | | | } |
| 98 | | | |
| 99 | | | /** |
| 100 | | | * Returns the audit principal of this audit log event. |
| 101 | | | * @return the audit principal of this audit log event. |
| 102 | | | */ |
| 103 | | | public final AuditPrincipal getAuditPrincipal () |
| 104 | | | { |
| 105 | | | return mAuditPrincipal; |
| 106 | | | } |
| 107 | | | |
| 108 | | | /** |
| 109 | | | * Indicates whether some other object is "equal to" this one. |
| 110 | | | * |
| 111 | | | * @param obj the object to compare to. |
| 112 | | | * @return true if this object is the same as the obj argument; false |
| 113 | | | * otherwise. |
| 114 | | | */ |
| 115 | | | public boolean equals (Object obj) |
| 116 | | | { |
| 117 | | | boolean equals = false; |
| 118 | | | if (obj instanceof AuditLogEvent) |
| 119 | | | { |
| 120 | | | final AuditLogEvent algEvent = (AuditLogEvent) obj; |
| 121 | | | if (mAuditPrincipal.equals(algEvent.getAuditPrincipal()) |
| 122 | | | && getLogMessageInfo().equals(algEvent.getLogMessageInfo()) |
| 123 | | | && getCause().equals(algEvent.getCause())) |
| 124 | | | { |
| 125 | | | equals = true; |
| 126 | | | } |
| 127 | | | } |
| 128 | | | return equals; |
| 129 | | | } |
| 130 | | | |
| 131 | | | /** |
| 132 | | | * Override hashCode. |
| 133 | | | * @return the Object's hashcode. |
| 134 | | | */ |
| 135 | | | public int hashCode () |
| 136 | | | { |
| 137 | | | if (mLazyHashCode == 0) |
| 138 | | | { |
| 139 | | | mLazyHashCode = HashCodeUtil.SEED; |
| 140 | | | mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, mAuditPrincipal); |
| 141 | | | mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, getLogMessageInfo()); |
| 142 | | | mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, getCause()); |
| 143 | | | } |
| 144 | | | return mLazyHashCode; |
| 145 | | | } |
| 146 | | | } |
| 147 | | | |