001: package org.enhydra.shark;
002:
003: import java.util.List;
004: import java.util.Map;
005:
006: import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
007: import org.enhydra.shark.api.client.wfmodel.InvalidPerformer;
008: import org.enhydra.shark.api.client.wfmodel.WfEventAudit;
009: import org.enhydra.shark.api.client.wfmodel.WfProcess;
010: import org.enhydra.shark.api.client.wfmodel.WfProcessIterator;
011: import org.enhydra.shark.api.client.wfmodel.WfRequester;
012: import org.enhydra.shark.api.internal.security.SecurityManager;
013:
014: /**
015: * WfRequesterWrapper - Workflow Requester implementation.
016: *
017: * @author Sasa Bojanic
018: */
019: public class WfRequesterWrapper implements WfRequester {
020:
021: protected WMSessionHandle shandle;
022:
023: protected String resourceUsername;
024:
025: protected WfRequesterWrapper(WMSessionHandle shandle,
026: String resUsername) {
027: this .shandle = shandle;
028: this .resourceUsername = resUsername;
029: }
030:
031: /**
032: * Gets the number of processes.
033: */
034: public int how_many_performer() throws Exception {
035: long tStamp = SharkUtilities.methodStart(shandle,
036: "WfRequesterWrapper.how_many_performer");
037:
038: try {
039: checkSecurity("how_many_performer", null);
040:
041: return SharkEngineManager.getInstance()
042: .getInstancePersistenceManager()
043: .getResourceRequestersProcessIds(shandle,
044: resourceUsername).size();
045: } finally {
046: SharkUtilities.methodEnd(shandle, tStamp,
047: "WfRequesterWrapper.how_many_performer", this );
048: }
049: }
050:
051: /**
052: * Gets an iterator of processes.
053: */
054: public WfProcessIterator get_iterator_performer() throws Exception {
055: long tStamp = SharkUtilities.methodStart(shandle,
056: "WfRequesterWrapper.get_iterator_performer");
057: try {
058: checkSecurity("get_iterator_performer", null);
059:
060: return SharkEngineManager.getInstance().getObjectFactory()
061: .createProcessIteratorWrapper(shandle,
062: resourceUsername, true);
063: } finally {
064: SharkUtilities.methodEnd(shandle, tStamp,
065: "WfRequesterWrapper.get_iterator_performer", this );
066: }
067: }
068:
069: /**
070: * Returns a list of processes.
071: *
072: * @return List of WfProcess objects.
073: */
074: public WfProcess[] get_sequence_performer(int max_number)
075: throws Exception {
076: long tStamp = SharkUtilities.methodStart(shandle,
077: "WfRequesterWrapper.get_sequence_performer");
078: try {
079: checkSecurity("get_sequence_performer", null);
080:
081: List alist = SharkUtilities
082: .createResourceRequesterPerformersWrapper(shandle,
083: resourceUsername);
084: if (max_number > alist.size() || max_number <= 0) {
085: max_number = alist.size();
086: }
087:
088: WfProcess[] ret = new WfProcess[max_number];
089: alist.subList(0, max_number).toArray(ret);
090: return ret;
091: } finally {
092: SharkUtilities.methodEnd(shandle, tStamp,
093: "WfRequesterWrapper.get_sequence_performer", this );
094: }
095: }
096:
097: /**
098: * Checks if a WfProcess is associated with this requester object.
099: *
100: * @return true if the process is found.
101: */
102: public boolean is_member_of_performer(WfProcess member)
103: throws Exception {
104: long tStamp = SharkUtilities.methodStart(shandle,
105: "WfRequesterWrapper.is_member_of_performer");
106: try {
107: checkSecurity("is_member_of_performer", null);
108:
109: String procId = member.key();
110: List ids = SharkEngineManager.getInstance()
111: .getInstancePersistenceManager()
112: .getResourceRequestersProcessIds(shandle,
113: resourceUsername);
114: return ids.contains(procId);
115: } finally {
116: SharkUtilities.methodEnd(shandle, tStamp,
117: "WfRequesterWrapper.is_member_of_performer", this );
118: }
119: }
120:
121: /**
122: * Receives notice of event status changes.
123: */
124: public void receive_event(WfEventAudit event) throws Exception,
125: InvalidPerformer {
126: long tStamp = SharkUtilities.methodStart(shandle,
127: "WfRequesterWrapper.receive_event");
128: try {
129: } finally {
130: SharkUtilities.methodEnd(shandle, tStamp,
131: "WfRequesterWrapper.receive_event", this );
132: }
133: }
134:
135: protected void checkSecurity(String methodName, Map d)
136: throws Exception {
137: SecurityManager sm = SharkEngineManager.getInstance()
138: .getSecurityManager();
139: if (sm != null) {
140: sm
141: .check_requester(shandle, resourceUsername,
142: methodName, d);
143: }
144: }
145:
146: }
|