root/trunk/src/java/org/jcoderz/commons/AuditLogEvent.java

Revision 1011, 5.0 kB (checked in by amandel, 4 years ago)

Aligned svn keyword settings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 *
4 * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *    * Redistributions of source code must retain the above copyright
11 *      notice, this list of conditions and the following disclaimer.
12 *    * Redistributions in binary form must reproduce the above
13 *      copyright notice, this list of conditions and the following
14 *      disclaimer in the documentation and/or other materials
15 *      provided with the distribution.
16 *    * Neither the name of the jCoderZ.org Project nor the names of
17 *      its contributors may be used to endorse or promote products
18 *      derived from this software without specific prior written
19 *      permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33package org.jcoderz.commons;
34
35import 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 */
51public 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}
Note: See TracBrowser for help on using the browser.