001: package org.enhydra.shark.corba;
002:
003: import javax.transaction.UserTransaction;
004:
005: import org.omg.WfBase.*;
006: import org.omg.WorkflowModel.*;
007:
008: /**
009: * WfResourceImpl - Workflow Resource Object implementation.
010: *
011: * @author Sasa Bojanic
012: * @version 1.0
013: */
014: public class WfResourceCORBA extends _WfResourceImplBase {
015: // private SharkCORBAServer myServer;
016:
017: org.enhydra.shark.api.client.wfmodel.WfResource sharkRes;
018:
019: private Collective __collective;
020:
021: /**
022: * Creates a new WfResource
023: *
024: * @param sharkRes a WfResource
025: */
026: protected WfResourceCORBA(Collective toJoin,
027: org.enhydra.shark.api.client.wfmodel.WfResource sharkRes) {
028: __collective = toJoin;
029: toJoin.__recruit(this );
030: this .sharkRes = sharkRes;
031: }
032:
033: /**
034: * Gets the number of work items currently assigned to this resource.
035: */
036: public int how_many_work_item() throws BaseException {
037: UserTransaction ut = null;
038: boolean e = SharkCORBAServer.doesTransactionExist();
039: try {
040: ut = SharkCORBAUtilities.beginTransaction(e);
041: int ret = sharkRes.how_many_work_item();
042: SharkCORBAUtilities.commitTransaction(ut, e);
043: return ret;
044: } catch (Exception ex) {
045: SharkCORBAUtilities.rollbackTransaction(ut, e);
046: throw new BaseException();
047: }
048: }
049:
050: /**
051: * Gets an iterator of work items.
052: */
053: public WfAssignmentIterator get_iterator_work_item()
054: throws BaseException {
055: UserTransaction ut = null;
056: boolean e = SharkCORBAServer.doesTransactionExist();
057: try {
058: ut = SharkCORBAUtilities.beginTransaction(e);
059: WfAssignmentIterator ret = new WfAssignmentIteratorCORBA(
060: __collective, sharkRes.get_iterator_work_item());
061: SharkCORBAUtilities.commitTransaction(ut, e);
062: return ret;
063: } catch (Exception ex) {
064: SharkCORBAUtilities.rollbackTransaction(ut, e);
065: throw new BaseException();
066: }
067: }
068:
069: /**
070: * Gets the work items.
071: *
072: * @return List of WfAssignment objects.
073: */
074: public WfAssignment[] get_sequence_work_item(int max_number)
075: throws BaseException {
076: UserTransaction ut = null;
077: boolean e = SharkCORBAServer.doesTransactionExist();
078: try {
079: ut = SharkCORBAUtilities.beginTransaction(e);
080: WfAssignment[] ret = SharkCORBAUtilities
081: .makeCORBAAssignments(__collective, sharkRes
082: .get_sequence_work_item(max_number));
083: SharkCORBAUtilities.commitTransaction(ut, e);
084: return ret;
085: } catch (Exception ex) {
086: SharkCORBAUtilities.rollbackTransaction(ut, e);
087: throw new BaseException();
088: }
089: }
090:
091: /**
092: * Checks if an assignment object is associated with this resource
093: *
094: * @return true if assignment is part of the work list for this resource.
095: */
096: public boolean is_member_of_work_items(WfAssignment member)
097: throws BaseException {
098: UserTransaction ut = null;
099: boolean e = SharkCORBAServer.doesTransactionExist();
100: try {
101: ut = SharkCORBAUtilities.beginTransaction(e);
102: WfAssignment[] ass = get_sequence_work_item(0);
103: boolean ret = false;
104: if (ass != null) {
105: for (int i = 0; i < ass.length; i++) {
106: WfAssignment as = ass[i];
107: if (as.equals(member)) {
108: ret = true;
109: break;
110: }
111: }
112: }
113: SharkCORBAUtilities.commitTransaction(ut, e);
114: return ret;
115: } catch (Exception ex) {
116: SharkCORBAUtilities.rollbackTransaction(ut, e);
117: throw new BaseException();
118: }
119: }
120:
121: /**
122: * Gets the resource username.
123: */
124: public String resource_key() throws BaseException {
125: UserTransaction ut = null;
126: boolean e = SharkCORBAServer.doesTransactionExist();
127: try {
128: ut = SharkCORBAUtilities.beginTransaction(e);
129: String ret = sharkRes.resource_key();
130: SharkCORBAUtilities.commitTransaction(ut, e);
131: return ret;
132: } catch (Exception ex) {
133: SharkCORBAUtilities.rollbackTransaction(ut, e);
134: throw new BaseException();
135: }
136: }
137:
138: /**
139: * Gets the resource name.
140: */
141: public String resource_name() throws BaseException {
142: UserTransaction ut = null;
143: boolean e = SharkCORBAServer.doesTransactionExist();
144: try {
145: ut = SharkCORBAUtilities.beginTransaction(e);
146: String ret = sharkRes.resource_name();
147: SharkCORBAUtilities.commitTransaction(ut, e);
148: return ret;
149: } catch (Exception ex) {
150: SharkCORBAUtilities.rollbackTransaction(ut, e);
151: throw new BaseException();
152: }
153: }
154:
155: /**
156: * Release the resouce from the assignment.
157: */
158: public void release(WfAssignment from_assigment, String release_info)
159: throws BaseException, NotAssigned {
160: UserTransaction ut = null;
161: boolean e = SharkCORBAServer.doesTransactionExist();
162: try {
163: ut = SharkCORBAUtilities.beginTransaction(e);
164: sharkRes.release(null, release_info);
165: SharkCORBAUtilities.commitTransaction(ut, e);
166: } catch (org.enhydra.shark.api.client.wfmodel.NotAssigned na) {
167: SharkCORBAUtilities.rollbackTransaction(ut, e);
168: throw new NotAssigned();
169: } catch (Exception ex) {
170: SharkCORBAUtilities.rollbackTransaction(ut, e);
171: throw new BaseException();
172: }
173: }
174:
175: /**
176: * It is assumed that there can't be two or more resources having the same resource
177: * key.
178: */
179: public boolean equals(Object obj) {
180: if (!(obj instanceof WfResource))
181: return false;
182: WfResource res = (WfResource) obj;
183: UserTransaction ut = null;
184: boolean e = SharkCORBAServer.doesTransactionExist();
185: try {
186: ut = SharkCORBAUtilities.beginTransaction(e);
187: boolean ret = res.resource_key().equals(resource_key());
188: SharkCORBAUtilities.commitTransaction(ut, e);
189: return ret;
190: } catch (Exception ex) {
191: SharkCORBAUtilities.rollbackTransaction(ut, e);
192: return false;
193: }
194: }
195:
196: public String toString() {
197: return sharkRes.toString();
198: }
199:
200: }
|