KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > InspectorBase


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23 package org.hammurapi;
24
25 import java.sql.SQLException JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.LinkedList JavaDoc;
29 import java.util.Properties JavaDoc;
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 /**
39  * @author Pavel Vlasov
40  * @version $Revision: 1.1 $
41  */

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 JavaDoc 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 JavaDoc getOrder() {
82         return getContext().getDescriptor().getOrder();
83     }
84
85     public String JavaDoc getConfigInfo() {
86         return null;
87     }
88     
89     /**
90      * Method from {@link com.pavelvlasov.util.DispatchingVisitor.Filter}
91      * interface. If inspector implements that interface it doesn't
92      * need to implement the method, but just provide apporve() methods.
93      * @see com.pavelvlasov.util.DispatchingVisitor.Filter#getTargets()
94      * @return Collection of targets to be filtered.
95      */

96     public Collection JavaDoc getTargets() {
97         return filterTargets;
98     }
99     
100     private Collection JavaDoc filterTargets=this instanceof Filter ? new LinkedList JavaDoc() : null;
101     
102     public void addTarget(Object JavaDoc target) {
103         if (this instanceof Filter && target!=null) {
104             filterTargets.add(target);
105         }
106     }
107     
108     /**
109      * Removes this inspector from invocation targets.
110      * Inspector shall invoke this method if it detects
111      * that it cannot continue functioning properly.
112      */

113     protected void disable(String JavaDoc 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 JavaDoc dbProperties) throws SQLException JavaDoc {
119         
120     }
121 }
122
Popular Tags