KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > attributes > CircularDependencyError


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.attributes;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 /**
22  * Thrown when an attribute repository class can't be
23  * loaded because it resulted in a circular dependency.
24  */

25 public class CircularDependencyError extends RepositoryError {
26    
27     /**
28      * Create a new CircularDependencyError.
29      *
30      * @param className the name of the class that started it all.
31      * @param dependencyList a list of the classes that the original
32      * class depended on, the classes they
33      * depended on, and so on. The list should
34      * show the chain of dependencies that resulted
35      * in the exception being thrown.
36      */

37     public CircularDependencyError (String JavaDoc className, List JavaDoc dependencyList) {
38         super (className + ":" + listDeps (dependencyList), null);
39     }
40     
41     /**
42      * Joins together the elements of a list with <code>-&gt;</code>
43      * delimiters. Used to show the sequence that resulted in the circular
44      * dependency.
45      */

46     private static String JavaDoc listDeps (List JavaDoc dependencyList) {
47         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ();
48         Iterator JavaDoc iter = dependencyList.iterator ();
49         while (iter.hasNext ()) {
50             sb.append (iter.next ());
51             if (iter.hasNext ()) {
52                 sb.append (" -> ");
53             }
54         }
55         
56         return sb.toString ();
57     }
58 }
Popular Tags