Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.engine.node;
 
 
 import java.util.List;


Logs RouteNodeInstance graphs in a format which is indented and easy to read.

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class NodeJotter {
 
     private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(NodeJotter.class);
     private static final String INDENT = "   ";
 
     public static void jotNodeInstance(DocumentRouteHeaderValue documentRouteNodeInstance nodeInstance) {
         try {
             if (.isDebugEnabled()) {
                 List initialNodeInstances = document.getInitialRouteNodeInstances();
                 for (Iterator iterator = initialNodeInstances.iterator(); iterator.hasNext();) {
                     RouteNodeInstance initialNodeInstance = (RouteNodeInstanceiterator.next();
                     NodeType nodeType = NodeType.fromNodeInstance(initialNodeInstance);
                     .debug(orchestrateOutput(initialNodeInstancenodeTypenull, 0));
                 }
             } else if (.isInfoEnabled()) {
                 NodeType nodeType = NodeType.fromNodeInstance(nodeInstance);
                 .info(outputNodeInstanceToLog(nodeInstancenodeType, 0));
             }
         } catch (Throwable t) {
             .warn("Caught error attempting to jot node instance" + nodeInstance);
         }
     }
 
     private static String orchestrateOutput(RouteNodeInstance nodeInstanceNodeType nodeTypeSplitJoinContext sjCtxint indentDepththrows Exception {
         String output = "";
         boolean isSplit = ..equals(nodeType);
         boolean isJoin = ..equals(nodeType);
         if (isJoin && sjCtx != null) {
             sjCtx.joinNodeInstance = nodeInstance;
             return output;
         }
         SplitJoinContext newSplitJoinContext = null;
         if (isSplit) {
             newSplitJoinContext = new SplitJoinContext(nodeInstance);
         }
         output += outputNodeInstanceToLog(nodeInstancenodeTypeindentDepth);
         for (Iterator iterator = nodeInstance.getNextNodeInstances().iterator(); iterator.hasNext();) {
             RouteNodeInstance nextNodeInstance = (RouteNodeInstanceiterator.next();
             nodeType = NodeType.fromNodeInstance(nextNodeInstance);
             if (newSplitJoinContext != null) {
                 output += orchestrateOutput(nextNodeInstancenodeTypenewSplitJoinContextindentDepth + 1);
             } else {
                 output += orchestrateOutput(nextNodeInstancenodeTypesjCtxindentDepth + 1);
             }
         }
         if (isSplit) {
             if (newSplitJoinContext != null && newSplitJoinContext.joinNodeInstance != null) {
                 nodeType = NodeType.fromNodeInstance(newSplitJoinContext.joinNodeInstance);
                 output += orchestrateOutput(newSplitJoinContext.joinNodeInstancenodeTypesjCtxindentDepth);
             }
         }
         return output;
     }
 
     private static String outputNodeInstanceToLog(RouteNodeInstance nodeInstanceNodeType nodeTypeint indentDepththrows Exception {
         String memAddress = nodeInstance.toString().split("@")[1];
         String dataIndent = getIndent(indentDepth + 1);
         String output = getIndent(indentDepth) + "[NODE type=" + nodeType.getName() + "]\n" + dataIndent + "Name: " + nodeInstance.getName() + "(" + memAddress + ")\n";
         output += dataIndent + "State: ";
         for (Iterator iterator = nodeInstance.getState().iterator(); iterator.hasNext();) {
             NodeState nodeState = (NodeStateiterator.next();
             output += nodeState.getKey() + "=" + nodeState.getValue();
             if (iterator.hasNext()) {
                 output += ",";
             }
         }
         output += "\n" + dataIndent + "Status Flags: initial=" + nodeInstance.isInitial() + ", active=" + nodeInstance.isActive() + ", complete=" + nodeInstance.isComplete();
         output += (nodeInstance.getProcess() == null ? "" : "\n" + dataIndent + "ProcessDefinition Name: " + nodeInstance.getProcess().getName());
         output += "\n";
         return output;
     }
    private static String getIndent(int indentDepth) {
        StringBuffer buffer = new StringBuffer();
        for (int depth = 0; depth < indentDepthdepth++) {
            buffer.append();
        }
        return buffer.toString();
    }
    private static class SplitJoinContext {
        public RouteNodeInstance splitNodeInstance;
        public RouteNodeInstance joinNodeInstance;
        public SplitJoinContext(RouteNodeInstance splitNodeInstance) {
            this. = splitNodeInstance;
        }
    }
New to GrepCode? Check out our FAQ X