Source Code Cross Referenced for InspectorContextImpl.java in  » Code-Analyzer » hammurapi-3.20.0.3 » org » hammurapi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » hammurapi 3.20.0.3 » org.hammurapi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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;
024:
025:        import java.util.Collection;
026:        import java.util.Date;
027:        import java.util.HashSet;
028:        import java.util.Iterator;
029:        import java.util.Set;
030:
031:        import org.hammurapi.results.Annotation;
032:        import org.hammurapi.results.DetailedResults;
033:        import org.hammurapi.results.ResultsFactory;
034:
035:        import com.pavelvlasov.logging.Logger;
036:        import com.pavelvlasov.review.Signed;
037:        import com.pavelvlasov.review.SimpleSourceMarker;
038:        import com.pavelvlasov.review.SourceMarker;
039:        import com.pavelvlasov.util.VisitorStackSource;
040:
041:        /**
042:         * @author Pavel Vlasov
043:         * @version $Revision: 1.7 $
044:         */
045:        public class InspectorContextImpl extends InspectorContextBase {
046:
047:            private Collection violationFilters;
048:
049:            /**
050:             * @param descriptor
051:             * @param logger
052:             * @param visitorStackSource
053:             */
054:            public InspectorContextImpl(InspectorDescriptor descriptor,
055:                    Logger logger, VisitorStackSource visitorStackSource,
056:                    SessionImpl session, Collection violationFilters) {
057:                super (descriptor, logger, visitorStackSource, session);
058:                this .violationFilters = violationFilters;
059:            }
060:
061:            /**
062:             * 
063:             * @param source
064:             * @param message
065:             */
066:            public void reportViolation(final SourceMarker source,
067:                    final String message) {
068:                try {
069:                    final DetailedResults threadResults = ResultsFactory
070:                            .getThreadResults();
071:                    final SourceMarker detachedSource = detach(source);
072:
073:                    ResultsFactory.getInstance().execute(
074:                            new ResultsFactory.Task() {
075:
076:                                public void execute() throws HammurapiException {
077:                                    SimpleViolation violation = new SimpleViolation(
078:                                            detachedSource, message, descriptor);
079:
080:                                    Iterator filterIterator = violationFilters == null ? null
081:                                            : violationFilters.iterator();
082:                                    while (filterIterator != null
083:                                            && filterIterator.hasNext()) {
084:                                        if (!((ViolationFilter) filterIterator
085:                                                .next()).accept(violation)) {
086:                                            return;
087:                                        }
088:                                    }
089:
090:                                    threadResults.addViolation(violation);
091:                                }
092:
093:                            });
094:                } catch (HammurapiException e) {
095:                    warn(source, e);
096:                }
097:            }
098:
099:            public void annotate(Annotation annotation) {
100:                ResultsFactory.getThreadResults().addAnnotation(annotation);
101:            }
102:
103:            public void addMetric(SourceMarker source, String name, double value) {
104:                ResultsFactory.getThreadResults().addMetric(detach(source),
105:                        name, value);
106:            }
107:
108:            /**
109:             * Report warning
110:             * @param source
111:             * @param message
112:             */
113:            public void warn(SourceMarker source, String message) {
114:                Violation violation = new SimpleViolation(source == null ? null
115:                        : new SimpleSourceMarker(source), message, descriptor);
116:                ResultsFactory.getThreadResults().addWarning(violation);
117:                if (source == null) {
118:                    System.err.println("WARNING: " + message);
119:                } else {
120:                    System.err.println("WARNING at " + source.getSourceURL()
121:                            + " " + source.getLine() + ":" + source.getColumn()
122:                            + " : " + message);
123:                }
124:            }
125:
126:            /**
127:             * Report warning
128:             * @param source
129:             */
130:            public void warn(SourceMarker source, Throwable th) {
131:                Violation violation = new SimpleViolation(detach(source), th
132:                        .toString(), descriptor);
133:                ResultsFactory.getThreadResults().addWarning(violation);
134:                // TODO better warning handling here
135:                if (source == null) {
136:                    System.err.println("WARNING: " + th);
137:                } else {
138:                    System.err.println("WARNING at " + source.getSourceURL()
139:                            + " " + source.getLine() + ":" + source.getColumn()
140:                            + " : " + th);
141:                }
142:                th.printStackTrace();
143:            }
144:
145:            /**
146:             * Creates a waiver for inspector with a given key
147:             * @param inspectorKey 
148:             */
149:            public void waive(Signed signed, final String inspectorKey) {
150:                final String iName = descriptor
151:                        .getWaivedInspectorName(inspectorKey);
152:                if (iName == null) {
153:                    warn(signed instanceof  SourceMarker ? (SourceMarker) signed
154:                            : null, descriptor.getName()
155:                            + ": Inspector with key '" + inspectorKey
156:                            + "' not found.");
157:                } else {
158:                    final String signature = signed == null ? null : signed
159:                            .getSignature();
160:                    final Set signatures = new HashSet();
161:                    if (signature != null) {
162:                        signatures.add(signature);
163:                    }
164:
165:                    if (logger != null) {
166:                        logger.debug(this , "Inspector "
167:                                + getDescriptor().getName() + " autowaives "
168:                                + iName + " at " + signature);
169:                    }
170:
171:                    final Waiver waiver = new Waiver() {
172:                        boolean active = true;
173:
174:                        public String getInspectorName() {
175:                            return iName;
176:                        }
177:
178:                        public boolean waive(Violation violation, boolean peek) {
179:                            if (iName.equals(violation.getDescriptor()
180:                                    .getName())) {
181:                                if (signature == null) {
182:                                    return true;
183:                                }
184:
185:                                if (violation.getSource() instanceof  Signed
186:                                        && signature.equals(((Signed) violation
187:                                                .getSource()).getSignature())) {
188:                                    if (!peek) {
189:                                        active = false;
190:                                    }
191:                                    return true;
192:                                }
193:                            }
194:                            return false;
195:                        }
196:
197:                        public Date getExpirationDate() {
198:                            return null;
199:                        }
200:
201:                        public String getReason() {
202:                            return descriptor.getWaiveReason(inspectorKey);
203:                        }
204:
205:                        public boolean isActive() {
206:                            return active;
207:                        }
208:
209:                        public Collection getSignatures() {
210:                            return signatures;
211:                        }
212:                    };
213:
214:                    final DetailedResults threadResults = ResultsFactory
215:                            .getThreadResults();
216:                    try {
217:                        ResultsFactory.getInstance().execute(
218:                                new ResultsFactory.Task() {
219:
220:                                    public void execute() {
221:                                        threadResults.getWaiverSet().addWaiver(
222:                                                waiver, date);
223:                                    }
224:
225:                                });
226:                    } catch (HammurapiException e) {
227:                        throw new HammurapiRuntimeException(e);
228:                    }
229:                }
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.