001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.workflow.impl;
019:
020: import java.sql.Timestamp;
021: import java.util.Date;
022:
023: import org.ofbiz.base.util.ObjectType;
024: import org.ofbiz.workflow.SourceNotAvailable;
025: import org.ofbiz.workflow.WfActivity;
026: import org.ofbiz.workflow.WfEventAudit;
027: import org.ofbiz.workflow.WfException;
028: import org.ofbiz.workflow.WfExecutionObject;
029: import org.ofbiz.workflow.WfProcess;
030:
031: /**
032: * WfEventAuditImpl - Workflow Event Audit implementation
033: */
034: public class WfEventAuditImpl implements WfEventAudit {
035:
036: private WfExecutionObject object = null;
037: private String eventType = null;
038: private Timestamp timeStamp = null;
039:
040: public WfEventAuditImpl(WfExecutionObject object, String eventType) {
041: this .object = object;
042: this .eventType = eventType;
043: this .timeStamp = new Timestamp(new Date().getTime());
044: }
045:
046: /**
047: * @see org.ofbiz.workflow.WfEventAudit#source()
048: */
049: public WfExecutionObject source() throws WfException,
050: SourceNotAvailable {
051: return object;
052: }
053:
054: /**
055: * @see org.ofbiz.workflow.WfEventAudit#timeStamp()
056: */
057: public Timestamp timeStamp() throws WfException {
058: return timeStamp;
059: }
060:
061: /**
062: * @see org.ofbiz.workflow.WfEventAudit#eventType()
063: */
064: public String eventType() throws WfException {
065: return eventType;
066: }
067:
068: /**
069: * @see org.ofbiz.workflow.WfEventAudit#activityKey()
070: */
071: public String activityKey() throws WfException {
072: try {
073: if (ObjectType.instanceOf(object,
074: "org.ofbiz.workflow.WfActivity"))
075: return object.key();
076: } catch (Exception e) {
077: throw new WfException("Source is not a WfActivity object");
078: }
079: throw new WfException("Source is not a WfActivity object");
080: }
081:
082: /**
083: * @see org.ofbiz.workflow.WfEventAudit#activityName()
084: */
085: public String activityName() throws WfException {
086: try {
087: if (ObjectType.instanceOf(object,
088: "org.ofbiz.workflow.WfActivity"))
089: return object.name();
090: } catch (Exception e) {
091: }
092: throw new WfException("Source is not a WfActivity object");
093:
094: }
095:
096: /**
097: * @see org.ofbiz.workflow.WfEventAudit#processKey()
098: */
099: public String processKey() throws WfException {
100: try {
101: if (ObjectType.instanceOf(object,
102: "org.ofbiz.workflow.WfProcess"))
103: return object.key();
104: } catch (Exception e) {
105: }
106: throw new WfException("Source is not a WfProcess object");
107:
108: }
109:
110: /**
111: * @see org.ofbiz.workflow.WfEventAudit#processName()
112: */
113: public String processName() throws WfException {
114: try {
115: if (ObjectType.instanceOf(object,
116: "org.ofbiz.workflow.WfProcess"))
117: return object.name();
118: } catch (Exception e) {
119: }
120: throw new WfException("Source is not a WfProcess object");
121:
122: }
123:
124: /**
125: * @see org.ofbiz.workflow.WfEventAudit#processMgrName()
126: */
127: public String processMgrName() throws WfException {
128: try {
129: if (ObjectType.instanceOf(object,
130: "org.ofbiz.workflow.WfProcess"))
131: return ((WfProcess) object).manager().name();
132: else if (ObjectType.instanceOf(object,
133: "org.ofbiz.workflow.WfActivity"))
134: return ((WfActivity) object).container().manager()
135: .name();
136: } catch (Exception e) {
137: }
138: throw new WfException("Illegal source object");
139: }
140:
141: /**
142: * @see org.ofbiz.workflow.WfEventAudit#processMgrVersion()
143: */
144: public String processMgrVersion() throws WfException {
145: try {
146: if (ObjectType.instanceOf(object,
147: "org.ofbiz.workflow.WfProcess"))
148: return ((WfProcess) object).manager().version();
149: else if (ObjectType.instanceOf(object,
150: "org.ofbiz.workflow.WfActivity"))
151: return ((WfActivity) object).container().manager()
152: .version();
153: } catch (Exception e) {
154: }
155: throw new WfException("Illegal source object");
156: }
157: }
|