001package com.ganteater.ae;
002
003import java.util.Vector;
004
005import com.ganteater.ae.processor.Processor;
006import com.ganteater.ae.util.xml.easyparser.Node;
007
008public class CommandException extends Exception {
009
010        private static final long serialVersionUID = 1L;
011        private Vector<Object> callTaskTrace;
012        private Node theCurrentAction;
013        private boolean isReviewed;
014
015        public CommandException(String message, Processor processor) {
016                super(message);
017                if (processor != null) {
018                        this.callTaskTrace = processor.getCallTaskTrace();
019                }
020        }
021
022        public CommandException(Throwable targetException, Processor unit, Node theCurrentAction) {
023                super(targetException);
024                this.callTaskTrace = unit.getCallTaskTrace();
025                this.theCurrentAction = theCurrentAction;
026        }
027
028        public String getTaskTrace() {
029                StringBuffer theText = new StringBuffer();
030                if (theCurrentAction != null) {
031                        theText.append("Command:\n");
032                        theText.append(theCurrentAction.getXMLText());
033                        theText.append("\n");
034                }
035
036                theText.append("Task trace:\n");
037                String callTaskTraceText = getCallTaskTraceText(callTaskTrace);
038                theText.append(callTaskTraceText);
039                return theText.toString();
040        }
041
042        private String getCallTaskTraceText(Vector<Object> vector) {
043                StringBuffer theText = new StringBuffer();
044                if (vector != null) {
045                        for (int i = 0; i < vector.size(); i++) {
046                                Object theCurrentRec = vector.get(i);
047                                if (theCurrentRec instanceof String) {
048                                        theText.append((String) theCurrentRec);
049                                }
050                                if (theCurrentRec instanceof Node) {
051                                        Node node = (Node) theCurrentRec;
052                                        theText.append("\t");
053                                        if (node != null) {
054                                                String id = node.getAttribute("$id");
055                                                if (id != null) {
056                                                        theText.append("#");
057                                                        theText.append(id);
058                                                        theText.append(" ");
059                                                }
060                                                String tag = node.getTag();
061                                                theText.append(tag);
062                                                theText.append(" ");
063
064                                                String recipe = node.getAttribute("recipe");
065                                                if (recipe != null) {
066                                                        theText.append("@");
067                                                        theText.append(recipe);
068                                                }
069                                                theText.append("\n");
070                                        }
071                                }
072                        }
073                }
074
075                return theText.toString();
076        }
077
078        public void reviewed() {
079                isReviewed = true;
080        }
081
082        public boolean isReviewed() {
083                return isReviewed;
084        }
085
086}