001    /*
002     *  jDTAUS Core API
003     *  Copyright (c) 2005 Christian Schulte
004     *
005     *  Christian Schulte, Haldener Strasse 72, 58095 Hagen, Germany
006     *  <schulte2005@users.sourceforge.net> (+49 2331 3543887)
007     *
008     *  This library is free software; you can redistribute it and/or
009     *  modify it under the terms of the GNU Lesser General Public
010     *  License as published by the Free Software Foundation; either
011     *  version 2.1 of the License, or any later version.
012     *
013     *  This library is distributed in the hope that it will be useful,
014     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
015     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016     *  Lesser General Public License for more details.
017     *
018     *  You should have received a copy of the GNU Lesser General Public
019     *  License along with this library; if not, write to the Free Software
020     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021     *
022     */
023    package org.jdtaus.core.container;
024    
025    import java.util.Locale;
026    
027    /**
028     * Gets thrown for cyclic dependency graphs.
029     *
030     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
031     * @version $Id: DependencyCycleException.java 8044 2009-07-02 01:29:05Z schulte2005 $
032     */
033    public class DependencyCycleException extends IllegalStateException
034    {
035        //--Constants---------------------------------------------------------------
036    
037        /** Serial version UID for backwards compatibility with 1.5.x classes. */
038        private static final long serialVersionUID = 8471828485552467121L;
039    
040        //---------------------------------------------------------------Constants--
041        //--Constructors------------------------------------------------------------
042    
043        /**
044         * Creates a new {@code DependencyCycleException} taking the involved
045         * implementations.
046         *
047         * @param impl1 the implementation the cycle was detected for.
048         * @param impl2 the implementation introducing the cycle to {@code impl1}.
049         *
050         * @throws NullPointerException if either {@code impl1} or {@code impl2}
051         * is {@code null}.
052         */
053        public DependencyCycleException( final Implementation impl1,
054                                         final Implementation impl2 )
055        {
056            super( DependencyCycleExceptionBundle.getInstance().
057                   getDependencyCycleMessage( Locale.getDefault(),
058                                              impl1.getIdentifier(),
059                                              impl2.getIdentifier() ) );
060    
061            this.implementations = new Implementation[]
062                {
063                    impl1, impl2
064                };
065        }
066    
067        /**
068         * Creates a new {@code DependencyCycleException} taking identifiers of the
069         * involved implementations.
070         *
071         * @param identifier1 the identifier of the implementation the cycle was
072         * detected for.
073         * @param identifier2 the identifier of the implementation introducing the
074         * cycle.
075         *
076         * @throws NullPointerException if either {@code identifier1} or
077         * {@code identifier2} is {@code null}.
078         */
079        public DependencyCycleException( final String identifier1,
080                                         final String identifier2 )
081        {
082            super( DependencyCycleExceptionBundle.getInstance().
083                   getDependencyCycleMessage( Locale.getDefault(),
084                                              identifier1,
085                                              identifier2 ) );
086    
087        }
088    
089        //------------------------------------------------------------Constructors--
090        //--DependencyCycleException------------------------------------------------
091    
092        /**
093         * The implementations introducing a cycle.
094         * @serial
095         */
096        private Implementation[] implementations;
097    
098        /**
099         * Gets the implementation introducing a cycle.
100         *
101         * @return the implementations introducing a cycle.
102         */
103        public Implementation[] getImplementations()
104        {
105            return this.implementations;
106        }
107    
108        //------------------------------------------------DependencyCycleException--
109    }