Source Code Cross Referenced for InspectorContextBase.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.lang.reflect.InvocationHandler;
026:        import java.lang.reflect.Method;
027:        import java.lang.reflect.Proxy;
028:        import java.text.MessageFormat;
029:        import java.util.Date;
030:        import java.util.HashMap;
031:        import java.util.List;
032:        import java.util.Map;
033:
034:        import com.pavelvlasov.jsel.CompilationUnit;
035:        import com.pavelvlasov.jsel.Package;
036:        import com.pavelvlasov.logging.Logger;
037:        import com.pavelvlasov.review.SourceMarker;
038:        import com.pavelvlasov.util.VisitorStack;
039:        import com.pavelvlasov.util.VisitorStackSource;
040:        import com.pavelvlasov.wrap.WrapperHandler;
041:
042:        /**
043:         * @author Pavel Vlasov	
044:         * @version $Revision: 1.7 $
045:         */
046:        public abstract class InspectorContextBase implements  InspectorContext {
047:            protected InspectorDescriptor descriptor;
048:            public final static String GENERIC_MESSAGE = "SimpleViolation. Message not found";
049:            protected Logger logger;
050:            private VisitorStackSource visitorStackSource;
051:            private SessionImpl session;
052:
053:            public InspectorDescriptor getDescriptor() {
054:                return descriptor;
055:            }
056:
057:            /**
058:             * Reports violation with a message from descriptor
059:             * @param source
060:             */
061:            public void reportViolation(SourceMarker source) {
062:                reportViolation(source, descriptor.getMessage());
063:            }
064:
065:            /**
066:             * Reports violation with a message from descriptor
067:             * @param source
068:             */
069:            public void reportViolationEx(SourceMarker source, String messageKey) {
070:                reportViolation(source, descriptor.getMessage(messageKey));
071:            }
072:
073:            /**
074:             * @param source
075:             */
076:            public SourceMarker detach(final SourceMarker source) {
077:                if (source == null) {
078:                    return null;
079:                }
080:
081:                Class sourceClass = source.getClass();
082:                // TODO - real detach through findBySignature
083:                final String[] sourceUrl = { source.getSourceURL() };
084:                List stack = getVisitorStack().getStack(CompilationUnit.class);
085:                if (!stack.isEmpty()) {
086:                    CompilationUnit cu = (CompilationUnit) stack.get(0);
087:                    Package pkg = cu.getPackage();
088:                    if (pkg.getName().length() == 0) {
089:                        sourceUrl[0] = cu.getName();
090:                    } else {
091:                        sourceUrl[0] = pkg.getName().replace('.', '/') + '/'
092:                                + cu.getName();
093:                    }
094:                }
095:
096:                return (SourceMarker) Proxy.newProxyInstance(sourceClass
097:                        .getClassLoader(), WrapperHandler
098:                        .getClassInterfaces(sourceClass),
099:                        new InvocationHandler() {
100:
101:                            public Object invoke(Object proxy, Method method,
102:                                    Object[] args) throws Throwable {
103:                                if (SourceMarker.class.getMethod(
104:                                        "getSourceURL", null).equals(method)) {
105:                                    return sourceUrl[0];
106:                                }
107:
108:                                return method.invoke(source, args);
109:                            }
110:
111:                        });
112:            }
113:
114:            /**
115:             * Formats message taken from InspectorDescriptor with parameters.
116:             * @param source
117:             * @param params
118:             */
119:            public void reportViolation(SourceMarker source, Object[] params) {
120:                String message = descriptor.getMessage();
121:                if (message == null) {
122:                    warn(source, "Message not found for inspector "
123:                            + getDescriptor().getName());
124:                    message = GENERIC_MESSAGE;
125:                }
126:                reportViolation(source, MessageFormat.format(message, params));
127:            }
128:
129:            /**
130:             * Formats message taken from InspectorDescriptor with parameters.
131:             * @param source
132:             * @param params
133:             */
134:            public void reportViolationEx(SourceMarker source, Object[] params,
135:                    String messageKey) {
136:                String message = descriptor.getMessage(messageKey);
137:                if (message == null) {
138:                    warn(source, "Message with key '" + messageKey
139:                            + "' not found for inspector "
140:                            + getDescriptor().getName());
141:                    message = GENERIC_MESSAGE;
142:                }
143:                reportViolation(source, MessageFormat.format(message
144:                        + " for key '" + messageKey + "'", params));
145:            }
146:
147:            /**
148:             * @param descriptor
149:             * @param session
150:             */
151:            public InspectorContextBase(InspectorDescriptor descriptor,
152:                    Logger logger, VisitorStackSource visitorStackSource,
153:                    SessionImpl session) {
154:                super ();
155:                this .descriptor = descriptor;
156:                this .logger = logger;
157:                this .visitorStackSource = visitorStackSource;
158:                this .session = session;
159:                if (session != null) {
160:                    session.addContext(descriptor.getName(), this );
161:                }
162:            }
163:
164:            /**
165:             * Outputs a message to the log
166:             * @param source
167:             * @param message
168:             */
169:            public void info(SourceMarker source, String message) {
170:                if (logger != null) {
171:                    logger.info(this , loggerMessage(source, message));
172:                }
173:            }
174:
175:            /**
176:             * Outputs a message to the log
177:             * @param source
178:             * @param message
179:             */
180:            public void debug(SourceMarker source, String message) {
181:                if (logger != null) {
182:                    logger.debug(this , loggerMessage(source, message));
183:                }
184:            }
185:
186:            /**
187:             * Outputs a message to the log
188:             * @param source
189:             * @param message
190:             */
191:            public void verbose(SourceMarker source, String message) {
192:                if (logger != null) {
193:                    logger.verbose(this , loggerMessage(source, message));
194:                }
195:            }
196:
197:            /**
198:             * @param source
199:             * @param message
200:             * @return formatted message
201:             */
202:            private String loggerMessage(SourceMarker source, String message) {
203:                return descriptor.getName() + " " + source.getSourceURL() + " "
204:                        + source.getLine() + ":" + source.getColumn() + " - "
205:                        + message;
206:            }
207:
208:            protected static final Date date = new Date();
209:
210:            public VisitorStack getVisitorStack() {
211:                return visitorStackSource == null ? null : visitorStackSource
212:                        .getVisitorStack();
213:            }
214:
215:            private Map attributes = new HashMap();
216:
217:            public void setAttribute(Object key, Object value) {
218:                attributes.put(key, value);
219:            }
220:
221:            public Object getAttribute(Object key) {
222:                return attributes.get(key);
223:            }
224:
225:            public Object removeAttribute(Object key) {
226:                return attributes.remove(key);
227:            }
228:
229:            public Session getSession() {
230:                return session;
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.