Project Report: fawkez

Packagesummary org.jcoderz.commons

org.jcoderz.commons.AuditLogEvent

LineHitsNoteSource
1  /*
2   * $Id: AuditLogEvent.java 1011 2008-06-16 17:57:36Z amandel $
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   */
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. */
6950    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     {
79100       super(messageInfo);
80100       mAuditPrincipal = principal;
81100       addParameter(AUDIT_PRINCIPAL_PARAMETER_NAME, principal);
82100    }
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     {
940       super(messageInfo, cause);
950       mAuditPrincipal = principal;
960       addParameter(AUDIT_PRINCIPAL_PARAMETER_NAME, principal);
970    }
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     {
105100       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     {
1170       boolean equals = false;
1180       if (obj instanceof AuditLogEvent)
119        {
1200          final AuditLogEvent algEvent = (AuditLogEvent) obj;
1210          if (mAuditPrincipal.equals(algEvent.getAuditPrincipal())
122                 && getLogMessageInfo().equals(algEvent.getLogMessageInfo())
123                 && getCause().equals(algEvent.getCause()))
124           {
1250             equals = true;
126           }
127        }
1280       return equals;
129     }
130  
131     /**
132      * Override hashCode.
133      * @return the Object's hashcode.
134      */
135     public int hashCode ()
136     {
1370       if (mLazyHashCode == 0)
138        {
1390          mLazyHashCode = HashCodeUtil.SEED;
1400          mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, mAuditPrincipal);
1410          mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, getLogMessageInfo());
1420          mLazyHashCode = HashCodeUtil.hash(mLazyHashCode, getCause());
143        }
1440       return mLazyHashCode;
145     }
146  }

Findings in this File