KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > WfEventAuditWrapper


1 package org.enhydra.shark;
2
3 import org.enhydra.shark.api.RootException;
4 import org.enhydra.shark.api.SharkTransaction;
5 import org.enhydra.shark.api.client.timebase.UtcT;
6 import org.enhydra.shark.api.client.wfbase.BaseException;
7 import org.enhydra.shark.api.client.wfmodel.SourceNotAvailable;
8 import org.enhydra.shark.api.client.wfmodel.WfExecutionObject;
9 import org.enhydra.shark.api.internal.eventaudit.EventAuditPersistenceInterface;
10 import org.enhydra.shark.api.internal.working.*;
11 import org.enhydra.shark.utilities.MiscUtilities;
12
13 /**
14  * WfEventAuditImpl - Workflow Event Audit implementation
15  *
16  * @author Sasa Bojanic
17  */

18 public abstract class WfEventAuditWrapper implements WfEventAuditInternal {
19
20    protected String JavaDoc userAuth;
21
22    protected UtcT timeStamp;
23    protected String JavaDoc eventType;
24    protected String JavaDoc activityId;
25    protected String JavaDoc activityName;
26    protected String JavaDoc processId;
27    protected String JavaDoc processName;
28    protected String JavaDoc processMgrName;
29    protected String JavaDoc processMgrVersion;
30    protected String JavaDoc activityDefinitionId;
31    protected String JavaDoc activitySetDefinitionId;
32    protected String JavaDoc processDefinitionId;
33    protected String JavaDoc packageId;
34
35    protected WfEventAuditWrapper(SharkTransaction t,WfExecutionObjectInternal object,String JavaDoc eventType) {
36       this.timeStamp = new UtcT(
37          MiscUtilities.getAbsoluteTimeInUTCFormat(),0,(short)0,(short)0);
38       initEventObject(t,object,eventType);
39    }
40
41    protected WfEventAuditWrapper(String JavaDoc userAuth,EventAuditPersistenceInterface po){
42       this.userAuth=userAuth;
43       restore(po);
44    }
45
46    public WfEventAuditWrapper () {}
47
48    // NOTE: this method should not be called from kernel
49
public WfExecutionObject source () throws BaseException, SourceNotAvailable {
50       WfExecutionObject ret=null;
51       SharkTransaction t = null;
52       try {
53          t = SharkUtilities.createTransaction();
54          ret = source(t);
55          //SharkUtilities.commitTransaction(t);
56
} catch (RootException e) {
57          //SharkUtilities.rollbackTransaction(t);
58
SharkUtilities.emptyCaches(t);
59          if (e instanceof SourceNotAvailable)
60             throw (SourceNotAvailable)e;
61          else if (e instanceof BaseException)
62             throw (BaseException)e;
63          else
64             throw new BaseException(e);
65       } finally {
66          SharkUtilities.releaseTransaction(t);
67       }
68       return ret;
69    }
70
71    // NOTE: this method should not be called from kernel
72
public WfExecutionObject source (SharkTransaction t) throws BaseException, SourceNotAvailable {
73       if (activityId!=null) {
74          WfActivityInternal act=SharkUtilities.getActivity(t,processId,activityId);
75          if (act!=null) {
76             return SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userAuth,act.manager_name(t),processId,activityId);
77          } else {
78             throw new SourceNotAvailable("The source of event audit is not available!");
79          }
80       } else {
81          WfProcessInternal proc=SharkUtilities.getProcess(t,processId);
82          if (proc!=null) {
83             return SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,proc.manager_name(t),processId);
84          } else {
85             throw new SourceNotAvailable("The source of event audit is not available!");
86          }
87       }
88    }
89
90    public UtcT time_stamp () throws BaseException {
91       return timeStamp;
92    }
93
94    public String JavaDoc event_type () throws BaseException {
95       return eventType;
96    }
97
98    public String JavaDoc activity_key () throws BaseException {
99       return activityId;
100    }
101
102    public String JavaDoc activity_name () throws BaseException {
103       return activityName;
104    }
105
106    public String JavaDoc process_key () throws BaseException {
107       return processId;
108    }
109
110    public String JavaDoc process_name () throws BaseException {
111       return processName;
112    }
113
114    public String JavaDoc process_mgr_name () throws BaseException {
115       return processMgrName;
116    }
117
118    public String JavaDoc process_mgr_version () throws BaseException {
119       return processMgrVersion;
120    }
121
122    public String JavaDoc activity_definition_id () throws BaseException {
123       return activityDefinitionId;
124    }
125
126    public String JavaDoc activity_set_definition_id () throws BaseException {
127       return activitySetDefinitionId;
128    }
129
130    public String JavaDoc process_definition_id () throws BaseException {
131       return processDefinitionId;
132    }
133
134    public String JavaDoc package_id () throws BaseException {
135       return packageId;
136    }
137
138    protected void fillPersistentObject (EventAuditPersistenceInterface po) {
139       po.setUTCTime(String.valueOf(this.timeStamp.time));
140       po.setType(this.eventType);
141       po.setActivityId(this.activityId);
142       po.setActivityName(this.activityName);
143       po.setProcessId(this.processId);
144       po.setProcessName(this.processName);
145       po.setProcessDefinitionName(this.processMgrName);
146       po.setProcessDefinitionVersion(this.processMgrVersion);
147       po.setActivityDefinitionId(this.activityDefinitionId);
148       po.setActivitySetDefinitionId(this.activitySetDefinitionId);
149       po.setProcessDefinitionId(this.processDefinitionId);
150       po.setPackageId(this.packageId);
151    }
152
153    protected void restore (EventAuditPersistenceInterface po) {
154       try {
155          this.timeStamp = new UtcT(Long.parseLong(po.getUTCTime()),0,(short)0,(short)0);
156       } catch (Exception JavaDoc ex) {}
157       this.eventType=po.getType();
158       this.activityId=po.getActivityId();
159       this.activityName=po.getActivityName();
160       this.processId=po.getProcessId();
161       this.processName=po.getProcessName();
162       this.processMgrName=po.getProcessDefinitionName();
163       this.processMgrVersion=po.getProcessDefinitionVersion();
164       this.activityDefinitionId=po.getActivityDefinitionId();
165       this.activitySetDefinitionId=po.getActivitySetDefinitionId();
166       this.processDefinitionId=po.getProcessDefinitionId();
167       this.packageId=po.getPackageId();
168    }
169
170    protected void initEventObject (SharkTransaction t,WfExecutionObjectInternal object,String JavaDoc eventType) {
171       this.eventType=eventType;
172       try {
173          if (object instanceof WfProcessInternal) {
174             this.processId=object.key(t);
175             this.processName=object.name(t);
176             this.processMgrName=((WfProcessInternal)object).manager_name(t);
177             this.processMgrVersion=((WfProcessInternal)object).manager_version(t);
178             this.processDefinitionId=((WfProcessInternal)object).process_definition_id(t);
179             this.packageId=((WfProcessInternal)object).package_id(t);
180          } else if (object instanceof WfActivityInternal) {
181             this.activityId=object.key(t);
182             this.activityName=object.name(t);
183             this.processId=((WfActivityInternal)object).container(t).key(t);
184             this.processName=((WfActivityInternal)object).container(t).name(t);
185             this.processMgrName=((WfActivityInternal)object).container(t).manager_name(t);
186             this.processMgrVersion=((WfActivityInternal)object).container(t).manager_version(t);
187             this.activityDefinitionId=((WfActivityInternal)object).activity_definition_id(t);
188             this.activitySetDefinitionId=((WfActivityInternal)object).activity_set_definition_id(t);
189             this.processDefinitionId=((WfActivityInternal)object).container(t).process_definition_id(t);
190             this.packageId=((WfActivityInternal)object).container(t).package_id(t);
191          }
192       } catch (Exception JavaDoc ex) {ex.printStackTrace();}
193    }
194
195 }
196
Popular Tags