KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > CyclicModuleDependencyException


1 package jfun.yan.xml;
2
3 import java.io.PrintStream JavaDoc;
4 import java.io.PrintWriter JavaDoc;
5 import java.util.Stack JavaDoc;
6
7 /**
8  * Represents an exception when module files have circular dependency.
9  * <p>
10  * @author Ben Yu
11  * Nov 20, 2005 4:28:24 PM
12  */

13 public class CyclicModuleDependencyException extends ConfigurationException {
14   private final Stack JavaDoc trace = new Stack JavaDoc();
15   
16   /**
17    * Create a CyclicModuleDependencyException object.
18    * @param msg the error message.
19    * @param loc the location where the dependency cycle is detected.
20    */

21   public CyclicModuleDependencyException(String JavaDoc msg, Location loc) {
22     super(msg, loc);
23   }
24
25   /**
26    * Pushes a frame to the exception.
27    * @param obj the frame.
28    */

29   public void push(Object JavaDoc obj){
30     trace.push(obj);
31   }
32   
33   /**
34    * Get the dependency trace that caused the cycle.
35    *
36    */

37   public Stack JavaDoc getDependencyTrace(){
38     return trace;
39   }
40   
41   /**
42    * Print the dependency trace.
43    * @param out the output stream.
44    */

45   public void printDependencyTrace(PrintStream JavaDoc out){
46     printDependencyTrace(new java.io.PrintWriter JavaDoc(out, true));
47   }
48   /**
49    * Print the dependency trace.
50    * @param out the output writer.
51    */

52   public void printDependencyTrace(java.io.PrintWriter JavaDoc out){
53     final int size = trace.size();
54     for(int i=0; i<size; i++){
55       out.println(trace.get(i));
56     }
57   }
58   /**
59    * Prints the dependency trace to the standard error output.
60    */

61   public void printDependencyTrace(){
62     printDependencyTrace(System.err);
63   }
64
65   public void printStackTrace(PrintStream JavaDoc s) {
66     printDependencyTrace(s);
67     super.printStackTrace(s);
68   }
69   public void printStackTrace(PrintWriter JavaDoc s) {
70     printDependencyTrace(s);
71     super.printStackTrace(s);
72   }
73 }
74
Popular Tags