1 21 22 package org.apache.derby.iapi.services.diag; 23 24 43 44 public class DiagnosticUtil 45 { 46 47 private DiagnosticUtil() 48 { 49 } 50 51 52 53 70 public static Diagnosticable findDiagnostic(Object ref) 71 { 72 Class refClass = ref.getClass(); 73 74 for (;;) { 75 try 76 { 77 String className = refClass.getName(); 78 int lastDot = className.lastIndexOf('.') + 1; 79 String diagClassName = 80 className.substring(0, lastDot) + 81 "D_" + className.substring(lastDot); 82 83 Class diagClass; 84 85 try { 86 diagClass = Class.forName(diagClassName); 87 } catch (ClassNotFoundException cnfe) { 88 89 refClass = refClass.getSuperclass(); 91 if (refClass == null) 92 return null; 93 94 continue; 95 } 96 97 98 Diagnosticable diag_obj = (Diagnosticable) diagClass.newInstance(); 99 100 diag_obj.init(ref); 101 102 return diag_obj; 103 } 104 catch (Exception e) 105 { 106 return null; 107 } 108 } 109 } 110 111 128 public static String toDiagString(Object obj) 129 { 130 String ret_string = null; 131 132 if (obj == null) return "null"; 133 134 try 135 { 136 Diagnosticable diag = DiagnosticUtil.findDiagnostic(obj); 137 if (diag != null) 138 ret_string = diag.diag(); 139 } 140 catch (Throwable t) 141 { 142 } 144 145 if (ret_string == null) 146 { 147 ret_string = obj.toString(); 148 } 149 150 return(ret_string); 151 } 152 153 154 155 } 156 | Popular Tags |