KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > def > CompositeActivity


1 package org.jbpm.bpel.def;
2
3 import java.util.*;
4
5 import org.jbpm.graph.def.Node;
6 import org.jbpm.graph.def.NodeCollection;
7 import org.jbpm.graph.def.ProcessDefinition;
8
9 import org.jbpm.bpel.data.def.VariableDefinition;
10 import org.jbpm.bpel.service.def.CorrelationSetDefinition;
11 import org.jbpm.bpel.service.def.PartnerLinkDefinition;
12
13 /**
14  * brings hierarchy into the activities of a bpel definition by creating a
15  * parent-child relation between {@link Activity}s
16  * @author Juan Cantú
17  * @version $Revision: 1.8 $ $Date: 2005/06/16 19:15:38 $
18  */

19 public abstract class CompositeActivity extends Activity implements NodeCollection {
20
21   private transient Map nodesMap = null;
22   
23   public CompositeActivity() {
24   }
25
26   public CompositeActivity(String JavaDoc name) {
27     super(name);
28   }
29   
30   public boolean isChildInitial(Activity activity) {
31     return false;
32   }
33   
34   // definition retrieval methods //////////////////////////////////////////////////////////////////////
35

36   public VariableDefinition findVariable(String JavaDoc varName) {
37     CompositeActivity parent = getCompositeActivity();
38     return parent != null ? parent.findVariable(varName) : null;
39   }
40   
41   public CorrelationSetDefinition findCorrelationSet(String JavaDoc csName) {
42     CompositeActivity parent = getCompositeActivity();
43     return parent != null ? parent.findCorrelationSet(csName) : null;
44   }
45   
46   public PartnerLinkDefinition findPartnerLink(String JavaDoc plinkName) {
47     CompositeActivity parent = getCompositeActivity();
48     return parent != null ? parent.findPartnerLink(plinkName) : null;
49   }
50
51   public Link findLink(String JavaDoc linkName) {
52     CompositeActivity parent = getCompositeActivity();
53     return parent != null ? parent.findLink(linkName) : null;
54   }
55   
56   // children management /////////////////////////////////////////////////////////////////////////////
57

58   /**{@inheritDoc}*/
59   public Map getNodesMap() {
60     List nodes = getNodes();
61     
62     if ( nodesMap==null && nodes!=null ) {
63       nodesMap = new HashMap();
64       Iterator iter = nodes.iterator();
65       while (iter.hasNext()) {
66         Node node = (Node) iter.next();
67         nodesMap.put(node.getName(), node);
68       }
69     }
70     return nodesMap;
71   }
72   
73   /**{@inheritDoc}*/
74   public String JavaDoc generateNodeName() {
75     return ProcessDefinition.generateNodeName(getNodes());
76   }
77
78   /**{@inheritDoc}*/
79   public Node findNode(String JavaDoc hierarchicalName) {
80     return ProcessDefinition.findNode(this, hierarchicalName);
81   }
82   
83   /**{@inheritDoc}*/
84   public Node getNode(String JavaDoc name) {
85     return (Node) getNodesMap().get(name);
86   }
87
88   /**{@inheritDoc}*/
89   public boolean hasNode(String JavaDoc name) {
90     return getNodesMap().containsKey(name);
91   }
92   
93   /**{@inheritDoc}*/
94   public Node findChild(String JavaDoc childName) {
95     Node node = getNode(childName);
96     if(node != null) return node;
97     
98     for(Iterator it = getNodes().iterator(); it.hasNext();) {
99       Object JavaDoc child = it.next();
100       if(child instanceof StructuredActivity) {
101         node = ((StructuredActivity)child).findChild(childName);
102         if(node != null) return node;
103       }
104     }
105     return null;
106   }
107 }
Popular Tags