KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > results > persistent > jdbc > BaselineSetupViolationFilter


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.results.persistent.jdbc;
24
25 import java.sql.SQLException JavaDoc;
26
27 import org.hammurapi.HammurapiException;
28 import org.hammurapi.Violation;
29 import org.hammurapi.ViolationFilter;
30 import org.hammurapi.results.persistent.jdbc.sql.BaselineViolationImpl;
31 import org.hammurapi.results.persistent.jdbc.sql.ResultsEngine;
32
33 import com.pavelvlasov.config.Component;
34 import com.pavelvlasov.config.ConfigurationException;
35 import com.pavelvlasov.review.Signed;
36
37 /**
38  * @author Pavel Vlasov
39  * @revision $Revision$
40  */

41 public class BaselineSetupViolationFilter implements ViolationFilter, Component {
42
43     private String JavaDoc reportName;
44     private ResultsEngine resultsEngine;
45
46     public boolean accept(Violation violation) throws HammurapiException {
47         if (violation.getDescriptor()!=null && violation.getSource() instanceof Signed)
48             try {
49                     BaselineViolationImpl bv=new BaselineViolationImpl(true);
50                     bv.setInspector(violation.getDescriptor().getName());
51                     String JavaDoc signature = ((Signed) violation.getSource()).getSignature();
52                     if (signature!=null) {
53                         bv.setSignature(signature);
54                         bv.setReportName(reportName);
55                         resultsEngine.insertBaselineViolation(bv);
56                         return false;
57                     }
58             } catch (SQLException JavaDoc e) {
59                 throw new HammurapiException("Cannot store baseline violation", e);
60             }
61         return true;
62     }
63
64     public void start() throws ConfigurationException {
65         ResultsFactory resultsFactory = ((ResultsFactory) org.hammurapi.results.ResultsFactory.getInstance());
66         try {
67             reportName = resultsFactory.getName();
68             resultsEngine = resultsFactory.getResultsEngine();
69             resultsEngine.deleteBaseline(reportName);
70         } catch (SQLException JavaDoc e) {
71             throw new ConfigurationException("Cannot delete old baseline", e);
72         }
73     }
74
75     public void stop() throws ConfigurationException {
76         // Nothing to do.
77
}
78
79     public void setOwner(Object JavaDoc owner) {
80         // Ignore
81
}
82
83 }
84
Popular Tags