KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > AmbiguousComponentResolutionException


1 /*****************************************************************************
2  * Copyright (c) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant *
9  *****************************************************************************/

10 package org.picocontainer.defaults;
11
12 import org.picocontainer.PicoIntrospectionException;
13
14 import java.util.Arrays JavaDoc;
15
16 /**
17  * Exception that is thrown as part of the introspection. Raised if a PicoContainer cannot resolve a
18  * type dependency because the registered {@link org.picocontainer.ComponentAdapter}s are not
19  * distinct.
20  *
21  * @author Paul Hammant
22  * @author Aslak Hellesøy
23  * @author Jon Tirsén
24  * @since 1.0
25  */

26 public class AmbiguousComponentResolutionException extends PicoIntrospectionException {
27     private Class JavaDoc component;
28     private Class JavaDoc ambiguousDependency;
29     private final Object JavaDoc[] ambiguousComponentKeys;
30
31
32     /**
33      * Construct a new exception with the ambigous class type and the ambiguous component keys.
34      *
35      * @param ambiguousDependency the unresolved dependency type
36      * @param componentKeys the ambiguous keys.
37      */

38     public AmbiguousComponentResolutionException(Class JavaDoc ambiguousDependency, Object JavaDoc[] componentKeys) {
39         super("");
40         this.ambiguousDependency = ambiguousDependency;
41         this.ambiguousComponentKeys = new Class JavaDoc[componentKeys.length];
42         for (int i = 0; i < componentKeys.length; i++) {
43             ambiguousComponentKeys[i] = componentKeys[i];
44         }
45     }
46
47     /**
48      * @return Returns a string containing the unresolved class type and the ambiguous keys.
49      */

50     public String JavaDoc getMessage() {
51         StringBuffer JavaDoc msg = new StringBuffer JavaDoc();
52         msg.append(component);
53         msg.append(" has ambiguous dependency on ");
54         msg.append(ambiguousDependency);
55         msg.append(", ");
56         msg.append("resolves to multiple classes: ");
57         msg.append(Arrays.asList(getAmbiguousComponentKeys()));
58         return msg.toString();
59     }
60
61     /**
62      * @return Returns the ambiguous component keys as array.
63      */

64     public Object JavaDoc[] getAmbiguousComponentKeys() {
65         return ambiguousComponentKeys;
66     }
67
68     public void setComponent(Class JavaDoc component) {
69         this.component = component;
70     }
71 }
72
Popular Tags