1 23 package org.hammurapi; 24 25 import java.sql.SQLException ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.LinkedList ; 29 import java.util.Properties ; 30 31 import com.pavelvlasov.jsel.statements.CompoundStatement; 32 import com.pavelvlasov.jsel.statements.EmptyStatement; 33 import com.pavelvlasov.jsel.statements.Statement; 34 import com.pavelvlasov.sql.SQLProcessor; 35 import com.pavelvlasov.util.OrderedTarget; 36 import com.pavelvlasov.util.DispatchingVisitor.Filter; 37 38 42 public class InspectorBase implements Inspector, OrderedTarget { 43 protected InspectorContext context; 44 45 public void setContext(InspectorContext context) { 46 this.context=context; 47 } 48 49 public void unSetContext() { 50 context=null; 51 } 52 53 public InspectorContext getContext() { 54 return context; 55 } 56 57 public static boolean isEmpty(Statement statement) { 58 if (statement==null) { 59 return true; 60 } if (statement instanceof EmptyStatement) { 61 return true; 62 } else if (statement instanceof CompoundStatement) { 63 Iterator it=((CompoundStatement) statement).getStatements().iterator(); 64 while (it.hasNext()) { 65 if (!isEmpty((Statement) it.next())) { 66 return false; 67 } 68 } 69 return true; 70 } else { 71 return false; 72 } 73 } 74 75 public void init() throws HammurapiException { 76 } 77 78 public void destroy() { 79 } 80 81 public Integer getOrder() { 82 return getContext().getDescriptor().getOrder(); 83 } 84 85 public String getConfigInfo() { 86 return null; 87 } 88 89 96 public Collection getTargets() { 97 return filterTargets; 98 } 99 100 private Collection filterTargets=this instanceof Filter ? new LinkedList () : null; 101 102 public void addTarget(Object target) { 103 if (this instanceof Filter && target!=null) { 104 filterTargets.add(target); 105 } 106 } 107 108 113 protected void disable(String message) { 114 getContext().getSession().disable(this); 115 getContext().warn(null, "Inspector "+getContext().getDescriptor().getName()+" disabled itself with message '"+message+"'"); 116 } 117 118 public void initDb(SQLProcessor processor, Properties dbProperties) throws SQLException { 119 120 } 121 } 122 | Popular Tags |