KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package org.hammurapi.results.persistent.jdbc;
25
26 import java.sql.SQLException JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Date JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
32
33 import org.hammurapi.HammurapiException;
34 import org.hammurapi.Violation;
35 import org.hammurapi.Waiver;
36 import org.hammurapi.WaiverEntry;
37 import org.hammurapi.WaiverSet;
38 import org.hammurapi.results.persistent.jdbc.sql.WaivedViolationJoined;
39
40 import com.pavelvlasov.convert.Converter;
41 import com.pavelvlasov.review.Signed;
42
43 /**
44  *
45  * @author Pavel Vlasov
46  * @version $Revision: 1.9 $
47  */

48 public class DetailedResults extends NamedResults implements org.hammurapi.results.DetailedResults {
49         
50     /**
51      * @param id
52      * @param factory
53      * @throws SQLException
54      */

55     public DetailedResults(int id, ResultsFactory factory) throws SQLException JavaDoc {
56         super(id, factory);
57     }
58     
59     DetailedResults(String JavaDoc name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException JavaDoc {
60         super(name, waiverSet, factory);
61     }
62     
63     public Waiver addViolation(final Violation violation) throws HammurapiException {
64         final Waiver waiver=super.addViolation(violation);
65         if (waiver!=null) {
66             insertViolation(
67                     violation,
68                     WAIVED_VIOLATION,
69                     new ViolationConfigurator() {
70                         public void setViolationInfo(org.hammurapi.results.persistent.jdbc.sql.Violation sqlViolation) {
71                             String JavaDoc reason = waiver.getReason();
72                             if (reason!=null) {
73                                 sqlViolation.setWaiverReason(new Integer JavaDoc(factory.addMessage(reason)));
74                             }
75                             
76                             Date JavaDoc expirationDate = waiver.getExpirationDate();
77                             if (expirationDate!=null) {
78                                 sqlViolation.setWaiverExpires(new java.sql.Date JavaDoc(expirationDate.getTime()));
79                             }
80                         }
81             });
82         }
83         return waiver;
84     }
85         
86     public Collection JavaDoc getViolations() {
87         return factory.getResultsEngine().getViolationJoined(getId(), violationConverter);
88     }
89         
90     private Converter waivedViolationConverter=new Converter() {
91         public Object JavaDoc convert(Object JavaDoc o) {
92             final WaivedViolationJoined wvj=(WaivedViolationJoined) o;
93             final Violation violation=(Violation) violationConverter.convert(o);
94             
95             final Set JavaDoc signatures=new HashSet JavaDoc();
96             final String JavaDoc signature=wvj.getSignature();
97             if (signature!=null) {
98                 StringTokenizer JavaDoc st=new StringTokenizer JavaDoc(signature,"|");
99                 while (st.hasMoreTokens()) {
100                     signatures.add(st.nextToken());
101                 }
102             }
103             Date JavaDoc waiverExpires = wvj.getWaiverExpires();
104             final java.util.Date JavaDoc expirationDate = waiverExpires==null ? null : new Date JavaDoc(waiverExpires.getTime());
105             
106             return new WaiverEntry() {
107
108                 /**
109                  * Comment for <code>serialVersionUID</code>
110                  */

111                 private static final long serialVersionUID = -5416258427336694577L;
112
113                 public Waiver getWaiver() {
114                     return new Waiver() {
115                         public String JavaDoc getInspectorName() {
116                             return violation.getDescriptor().getName();
117                         }
118
119                         public java.util.Date JavaDoc getExpirationDate() {
120                             return expirationDate;
121                         }
122
123                         public String JavaDoc getReason() {
124                             return wvj.getWaiverReason();
125                         }
126
127                         public boolean waive(Violation v, boolean peek) {
128                             if (violation.getDescriptor().getName().equals(v.getDescriptor().getName())) {
129                                 if (signature==null) {
130                                     return true;
131                                 }
132                                 
133                                 String JavaDoc vSignature = ((Signed) violation.getSource()).getSignature();
134                                 if (violation.getSource() instanceof Signed && signatures.contains(vSignature)) {
135                                     if (!peek) {
136                                         signatures.remove(vSignature);
137                                     }
138                                     return true;
139                                 }
140                             }
141                             return false;
142                         }
143
144                         public boolean isActive() {
145                             return !signatures.isEmpty();
146                         }
147
148                         public Collection JavaDoc getSignatures() {
149                             return signatures;
150                         }
151                     };
152                 }
153
154                 public Violation getViolation() {
155                     return violation;
156                 }
157             };
158         }
159     };
160     
161     public Collection JavaDoc getWaivedViolations() {
162         return factory.getResultsEngine().getWaivedViolationJoined(getId(), waivedViolationConverter);
163     }
164 }
165
Popular Tags