KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > service > exe > NonStartListener


1 package org.jbpm.bpel.service.exe;
2
3 import java.util.Map JavaDoc;
4
5 import javax.jms.Destination JavaDoc;
6 import javax.jms.JMSException JavaDoc;
7 import javax.jms.ObjectMessage JavaDoc;
8
9 import org.w3c.dom.Element JavaDoc;
10
11 import org.jbpm.context.exe.ContextInstance;
12 import org.jbpm.graph.exe.Token;
13
14 import org.jbpm.bpel.service.def.Receiver;
15 import org.jbpm.bpel.service.def.InboundMessageActivity;
16
17 /**
18  * @author Alejandro Guízar
19  * @version $Revision: 1.2 $ $Date: 2005/05/13 20:07:06 $
20  */

21 public class NonStartListener extends RequestListener {
22   
23   private Token token;
24   
25   public static final String JavaDoc RECEIVER_NAME = "_$receiver_";
26   
27   NonStartListener() {
28   }
29   
30   NonStartListener(Receiver receiver, Token token) {
31     super(receiver);
32     this.token = token;
33   }
34   
35   public Token getToken() {
36     return token;
37   }
38   
39   public void setToken(Token token) {
40     this.token = token;
41   }
42   
43   public void deliverRequest(ObjectMessage JavaDoc request) throws JMSException JavaDoc {
44     // register outstanding request
45
Receiver receiver = getReceiver();
46     Destination JavaDoc replyTo = request.getJMSReplyTo();
47     if (replyTo != null) {
48       receiver.registerRequest(new OutstandingRequest(replyTo, request.getJMSMessageID()), token);
49     }
50     // get message contents
51
Element JavaDoc messageElem = (Element JavaDoc) request.getObject();
52     // the session is transacted: no need to acknowledge the message explicitly
53
/* request.acknowledge(); */
54     // pass message content to the activity
55
InboundMessageActivity activity = (InboundMessageActivity) receiver.getInboundMessageActivity();
56     activity.messageReceived(receiver, messageElem, token);
57   }
58   
59   protected Map JavaDoc getReceptionProperties() {
60     return getReceiver().getCorrelations().getReceptionProperties(token);
61   }
62   
63   public static NonStartListener create(Receiver receiver, Token token) {
64     NonStartListener instance = new NonStartListener(receiver, token);
65     ContextInstance context = token.getProcessInstance().getContextInstance();
66     context.createVariable(RECEIVER_NAME + receiver.getId(), instance, token);
67     return instance;
68   }
69   
70   public static NonStartListener get(Receiver receiver, Token token) {
71     ContextInstance context = token.getProcessInstance().getContextInstance();
72     NonStartListener instance = ((NonStartListener) context.getVariable(RECEIVER_NAME + receiver.getId(), token));
73     return instance;
74   }
75 }
76
Popular Tags