001: /* WfAssignmentSSBean.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.rmi.PortableRemoteObject;
012:
013: import org.enhydra.shark.api.client.wfmodel.CannotAcceptSuspended;
014: import org.enhydra.shark.api.client.wfmodel.InvalidResource;
015: import org.enhydra.shark.api.client.wfmodel.WfActivity;
016: import org.enhydra.shark.api.client.wfmodel.WfAssignment;
017: import org.enhydra.shark.api.client.wfmodel.WfResource;
018:
019: /**
020: * @ejb.bean
021: * name="WfAssignmentSS"
022: * type="Stateful"
023: * display-name="WfAssignment"
024: * jndi-name="org/enhydra/shark/ejb/WfAssignmentSS"
025: * local-jndi-name="org/enhydra/shark/ejb/WfAssignmentSSLocal"
026: * transaction-type="Container"
027: * view-type="both"
028: * local-business-interface="org.enhydra.shark.api.client.wfmodel.WfAssignment"
029: *
030: * @ejb.ejb-ref ejb-name="WfActivitySS"
031: * view-type="both"
032: * ref-name="org/enhydra/shark/ejb/WfActivitySS"
033: * @ejb.ejb-ref ejb-name="WfResourceSS"
034: * view-type="both"
035: * ref-name="org/enhydra/shark/ejb/WfResourceSS"
036: *
037: * @ejb:interface
038: * extends="org.enhydra.shark.api.client.wfmodel.WfAssignment,javax.ejb.EJBObject"
039: *
040: * @ejb:transaction
041: * type="Required"
042: *
043: * @jonas:bean
044: * ejb-name="WfAssignmentSS"
045: * jndi-name="org/enhydra/shark/ejb/WfAssignmentSS"
046: *
047: * OMG definition: WfAssignment links WfActivity objects to WfResource objects. These
048: * links represent real assignments for enacting the activity. This interface may be
049: * specialized by resource management facilities that interpret the context of the
050: * activity to create and negotiate assignments with resources. Assignments are created as
051: * part of the resource selection process before an activity becomes ready for execution.
052: * The lifetime of an assignment is limited by that of the associated activity.
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: * <p>
059: * Also, we added two additional methods for accepting assignment and getting accepted
060: * status.
061: *
062: * @author V.Puskas
063: * @author S.Bojanic
064: * @author T.Jovanovic
065: * @version 0.1
066: */
067: public abstract class WfAssignmentSSBean implements WfAssignment,
068: SessionBean {
069:
070: private SessionContext context;
071: protected org.enhydra.shark.api.client.wfmodel.WfAssignment sharkObj;
072:
073: /**
074: * @ejb:interface-method
075: * view-type="both"
076: * A WfAssignment is associated with one WfActivity; the association is established
077: * when the assignment is created as part of the resource selection process for the
078: * activity. The following operation returns the associated WfActivity.
079: */
080: public WfActivity activity() throws Exception {
081: WfActivity wfshark = sharkObj.activity();
082: WfActivitySS wf = null;
083: try {
084: Context initialContext = EJBJNDIContext.getInstance()
085: .getInitialContext();
086: wf = ((org.enhydra.shark.ejb.WfActivitySSHome) PortableRemoteObject
087: .narrow(
088: initialContext
089: .lookup("org/enhydra/shark/ejb/WfActivitySS"),
090: org.enhydra.shark.ejb.WfActivitySSHome.class))
091: .create(wfshark);
092: return (WfActivitySS) wf.getPassedEJBObject();
093: } catch (Exception ex) {
094: throw new EJBException(ex);
095: }
096: }
097:
098: /**
099: * @ejb:interface-method
100: * view-type="both"
101: * A WfAssignment is associated with one WfResource. The association is established
102: * when the assignment is created as part of the resource selection process for the
103: * activity; the assignment can be reassigned to another resource at a later point in
104: * time. The following operation support the assignee relationship.
105: */
106: public WfResource assignee() throws Exception {
107: WfResource wfshark = sharkObj.assignee();
108: WfResourceSS wf = null;
109: try {
110: Context initialContext = EJBJNDIContext.getInstance()
111: .getInitialContext();
112: wf = ((org.enhydra.shark.ejb.WfResourceSSHome) PortableRemoteObject
113: .narrow(
114: initialContext
115: .lookup("org/enhydra/shark/ejb/WfResourceSS"),
116: org.enhydra.shark.ejb.WfResourceSSHome.class))
117: .create(wfshark);
118: return (WfResourceSS) wf.getPassedEJBObject();
119: } catch (Exception ex) {
120: throw new EJBException(ex);
121: }
122: }
123:
124: /**
125: * @ejb:interface-method
126: * view-type="both"
127: * A WfAssignment is associated with one WfResource. The association is established
128: * when the assignment is created as part of the resource selection process for the
129: * activity; the assignment can be reassigned to another resource at a later point in
130: * time. The following operation support changing the assignee relationship. An
131: * InvalidResource exception is raised by an attempt to assign an invalid resource to
132: * the assignment.
133: */
134: public void set_assignee(WfResource new_value) throws Exception,
135: InvalidResource {
136: try {
137: sharkObj.set_assignee(new WfResourceHelper(new_value
138: .resource_key()));
139: // WfResource res = SharkEJBUtilities.getExpBuilderResource(new_value.resource_key());
140: // sharkAss.set_assignee(res);
141: } catch (Exception ex) {
142: throw new EJBException(ex);
143: }
144: }
145:
146: // doesn't exist in original OMG spec - should we remove it???
147: /**
148: * @ejb:interface-method
149: * view-type="both"
150: * Extension to OMG interface. Marks assignment's activity to be accepted by the
151: * assignment's assignee.
152: */
153: public void set_accepted_status(boolean accept) throws Exception,
154: CannotAcceptSuspended {
155: sharkObj.set_accepted_status(accept);
156: }
157:
158: /**
159: * @ejb:interface-method
160: * view-type="both"
161: * Extension to OMG interface. Returns if assignment is accepted.
162: */
163: public boolean get_accepted_status() throws Exception {
164: return sharkObj.get_accepted_status();
165: }
166:
167: /**
168: * @ejb.interface-method
169: * view-type="both"
170: **/
171: public EJBObject getPassedEJBObject() throws EJBException {
172: try {
173: return context.getEJBObject();
174: } catch (Exception ex) {
175: throw new EJBException(ex);
176: }
177: }
178:
179: public void setSessionContext(SessionContext ctx)
180: throws EJBException, RemoteException {
181: context = ctx;
182: }
183:
184: /**
185: * @ejb:create-method
186: */
187: public void ejbCreate(
188: org.enhydra.shark.api.client.wfmodel.WfAssignment as) {
189: sharkObj = as;
190: }
191:
192: /* (non-Javadoc)
193: * @see javax.ejb.SessionBean#ejbActivate()
194: */
195: public void ejbActivate() throws EJBException, RemoteException {
196: }
197:
198: /* (non-Javadoc)
199: * @see javax.ejb.SessionBean#ejbPassivate()
200: */
201: public void ejbPassivate() throws EJBException, RemoteException {
202: }
203:
204: /* (non-Javadoc)
205: * @see javax.ejb.SessionBean#ejbRemove()
206: */
207: public void ejbRemove() throws EJBException, RemoteException {
208: }
209: }
|