001: /* SharkConnectionSSBean.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.wfmc.wapi.WMConnectInfo;
015: import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
016: import org.enhydra.shark.api.client.wfmodel.WfActivity;
017: import org.enhydra.shark.api.client.wfmodel.WfActivityIterator;
018: import org.enhydra.shark.api.client.wfmodel.WfAssignment;
019: import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator;
020: import org.enhydra.shark.api.client.wfmodel.WfProcess;
021: import org.enhydra.shark.api.client.wfmodel.WfProcessIterator;
022: import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
023: import org.enhydra.shark.api.client.wfmodel.WfResource;
024: import org.enhydra.shark.api.client.wfservice.SharkConnection;
025: import org.enhydra.shark.api.client.wfservice.WfProcessMgrIterator;
026: import org.enhydra.shark.api.client.wfservice.WfResourceIterator;
027:
028: /**
029: * @ejb.bean
030: * name="SharkConnectionSS"
031: * type="Stateful"
032: * display-name="SharkConnection"
033: * jndi-name="org/enhydra/shark/ejb/SharkConnectionSS"
034: * local-jndi-name="org/enhydra/shark/ejb/SharkConnectionSSLocal"
035: * transaction-type="Container"
036: * view-type="both"
037: * local-business-interface="org.enhydra.shark.api.client.wfservice.SharkConnection"
038: *
039: * @ejb.ejb-ref ejb-name="WfResourceSS"
040: * view-type="both"
041: * ref-name="org/enhydra/shark/ejb/WfResourceSS"
042: * @ejb.ejb-ref ejb-name="WfProcessMgrIteratorSS"
043: * view-type="both"
044: * ref-name="org/enhydra/shark/ejb/WfProcessMgrIteratorSS"
045: * @ejb.ejb-ref ejb-name="WfProcessMgrSS"
046: * view-type="both"
047: * ref-name="org/enhydra/shark/ejb/WfProcessMgrSS"
048: * @ejb.ejb-ref ejb-name="WfResourceIteratorSS"
049: * view-type="both"
050: * ref-name="org/enhydra/shark/ejb/WfResourceIteratorSS"
051: * @ejb.ejb-ref ejb-name="WfProcessSS"
052: * view-type="both"
053: * ref-name="org/enhydra/shark/ejb/WfProcessSS"
054: * @ejb.ejb-ref ejb-name="WfActivitySS"
055: * view-type="both"
056: * ref-name="org/enhydra/shark/ejb/WfActivitySS"
057: * @ejb.ejb-ref ejb-name="WfAssignmentSS"
058: * view-type="both"
059: * ref-name="org/enhydra/shark/ejb/WfAssignmentSS"
060: * @ejb.ejb-ref ejb-name="WfProcessIteratorSS"
061: * view-type="both"
062: * ref-name="org/enhydra/shark/ejb/WfProcessIteratorSS"
063: * @ejb.ejb-ref ejb-name="WfActivityIteratorSS"
064: * view-type="both"
065: * ref-name="org/enhydra/shark/ejb/WfActivityIteratorSS"
066: * @ejb.ejb-ref ejb-name="WfAssignmentIteratorSS"
067: * view-type="both"
068: * ref-name="org/enhydra/shark/ejb/WfAssignmentIteratorSS"
069: *
070: *
071: * @ejb:interface
072: * extends="org.enhydra.shark.api.client.wfservice.SharkConnection,javax.ejb.EJBObject"
073: *
074: * @ejb:transaction
075: * type="Required"
076: *
077: * @jonas:bean
078: * ejb-name="SharkConnectionSS"
079: * jndi-name="org/enhydra/shark/ejb/SharkConnectionSS"
080: *
081: * Interface used to perform some administrative operations that concern execution engine
082: * objects.
083: * <p>
084: * The first method to be called by client application is the first method of this
085: * interface - connect(), and only if user authentication is OK, other methods can be used
086: * (otherwise, every method throws NotConnected exception).
087: *
088: * @author V.Puskas
089: * @author S.Bojanic
090: * @author T.Jovanovic
091: * @version 0.1
092: */
093: public abstract class SharkConnectionSSBean implements SharkConnection,
094: SessionBean { // impl is serializable
095:
096: private SessionContext context;
097: private org.enhydra.shark.api.client.wfservice.SharkConnection sharkObj;
098:
099: /**
100: * @ejb:interface-method
101: * view-type="both"
102: * This is the first method to be called in order to communicate with the engine. If
103: * the login parameters are correct, user can use other methods of this interface to
104: * communicate with the shark engine, and if not, he can't do anything.
105: *
106: * @param connectInfo structure holding connection request data
107: * @throws Exception If something unexpected happens.
108: */
109: public void connect(WMConnectInfo connectInfo) throws Exception {
110: sharkObj.connect(connectInfo);
111: }
112:
113: /**
114: * @ejb:interface-method
115: * view-type="both"
116: */
117: public void attachToHandle(WMSessionHandle shandle)
118: throws Exception {
119: sharkObj.attachToHandle(shandle);
120: }
121:
122: /**
123: * @ejb.interface-method
124: * view-type="both"
125: * Disconnects from shark engine.
126: *
127: * @throws Exception If something unexpected happens.
128: */
129: public void disconnect() throws Exception {
130: sharkObj.disconnect();
131: }
132:
133: /**
134: * @ejb:interface-method
135: * view-type="both"
136: */
137: public WMSessionHandle getSessionHandle() throws Exception {
138: return sharkObj.getSessionHandle();
139: }
140:
141: /**
142: * @ejb.interface-method
143: * view-type="both"
144: * Returns WfResource object belonging to the user that has been connected to shark
145: * through this interface. This will be the WfResource object that has the same
146: * username attribute as the one used in connect() method. After getting this object,
147: * client application can present user a list of its assignments that can be retrieved
148: * throug this WfResource object.
149: *
150: * @return WfResource object belonging to the user.
151: * @throws Exception If something unexpected happens.
152: */
153: public WfResource getResourceObject() throws Exception {
154: WfResource wfshark = sharkObj.getResourceObject();
155: WfResourceSS wf = null;
156: try {
157: Context initialContext = EJBJNDIContext.getInstance()
158: .getInitialContext();
159: wf = ((org.enhydra.shark.ejb.WfResourceSSHome) PortableRemoteObject
160: .narrow(
161: initialContext
162: .lookup("org/enhydra/shark/ejb/WfResourceSS"),
163: org.enhydra.shark.ejb.WfResourceSSHome.class))
164: .create(wfshark);
165: return (WfResourceSS) wf.getPassedEJBObject();
166: } catch (Exception ex) {
167: throw new EJBException(ex);
168: }
169: }
170:
171: /**
172: * @ejb.interface-method
173: * view-type="both"
174: * Returns an iterator that can be used to retrieve WfProcessMgr objects that represent
175: * appropriate XPDL process definitions, and are used to create new process instances.
176: *
177: * @return WfProcessMgrIterator for retrieving WfProcessMgr objects.
178: * @throws Exception If something unexpected happens.
179: */
180: public WfProcessMgrIterator get_iterator_processmgr()
181: throws Exception {
182: WfProcessMgrIterator wfshark = sharkObj
183: .get_iterator_processmgr();
184: WfProcessMgrIteratorSS wf = null;
185: try {
186: Context initialContext = EJBJNDIContext.getInstance()
187: .getInitialContext();
188: wf = ((org.enhydra.shark.ejb.WfProcessMgrIteratorSSHome) PortableRemoteObject
189: .narrow(
190: initialContext
191: .lookup("org/enhydra/shark/ejb/WfProcessMgrIteratorSS"),
192: org.enhydra.shark.ejb.WfProcessMgrIteratorSSHome.class))
193: .create(wfshark);
194: return (WfProcessMgrIteratorSS) wf.getPassedEJBObject();
195: } catch (Exception ex) {
196: throw new EJBException(ex);
197: }
198: }
199:
200: /**
201: * @ejb.interface-method
202: * view-type="both"
203: * Returns an array of WfProcessMgr objects.
204: *
205: * @param max_number The maximum number of WfProcessMgr instances to be returned. If
206: * set to 0, all existing instances will be returned (this will be equal to
207: * the number of XPDL process definitions in all packages that are loaded
208: * into engine).
209: * @return Array of specified WfProcessMgr objects.
210: * @throws Exception If something unexpected happens.
211: */
212: public WfProcessMgr[] get_sequence_processmgr(int max_number)
213: throws Exception {
214: WfProcessMgr[] wfsshark = sharkObj
215: .get_sequence_processmgr(max_number);
216: WfProcessMgrSSHome home = null;
217: InitialContext initialContext = EJBJNDIContext.getInstance()
218: .getInitialContext();
219: home = (WfProcessMgrSSHome) PortableRemoteObject
220: .narrow(
221: initialContext
222: .lookup("org/enhydra/shark/ejb/WfProcessMgrSS"),
223: org.enhydra.shark.ejb.WfProcessMgrSSHome.class);
224: int len = wfsshark.length;
225: WfProcessMgrSS[] remotes = new WfProcessMgrSS[len];
226: for (int i = 0; i < len; i++) {
227: remotes[i] = (WfProcessMgrSS) (home.create(wfsshark[i]))
228: .getPassedEJBObject();
229: }
230: return remotes;
231: }
232:
233: /**
234: * @ejb.interface-method
235: * view-type="both"
236: * Returns an iterator that can be used to retrieve WfResource objects that represent
237: * appropriate shark users.
238: *
239: * @return WfResourceIterator for retrieving WfResource objects. that represent
240: * appropriate shark users.
241: * @throws Exception If something unexpected happens.
242: */
243: public WfResourceIterator get_iterator_resource() throws Exception {
244: WfResourceIterator wfshark = sharkObj.get_iterator_resource();
245: WfResourceIteratorSS wf = null;
246: try {
247: Context initialContext = EJBJNDIContext.getInstance()
248: .getInitialContext();
249: wf = ((org.enhydra.shark.ejb.WfResourceIteratorSSHome) PortableRemoteObject
250: .narrow(
251: initialContext
252: .lookup("org/enhydra/shark/ejb/WfResourceIteratorSS"),
253: org.enhydra.shark.ejb.WfResourceIteratorSSHome.class))
254: .create(wfshark);
255: return (WfResourceIteratorSS) wf.getPassedEJBObject();
256: } catch (Exception ex) {
257: throw new EJBException(ex);
258: }
259: }
260:
261: /**
262: * @ejb.interface-method
263: * view-type="both"
264: * Returns an array of WfResource objects.
265: *
266: * @param max_number The maximum number of WfResource instances to be returned. If set
267: * to 0, all existing instances will be returned.
268: * @return Specified array of WfResource objects.
269: * @throws Exception If something unexpected happens.
270: */
271: public WfResource[] get_sequence_resource(int max_number)
272: throws Exception {
273: WfResource[] wfsshark = sharkObj
274: .get_sequence_resource(max_number);
275: WfResourceSSHome home = null;
276: InitialContext initialContext = EJBJNDIContext.getInstance()
277: .getInitialContext();
278: home = (WfResourceSSHome) PortableRemoteObject.narrow(
279: initialContext
280: .lookup("org/enhydra/shark/ejb/WfResourceSS"),
281: org.enhydra.shark.ejb.WfResourceSSHome.class);
282: int len = wfsshark.length;
283: WfResourceSS[] remotes = new WfResourceSS[len];
284: for (int i = 0; i < len; i++) {
285: remotes[i] = (WfResourceSS) (home.create(wfsshark[i]))
286: .getPassedEJBObject();
287: }
288: return remotes;
289: }
290:
291: /**
292: * @ejb.interface-method
293: * view-type="both"
294: * Returns WfProcessMgr object that has the given name, or null if such does not exist.
295: *
296: * @param name WfProcessMgr object name.
297: * @return WfProcessMgr with the given name, or null if does not exist.
298: * @throws Exception If something unexpected happens.
299: */
300: public WfProcessMgr getProcessMgr(String name) throws Exception {
301: WfProcessMgr wfshark = sharkObj.getProcessMgr(name);
302: WfProcessMgrSS wf = null;
303: try {
304: Context initialContext = EJBJNDIContext.getInstance()
305: .getInitialContext();
306: wf = ((org.enhydra.shark.ejb.WfProcessMgrSSHome) PortableRemoteObject
307: .narrow(
308: initialContext
309: .lookup("org/enhydra/shark/ejb/WfProcessMgrSS"),
310: org.enhydra.shark.ejb.WfProcessMgrSSHome.class))
311: .create(wfshark);
312: return (WfProcessMgrSS) wf.getPassedEJBObject();
313: } catch (Exception ex) {
314: throw new EJBException(ex);
315: }
316: }
317:
318: /**
319: * @ejb.interface-method
320: * view-type="both"
321: * Returns WfResource object that has the given username, or null if such doesn't
322: * exist.
323: *
324: * @param username username of WfResource instance.
325: * @return WfResource with the given name, or null if does not exist.
326: * @throws Exception If something unexpected happens.
327: */
328: public WfResource getResource(String username) throws Exception {
329: WfResource wfshark = sharkObj.getResource(username);
330: WfResourceSS wf = null;
331: try {
332: Context initialContext = EJBJNDIContext.getInstance()
333: .getInitialContext();
334: wf = ((org.enhydra.shark.ejb.WfResourceSSHome) PortableRemoteObject
335: .narrow(
336: initialContext
337: .lookup("org/enhydra/shark/ejb/WfResourceSS"),
338: org.enhydra.shark.ejb.WfResourceSSHome.class))
339: .create(wfshark);
340: return (WfResourceSS) wf.getPassedEJBObject();
341: } catch (Exception ex) {
342: throw new EJBException(ex);
343: }
344: }
345:
346: /**
347: * @ejb.interface-method
348: * view-type="both"
349: * Returns WfProcess object that has the given Id, or null if such does not exist.
350: *
351: * @param procId process instance Id.
352: * @return WfProcess with the given name, or null if does not exist.
353: * @throws Exception If something unexpected happens.
354: */
355: public WfProcess getProcess(String procId) throws Exception {
356: WfProcess wfshark = sharkObj.getProcess(procId);
357: WfProcessSS wf = null;
358: try {
359: Context initialContext = EJBJNDIContext.getInstance()
360: .getInitialContext();
361: wf = ((org.enhydra.shark.ejb.WfProcessSSHome) PortableRemoteObject
362: .narrow(
363: initialContext
364: .lookup("org/enhydra/shark/ejb/WfProcessSS"),
365: org.enhydra.shark.ejb.WfProcessSSHome.class))
366: .create(wfshark);
367: return (WfProcessSS) wf.getPassedEJBObject();
368: } catch (Exception ex) {
369: throw new EJBException(ex);
370: }
371: }
372:
373: /**
374: * @ejb.interface-method
375: * view-type="both"
376: * Returns WfActivity object that has the given Id, or null if such doesn't exist.
377: *
378: * @param procId activity's process Id.
379: * @param actId activity instance Id.
380: * @return WfActivity with the given Id, or null if does not exist.
381: * @throws Exception If something unexpected happens.
382: */
383: public WfActivity getActivity(String procId, String actId)
384: throws Exception {
385: WfActivity wfshark = sharkObj.getActivity(procId, actId);
386: WfActivitySS wf = null;
387: try {
388: Context initialContext = EJBJNDIContext.getInstance()
389: .getInitialContext();
390: wf = ((org.enhydra.shark.ejb.WfActivitySSHome) PortableRemoteObject
391: .narrow(
392: initialContext
393: .lookup("org/enhydra/shark/ejb/WfActivitySS"),
394: org.enhydra.shark.ejb.WfActivitySSHome.class))
395: .create(wfshark);
396: return (WfActivitySS) wf.getPassedEJBObject();
397: } catch (Exception ex) {
398: throw new EJBException(ex);
399: }
400: }
401:
402: /**
403: * @ejb.interface-method
404: * view-type="both"
405: * Returns WfAssignment object for activity with given Id, and resource with the given
406: * username, or null if such doesn't exist.
407: *
408: * @param procId the assignment's activity's process instance Id.
409: * @param actId the assignment's activity instance Id.
410: * @param username the assignement's username
411: * @return Specified WfAssignment , or null if does not exist.
412: * @throws Exception If something unexpected happens.
413: */
414: public WfAssignment getAssignment(String procId, String actId,
415: String username) throws Exception {
416: WfAssignment wfshark = sharkObj.getAssignment(procId, actId,
417: username);
418: WfAssignmentSS wf = null;
419: try {
420: Context initialContext = EJBJNDIContext.getInstance()
421: .getInitialContext();
422: wf = ((org.enhydra.shark.ejb.WfAssignmentSSHome) PortableRemoteObject
423: .narrow(
424: initialContext
425: .lookup("org/enhydra/shark/ejb/WfAssignmentSS"),
426: org.enhydra.shark.ejb.WfAssignmentSSHome.class))
427: .create(wfshark);
428: return (WfAssignmentSS) wf.getPassedEJBObject();
429: } catch (Exception ex) {
430: throw new EJBException(ex);
431: }
432: }
433:
434: /**
435: * @ejb.interface-method
436: * view-type="both"
437: * Returns WfAssignment object for given Id, or null if such doesn't exist. NOTE: this
438: * method is here only because of standardization (having one method with transaction,
439: * and other without), and is not supposed to be used in normal situations - tool
440: * agents can call the same method but with additional transaction parameter, and user
441: * applications should call the same method but with actId and username parameters
442: * instead of assId parameter.
443: *
444: * @param procId the assignment's activity's process instance Id.
445: * @param assId the assignment Id.
446: * @return Specified WfAssignment , or null if does not exist.
447: * @throws Exception If something unexpected happens.
448: */
449: public WfAssignment getAssignment(String procId, String assId)
450: throws Exception {
451: WfAssignment wfshark = sharkObj.getAssignment(procId, assId);
452: WfAssignmentSS wf = null;
453: try {
454: Context initialContext = EJBJNDIContext.getInstance()
455: .getInitialContext();
456: wf = ((org.enhydra.shark.ejb.WfAssignmentSSHome) PortableRemoteObject
457: .narrow(
458: initialContext
459: .lookup("org/enhydra/shark/ejb/WfAssignmentSS"),
460: org.enhydra.shark.ejb.WfAssignmentSSHome.class))
461: .create(wfshark);
462: return (WfAssignmentSS) wf.getPassedEJBObject();
463: } catch (Exception ex) {
464: throw new EJBException(ex);
465: }
466: }
467:
468: /**
469: * @ejb.interface-method
470: * view-type="both"
471: * @return unbound assignment iterator
472: * @throws Exception
473: */
474: public WfAssignmentIterator get_iterator_assignment()
475: throws Exception {
476: WfAssignmentIterator wfshark = sharkObj
477: .get_iterator_assignment();
478: WfAssignmentIteratorSS wf = null;
479: try {
480: Context initialContext = EJBJNDIContext.getInstance()
481: .getInitialContext();
482: wf = ((org.enhydra.shark.ejb.WfAssignmentIteratorSSHome) PortableRemoteObject
483: .narrow(
484: initialContext
485: .lookup("org/enhydra/shark/ejb/WfAssignmentIteratorSS"),
486: org.enhydra.shark.ejb.WfAssignmentIteratorSSHome.class))
487: .create(wfshark);
488: return (WfAssignmentIteratorSS) wf.getPassedEJBObject();
489: } catch (Exception ex) {
490: throw new EJBException(ex);
491: }
492: }
493:
494: /**
495: * @ejb.interface-method
496: * view-type="both"
497: * @return unbound process iterator
498: * @throws Exception
499: */
500: public WfProcessIterator get_iterator_process() throws Exception {
501: WfProcessIterator wfshark = sharkObj.get_iterator_process();
502: WfProcessIteratorSS wf = null;
503: try {
504: Context initialContext = EJBJNDIContext.getInstance()
505: .getInitialContext();
506: wf = ((org.enhydra.shark.ejb.WfProcessIteratorSSHome) PortableRemoteObject
507: .narrow(
508: initialContext
509: .lookup("org/enhydra/shark/ejb/WfProcessIteratorSS"),
510: org.enhydra.shark.ejb.WfProcessIteratorSSHome.class))
511: .create(wfshark);
512: return (WfProcessIteratorSS) wf.getPassedEJBObject();
513: } catch (Exception ex) {
514: throw new EJBException(ex);
515: }
516: }
517:
518: /**
519: * @ejb.interface-method
520: * view-type="both"
521: * @return unbound activity iterator
522: * @throws Exception
523: */
524: public WfActivityIterator get_iterator_activity() throws Exception {
525: WfActivityIterator wfshark = sharkObj.get_iterator_activity();
526: WfActivityIteratorSS wf = null;
527: try {
528: Context initialContext = EJBJNDIContext.getInstance()
529: .getInitialContext();
530: wf = ((org.enhydra.shark.ejb.WfActivityIteratorSSHome) PortableRemoteObject
531: .narrow(
532: initialContext
533: .lookup("org/enhydra/shark/ejb/WfActivityIteratorSS"),
534: org.enhydra.shark.ejb.WfActivityIteratorSSHome.class))
535: .create(wfshark);
536: return (WfActivityIteratorSS) wf.getPassedEJBObject();
537: } catch (Exception ex) {
538: throw new EJBException(ex);
539: }
540: }
541:
542: /**
543: * @ejb.interface-method
544: * view-type="both"
545: **/
546: public EJBObject getPassedEJBObject() throws EJBException {
547: try {
548: return context.getEJBObject();
549: } catch (Exception ex) {
550: throw new EJBException(ex);
551: }
552: }
553:
554: public void setSessionContext(SessionContext ctx)
555: throws EJBException, RemoteException {
556: context = ctx;
557: }
558:
559: /**
560: * @ejb:create-method
561: */
562: public void ejbCreate(
563: org.enhydra.shark.api.client.wfservice.SharkConnection con) {
564: sharkObj = con;
565: }
566:
567: /* (non-Javadoc)
568: * @see javax.ejb.SessionBean#ejbActivate()
569: */
570: public void ejbActivate() throws EJBException, RemoteException {
571: }
572:
573: /* (non-Javadoc)
574: * @see javax.ejb.SessionBean#ejbPassivate()
575: */
576: public void ejbPassivate() throws EJBException, RemoteException {
577: }
578:
579: /* (non-Javadoc)
580: * @see javax.ejb.SessionBean#ejbRemove()
581: */
582: public void ejbRemove() throws EJBException, RemoteException {
583: }
584: }
|