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. import java.util.Iterator;
  18. import java.util.List;
  19. /**
  20. * Thrown when an attribute repository class can't be
  21. * loaded because it resulted in a circular dependency.
  22. */
  23. public class CircularDependencyError extends RepositoryError {
  24. /**
  25. * Create a new CircularDependencyError.
  26. *
  27. * @param className the name of the class that started it all.
  28. * @param dependencyList a list of the classes that the original
  29. * class depended on, the classes they
  30. * depended on, and so on. The list should
  31. * show the chain of dependencies that resulted
  32. * in the exception being thrown.
  33. */
  34. public CircularDependencyError (String className, List dependencyList) {
  35. super (className + ":" + listDeps (dependencyList), null);
  36. }
  37. /**
  38. * Joins together the elements of a list with <code>-></code>
  39. * delimiters. Used to show the sequence that resulted in the circular
  40. * dependency.
  41. */
  42. private static String listDeps (List dependencyList) {
  43. StringBuffer sb = new StringBuffer ();
  44. Iterator iter = dependencyList.iterator ();
  45. while (iter.hasNext ()) {
  46. sb.append (iter.next ());
  47. if (iter.hasNext ()) {
  48. sb.append (" -> ");
  49. }
  50. }
  51. return sb.toString ();
  52. }
  53. }