/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: DefaultDataAuditEvent.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1 2003/06/30 20:05:15 drmlipp
* Initial import
*
* Revision 1.9 2003/06/27 08:51:45 lipp
* Fixed copyright/license information.
*
* Revision 1.8 2003/03/31 09:10:16 huaiyang
* nullpoint exception in toString method fixed.
*
* Revision 1.7 2003/02/11 08:49:55 lipp
* Shortened toString repr.
*
* Revision 1.6 2002/10/07 12:03:47 barzik
* toString formatting modified
*
* Revision 1.5 2002/10/02 15:07:23 lipp
* Avoid serializing JDBCPersistentData.
*
* Revision 1.4 2002/10/02 11:27:07 barzik
* bug fixes and more ...
*
* Revision 1.3 2002/10/01 16:06:00 lipp
* Event queue activated.
*
* Revision 1.2 2002/10/01 11:03:14 barzik
* add toString()
*
* Revision 1.1 2002/10/01 09:10:38 lipp
* AuditEvent handling restructured.
*
* Revision 1.5 2002/10/01 06:45:23 barzik
* no message
*
* Revision 1.4 2002/09/30 12:42:05 barzik
* audit event handling using base event information
*
* Revision 1.3 2002/09/26 12:01:45 barzik
* introduced usage of ProcessData instaed of NameValuePair ...
*
* Revision 1.2 2002/09/26 08:02:31 barzik
* Moved EventType to WfAuditEvent.java
*
* Revision 1.1 2002/09/24 12:23:02 barzik
* Initial implementation
*
*/
package de.danet.an.workflow.domain;
import java.util.Iterator;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.WfAuditEvent;
import de.danet.an.workflow.omgcore.WfDataAuditEvent;
import de.danet.an.workflow.api.DefaultProcessData;
/**
* A <code>DefaultDataAuditEvent</code> implements an audit record of
* either context changes of a <code>WfExecutionObject</code> or
* result changes of a <code>WfActivity</code>.
*/
public class DefaultDataAuditEvent extends DefaultAuditEvent
implements WfDataAuditEvent {
/**
* The attribute <code>oldData</code>. It identifies the
* the data used by the execution object, before the data change.
* If the object was created, the value is <code>null</code>.
* Hence, setting the attribute is optional.
*/
private ProcessData oldData = null;
/**
* The attribute <code>newData</code>. It identifies the
* the data used by the execution object, after the data change.
* Setting the attribute is mandatory.
*/
private ProcessData newData = null;
/**
* Creates a new <code>WfDataAuditEvent</code> assigning the given
* attributes.
* @param baseInfo a <code>WfAuditEvent</code> containing further
* information for the event.
* @param oldData the attribute <code>oldData</code>.
* @param newData the attribute <code>newData</code>.
* @throws IllegalArgumentException in case of a given illegal event
* type
*/
public DefaultDataAuditEvent(WfAuditEvent baseInfo,
ProcessData oldData,
ProcessData newData)
throws IllegalArgumentException {
// setup base attributes
super(baseInfo);
// check event type
if ( (!eventType().equals(PROCESS_CONTEXT_CHANGED))
&& (!eventType().equals(ACTIVITY_CONTEXT_CHANGED))
&& (!eventType().equals(ACTIVITY_RESULT_CHANGED))){
throw new IllegalArgumentException
("Event type is '" + eventType()
+ "' must either be '"
+ PROCESS_CONTEXT_CHANGED + "' or '"
+ ACTIVITY_CONTEXT_CHANGED + "' or '"
+ ACTIVITY_RESULT_CHANGED + "'" );
}
// check mandatory parameters
if (newData == null){
throw new IllegalArgumentException
("The argument 'newData' MUST be supplied.");
}
// specialized attributes
if (oldData == null || (oldData instanceof DefaultProcessData)) {
this.oldData = oldData;
} else {
this.oldData = new DefaultProcessData (oldData);
}
if (newData == null || (newData instanceof DefaultProcessData)) {
this.newData = newData;
} else {
this.newData = new DefaultProcessData (newData);
}
}
/**
* Creates a new <code>DefaultDataAuditEvent</code> with the
* given source and all other attributes copied from the given
* event.
* @param source the value for the source attribute.
* @param baseInfo a <code>DefaultStateAuditEvent</code>
* containing further information for the event.
*/
private DefaultDataAuditEvent(Object source,
DefaultDataAuditEvent baseInfo) {
super (source, baseInfo);
// specialized attributes
oldData= baseInfo.oldData;
newData = baseInfo.newData;
}
/**
* Return a new audit event object with the source attribute
* replaced with the given object.
* @param source the new source attribute.
* @return the new audit event.
*/
public DefaultAuditEvent replaceSource (Object source) {
return new DefaultDataAuditEvent (source, this);
}
/**
* Returns the current value of the attribute <code>oldData</code>.
* @return the current value of the attribute.
*/
public ProcessData oldData(){
return oldData;
}
/**
* Returns the current value of the attribute <code>newData</code>.
* @return the current value of the attribute.
*/
public ProcessData newData(){
return newData;
}
/**
* Returns a textual representation of the event.
* @return the textual representation
*/
public String toString() {
String event = "WfDataAuditEvent[";
String key = null;
Object value = null;
StringBuffer oldDataBuffer = new StringBuffer();
StringBuffer newDataBuffer = new StringBuffer();
// old data
if (oldData == null){
oldDataBuffer.append("=null");
} else if (oldData.isEmpty()){
oldDataBuffer.append("=<empty>");
} else {
for (Iterator i = oldData.keySet().iterator(); i.hasNext();) {
key = (String)i.next();
value = oldData.get(key);
if (value == null) {
value = "null";
}
oldDataBuffer.append(", " + key + "=" + value);
}
oldDataBuffer.deleteCharAt(0);
oldDataBuffer.insert(0, "[");
oldDataBuffer.append("]");
}
// new Data
if (newData == null){
newDataBuffer.append("=null");
} else if (newData.isEmpty()){
newDataBuffer.append("=<empty>");
} else {
for (Iterator i = newData.keySet().iterator(); i.hasNext();) {
key = (String)i.next();
value = newData.get(key);
if (value == null) {
value = "null";
}
newDataBuffer.append(", " + key + "=" + value);
}
newDataBuffer.deleteCharAt(0);
newDataBuffer.insert(0, "[");
newDataBuffer.append("]");
}
// result
return event + super.toString()
+ ", oldData" + new String(oldDataBuffer)
+ ", newData" + new String(newDataBuffer)
+ "]";
}
}