1
2
3
4
5
6 package net.kwfgrid.gwui.graphview;
7
8 import net.kwfgrid.gwui.util.Utilities;
9 import net.kwfgrid.gworkflowdl.structure.*;
10
11 import org.apache.log4j.Logger;
12 import org.jdom.Element;
13 import org.jdom.Namespace;
14
15 /***
16 Default implementation of <code>WorkflowGraphAnalyzer</code>.
17 */
18 public class DefaultWorkflowGraphAnalyzer implements WorkflowGraphAnalyzer {
19 private static final Logger logger = Logger.getLogger(DefaultWorkflowGraphAnalyzer.class);
20 public static final Namespace NAMESPACE_SOAPENV = Namespace.getNamespace("soapenv", "http://www.w3.org/2003/05/soap-envelope");
21
22 public DefaultWorkflowGraphAnalyzer() {
23 logger.debug("DefaultWorkflowGraphAnalyzer instantiated.");
24 }
25
26 public void updatePlaceNode(PlaceNode node) {
27 Place p = node.getPlace();
28 node.setQuasiLive(isQuasiLive(p.getProperties()));
29 node.setHasFault(hasFault(p));
30 }
31
32
33 public void updateTransitionNode(TransitionNode node) {
34 Transition t = node.getTransition();
35 node.setOperationProperties(getOperationProperties(t));
36 node.setQuasiLive(isQuasiLive(t.getProperties()));
37 }
38
39 /***
40 Returns <code>false</code> if the specified properties contain a property with name "isQuasiLive" and value "false",
41 <code>true</code> otherwise.
42 */
43 protected boolean isQuasiLive(GenericProperties p) {
44 return !"false".equals(p.get("isQuasiLive"));
45 }
46
47 protected boolean hasFault(Place p) {
48 Token[] tokens = p.getTokens();
49 for (int i = 0; i<tokens.length; i++) {
50 Data data = tokens[i].getData();
51 if (data!=null) {
52 Element element = (Element) data.get();
53 if (element.getChild("Fault",NAMESPACE_SOAPENV)!=null) {
54 return true;
55 }
56 }
57 }
58
59 return false;
60 }
61
62
63 /***
64 Get the correct instance of <code>OperationProperties</code> for the specified Transition.
65 Called by <code>updateTransitionNode()</code>.
66 */
67 protected OperationProperties getOperationProperties(Transition t) {
68 Operation o = t.getOperation();
69
70 logger.debug("Checking operation type...");
71
72 if (o != null) {
73 if (o.get() instanceof OperationClass) {
74 OperationClass operationClass = (OperationClass) o.get();
75 OperationCandidate[] operationCandidates = operationClass.getOperationCandidates();
76 if (operationCandidates != null && operationCandidates.length > 0) {
77 logger.debug("Instantiating OperationCandidateProperties.");
78 return new OperationCandidateProperties(operationClass);
79 }
80 } else {
81 logger.debug("Instantiating NullOperationProperties.");
82 return new NullOperationProperties(t);
83 }
84 }
85
86 logger.debug("Returning NullOperationProperties after failed check.");
87
88 return new NullOperationProperties(t);
89 }
90
91 public void updateWorkflowGraph(WorkflowGraph graph) {
92 }
93
94 public void updateReadEdge(ReadEdge edge) {
95 updateEdge(edge);
96 }
97
98 public void updateInEdge(InEdge edge) {
99 updateEdge(edge);
100 }
101
102 public void updateOutEdge(OutEdge edge) {
103 updateEdge(edge);
104 }
105
106 protected void updateEdge(ArcEdge edge) {
107 logger.debug("Updating edge.");
108
109 String oldlabel = edge.getLabel();
110 String newlabel = getEdgeLabel(edge.getArc());
111 if (!Utilities.equal(oldlabel, newlabel)) {
112 edge.setLabel(getEdgeLabel(edge.getArc()));
113
114
115
116
117 }
118 }
119
120 /***
121 Get the label for the specified arc.
122 Called by <code>updateInEdge()</code> and <code>updateOutEdge()</code>
123 */
124 protected String getEdgeLabel(Edge arc) {
125 String edgeexpression = arc.getExpression();
126 edgeexpression = edgeexpression==null?"":edgeexpression.substring(edgeexpression.lastIndexOf("#")+1);
127
128
129
130 return edgeexpression;
131 }
132 }