001 /***************************************************************************** 002 * Copyright (c) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant * 009 *****************************************************************************/ 010 011 package org.picocontainer.defaults; 012 013 import org.picocontainer.PicoIntrospectionException; 014 015 import java.util.LinkedList; 016 import java.util.List; 017 018 /** 019 * @author Aslak Hellesøy 020 * @author Jörg Schaible 021 * @version $Revision: 1801 $ 022 */ 023 public class CyclicDependencyException extends PicoIntrospectionException { 024 private final List stack; 025 026 /** 027 * @since 1.1 028 */ 029 public CyclicDependencyException(Class element) { 030 super((Throwable)null); 031 this.stack = new LinkedList(); 032 push(element); 033 } 034 035 /** 036 * @since 1.1 037 */ 038 public void push(Class element) { 039 stack.add(element); 040 } 041 042 public Class[] getDependencies() { 043 return (Class[]) stack.toArray(new Class[stack.size()]); 044 } 045 046 public String getMessage() { 047 return "Cyclic dependency: " + stack.toString(); 048 } 049 }