KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.corba.poa;
2
3 import org.omg.WfBase.*;
4 import org.omg.WorkflowModel.*;
5 import org.omg.CORBA.ORB JavaDoc;
6 import org.omg.PortableServer.POA JavaDoc;
7 import org.omg.PortableServer.POAHelper JavaDoc;
8 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
9 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
10 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
11 import org.enhydra.shark.corba.poa.Collective;
12 import org.enhydra.shark.corba.poa.SharkCORBAUtilities;
13 import org.enhydra.shark.corba.poa.WfAssignmentIteratorCORBA;
14
15 /**
16  * WfResourceImpl - Workflow Resource Object implementation.
17  *
18  * @author David Forslund
19  * @version 1.0
20  */

21 public class WfResourceCORBA extends WfResourcePOA {
22     //private SharkCORBAServer myServer;
23

24     org.enhydra.shark.api.client.wfmodel.WfResource sharkRes;
25     private Collective __collective;
26     private ORB JavaDoc orb;
27
28     /**
29      * Creates a new WfResource
30      *
31      * @param orb
32      * @param sharkRes a WfResource
33      */

34     protected WfResourceCORBA(ORB JavaDoc orb, Collective toJoin,
35                               org.enhydra.shark.api.client.wfmodel.WfResource sharkRes) {
36         __collective = toJoin;
37         this.orb = orb;
38
39      // toJoin.__recruit(this);
40
this.sharkRes = sharkRes;
41     }
42
43     /**
44      * Gets the number of work items currently assigned to this resource.
45      */

46     public int how_many_work_item() throws BaseException {
47         try {
48             return sharkRes.how_many_work_item();
49         } catch (Exception JavaDoc ex) {
50             throw new BaseException();
51         }
52     }
53
54     /**
55      * Gets an iterator of work items.
56      */

57     public WfAssignmentIterator get_iterator_work_item() throws BaseException {
58         try {
59             WfAssignmentIterator wfAss = SharkCORBAUtilities.makeWfAssignmentIterator( new WfAssignmentIteratorCORBA(orb,__collective,
60                     sharkRes.get_iterator_work_item()));
61             __collective.__recruit(wfAss);
62             return wfAss;
63
64         } catch (Exception JavaDoc ex) {
65             throw new BaseException();
66         }
67
68     }
69
70     /**
71      * Gets the work items.
72      *
73      * @return List of WfAssignment objects.
74      */

75     public WfAssignment[] get_sequence_work_item(int max_number) throws BaseException {
76         try {
77             return SharkCORBAUtilities.makeCORBAAssignments( __collective,
78                     sharkRes.get_sequence_work_item(max_number));
79         } catch (Exception JavaDoc ex) {
80             throw new BaseException();
81         }
82     }
83
84     /**
85      * Checks if an assignment object is associated with this resource
86      *
87      * @return true if assignment is part of the work list for this
88      * resource.
89      */

90     public boolean is_member_of_work_items(WfAssignment member) throws BaseException {
91         try {
92             WfAssignment[] ass = get_sequence_work_item(0);
93             boolean ret = false;
94             if (ass != null) {
95                 for (int i = 0; i < ass.length; i++) {
96                     WfAssignment as = ass[i];
97                     if (as.equals(member)) {
98                         ret = true;
99                         break;
100                     }
101                 }
102             }
103             return ret;
104         } catch (Exception JavaDoc ex) {
105             throw new BaseException();
106         }
107     }
108
109     /**
110      * Gets the resource username.
111      */

112     public String JavaDoc resource_key() throws BaseException {
113         try {
114             return sharkRes.resource_key();
115         } catch (Exception JavaDoc ex) {
116             throw new BaseException();
117         }
118     }
119
120     /**
121      * Gets the resource name.
122      */

123     public String JavaDoc resource_name() throws BaseException {
124         try {
125             return sharkRes.resource_name();
126         } catch (Exception JavaDoc ex) {
127             throw new BaseException();
128         }
129     }
130
131     /**
132      * Release the resouce from the assignment.
133      */

134     public void release(WfAssignment from_assigment, String JavaDoc release_info) throws BaseException,
135             NotAssigned {
136         try {
137             sharkRes.release(null, release_info);
138         } catch (org.enhydra.shark.api.client.wfmodel.NotAssigned na) {
139             throw new NotAssigned();
140         } catch (Exception JavaDoc ex) {
141             throw new BaseException();
142         }
143     }
144
145     /**
146      * It is assumed that there can't be two or more resources having the
147      * same resource key.
148      */

149     public boolean equals(Object JavaDoc obj) {
150         if (!(obj instanceof WfResource)) return false;
151         WfResource res = (WfResource) obj;
152         try {
153             return res.resource_key().equals(resource_key());
154         } catch (Exception JavaDoc ex) {
155             return false;
156         }
157     }
158
159     public String JavaDoc toString() {
160         return sharkRes.toString();
161     }
162
163 }
Popular Tags