KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > render > dom > InspectorDescriptorRenderer


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.render.dom;
25
26 import java.util.Iterator JavaDoc;
27
28 import org.hammurapi.Inspector;
29 import org.hammurapi.InspectorDescriptor;
30 import org.w3c.dom.Document JavaDoc;
31 import org.w3c.dom.Element JavaDoc;
32
33 import com.pavelvlasov.config.ConfigurationException;
34 import com.pavelvlasov.render.RenderRequest;
35 import com.pavelvlasov.render.RenderingException;
36 import com.pavelvlasov.render.dom.AbstractRenderer;
37
38 /**
39  *
40  * @author Pavel Vlasov
41  * @version $Revision: 1.4 $
42  */

43 public class InspectorDescriptorRenderer extends AbstractRenderer {
44     
45     /** Creates a new instance of InspectorDescriptorRendrerer */
46     public InspectorDescriptorRenderer(RenderRequest request) {
47         super(request);
48     }
49     
50     public Element JavaDoc render(Document JavaDoc document) throws RenderingException {
51         Element JavaDoc ret=document.createElement("inspector-descriptor");
52         InspectorDescriptor descriptor=(InspectorDescriptor) request.getRenderee();
53
54         if (descriptor.getDescription()!=null) {
55             ret
56             .appendChild(document.createElement("description"))
57             .appendChild(document.createTextNode(descriptor.getDescription()));
58         }
59         
60         if (descriptor.getMessage()!=null) {
61             ret
62             .appendChild(document.createElement("message"))
63             .appendChild(document.createTextNode(descriptor.getMessage()));
64         }
65         
66         try {
67             if (descriptor.getInspector()!=null) {
68                 Element JavaDoc inspectorElement=document.createElement("inspector");
69                 inspectorElement.setAttribute("type", descriptor.getInspector().getClass().getName());
70                 ret.appendChild(inspectorElement);
71             }
72         } catch (ConfigurationException e) {
73             throw new RenderingException(e);
74         }
75         
76         if (descriptor.isEnabled()!=null) {
77             ret
78             .appendChild(document.createElement("enabled"))
79             .appendChild(document.createTextNode(Boolean.TRUE.equals(descriptor.isEnabled()) ? "yes" : "no"));
80         }
81         
82         if (descriptor.isWaivable()!=null) {
83             ret
84             .appendChild(document.createElement("waivable"))
85             .appendChild(document.createTextNode(Boolean.TRUE.equals(descriptor.isWaivable()) ? "yes" : "no"));
86         }
87         
88         if (descriptor.getName()!=null) {
89             ret
90             .appendChild(document.createElement("name"))
91             .appendChild(document.createTextNode(descriptor.getName()));
92         }
93         
94         if (descriptor.getSeverity()!=null) {
95             ret
96             .appendChild(document.createElement("severity"))
97             .appendChild(document.createTextNode(descriptor.getSeverity().toString()));
98         }
99         
100         if (descriptor.getOrder()!=null) {
101             ret
102             .appendChild(document.createElement("order"))
103             .appendChild(document.createTextNode(descriptor.getOrder().toString()));
104         }
105         
106         if (descriptor.getRationale()!=null) {
107             ret
108             .appendChild(document.createElement("rationale"))
109             .appendChild(document.createTextNode(descriptor.getRationale()));
110         }
111         
112         if (descriptor.getViolationSample()!=null) {
113             ret
114             .appendChild(document.createElement("violation-sample"))
115             .appendChild(document.createTextNode(descriptor.getViolationSample()));
116         }
117
118         if (descriptor.getFixSample()!=null) {
119             ret
120             .appendChild(document.createElement("fix-sample"))
121             .appendChild(document.createTextNode(descriptor.getFixSample()));
122         }
123         
124         if (descriptor.getResources()!=null) {
125             ret
126             .appendChild(document.createElement("resources"))
127             .appendChild(document.createTextNode(descriptor.getResources()));
128         }
129
130         if (descriptor.getCategory()!=null) {
131             ret
132             .appendChild(document.createElement("category"))
133             .appendChild(document.createTextNode(descriptor.getCategory()));
134         }
135         
136 // Iterator it=descriptor.getParameters().entrySet().iterator();
137
// while (it.hasNext()) {
138
// Map.Entry entry=(Map.Entry) it.next();
139
// Element e=document.createElement("parameter");
140
// ret.appendChild(e);
141
// e.setAttribute("name", (String) entry.getKey());
142
// e.appendChild(document.createTextNode((String) entry.getValue()));
143
// }
144

145         Iterator JavaDoc it=descriptor.getWaiveCases().iterator();
146         while (it.hasNext()) {
147             Element JavaDoc e=document.createElement("waive-case");
148             ret.appendChild(e);
149             e.appendChild(document.createTextNode((String JavaDoc) it.next()));
150         }
151         
152         try {
153             Inspector inspector=descriptor.getInspector();
154             if (inspector!=null) {
155                 String JavaDoc inspectorConfigInfo=inspector.getConfigInfo();
156                 if (inspectorConfigInfo!=null) {
157                     ret
158                     .appendChild(document.createElement("config-info"))
159                     .appendChild(document.createTextNode(inspectorConfigInfo));
160                 }
161             }
162         } catch (ConfigurationException e) {
163             throw new RenderingException("Unable to read inspector configuration info", e);
164         }
165         
166         return ret;
167     }
168 }
169
Popular Tags