001: /*
002: * $Id: WfEventAuditImpl.java,v 1.3 2003/08/19 17:45:18 jonesde Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.workflow.impl;
026:
027: import java.sql.Timestamp;
028: import java.util.Date;
029:
030: import org.ofbiz.base.util.ObjectType;
031: import org.ofbiz.workflow.SourceNotAvailable;
032: import org.ofbiz.workflow.WfActivity;
033: import org.ofbiz.workflow.WfEventAudit;
034: import org.ofbiz.workflow.WfException;
035: import org.ofbiz.workflow.WfExecutionObject;
036: import org.ofbiz.workflow.WfProcess;
037:
038: /**
039: * WfEventAuditImpl - Workflow Event Audit implementation
040: *
041: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
042: * @version $Revision: 1.3 $
043: * @since 2.0
044: */
045: public class WfEventAuditImpl implements WfEventAudit {
046:
047: private WfExecutionObject object = null;
048: private String eventType = null;
049: private Timestamp timeStamp = null;
050:
051: public WfEventAuditImpl(WfExecutionObject object, String eventType) {
052: this .object = object;
053: this .eventType = eventType;
054: this .timeStamp = new Timestamp(new Date().getTime());
055: }
056:
057: /**
058: * @see org.ofbiz.workflow.WfEventAudit#source()
059: */
060: public WfExecutionObject source() throws WfException,
061: SourceNotAvailable {
062: return object;
063: }
064:
065: /**
066: * @see org.ofbiz.workflow.WfEventAudit#timeStamp()
067: */
068: public Timestamp timeStamp() throws WfException {
069: return timeStamp;
070: }
071:
072: /**
073: * @see org.ofbiz.workflow.WfEventAudit#eventType()
074: */
075: public String eventType() throws WfException {
076: return eventType;
077: }
078:
079: /**
080: * @see org.ofbiz.workflow.WfEventAudit#activityKey()
081: */
082: public String activityKey() throws WfException {
083: try {
084: if (ObjectType.instanceOf(object,
085: "org.ofbiz.workflow.WfActivity"))
086: return object.key();
087: } catch (Exception e) {
088: throw new WfException("Source is not a WfActivity object");
089: }
090: throw new WfException("Source is not a WfActivity object");
091: }
092:
093: /**
094: * @see org.ofbiz.workflow.WfEventAudit#activityName()
095: */
096: public String activityName() throws WfException {
097: try {
098: if (ObjectType.instanceOf(object,
099: "org.ofbiz.workflow.WfActivity"))
100: return object.name();
101: } catch (Exception e) {
102: }
103: throw new WfException("Source is not a WfActivity object");
104:
105: }
106:
107: /**
108: * @see org.ofbiz.workflow.WfEventAudit#processKey()
109: */
110: public String processKey() throws WfException {
111: try {
112: if (ObjectType.instanceOf(object,
113: "org.ofbiz.workflow.WfProcess"))
114: return object.key();
115: } catch (Exception e) {
116: }
117: throw new WfException("Source is not a WfProcess object");
118:
119: }
120:
121: /**
122: * @see org.ofbiz.workflow.WfEventAudit#processName()
123: */
124: public String processName() throws WfException {
125: try {
126: if (ObjectType.instanceOf(object,
127: "org.ofbiz.workflow.WfProcess"))
128: return object.name();
129: } catch (Exception e) {
130: }
131: throw new WfException("Source is not a WfProcess object");
132:
133: }
134:
135: /**
136: * @see org.ofbiz.workflow.WfEventAudit#processMgrName()
137: */
138: public String processMgrName() throws WfException {
139: try {
140: if (ObjectType.instanceOf(object,
141: "org.ofbiz.workflow.WfProcess"))
142: return ((WfProcess) object).manager().name();
143: else if (ObjectType.instanceOf(object,
144: "org.ofbiz.workflow.WfActivity"))
145: return ((WfActivity) object).container().manager()
146: .name();
147: } catch (Exception e) {
148: }
149: throw new WfException("Illegal source object");
150: }
151:
152: /**
153: * @see org.ofbiz.workflow.WfEventAudit#processMgrVersion()
154: */
155: public String processMgrVersion() throws WfException {
156: try {
157: if (ObjectType.instanceOf(object,
158: "org.ofbiz.workflow.WfProcess"))
159: return ((WfProcess) object).manager().version();
160: else if (ObjectType.instanceOf(object,
161: "org.ofbiz.workflow.WfActivity"))
162: return ((WfActivity) object).container().manager()
163: .version();
164: } catch (Exception e) {
165: }
166: throw new WfException("Illegal source object");
167: }
168: }
|