KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.service.exe;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import javax.xml.namespace.QName JavaDoc;
8
9 import org.jbpm.bpel.data.exe.MessageVariableInstance;
10 import org.jbpm.bpel.service.def.CorrelationSetDefinition;
11 import org.jbpm.bpel.wsdl.def.Property;
12
13 /**
14  * @author Alejandro Guízar
15  * @version $Revision: 1.3 $ $Date: 2005/05/07 00:03:41 $
16  */

17 public class CorrelationSetInstance {
18   
19   private CorrelationSetDefinition definition;
20   private Map JavaDoc properties;
21   
22   public CorrelationSetInstance() {
23   }
24   
25   public CorrelationSetDefinition getDefinition() {
26     return definition;
27   }
28   
29   public void setDefinition(CorrelationSetDefinition definition) {
30     this.definition = definition;
31   }
32   
33   public boolean isInitialized() {
34     return properties != null && properties.size() > 0;
35   }
36   
37   public void initialize(Map JavaDoc propertyValues) {
38     checkNotInitialized();
39     properties = new HashMap JavaDoc();
40     Iterator JavaDoc propertyIter = definition.getProperties().iterator();
41     while (propertyIter.hasNext()) {
42       Property property = (Property) propertyIter.next();
43       QName JavaDoc name = property.getQName();
44       properties.put(name, propertyValues.get(name));
45     }
46   }
47   
48   public void initialize(MessageVariableInstance messageInstance) {
49     checkNotInitialized();
50     properties = new HashMap JavaDoc();
51     Iterator JavaDoc propertyIter = definition.getProperties().iterator();
52     while (propertyIter.hasNext()) {
53       Property property = (Property) propertyIter.next();
54       QName JavaDoc name = property.getQName();
55       properties.put(name, messageInstance.getProperty(name));
56     }
57   }
58   
59   public Object JavaDoc getProperty(QName JavaDoc propertyName) {
60     checkInitialized();
61     return properties.get(propertyName);
62   }
63   
64   public Map JavaDoc getProperties() {
65     checkInitialized();
66     return properties;
67   }
68   
69   public void validateConstraint(MessageVariableInstance messageInstance) {
70     checkInitialized();
71     Iterator JavaDoc entryIt = properties.entrySet().iterator();
72     while (entryIt.hasNext()) {
73       Map.Entry JavaDoc nameValueEntry = (Map.Entry JavaDoc) entryIt.next();
74       QName JavaDoc propertyName = (QName JavaDoc) nameValueEntry.getKey();
75       Object JavaDoc messageValue = messageInstance.getProperty(propertyName);
76       if (!nameValueEntry.getValue().equals(messageValue)) {
77         throw new RuntimeException JavaDoc("Correlation violation (property value mismatch)");
78       }
79     }
80   }
81   
82   private void checkInitialized() {
83     if (!isInitialized()) {
84       throw new RuntimeException JavaDoc("Correlation violation (correlation set not initiated):" +
85           " set=" + definition.getName());
86     }
87   }
88   
89   private void checkNotInitialized() {
90     if (isInitialized()) {
91       throw new RuntimeException JavaDoc("Correlation violation (correlation set already initiated):" +
92           " set=" + definition.getName());
93     }
94   }
95 }
96
Popular Tags