KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > monitors > AbstractComponentMonitor


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  * Original code by Paul Hammaant *
9  *****************************************************************************/

10
11 package org.picocontainer.monitors;
12
13 import java.text.MessageFormat JavaDoc;
14 import java.lang.reflect.Constructor JavaDoc;
15 import java.lang.reflect.Method JavaDoc;
16
17 import org.picocontainer.ComponentMonitor;
18
19 /**
20  * An abstract {@link ComponentMonitor} which supports all the message formats.
21  *
22  * @author Mauro Talevi
23  * @version $Revision: $
24  */

25 public abstract class AbstractComponentMonitor implements ComponentMonitor {
26
27     public final static String JavaDoc INSTANTIATING = "PicoContainer: instantiating {0}";
28     public final static String JavaDoc INSTANTIATED = "PicoContainer: instantiated {0} [{1} ms]";
29     public final static String JavaDoc INSTANTIATED2 = "PicoContainer: instantiated {0} [{1} ms], component {2}, injected [{3}]";
30     public final static String JavaDoc INSTANTIATION_FAILED = "PicoContainer: instantiation failed: {0}, reason: {1}";
31     public final static String JavaDoc INVOKING = "PicoContainer: invoking {0} on {1}";
32     public final static String JavaDoc INVOKED = "PicoContainer: invoked {0} on {1} [{2} ms]";
33     public final static String JavaDoc INVOCATION_FAILED = "PicoContainer: invocation failed: {0} on {1}, reason: {2}";
34     public final static String JavaDoc LIFECYCLE_INVOCATION_FAILED = "PicoContainer: lifecycle invocation failed: {0} on {1}, reason: {2}";
35
36     public static String JavaDoc format(String JavaDoc template, Object JavaDoc[] arguments) {
37         return MessageFormat.format(template, arguments);
38     }
39
40     public static String JavaDoc toString(Object JavaDoc[] injected) {
41         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
42         for (int i = 0; i < injected.length; i++) {
43             String JavaDoc s = injected[i].getClass().getName();
44             sb.append(s);
45             if (i < injected.length-1) {
46                 sb.append(", ");
47             }
48         }
49         return sb.toString();
50     }
51
52     public static String JavaDoc toString(Constructor JavaDoc constructor) {
53         Class JavaDoc[] params = constructor.getParameterTypes();
54         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(constructor.getName());
55         sb.append("(");
56         for (int i = 0; i < params.length; i++) {
57             String JavaDoc s = params[i].getName();
58             sb.append(s);
59             if (i < params.length-1) {
60                 sb.append(", ");
61             }
62         }
63         sb.append(")");
64         return sb.toString();
65     }
66
67     public static String JavaDoc toString(Method JavaDoc method) {
68         Class JavaDoc[] params = method.getParameterTypes();
69         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(method.getName());
70         sb.append("(");
71         for (int i = 0; i < params.length; i++) {
72             String JavaDoc s = params[i].getName();
73             sb.append(s);
74             if (i < params.length-1) {
75                 sb.append(", ");
76             }
77         }
78         sb.append(")");
79         return sb.toString();
80     }
81
82
83 }
84
Popular Tags