KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.service.def;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import org.jbpm.graph.exe.Token;
9
10 import org.jbpm.bpel.data.exe.MessageVariableInstance;
11 import org.jbpm.bpel.service.def.Correlation.Initiate;
12 import org.jbpm.bpel.service.exe.CorrelationSetInstance;
13
14 /**
15  * Groups the correlations ocurring in the message being sent or received
16  * in an activity.
17  * @see "WS-BPEL 2.0 §10.2"
18  * @author Alejandro Guízar
19  * @version $Revision: 1.6 $ $Date: 2005/05/31 00:49:53 $
20  */

21 public class Correlations implements Serializable JavaDoc {
22
23   private static final long serialVersionUID = 1L;
24   
25   long id;
26   private Map JavaDoc correlations;
27   
28   public Correlations() {
29   }
30   
31   public void addCorrelation(Correlation correlation) {
32     if (correlations == null) {
33       correlations = new HashMap JavaDoc();
34     }
35     correlations.put(correlation.getSet().getName(), correlation);
36   }
37   
38   public Correlation getCorrelation(String JavaDoc setName) {
39     return (Correlation) correlations.get(setName);
40   }
41
42   public Map JavaDoc getCorrelations() {
43     return correlations;
44   }
45   
46   public void setCorrelations(Map JavaDoc correlations) {
47     this.correlations = correlations;
48   }
49   
50   public Map JavaDoc getReceptionProperties(Token token) {
51     Map JavaDoc receptionProperties = new HashMap JavaDoc();
52     Iterator JavaDoc correlationIter = correlations.values().iterator();
53     while (correlationIter.hasNext()) {
54       Correlation correlation = (Correlation) correlationIter.next();
55       Initiate initiate = correlation.getInitiate();
56       if (initiate != Initiate.YES) {
57         CorrelationSetInstance setInstance = correlation.getSet().getInstance(token);
58         if (initiate == Initiate.NO || setInstance.isInitialized()) {
59           receptionProperties.putAll(setInstance.getProperties());
60         }
61       }
62     }
63     return receptionProperties;
64   }
65   
66   public void ensureConstraint(MessageVariableInstance messageInstance, Token token) {
67     Iterator JavaDoc correlationIter = correlations.values().iterator();
68     while (correlationIter.hasNext()) {
69       Correlation correlation = (Correlation) correlationIter.next();
70       CorrelationSetInstance setInstance = correlation.getSet().getInstance(token);
71       Initiate initiate = correlation.getInitiate();
72       if (initiate == Initiate.YES) {
73         setInstance.initialize(messageInstance);
74       }
75       else if (initiate == Initiate.NO) {
76         setInstance.validateConstraint(messageInstance);
77       }
78       else if (initiate == Initiate.RENDEZVOUS) {
79         if (setInstance.isInitialized())
80           setInstance.validateConstraint(messageInstance);
81         else
82           setInstance.initialize(messageInstance);
83       }
84       else throw new IllegalStateException JavaDoc("illegal property value: initiate=" + initiate);
85     }
86   }
87 }
88
Popular Tags