DomWaiverSource.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase1010
Reviews1681
DPMO577
Sigma4.75

Metrics
NameNumberMinAvgMaxTotal
Class complexity114.0014.0014.0014.00
Code length51.007.0020.0035.00
File length1106.00106.00106.00106.00
Operation complexity51.002.806.0014.00
Work order150.7650.7650.7650.76

Violations
#LineColumnNameSeverityDescription
1241ER-0233Packages should begin with []
26584ER-0363Line is too long
37198ER-0363Line is too long
48286ER-0363Line is too long
59686ER-0363Line is too long
6501ER-0492Unify logging strategy - define individual logger for class
7535ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
8535ER-1093It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule )
9575ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
10575ER-1093It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule )
11615ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
12615ER-1093It is good practice to call in any case super() in a constructor. (see also: UnnecessaryConstructorRule )
136411ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
146542ER-0303Avoid hardwired string literals
157311ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
167511ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
177711ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
18825ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
198333ER-0303Avoid hardwired string literals
208557ER-0303Avoid hardwired string literals
218815ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
228946ER-0303Avoid hardwired string literals
239015ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )
249677ER-0303Avoid hardwired string literals
2510111ER-1032Catch-blocks should log the exeption with Log4J.error("Context String" , exception )

JavaDoc
DomWaiverSource

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
24package org.hammurapi;
25
26import java.io.File;
27import java.io.FileInputStream;
28import java.io.FileNotFoundException;
29import java.io.IOException;
30import java.io.InputStream;
31import java.net.MalformedURLException;
32import java.net.URL;
33import java.util.Date;
34
35import javax.xml.parsers.DocumentBuilderFactory;
36import javax.xml.parsers.ParserConfigurationException;
37import javax.xml.transform.TransformerException;
38
39import org.apache.xpath.XPathAPI;
40import org.w3c.dom.Document;
41import org.w3c.dom.Element;
42import org.w3c.dom.traversal.NodeIterator;
43import org.xml.sax.SAXException;
44
45/**
46 *
47 * @author Pavel Vlasov
48 * @version $Revision: 1.3 $
49 */

50public class DomWaiverSource implements WaiverSource {
51 private Element holder;
52
53 public DomWaiverSource(Element holder) {
54 this.holder=holder;
55 }
56
57 public DomWaiverSource(InputStream in) throws HammurapiException {
58 load(in);
59 }
60
61 public DomWaiverSource(File f) throws HammurapiException {
62 try {
63 load(new FileInputStream(f));
64 } catch (FileNotFoundException e) {
65 throw new HammurapiException("File not found: "+f.getAbsolutePath(), e);
66 }
67 }
68
69 private void load(InputStream in) throws HammurapiException {
70 try {
71 Document document=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
72 holder=document.getDocumentElement();
73 } catch (ParserConfigurationException e) {
74 throw new HammurapiException(e.toString(), e);
75 } catch (SAXException e) {
76 throw new HammurapiException(e.toString(), e);
77 } catch (IOException e) {
78 throw new HammurapiException(e.toString(), e);
79 }
80 }
81
82 public void loadWaivers(WaiverSet waiverSet, Date now) throws HammurapiException {
83 if (holder.hasAttribute("base")) {
84 try {
85 URL baseURL=new URL(holder.getAttribute("base"));
86 DomWaiverSource base=new DomWaiverSource(baseURL.openStream());
87 base.loadWaivers(waiverSet, now);
88 } catch (MalformedURLException e) {
89 throw new HammurapiException("Malformed base URL: "+e, e);
90 } catch (IOException e) {
91 throw new HammurapiException(e.toString(), e);
92 }
93 }
94
95 try {
96 NodeIterator waiverIterator=XPathAPI.selectNodeIterator(holder, "waiver");
97 Element waiverElement;
98 while ((waiverElement=(Element) waiverIterator.nextNode())!=null) {
99 waiverSet.addWaiver(new DomWaiver(waiverElement), now);
100 }
101 } catch (TransformerException e) {
102 new HammurapiException(e);
103 }
104 }
105}
106
107

Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.