Source Code Cross Referenced for XmlReportingListener.java in  » Code-Analyzer » macker » net » innig » macker » event » 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 » macker » net.innig.macker.event 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.innig.macker.event;
002:
003:        import net.innig.macker.rule.RuleSet;
004:        import net.innig.macker.structure.ClassInfo;
005:
006:        import java.io.File;
007:        import java.io.FileOutputStream;
008:        import java.io.OutputStreamWriter;
009:        import java.io.BufferedWriter;
010:        import java.io.Writer;
011:        import java.io.IOException;
012:        import java.util.LinkedList;
013:        import java.util.Iterator;
014:
015:        import org.jdom.Document;
016:        import org.jdom.Element;
017:        import org.jdom.output.XMLOutputter;
018:
019:        import org.apache.commons.lang.StringUtils;
020:
021:        public class XmlReportingListener implements  MackerEventListener {
022:            private Writer out;
023:            private String encoding;
024:
025:            private Document document;
026:            private Element curElem;
027:            private LinkedList elemStack;
028:
029:            public XmlReportingListener(File outFile) throws ListenerException {
030:                try {
031:                    if (outFile.exists())
032:                        outFile.delete();
033:                    OutputStreamWriter out = new OutputStreamWriter(
034:                            new FileOutputStream(outFile), "UTF-8");
035:                    BufferedWriter bufferedOut = new BufferedWriter(out);
036:                    init(bufferedOut, "UTF-8");
037:                } catch (IOException ioe) {
038:                    throw new ListenerException(this ,
039:                            "Unable to remove and re-create report file \""
040:                                    + outFile + "\"", ioe);
041:                }
042:            }
043:
044:            public XmlReportingListener(Writer out, String encoding)
045:                    throws ListenerException {
046:                init(out, encoding);
047:            }
048:
049:            private void init(Writer out, String encoding)
050:                    throws ListenerException {
051:                this .out = out;
052:                this .encoding = encoding;
053:
054:                elemStack = new LinkedList();
055:                Element topElem = new Element("macker-report");
056:                Element timestampElem = new Element("timestamp");
057:                timestampElem.setText(new java.util.Date().toString()); // to heck with sophisticated localization!
058:                topElem.addContent(timestampElem);
059:
060:                pushElem(topElem);
061:                document = new Document(topElem);
062:            }
063:
064:            public void flush() throws ListenerException {
065:                try {
066:                    XMLOutputter xmlOut = new XMLOutputter("    ", true,
067:                            encoding);
068:                    xmlOut.output(document, out);
069:                    out.flush();
070:                } catch (IOException ioe) {
071:                    throw new ListenerException(this ,
072:                            "Unable to write XML report", ioe);
073:                }
074:            }
075:
076:            public void close() throws ListenerException {
077:                try {
078:                    out.close();
079:                } catch (IOException ioe) {
080:                    throw new ListenerException(this ,
081:                            "Unable to close XML report", ioe);
082:                }
083:            }
084:
085:            public void mackerStarted(RuleSet ruleSet) {
086:                if (ruleSet.hasName()) {
087:                    Element ruleSetElem = new Element("ruleset");
088:                    ruleSetElem.setAttribute("name", ruleSet.getName());
089:                    curElem.addContent(ruleSetElem);
090:                    pushElem(ruleSetElem);
091:                } else
092:                    pushElem(curElem); // push again so finish can pop
093:            }
094:
095:            public void mackerFinished(RuleSet ruleSet)
096:                    throws MackerIsMadException, ListenerException {
097:                popElem();
098:            }
099:
100:            public void mackerAborted(RuleSet ruleSet) {
101:                curElem = null;
102:            }
103:
104:            public void handleMackerEvent(RuleSet ruleSet, MackerEvent event)
105:                    throws MackerIsMadException {
106:                if (event instanceof  MessageEvent) {
107:                    Element messageRuleElem = new Element("message-rule");
108:                    handleEventBasics(messageRuleElem, event);
109:                    curElem.addContent(messageRuleElem);
110:                }
111:
112:                if (event instanceof  AccessRuleViolation) {
113:                    AccessRuleViolation violation = (AccessRuleViolation) event;
114:                    Element violationElem = new Element("access-rule-violation");
115:
116:                    handleEventBasics(violationElem, violation);
117:
118:                    Element fromElem = new Element("from");
119:                    Element toElem = new Element("to");
120:                    describeClass(fromElem, violation.getFrom());
121:                    describeClass(toElem, violation.getTo());
122:                    violationElem.addContent(fromElem);
123:                    violationElem.addContent(toElem);
124:
125:                    curElem.addContent(violationElem);
126:                }
127:
128:                if (event instanceof  ForEachStarted) {
129:                    ForEachStarted forEachStarted = (ForEachStarted) event;
130:                    Element forEachElem = new Element("foreach");
131:                    forEachElem.setAttribute("var", forEachStarted.getForEach()
132:                            .getVariableName());
133:                    curElem.addContent(forEachElem);
134:                    pushElem(forEachElem);
135:                }
136:
137:                if (event instanceof  ForEachIterationStarted) {
138:                    ForEachIterationStarted forEachIter = (ForEachIterationStarted) event;
139:                    Element iterElem = new Element("iteration");
140:                    iterElem.setAttribute("value", forEachIter
141:                            .getVariableValue());
142:                    curElem.addContent(iterElem);
143:                    pushElem(iterElem);
144:                }
145:
146:                if (event instanceof  ForEachIterationFinished
147:                        || event instanceof  ForEachFinished)
148:                    popElem();
149:            }
150:
151:            private void handleEventBasics(Element elem, MackerEvent event) {
152:                elem.setAttribute("severity", event.getRule().getSeverity()
153:                        .getName());
154:                for (Iterator msgIter = event.getMessages().iterator(); msgIter
155:                        .hasNext();) {
156:                    String message = (String) msgIter.next();
157:                    Element messageElem = new Element("message");
158:                    messageElem.setText(message);
159:                    elem.addContent(messageElem);
160:                }
161:            }
162:
163:            private void describeClass(Element classInfoElem,
164:                    ClassInfo classInfo) {
165:                Element fullElem = new Element("full-name");
166:                Element classElem = new Element("class");
167:                Element packElem = new Element("package");
168:                fullElem.setText(classInfo.getFullName());
169:                classElem.setText(classInfo.getClassName());
170:                packElem.setText(classInfo.getPackageName());
171:                classInfoElem.addContent(fullElem);
172:                classInfoElem.addContent(classElem);
173:                if (!StringUtils.isEmpty(classInfo.getPackageName()))
174:                    classInfoElem.addContent(packElem);
175:            }
176:
177:            private void pushElem(Element elem) {
178:                elemStack.addLast(curElem);
179:                curElem = elem;
180:            }
181:
182:            private void popElem() {
183:                curElem = (Element) elemStack.removeLast();
184:            }
185:
186:            public String toString() {
187:                return "XmlReportingListener";
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.