| 1 | /* |
| 2 | * jDTAUS Core API |
| 3 | * Copyright (C) 2005 Christian Schulte |
| 4 | * <cs@schulte.it> |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | package org.jdtaus.core.container; |
| 22 | |
| 23 | import java.util.Locale; |
| 24 | |
| 25 | /** |
| 26 | * Gets thrown for cyclic dependency graphs. |
| 27 | * |
| 28 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
| 29 | * @version $JDTAUS: DependencyCycleException.java 8743 2012-10-07 03:06:20Z schulte $ |
| 30 | */ |
| 31 | public class DependencyCycleException extends IllegalStateException |
| 32 | { |
| 33 | //--Constants--------------------------------------------------------------- |
| 34 | |
| 35 | /** Serial version UID for backwards compatibility with 1.5.x classes. */ |
| 36 | private static final long serialVersionUID = 8471828485552467121L; |
| 37 | |
| 38 | //---------------------------------------------------------------Constants-- |
| 39 | //--Constructors------------------------------------------------------------ |
| 40 | |
| 41 | /** |
| 42 | * Creates a new {@code DependencyCycleException} taking the involved |
| 43 | * implementations. |
| 44 | * |
| 45 | * @param impl1 the implementation the cycle was detected for. |
| 46 | * @param impl2 the implementation introducing the cycle to {@code impl1}. |
| 47 | * |
| 48 | * @throws NullPointerException if either {@code impl1} or {@code impl2} |
| 49 | * is {@code null}. |
| 50 | */ |
| 51 | public DependencyCycleException( final Implementation impl1, |
| 52 | final Implementation impl2 ) |
| 53 | { |
| 54 | super( DependencyCycleExceptionBundle.getInstance(). |
| 55 | getDependencyCycleMessage( Locale.getDefault(), |
| 56 | impl1.getIdentifier(), |
| 57 | impl2.getIdentifier() ) ); |
| 58 | |
| 59 | this.implementations = new Implementation[] |
| 60 | { |
| 61 | impl1, impl2 |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Creates a new {@code DependencyCycleException} taking identifiers of the |
| 67 | * involved implementations. |
| 68 | * |
| 69 | * @param identifier1 the identifier of the implementation the cycle was |
| 70 | * detected for. |
| 71 | * @param identifier2 the identifier of the implementation introducing the |
| 72 | * cycle. |
| 73 | * |
| 74 | * @throws NullPointerException if either {@code identifier1} or |
| 75 | * {@code identifier2} is {@code null}. |
| 76 | */ |
| 77 | public DependencyCycleException( final String identifier1, |
| 78 | final String identifier2 ) |
| 79 | { |
| 80 | super( DependencyCycleExceptionBundle.getInstance(). |
| 81 | getDependencyCycleMessage( Locale.getDefault(), |
| 82 | identifier1, |
| 83 | identifier2 ) ); |
| 84 | |
| 85 | this.implementations = null; |
| 86 | } |
| 87 | |
| 88 | //------------------------------------------------------------Constructors-- |
| 89 | //--DependencyCycleException------------------------------------------------ |
| 90 | |
| 91 | /** |
| 92 | * The implementations introducing a cycle. |
| 93 | * @serial |
| 94 | */ |
| 95 | private final Implementation[] implementations; |
| 96 | |
| 97 | /** |
| 98 | * Gets the implementation introducing a cycle. |
| 99 | * |
| 100 | * @return the implementations introducing a cycle. |
| 101 | */ |
| 102 | public Implementation[] getImplementations() |
| 103 | { |
| 104 | return this.implementations; |
| 105 | } |
| 106 | |
| 107 | //------------------------------------------------DependencyCycleException-- |
| 108 | } |