1 10 11 package org.picocontainer.monitors; 12 13 import java.text.MessageFormat ; 14 import java.lang.reflect.Constructor ; 15 import java.lang.reflect.Method ; 16 17 import org.picocontainer.ComponentMonitor; 18 19 25 public abstract class AbstractComponentMonitor implements ComponentMonitor { 26 27 public final static String INSTANTIATING = "PicoContainer: instantiating {0}"; 28 public final static String INSTANTIATED = "PicoContainer: instantiated {0} [{1} ms]"; 29 public final static String INSTANTIATED2 = "PicoContainer: instantiated {0} [{1} ms], component {2}, injected [{3}]"; 30 public final static String INSTANTIATION_FAILED = "PicoContainer: instantiation failed: {0}, reason: {1}"; 31 public final static String INVOKING = "PicoContainer: invoking {0} on {1}"; 32 public final static String INVOKED = "PicoContainer: invoked {0} on {1} [{2} ms]"; 33 public final static String INVOCATION_FAILED = "PicoContainer: invocation failed: {0} on {1}, reason: {2}"; 34 public final static String LIFECYCLE_INVOCATION_FAILED = "PicoContainer: lifecycle invocation failed: {0} on {1}, reason: {2}"; 35 36 public static String format(String template, Object [] arguments) { 37 return MessageFormat.format(template, arguments); 38 } 39 40 public static String toString(Object [] injected) { 41 StringBuffer sb = new StringBuffer (); 42 for (int i = 0; i < injected.length; i++) { 43 String 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 toString(Constructor constructor) { 53 Class [] params = constructor.getParameterTypes(); 54 StringBuffer sb = new StringBuffer (constructor.getName()); 55 sb.append("("); 56 for (int i = 0; i < params.length; i++) { 57 String 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 toString(Method method) { 68 Class [] params = method.getParameterTypes(); 69 StringBuffer sb = new StringBuffer (method.getName()); 70 sb.append("("); 71 for (int i = 0; i < params.length; i++) { 72 String 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 |