001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi.inspectors;
024:
025: import org.hammurapi.InspectorBase;
026:
027: import com.pavelvlasov.jsel.JselException;
028: import com.pavelvlasov.jsel.Parameter;
029: import com.pavelvlasov.jsel.VariableDefinition;
030: import com.pavelvlasov.jsel.expressions.Ident;
031: import com.pavelvlasov.review.SourceMarker;
032:
033: /**
034: * ER-070
035: * ResultSetMetaData is banned. The disclosure of DB internals (here Column Names) on Business/Service layer is bad design
036: * @author Pavel Vlasov
037: * @version $Revision: 1.3 $
038: */
039: public class ResultSetMetaData extends InspectorBase {
040:
041: /**
042: * The not allowed class
043: */
044: private static final String VIOLATION_CLASS = "java.sql.ResultSetMetaData";
045:
046: /**
047: * Reviews if the not allowed class is used.
048: *
049: * @param element the parameter to be reviewed.
050: */
051: public void visit(Parameter element) {
052: try {
053: String fcn = element.getTypeSpecification().getType()
054: .getName();
055: if (fcn != null && VIOLATION_CLASS.equals(fcn)) {
056: context.reportViolation((SourceMarker) element);
057: }
058: } catch (JselException e) {
059: context.warn((SourceMarker) element, e);
060: }
061: }
062:
063: /**
064: * Reviews if the not allowed class is used.
065: *
066: * @param element the variable definition to be reviewed
067: */
068: public void visit(VariableDefinition element) {
069: try {
070: String fcn = element.getTypeSpecification().getType()
071: .getName();
072: if (fcn != null && VIOLATION_CLASS.equals(fcn)) {
073: context.reportViolation((SourceMarker) element);
074: }
075: } catch (JselException e) {
076: context.warn((SourceMarker) element, e);
077: }
078: }
079:
080: /**
081: * Reviews if the not allowed class is used.
082: *
083: * @param element the identifier to be reviewed.
084: */
085: public void visit(Ident element) {
086: try {
087: Object obj = element.getProvider();
088: String fcn = null;
089: if (obj instanceof VariableDefinition) {
090: fcn = ((VariableDefinition) obj).getTypeSpecification()
091: .getType().getName();
092: } else if (obj instanceof Parameter) {
093: fcn = ((Parameter) obj).getTypeSpecification()
094: .getType().getName();
095: }
096: if (fcn != null && VIOLATION_CLASS.compareTo(fcn) == 0) {
097: context.reportViolation((SourceMarker) element);
098: }
099: } catch (JselException e) {
100: context.warn((SourceMarker) element, e);
101: }
102: }
103:
104: }
|