KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > ResultSetMetaData


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.inspectors;
24
25 import org.hammurapi.InspectorBase;
26
27 import com.pavelvlasov.jsel.JselException;
28 import com.pavelvlasov.jsel.Parameter;
29 import com.pavelvlasov.jsel.VariableDefinition;
30 import com.pavelvlasov.jsel.expressions.Ident;
31 import com.pavelvlasov.review.SourceMarker;
32
33
34 /**
35  * ER-070
36  * ResultSetMetaData is banned. The disclosure of DB internals (here Column Names) on Business/Service layer is bad design
37  * @author Pavel Vlasov
38  * @version $Revision: 1.3 $
39  */

40 public class ResultSetMetaData extends InspectorBase {
41
42     /**
43      * The not allowed class
44      */

45     private static final String JavaDoc VIOLATION_CLASS = "java.sql.ResultSetMetaData";
46     
47     /**
48      * Reviews if the not allowed class is used.
49      *
50      * @param element the parameter to be reviewed.
51      */

52     public void visit(Parameter element) {
53         try {
54             String JavaDoc fcn =
55                 element.getTypeSpecification().getType().getName();
56             if (fcn!=null && VIOLATION_CLASS.equals(fcn)) {
57                 context.reportViolation((SourceMarker) element);
58             }
59         } catch (JselException e) {
60             context.warn((SourceMarker) element, e);
61         }
62     }
63     
64     /**
65      * Reviews if the not allowed class is used.
66      *
67      * @param element the variable definition to be reviewed
68      */

69     public void visit(VariableDefinition element) {
70         try {
71             String JavaDoc fcn = element.getTypeSpecification().getType().getName();
72             if (fcn!=null && VIOLATION_CLASS.equals(fcn)) {
73                 context.reportViolation((SourceMarker) element);
74             }
75         } catch (JselException e) {
76             context.warn((SourceMarker) element, e);
77         }
78     }
79     
80     /**
81      * Reviews if the not allowed class is used.
82      *
83      * @param element the identifier to be reviewed.
84      */

85     public void visit(Ident element) {
86         try {
87             Object JavaDoc obj = element.getProvider();
88             String JavaDoc fcn = null;
89             if (obj instanceof VariableDefinition) {
90                 fcn =
91                     ((VariableDefinition)obj).getTypeSpecification().getType().getName();
92             } else if (obj instanceof Parameter) {
93                 fcn =
94                     ((Parameter)obj).getTypeSpecification().getType().getName();
95             }
96             if (fcn!=null && VIOLATION_CLASS.compareTo(fcn)==0) {
97                 context.reportViolation((SourceMarker) element);
98             }
99         } catch (JselException e) {
100             context.warn((SourceMarker) element, e);
101         }
102     }
103     
104 }
105
Popular Tags