001: /*
002: * $Id: Log.java 562 2005-10-24 19:03:40Z hengels $
003: * (c) Copyright 2004 con:cern development team.
004: *
005: * This file is part of con:cern (http://concern.sf.net).
006: *
007: * con:cern is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU Lesser General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.concern.controller;
015:
016: import java.sql.Timestamp;
017: import java.util.Map;
018: import java.io.Serializable;
019:
020: /**
021: */
022: public class Log implements Comparable, Serializable {
023: private Integer id;
024: private Subject subject;
025:
026: private String activity;
027: private boolean success;
028: private String message;
029: private String details;
030: private Map /* <String, String> */annotations;
031: private Timestamp timestamp;
032:
033: public Log() {
034: }
035:
036: public Log(String activity) {
037: this .activity = activity;
038: this .timestamp = new Timestamp(System.currentTimeMillis());
039: }
040:
041: public Log(String activity, String message) {
042: this .activity = activity;
043: this .message = message;
044: this .timestamp = new Timestamp(System.currentTimeMillis());
045: }
046:
047: public Log(String activity, String message, String details) {
048: this .activity = activity;
049: this .message = message;
050: setDetails(details);
051: this .timestamp = new Timestamp(System.currentTimeMillis());
052: }
053:
054: Log(String activity, Timestamp timestamp) {
055: this .activity = activity;
056: this .timestamp = timestamp;
057: }
058:
059: public Integer getId() {
060: return id;
061: }
062:
063: public void setId(final Integer id) {
064: this .id = id;
065: }
066:
067: public Subject getSubject() {
068: return subject;
069: }
070:
071: public void setSubject(final Subject subject) {
072: this .subject = subject;
073: }
074:
075: /**
076: * @hibernate.property length="64"
077: */
078: public String getActivity() {
079: return activity;
080: }
081:
082: public void setActivity(String activity) {
083: this .activity = activity;
084: }
085:
086: /**
087: * @hibernate.property
088: */
089: public boolean isSuccess() {
090: return success;
091: }
092:
093: public void setSuccess(boolean success) {
094: this .success = success;
095: }
096:
097: /**
098: * @hibernate.property length="512"
099: */
100: public String getMessage() {
101: return message;
102: }
103:
104: public void setMessage(String message) {
105: this .message = message;
106: }
107:
108: /**
109: * @hibernate.property length="2048"
110: */
111: public String getDetails() {
112: return details;
113: }
114:
115: public void setDetails(String details) {
116: if (details != null && details.length() > 2048)
117: details = details.substring(0, 2048);
118: this .details = details;
119: }
120:
121: public Map /* <String, String> */getAnnotations() {
122: return this .annotations;
123: }
124:
125: public void setAnnotations(Map /* <String, String> */annotations) {
126: this .annotations = annotations;
127: }
128:
129: /**
130: * @hibernate.property
131: */
132: public Timestamp getTimestamp() {
133: return timestamp;
134: }
135:
136: public void setTimestamp(Timestamp timestamp) {
137: this .timestamp = timestamp;
138: }
139:
140: public int compareTo(Object o) {
141: Log log = (Log) o;
142: int diff = activity.compareTo(log.activity);
143: if (diff != 0)
144: return diff;
145: return timestamp.compareTo(log.timestamp);
146: }
147:
148: public String toString() {
149: return (success ? "+ " : "- ") + activity + " " + message;
150: }
151:
152: public boolean equals(Object o) {
153: if (this == o)
154: return true;
155: if (!(o instanceof Log))
156: return false;
157:
158: final Log log = (Log) o;
159:
160: if (!activity.equals(log.activity))
161: return false;
162: if (!timestamp.equals(log.timestamp))
163: return false;
164:
165: return true;
166: }
167:
168: public int hashCode() {
169: int result;
170: result = activity.hashCode();
171: result = 29 * result + timestamp.hashCode();
172: return result;
173: }
174: }
|