1 package org.jbpm.bpel.service.exe; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import javax.xml.namespace.QName ; 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 17 public class CorrelationSetInstance { 18 19 private CorrelationSetDefinition definition; 20 private Map 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 propertyValues) { 38 checkNotInitialized(); 39 properties = new HashMap (); 40 Iterator propertyIter = definition.getProperties().iterator(); 41 while (propertyIter.hasNext()) { 42 Property property = (Property) propertyIter.next(); 43 QName 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 (); 51 Iterator propertyIter = definition.getProperties().iterator(); 52 while (propertyIter.hasNext()) { 53 Property property = (Property) propertyIter.next(); 54 QName name = property.getQName(); 55 properties.put(name, messageInstance.getProperty(name)); 56 } 57 } 58 59 public Object getProperty(QName propertyName) { 60 checkInitialized(); 61 return properties.get(propertyName); 62 } 63 64 public Map getProperties() { 65 checkInitialized(); 66 return properties; 67 } 68 69 public void validateConstraint(MessageVariableInstance messageInstance) { 70 checkInitialized(); 71 Iterator entryIt = properties.entrySet().iterator(); 72 while (entryIt.hasNext()) { 73 Map.Entry nameValueEntry = (Map.Entry ) entryIt.next(); 74 QName propertyName = (QName ) nameValueEntry.getKey(); 75 Object messageValue = messageInstance.getProperty(propertyName); 76 if (!nameValueEntry.getValue().equals(messageValue)) { 77 throw new RuntimeException ("Correlation violation (property value mismatch)"); 78 } 79 } 80 } 81 82 private void checkInitialized() { 83 if (!isInitialized()) { 84 throw new RuntimeException ("Correlation violation (correlation set not initiated):" + 85 " set=" + definition.getName()); 86 } 87 } 88 89 private void checkNotInitialized() { 90 if (isInitialized()) { 91 throw new RuntimeException ("Correlation violation (correlation set already initiated):" + 92 " set=" + definition.getName()); 93 } 94 } 95 } 96 | Popular Tags |