001: /* WfResourceSSBean.java */
002: package org.enhydra.shark.ejb;
003:
004: import java.rmi.RemoteException;
005:
006: import javax.ejb.EJBException;
007: import javax.ejb.EJBObject;
008: import javax.ejb.SessionBean;
009: import javax.ejb.SessionContext;
010: import javax.naming.Context;
011: import javax.naming.InitialContext;
012: import javax.rmi.PortableRemoteObject;
013:
014: import org.enhydra.shark.api.client.wfmodel.NotAssigned;
015: import org.enhydra.shark.api.client.wfmodel.WfAssignment;
016: import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator;
017: import org.enhydra.shark.api.client.wfmodel.WfResource;
018:
019: /**
020: * @ejb.bean
021: * name="WfResourceSS"
022: * type="Stateful"
023: * display-name="WfResource"
024: * jndi-name="org/enhydra/shark/ejb/WfResourceSS"
025: * local-jndi-name="org/enhydra/shark/ejb/WfResourceSSLocal"
026: * transaction-type="Container"
027: * view-type="both"
028: * local-business-interface="org.enhydra.shark.api.client.wfmodel.WfResource"
029: *
030: * @ejb.ejb-ref ejb-name="WfAssignmentIteratorSS"
031: * view-type="both"
032: * ref-name="org/enhydra/shark/ejb/WfAssignmentIteratorSS"
033: * @ejb.ejb-ref ejb-name="WfAssignmentSS"
034: * view-type="both"
035: * ref-name="org/enhydra/shark/ejb/WfAssignmentSS"
036: *
037: * @ejb:interface
038: * extends="org.enhydra.shark.api.client.wfmodel.WfResource,javax.ejb.EJBObject"
039: *
040: * @ejb:transaction
041: * type="Required"
042: *
043: * @jonas:bean
044: * ejb-name="WfResourceSS"
045: * jndi-name="org/enhydra/shark/ejb/WfResourceSS"
046: *
047: * OMG definition: WfResource is an abstraction that represents a person or thing that
048: * will potentially accept an assignment to an activity. Potential and/or accepted
049: * WfAssignments are links between the requesting WfActivities and WfResource objects. It
050: * is expected that this interface will be used to implement adapters for objects
051: * representing people and things implemented in user, organization, and resource models.
052: * These models are outside the scope of this specification.
053: * <p>
054: * We extended OMG's interface by duplicating methods, and adding additional parameter
055: * that represents transaction. If you use methods without SharkTransaction parameter, the
056: * transaction will be implicitly created, and if you use it with SharkTransaction
057: * parameter you must obey to some rules explained in HowTo documentation.
058: *
059: * @author V.Puskas
060: * @author S.Bojanic
061: * @author T.Jovanovic
062: * @version 0.1
063: */
064: public abstract class WfResourceSSBean implements WfResource,
065: SessionBean {
066:
067: private SessionContext context;
068: private org.enhydra.shark.api.client.wfmodel.WfResource sharkObj;
069:
070: /**
071: * @ejb:interface-method
072: * view-type="both"
073: * Zero or more WfAssignments are associated with a resource. The association is
074: * established when the assignment is created as part of the resource selection process
075: * for an activity; the assignment can be reassigned to another resource at a later
076: * point in time.
077: * <p>
078: * The following operation returns the number of WfAssignments associated with a
079: * resource.
080: */
081: public int how_many_work_item() throws Exception {
082: return sharkObj.how_many_work_item();
083: }
084:
085: /**
086: * @ejb:interface-method
087: * view-type="both"
088: * Zero or more WfAssignments are associated with a resource. The association is
089: * established when the assignment is created as part of the resource selection process
090: * for an activity; the assignment can be reassigned to another resource at a later
091: * point in time.
092: * <p>
093: * The following operation returns iterator for qurying associated assignments based on
094: * some criteria.
095: */
096: public WfAssignmentIterator get_iterator_work_item()
097: throws Exception {
098: WfAssignmentIterator wfshark = sharkObj
099: .get_iterator_work_item();
100: WfAssignmentIteratorSS wf = null;
101: try {
102: Context initialContext = EJBJNDIContext.getInstance()
103: .getInitialContext();
104: wf = ((org.enhydra.shark.ejb.WfAssignmentIteratorSSHome) PortableRemoteObject
105: .narrow(
106: initialContext
107: .lookup("org/enhydra/shark/ejb/WfAssignmentIteratorSS"),
108: org.enhydra.shark.ejb.WfAssignmentIteratorSSHome.class))
109: .create(wfshark);
110: return (WfAssignmentIteratorSS) wf.getPassedEJBObject();
111: } catch (Exception ex) {
112: throw new EJBException(ex);
113: }
114: }
115:
116: /**
117: * @ejb:interface-method
118: * view-type="both"
119: * Zero or more WfAssignments are associated with a resource. The association is
120: * established when the assignment is created as part of the resource selection process
121: * for an activity; the assignment can be reassigned to another resource at a later
122: * point in time.
123: * <p>
124: * The following operation returns max_number of WfAssignment objects associated with a
125: * resource. If max_number is less or eaqual to zero, or it is greater than the number
126: * of existing assignments, all associated WfAssignments objects will be returned.
127: */
128: public WfAssignment[] get_sequence_work_item(int max_number)
129: throws Exception {
130: WfAssignment[] wfsshark = sharkObj
131: .get_sequence_work_item(max_number);
132: WfAssignmentSSHome home = null;
133: InitialContext initialContext = EJBJNDIContext.getInstance()
134: .getInitialContext();
135: home = (WfAssignmentSSHome) PortableRemoteObject
136: .narrow(
137: initialContext
138: .lookup("org/enhydra/shark/ejb/WfAssignmentSS"),
139: org.enhydra.shark.ejb.WfAssignmentSSHome.class);
140: int len = wfsshark.length;
141: WfAssignmentSS[] remotes = new WfAssignmentSS[len];
142: for (int i = 0; i < len; i++) {
143: remotes[i] = (WfAssignmentSS) (home.create(wfsshark[i]))
144: .getPassedEJBObject();
145: }
146: return remotes;
147: }
148:
149: /**
150: * @ejb:interface-method
151: * view-type="both"
152: * Zero or more WfAssignments are associated with a resource. The association is
153: * established when the assignment is created as part of the resource selection process
154: * for an activity; the assignment can be reassigned to another resource at a later
155: * point in time.
156: * <p>
157: * The following operation returns true if given assignment is associated with
158: * resource.
159: */
160: public boolean is_member_of_work_items(WfAssignment member)
161: throws Exception {
162: try {
163: WfAssignment[] ass = get_sequence_work_item(0);
164: boolean ret = false;
165: if (ass != null) {
166: for (int i = 0; i < ass.length; i++) {
167: WfAssignment as = ass[i];
168: if (as.equals(member)) {
169: ret = true;
170: break;
171: }
172: }
173: }
174: return ret;
175: } catch (Exception ex) {
176: throw new EJBException(ex);
177: }
178: }
179:
180: /**
181: * @ejb:interface-method
182: * view-type="both"
183: * Returns the resource key that identifies a resource within a given business domain.
184: * It is assumed that resources are defined in the same business domain as the workflow
185: * processes they are associated with.
186: * <p>
187: * The key is set when the object is initialized; modification of the key can be done
188: * in the context of a resource management facility.
189: */
190: public String resource_key() throws Exception {
191: return sharkObj.resource_key();
192: }
193:
194: /**
195: * @ejb:interface-method
196: * view-type="both"
197: * Returns a human readable, descriptive name of the resource.
198: */
199: public String resource_name() throws Exception {
200: return sharkObj.resource_name();
201: }
202:
203: /**
204: * @ejb:interface-method
205: * view-type="both"
206: * The release operation is used to signal that the resource is no longer needed for a
207: * specific assignment. It takes the assignment that is no longer associated with the
208: * resource and a string that specifies additional information on the reason for
209: * realizing the resource as input. A NotAssigned exception is raised when the
210: * WfAssignment specified as input is not assigned to the WfResource. It is assumed
211: * that this operation is invoked when an assignment is deleted or when an assignment
212: * is reassigned to another resource.
213: */
214: public void release(WfAssignment from_assigment, String release_info)
215: throws Exception, NotAssigned {
216: try {
217: sharkObj.release(null, release_info); // same as CORBA
218: /*
219: WfAssignment ass =
220: SharkEJBUtilities.getExpBuilderAssignment(from_assignment.assignee().resource_key(),
221: from_assignment.activity().container().key(),
222: from_assignment.activity().key());
223: sharkRes.release(ass,release_info);
224: */
225:
226: } catch (Exception ex) {
227: throw new EJBException(ex);
228: }
229: }
230:
231: /**
232: * @ejb.interface-method
233: * view-type="both"
234: **/
235: public EJBObject getPassedEJBObject() throws EJBException {
236: try {
237: return context.getEJBObject();
238: } catch (Exception ex) {
239: throw new EJBException(ex);
240: }
241: }
242:
243: public void setSessionContext(SessionContext ctx)
244: throws EJBException, RemoteException {
245: context = ctx;
246: }
247:
248: /**
249: * @ejb:create-method
250: */
251: public void ejbCreate(
252: org.enhydra.shark.api.client.wfmodel.WfResource res) {
253: sharkObj = res;
254: }
255:
256: /* (non-Javadoc)
257: * @see javax.ejb.SessionBean#ejbActivate()
258: */
259: public void ejbActivate() throws EJBException, RemoteException {
260: }
261:
262: /* (non-Javadoc)
263: * @see javax.ejb.SessionBean#ejbPassivate()
264: */
265: public void ejbPassivate() throws EJBException, RemoteException {
266: }
267:
268: /* (non-Javadoc)
269: * @see javax.ejb.SessionBean#ejbRemove()
270: */
271: public void ejbRemove() throws EJBException, RemoteException {
272: }
273: }
|