KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > def > Receiver


1 package org.jbpm.bpel.service.def;
2
3 import java.io.Serializable JavaDoc;
4
5 import javax.wsdl.Operation;
6 import javax.wsdl.OperationType;
7
8 import org.w3c.dom.Element JavaDoc;
9
10 import org.jbpm.graph.exe.Token;
11
12 import org.jbpm.bpel.data.def.VariableDefinition;
13 import org.jbpm.bpel.data.exe.MessageVariableInstance;
14 import org.jbpm.bpel.def.Activity;
15 import org.jbpm.bpel.messager.MessagerSession;
16 import org.jbpm.bpel.service.exe.NonStartListener;
17 import org.jbpm.bpel.service.exe.OutstandingRequest;
18 import org.jbpm.bpel.service.exe.RequestListener;
19
20 /**
21  * @author Alejandro Guízar
22  * @version $Revision: 1.8 $ $Date: 2005/05/13 20:07:06 $
23  */

24 public class Receiver implements Serializable JavaDoc {
25   
26   private long id;
27   private PartnerLinkDefinition partnerLink;
28   private Operation operation;
29   private VariableDefinition variable;
30   private String JavaDoc messageExchange;
31   private Correlations correlations;
32
33   private Activity inboundMessageActivity;
34   
35   private static final long serialVersionUID = 1L;
36   
37   public Receiver() {
38   }
39   
40   public Receiver(Activity inboundMessageActivity) {
41     setInboundMessageActivity(inboundMessageActivity);
42   }
43   
44   public PartnerLinkDefinition getPartnerLink() {
45     return partnerLink;
46   }
47   
48   public void setPartnerLink(PartnerLinkDefinition partnerLink) {
49     this.partnerLink = partnerLink;
50   }
51   
52   public Operation getOperation() {
53     return operation;
54   }
55   
56   public void setOperation(Operation operation) {
57     this.operation = operation;
58   }
59   
60   public String JavaDoc getMessageExchange() {
61     return messageExchange;
62   }
63   
64   public void setMessageExchange(String JavaDoc messageExchange) {
65     this.messageExchange = messageExchange;
66   }
67   
68   public VariableDefinition getVariable() {
69     return variable;
70   }
71   
72   public void setVariable(VariableDefinition variable) {
73     this.variable = variable;
74   }
75   
76   public Correlations getCorrelations() {
77     return correlations;
78   }
79   
80   public void setCorrelations(Correlations correlations) {
81     this.correlations = correlations;
82   }
83   
84   public Activity getInboundMessageActivity() {
85     return inboundMessageActivity;
86   }
87   
88   public void setInboundMessageActivity(Activity activity) {
89     if (!(activity instanceof InboundMessageActivity))
90       throw new ClassCastException JavaDoc("the activity must implement " + InboundMessageActivity.class.getName());
91     inboundMessageActivity = activity;
92   }
93   
94   public void receive(Token token) {
95     RequestListener reqListener = NonStartListener.create(this, token);
96     reqListener.receiveRequest(MessagerSession.getCurrentSession());
97   }
98   
99   public void close(Token token) {
100     //TODO delete instance?
101
RequestListener listener = NonStartListener.get(this, token);
102     if (listener != null) listener.close();
103   }
104   
105   public void registerRequest(OutstandingRequest request, Token token) {
106     // register an outstanding request, if the operation expects a response
107
if (operation.getStyle().equals(OperationType.ONE_WAY))
108       throw new IllegalStateException JavaDoc("cannot register an outstanding request for one-way operation");
109     request.setReceiver(this);
110     partnerLink.getInstance(token).registerRequest(request);
111   }
112   
113   public void readMessage(Element JavaDoc messageElement, Token token) {
114     // save the received element
115
MessageVariableInstance messageInstance = (MessageVariableInstance) variable.getInstance(token);
116     messageInstance.setMessage(messageElement);
117     // ensure the correlation constraint
118
if (correlations != null)
119       correlations.ensureConstraint(messageInstance, token);
120   }
121
122   public long getId() {
123     return id;
124   }
125
126   public void setId(long id) {
127     this.id = id;
128   }
129 }
130
Popular Tags