KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corba > WfResourceCORBA


1 package org.enhydra.shark.corba;
2
3 import org.omg.WfBase.*;
4 import org.omg.WorkflowModel.*;
5
6 /**
7  * WfResourceImpl - Workflow Resource Object implementation.
8  *
9  * @author Sasa Bojanic
10  * @version 1.0
11  */

12 public class WfResourceCORBA extends _WfResourceImplBase {
13    //private SharkCORBAServer myServer;
14

15    org.enhydra.shark.api.client.wfmodel.WfResource sharkRes;
16    private Collective __collective;
17
18    /**
19     * Creates a new WfResource
20     *
21     * @param sharkRes a WfResource
22     */

23    protected WfResourceCORBA(Collective toJoin,
24                              org.enhydra.shark.api.client.wfmodel.WfResource sharkRes) {
25       __collective = toJoin;
26       toJoin.__recruit(this);
27       this.sharkRes = sharkRes;
28    }
29
30    /**
31     * Gets the number of work items currently assigned to this resource.
32     */

33    public int how_many_work_item() throws BaseException {
34       try {
35          return sharkRes.how_many_work_item();
36       } catch (Exception JavaDoc ex) {
37          throw new BaseException();
38       }
39    }
40
41    /**
42     * Gets an iterator of work items.
43     */

44    public WfAssignmentIterator get_iterator_work_item() throws BaseException {
45       try {
46          return new WfAssignmentIteratorCORBA(__collective,
47                                               sharkRes.get_iterator_work_item());
48       } catch (Exception JavaDoc ex) {
49          throw new BaseException();
50       }
51    }
52
53    /**
54     * Gets the work items.
55     *
56     * @return List of WfAssignment objects.
57     */

58    public WfAssignment[] get_sequence_work_item(int max_number) throws BaseException {
59       try {
60          return SharkCORBAUtilities.makeCORBAAssignments(__collective,
61                                                          sharkRes.get_sequence_work_item(max_number));
62       } catch (Exception JavaDoc ex) {
63          throw new BaseException();
64       }
65    }
66
67    /**
68     * Checks if an assignment object is associated with this resource
69     *
70     * @return true if assignment is part of the work list for this
71     * resource.
72     */

73    public boolean is_member_of_work_items(WfAssignment member) throws BaseException {
74       try {
75          WfAssignment[] ass = get_sequence_work_item(0);
76          boolean ret = false;
77          if (ass != null) {
78             for (int i = 0; i < ass.length; i++) {
79                WfAssignment as = ass[i];
80                if (as.equals(member)) {
81                   ret = true;
82                   break;
83                }
84             }
85          }
86          return ret;
87       } catch (Exception JavaDoc ex) {
88          throw new BaseException();
89       }
90    }
91
92    /**
93     * Gets the resource username.
94     */

95    public String JavaDoc resource_key() throws BaseException {
96       try {
97          return sharkRes.resource_key();
98       } catch (Exception JavaDoc ex) {
99          throw new BaseException();
100       }
101    }
102
103    /**
104     * Gets the resource name.
105     */

106    public String JavaDoc resource_name() throws BaseException {
107       try {
108          return sharkRes.resource_name();
109       } catch (Exception JavaDoc ex) {
110          throw new BaseException();
111       }
112    }
113
114    /**
115     * Release the resouce from the assignment.
116     */

117    public void release(WfAssignment from_assigment, String JavaDoc release_info) throws BaseException,
118                                                                         NotAssigned {
119       try {
120          sharkRes.release(null, release_info);
121       } catch (org.enhydra.shark.api.client.wfmodel.NotAssigned na) {
122          throw new NotAssigned();
123       } catch (Exception JavaDoc ex) {
124          throw new BaseException();
125       }
126    }
127
128    /**
129     * It is assumed that there can't be two or more resources having the
130     * same resource key.
131     */

132    public boolean equals(Object JavaDoc obj) {
133       if (!(obj instanceof WfResource)) return false;
134       WfResource res = (WfResource) obj;
135       try {
136          return res.resource_key().equals(resource_key());
137       } catch (Exception JavaDoc ex) {
138          return false;
139       }
140    }
141
142    public String JavaDoc toString() {
143       return sharkRes.toString();
144    }
145
146 }
Popular Tags