001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: DefaultDataAuditEvent.java,v 1.2 2006/09/29 12:32:08 drmlipp Exp $
021: *
022: * $Log: DefaultDataAuditEvent.java,v $
023: * Revision 1.2 2006/09/29 12:32:08 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1.1.1 2003/06/30 20:05:15 drmlipp
027: * Initial import
028: *
029: * Revision 1.9 2003/06/27 08:51:45 lipp
030: * Fixed copyright/license information.
031: *
032: * Revision 1.8 2003/03/31 09:10:16 huaiyang
033: * nullpoint exception in toString method fixed.
034: *
035: * Revision 1.7 2003/02/11 08:49:55 lipp
036: * Shortened toString repr.
037: *
038: * Revision 1.6 2002/10/07 12:03:47 barzik
039: * toString formatting modified
040: *
041: * Revision 1.5 2002/10/02 15:07:23 lipp
042: * Avoid serializing JDBCPersistentData.
043: *
044: * Revision 1.4 2002/10/02 11:27:07 barzik
045: * bug fixes and more ...
046: *
047: * Revision 1.3 2002/10/01 16:06:00 lipp
048: * Event queue activated.
049: *
050: * Revision 1.2 2002/10/01 11:03:14 barzik
051: * add toString()
052: *
053: * Revision 1.1 2002/10/01 09:10:38 lipp
054: * AuditEvent handling restructured.
055: *
056: * Revision 1.5 2002/10/01 06:45:23 barzik
057: * no message
058: *
059: * Revision 1.4 2002/09/30 12:42:05 barzik
060: * audit event handling using base event information
061: *
062: * Revision 1.3 2002/09/26 12:01:45 barzik
063: * introduced usage of ProcessData instaed of NameValuePair ...
064: *
065: * Revision 1.2 2002/09/26 08:02:31 barzik
066: * Moved EventType to WfAuditEvent.java
067: *
068: * Revision 1.1 2002/09/24 12:23:02 barzik
069: * Initial implementation
070: *
071: */
072:
073: package de.danet.an.workflow.domain;
074:
075: import java.util.Iterator;
076:
077: import de.danet.an.workflow.omgcore.ProcessData;
078: import de.danet.an.workflow.omgcore.WfAuditEvent;
079: import de.danet.an.workflow.omgcore.WfDataAuditEvent;
080: import de.danet.an.workflow.api.DefaultProcessData;
081:
082: /**
083: * A <code>DefaultDataAuditEvent</code> implements an audit record of
084: * either context changes of a <code>WfExecutionObject</code> or
085: * result changes of a <code>WfActivity</code>.
086: */
087: public class DefaultDataAuditEvent extends DefaultAuditEvent implements
088: WfDataAuditEvent {
089:
090: /**
091: * The attribute <code>oldData</code>. It identifies the
092: * the data used by the execution object, before the data change.
093: * If the object was created, the value is <code>null</code>.
094: * Hence, setting the attribute is optional.
095: */
096: private ProcessData oldData = null;
097:
098: /**
099: * The attribute <code>newData</code>. It identifies the
100: * the data used by the execution object, after the data change.
101: * Setting the attribute is mandatory.
102: */
103: private ProcessData newData = null;
104:
105: /**
106: * Creates a new <code>WfDataAuditEvent</code> assigning the given
107: * attributes.
108: * @param baseInfo a <code>WfAuditEvent</code> containing further
109: * information for the event.
110: * @param oldData the attribute <code>oldData</code>.
111: * @param newData the attribute <code>newData</code>.
112: * @throws IllegalArgumentException in case of a given illegal event
113: * type
114: */
115: public DefaultDataAuditEvent(WfAuditEvent baseInfo,
116: ProcessData oldData, ProcessData newData)
117: throws IllegalArgumentException {
118:
119: // setup base attributes
120: super (baseInfo);
121:
122: // check event type
123: if ((!eventType().equals(PROCESS_CONTEXT_CHANGED))
124: && (!eventType().equals(ACTIVITY_CONTEXT_CHANGED))
125: && (!eventType().equals(ACTIVITY_RESULT_CHANGED))) {
126: throw new IllegalArgumentException("Event type is '"
127: + eventType() + "' must either be '"
128: + PROCESS_CONTEXT_CHANGED + "' or '"
129: + ACTIVITY_CONTEXT_CHANGED + "' or '"
130: + ACTIVITY_RESULT_CHANGED + "'");
131: }
132:
133: // check mandatory parameters
134: if (newData == null) {
135: throw new IllegalArgumentException(
136: "The argument 'newData' MUST be supplied.");
137: }
138:
139: // specialized attributes
140: if (oldData == null || (oldData instanceof DefaultProcessData)) {
141: this .oldData = oldData;
142: } else {
143: this .oldData = new DefaultProcessData(oldData);
144: }
145: if (newData == null || (newData instanceof DefaultProcessData)) {
146: this .newData = newData;
147: } else {
148: this .newData = new DefaultProcessData(newData);
149: }
150: }
151:
152: /**
153: * Creates a new <code>DefaultDataAuditEvent</code> with the
154: * given source and all other attributes copied from the given
155: * event.
156: * @param source the value for the source attribute.
157: * @param baseInfo a <code>DefaultStateAuditEvent</code>
158: * containing further information for the event.
159: */
160: private DefaultDataAuditEvent(Object source,
161: DefaultDataAuditEvent baseInfo) {
162: super (source, baseInfo);
163: // specialized attributes
164: oldData = baseInfo.oldData;
165: newData = baseInfo.newData;
166: }
167:
168: /**
169: * Return a new audit event object with the source attribute
170: * replaced with the given object.
171: * @param source the new source attribute.
172: * @return the new audit event.
173: */
174: public DefaultAuditEvent replaceSource(Object source) {
175: return new DefaultDataAuditEvent(source, this );
176: }
177:
178: /**
179: * Returns the current value of the attribute <code>oldData</code>.
180: * @return the current value of the attribute.
181: */
182: public ProcessData oldData() {
183: return oldData;
184: }
185:
186: /**
187: * Returns the current value of the attribute <code>newData</code>.
188: * @return the current value of the attribute.
189: */
190: public ProcessData newData() {
191: return newData;
192: }
193:
194: /**
195: * Returns a textual representation of the event.
196: * @return the textual representation
197: */
198: public String toString() {
199: String event = "WfDataAuditEvent[";
200: String key = null;
201: Object value = null;
202: StringBuffer oldDataBuffer = new StringBuffer();
203: StringBuffer newDataBuffer = new StringBuffer();
204:
205: // old data
206: if (oldData == null) {
207: oldDataBuffer.append("=null");
208: } else if (oldData.isEmpty()) {
209: oldDataBuffer.append("=<empty>");
210: } else {
211: for (Iterator i = oldData.keySet().iterator(); i.hasNext();) {
212: key = (String) i.next();
213: value = oldData.get(key);
214: if (value == null) {
215: value = "null";
216: }
217: oldDataBuffer.append(", " + key + "=" + value);
218: }
219: oldDataBuffer.deleteCharAt(0);
220: oldDataBuffer.insert(0, "[");
221: oldDataBuffer.append("]");
222: }
223:
224: // new Data
225: if (newData == null) {
226: newDataBuffer.append("=null");
227: } else if (newData.isEmpty()) {
228: newDataBuffer.append("=<empty>");
229: } else {
230: for (Iterator i = newData.keySet().iterator(); i.hasNext();) {
231: key = (String) i.next();
232: value = newData.get(key);
233: if (value == null) {
234: value = "null";
235: }
236: newDataBuffer.append(", " + key + "=" + value);
237: }
238: newDataBuffer.deleteCharAt(0);
239: newDataBuffer.insert(0, "[");
240: newDataBuffer.append("]");
241: }
242:
243: // result
244: return event + super .toString() + ", oldData"
245: + new String(oldDataBuffer) + ", newData"
246: + new String(newDataBuffer) + "]";
247: }
248: }
|