KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > bar > ScopeMatcher


1 package org.jbpm.bpel.bar;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
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 /**
15  * @author Juan Cantu
16  * @version $Revision: 1.1 $ $Date: 2005/06/04 00:08:20 $
17  */

18 public class ScopeMatcher implements BarVisitor {
19   
20   private Map JavaDoc scopeConfigurations;
21   private Scope parent;
22   
23   /**
24    * Matches a bpel definition with the given configuration
25    * @param definition the bpel definition
26    * @param configuration the bpel configuration to use
27    * @return the resulting match map of scope definitions with their corresponding configuration
28    */

29   public Map JavaDoc match(BpelDefinition definition, BarApplication configuration) {
30     scopeConfigurations = new HashMap JavaDoc();
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     //TODO if not found throw error?
44
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 JavaDoc 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 JavaDoc configName, NodeCollection parent) {
67     Iterator JavaDoc 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 JavaDoc("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 JavaDoc("conflicting name");
86         matchingScope = scope;
87       }
88     }
89     
90     return matchingScope;
91   }
92 }
93
Popular Tags