1 package org.jbpm.bpel.bar; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import org.jbpm.graph.def.NodeCollection; 8 9 import org.jbpm.bpel.def.Activity; 10 import org.jbpm.bpel.def.BpelDefinition; 11 import org.jbpm.bpel.def.CompositeActivity; 12 import org.jbpm.bpel.def.Scope; 13 14 18 public class ScopeMatcher implements BarVisitor { 19 20 private Map scopeConfigurations; 21 private Scope parent; 22 23 29 public Map match(BpelDefinition definition, BarApplication configuration) { 30 scopeConfigurations = new HashMap (); 31 this.parent = definition.getScope(); 32 visit(configuration); 33 return scopeConfigurations; 34 } 35 36 public void visit(BarApplication processConfig) { 37 scopeConfigurations.put(parent, processConfig); 38 propagate(processConfig); 39 } 40 41 public void visit(BarScope scopeConfig) { 42 Scope scope = findScope(scopeConfig.getName(), parent); 43 if(scope != null) { 45 scopeConfigurations.put(scope, scopeConfig); 46 47 Scope previousParent = parent; 48 parent = scope; 49 propagate(scopeConfig); 50 parent = previousParent; 51 } 52 } 53 54 public void visit(BarPartnerLink plinkConfig) { 55 } 56 57 public void propagate(BarScope config) { 58 Iterator configIt = config.getScopes().iterator(); 59 60 while(configIt.hasNext()) { 61 BarScope scopeConfig = (BarScope) configIt.next(); 62 scopeConfig.accept(this); 63 } 64 } 65 66 private Scope findScope(String configName, NodeCollection parent) { 67 Iterator nodesIt = parent.getNodes().iterator(); 68 69 Scope matchingScope = null; 70 71 while(nodesIt.hasNext()) { 72 Activity activity = (Activity) nodesIt.next(); 73 74 if(!(activity instanceof CompositeActivity)) continue; 75 76 if(activity instanceof Scope && 77 (configName == null && activity.getName() == null) || 78 (configName != null && configName.equals(activity.getName()))) { 79 if(matchingScope != null) throw new RuntimeException ("conflicting name"); 80 matchingScope = (Scope) activity; 81 } 82 83 Scope scope = findScope(configName, ((NodeCollection)activity)); 84 if(scope != null) { 85 if(matchingScope != null) throw new RuntimeException ("conflicting name"); 86 matchingScope = scope; 87 } 88 } 89 90 return matchingScope; 91 } 92 } 93 | Popular Tags |