1 21 package com.db4o.inside.diagnostic; 22 23 import com.db4o.*; 24 import com.db4o.diagnostic.*; 25 import com.db4o.foundation.*; 26 import com.db4o.query.*; 27 28 33 public class DiagnosticProcessor implements DiagnosticConfiguration, DeepClone{ 34 35 private Collection4 _listeners; 36 37 public DiagnosticProcessor() { 38 } 39 40 private DiagnosticProcessor(Collection4 listeners) { 41 _listeners = listeners; 42 } 43 44 public void addListener(DiagnosticListener listener) { 45 if(_listeners == null){ 46 _listeners = new Collection4(); 47 } 48 _listeners.add(listener); 49 } 50 51 public void checkClassHasFields(YapClass yc){ 52 YapField[] fields = yc.i_fields; 53 if(fields != null && fields.length == 0){ 54 String name = yc.getName(); 55 String [] ignoredPackages = new String []{ 56 "java.util." 57 }; 58 for (int i = 0; i < ignoredPackages.length; i++) { 59 if (name.indexOf(ignoredPackages[i]) == 0){ 60 return; 61 } 62 } 63 if(isDb4oClass(yc)){ 64 return; 65 } 66 onDiagnostic(new ClassHasNoFields(name)); 67 } 68 } 69 70 public void checkUpdateDepth(int depth) { 71 if (depth > 1) { 72 onDiagnostic(new UpdateDepthGreaterOne(depth)); 73 } 74 } 75 76 public Object deepClone(Object context) { 77 return new DiagnosticProcessor(cloneListeners()); 78 } 79 80 private Collection4 cloneListeners() { 81 return _listeners != null 82 ? new Collection4(_listeners) 83 : null; 84 } 85 86 public boolean enabled(){ 87 return _listeners != null; 88 } 89 90 private boolean isDb4oClass(YapClass yc){ 91 return Platform4.isDb4oClass(yc.getName()); 92 } 93 94 public void loadedFromClassIndex(YapClass yc) { 95 if(isDb4oClass(yc)){ 96 return; 97 } 98 onDiagnostic(new LoadedFromClassIndex(yc.getName())); 99 } 100 101 public void descendIntoTranslator(YapClass parent,String fieldName) { 102 onDiagnostic(new DescendIntoTranslator(parent.getName(),fieldName)); 103 } 104 105 public void nativeQueryUnoptimized(Predicate predicate) { 106 onDiagnostic(new NativeQueryNotOptimized(predicate)); 107 } 108 109 private void onDiagnostic(Diagnostic d) { 110 if(_listeners == null){ 111 return; 112 } 113 Iterator4 i = _listeners.iterator(); 114 while(i.moveNext()){ 115 ((DiagnosticListener)i.current()).onDiagnostic(d); 116 } 117 } 118 119 public void removeAllListeners() { 120 _listeners = null; 121 } 122 } 123 | Popular Tags |