1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.engine.node; |
17 | |
|
18 | |
import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue; |
19 | |
|
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class NodeJotter { |
30 | |
|
31 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NodeJotter.class); |
32 | |
private static final String INDENT = " "; |
33 | |
|
34 | |
public static void jotNodeInstance(DocumentRouteHeaderValue document, RouteNodeInstance nodeInstance) { |
35 | |
try { |
36 | 0 | if (LOG.isDebugEnabled()) { |
37 | 0 | List initialNodeInstances = document.getInitialRouteNodeInstances(); |
38 | 0 | for (Iterator iterator = initialNodeInstances.iterator(); iterator.hasNext();) { |
39 | 0 | RouteNodeInstance initialNodeInstance = (RouteNodeInstance) iterator.next(); |
40 | 0 | NodeType nodeType = NodeType.fromNodeInstance(initialNodeInstance); |
41 | 0 | LOG.debug(orchestrateOutput(initialNodeInstance, nodeType, null, 0)); |
42 | 0 | } |
43 | 0 | } else if (LOG.isInfoEnabled()) { |
44 | 0 | NodeType nodeType = NodeType.fromNodeInstance(nodeInstance); |
45 | 0 | LOG.info(outputNodeInstanceToLog(nodeInstance, nodeType, 0)); |
46 | |
} |
47 | 0 | } catch (Throwable t) { |
48 | 0 | LOG.warn("Caught error attempting to jot node instance" + nodeInstance); |
49 | 0 | } |
50 | 0 | } |
51 | |
|
52 | |
private static String orchestrateOutput(RouteNodeInstance nodeInstance, NodeType nodeType, SplitJoinContext sjCtx, int indentDepth) throws Exception { |
53 | 0 | String output = ""; |
54 | 0 | boolean isSplit = NodeType.SPLIT.equals(nodeType); |
55 | 0 | boolean isJoin = NodeType.JOIN.equals(nodeType); |
56 | 0 | if (isJoin && sjCtx != null) { |
57 | 0 | sjCtx.joinNodeInstance = nodeInstance; |
58 | 0 | return output; |
59 | |
} |
60 | 0 | SplitJoinContext newSplitJoinContext = null; |
61 | 0 | if (isSplit) { |
62 | 0 | newSplitJoinContext = new SplitJoinContext(nodeInstance); |
63 | |
} |
64 | 0 | output += outputNodeInstanceToLog(nodeInstance, nodeType, indentDepth); |
65 | 0 | for (Iterator iterator = nodeInstance.getNextNodeInstances().iterator(); iterator.hasNext();) { |
66 | 0 | RouteNodeInstance nextNodeInstance = (RouteNodeInstance) iterator.next(); |
67 | 0 | nodeType = NodeType.fromNodeInstance(nextNodeInstance); |
68 | 0 | if (newSplitJoinContext != null) { |
69 | 0 | output += orchestrateOutput(nextNodeInstance, nodeType, newSplitJoinContext, indentDepth + 1); |
70 | |
} else { |
71 | 0 | output += orchestrateOutput(nextNodeInstance, nodeType, sjCtx, indentDepth + 1); |
72 | |
} |
73 | 0 | } |
74 | 0 | if (isSplit) { |
75 | 0 | if (newSplitJoinContext != null && newSplitJoinContext.joinNodeInstance != null) { |
76 | 0 | nodeType = NodeType.fromNodeInstance(newSplitJoinContext.joinNodeInstance); |
77 | 0 | output += orchestrateOutput(newSplitJoinContext.joinNodeInstance, nodeType, sjCtx, indentDepth); |
78 | |
} |
79 | |
} |
80 | 0 | return output; |
81 | |
} |
82 | |
|
83 | |
private static String outputNodeInstanceToLog(RouteNodeInstance nodeInstance, NodeType nodeType, int indentDepth) throws Exception { |
84 | 0 | String memAddress = nodeInstance.toString().split("@")[1]; |
85 | 0 | String dataIndent = getIndent(indentDepth + 1); |
86 | 0 | String output = getIndent(indentDepth) + "[NODE type=" + nodeType.getName() + "]\n" + dataIndent + "Name: " + nodeInstance.getName() + "(" + memAddress + ")\n"; |
87 | 0 | output += dataIndent + "State: "; |
88 | 0 | for (Iterator iterator = nodeInstance.getState().iterator(); iterator.hasNext();) { |
89 | 0 | NodeState nodeState = (NodeState) iterator.next(); |
90 | 0 | output += nodeState.getKey() + "=" + nodeState.getValue(); |
91 | 0 | if (iterator.hasNext()) { |
92 | 0 | output += ","; |
93 | |
} |
94 | 0 | } |
95 | 0 | output += "\n" + dataIndent + "Status Flags: initial=" + nodeInstance.isInitial() + ", active=" + nodeInstance.isActive() + ", complete=" + nodeInstance.isComplete(); |
96 | 0 | output += (nodeInstance.getProcess() == null ? "" : "\n" + dataIndent + "ProcessDefinition Name: " + nodeInstance.getProcess().getName()); |
97 | 0 | output += "\n"; |
98 | 0 | return output; |
99 | |
} |
100 | |
|
101 | |
private static String getIndent(int indentDepth) { |
102 | 0 | StringBuffer buffer = new StringBuffer(); |
103 | 0 | for (int depth = 0; depth < indentDepth; depth++) { |
104 | 0 | buffer.append(INDENT); |
105 | |
} |
106 | 0 | return buffer.toString(); |
107 | |
} |
108 | |
|
109 | 0 | private static class SplitJoinContext { |
110 | |
public RouteNodeInstance splitNodeInstance; |
111 | |
public RouteNodeInstance joinNodeInstance; |
112 | |
|
113 | 0 | public SplitJoinContext(RouteNodeInstance splitNodeInstance) { |
114 | 0 | this.splitNodeInstance = splitNodeInstance; |
115 | 0 | } |
116 | |
} |
117 | |
|
118 | |
} |