001: package org.enhydra.shark.corba;
002:
003: import javax.transaction.UserTransaction;
004:
005: import org.enhydra.shark.api.client.wfbase.BaseException;
006: import org.enhydra.shark.api.client.wfmodel.NotAssigned;
007: import org.enhydra.shark.api.client.wfmodel.WfAssignment;
008: import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator;
009: import org.enhydra.shark.api.client.wfmodel.WfResource;
010:
011: /**
012: * WfResourceHelper - Helper class to be able to implement method
013: * WfAssignment.set_assignee(). Only required method to be implemented is resource_key().
014: *
015: * @author Sasa Bojanic
016: */
017: public class WfResourceHelper implements WfResource {
018: private String username;
019:
020: /**
021: * Creates a new WfResource
022: *
023: * @param username - Uniquely identifies the resource
024: */
025: protected WfResourceHelper(String username) {
026: this .username = username;
027: }
028:
029: /**
030: * Gets the number of work items currently assigned to this resource.
031: */
032: public int how_many_work_item() throws BaseException {
033: throw new BaseException("Not implemented");
034: }
035:
036: /**
037: * Gets an iterator of work items.
038: */
039: public WfAssignmentIterator get_iterator_work_item()
040: throws BaseException {
041: throw new BaseException("Not implemented");
042: }
043:
044: /**
045: * Gets the work items.
046: *
047: * @return List of WfAssignment objects.
048: */
049: public WfAssignment[] get_sequence_work_item(int max_number)
050: throws BaseException {
051: throw new BaseException("Not implemented");
052: }
053:
054: /**
055: * Checks if an assignment object is associated with this resource
056: *
057: * @return true if assignment is part of the work list for this resource.
058: */
059: public boolean is_member_of_work_items(WfAssignment member)
060: throws BaseException {
061: throw new BaseException("Not implemented");
062: }
063:
064: /**
065: * Gets the resource username.
066: */
067: public String resource_key() throws BaseException {
068: return username;
069: }
070:
071: /**
072: * Gets the resource name.
073: */
074: public String resource_name() throws BaseException {
075: throw new BaseException("Not implemented");
076: }
077:
078: /**
079: * Release the resouce from the assignment.
080: */
081: public void release(WfAssignment from_assigment, String release_info)
082: throws BaseException, NotAssigned {
083: throw new BaseException("Not implemented");
084: }
085:
086: public String toString() {
087: return "[Id=" + username + "]";
088: }
089:
090: /**
091: * It is assumed that there can't be two or more resources having the same resource
092: * key.
093: */
094: public boolean equals(Object obj) {
095: if (!(obj instanceof WfResource))
096: return false;
097: WfResource res = (WfResource) obj;
098: UserTransaction ut = null;
099: boolean e = SharkCORBAServer.doesTransactionExist();
100: try {
101: ut = SharkCORBAUtilities.beginTransaction(e);
102: boolean ret = res.resource_key().equals(username);
103: SharkCORBAUtilities.commitTransaction(ut, ret);
104: return ret;
105: } catch (Exception ex) {
106: SharkCORBAUtilities.rollbackTransaction(ut, e);
107: return false;
108: }
109: }
110:
111: }
|