EMMA Coverage Report (generated Wed Dec 16 17:19:59 CET 2009)
[all classes][org.sourceforge.xradar.results]

COVERAGE SUMMARY FOR SOURCE FILE [AnalysingProcess.java]

nameclass, %method, %block, %line, %
AnalysingProcess.java100% (1/1)50%  (5/10)27%  (70/261)31%  (15.9/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AnalysingProcess100% (1/1)50%  (5/10)27%  (70/261)31%  (15.9/52)
addRuleToViolations (List, Rule): List 0%   (0/1)0%   (0/16)0%   (0/3)
analyseResults (List): List 0%   (0/1)0%   (0/82)0%   (0/12)
getViolations (): List 0%   (0/1)0%   (0/3)0%   (0/1)
loadDataFile (String): InputStream 0%   (0/1)0%   (0/28)0%   (0/6)
setViolations (List): void 0%   (0/1)0%   (0/4)0%   (0/2)
getAnalyserInstance (Rule): Analyser 100% (1/1)33%  (28/85)40%  (8/20)
isRuleHasNameAndQueryDefined (Rule): boolean 100% (1/1)93%  (13/14)92%  (0.9/1)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
AnalysingProcess (): void 100% (1/1)100% (15/15)100% (3/3)
findClassNameForType (String): String 100% (1/1)100% (9/9)100% (3/3)

1 
2/**
3 * 
4 */
5package org.sourceforge.xradar.results;
6 
7import java.io.InputStream;
8import java.util.HashMap;
9import java.util.List;
10import java.util.Map;
11import java.util.logging.Logger;
12 
13import javax.xml.parsers.DocumentBuilder;
14 
15import org.sourceforge.xradar.XRadarException;
16import org.sourceforge.xradar.util.FileUtils;
17import org.sourceforge.xradar.util.StreamUtils;
18import org.sourceforge.xradar.util.XMLUtils;
19import org.w3c.dom.Document;
20import org.w3c.dom.Element;
21import org.w3c.dom.NodeList;
22import org.xml.sax.SAXException;
23 
24/**
25 * 
26 * @author Romain PELISSE, <belaran@gmail.com>
27 */
28public class AnalysingProcess {
29 
30        private static final Logger logger = Logger.getLogger(AnalysingProcess.class.getSimpleName());
31        private List<Violation> violations;
32 
33        private Map<String,Analyser> alreadyLoaded = new HashMap<String,Analyser>(0);
34        private Map<String,InputStream> resourcesLoaded = new HashMap<String, InputStream>(0);
35 
36        private boolean isRuleHasNameAndQueryDefined(Rule rule) {
37 
38                return ! "".equals(rule.getName()) && ! "".equals(rule.getQuery()) ;
39        }
40 
41        public List<Violation> analyseResults(List<Rule> rules) throws XRadarResultsAnalyserException, XRadarException {
42                logger.finest("invoked");
43                if ( violations == null )
44                        throw new XRadarResultsAnalyserException("initialization error, please set 'violations' through appropriate getter");
45                logger.finest("called with violations=" + violations);
46                for (Rule rule : rules ) {
47                        logger.finest("descriptor:" + rule.toString());
48                        if ( rule.getType() == null || "".equals(rule.getType() ) )
49                                throw new XRadarResultsAnalyserException("empty or null  analyser:");
50                        Analyser analyser = this.getAnalyserInstance(rule);
51                        violations.addAll(addRuleToViolations(analyser.analyse(new QueryData(rule.getQuery(),loadDataFile(rule.getFile()))),rule));
52                }
53                return violations;
54        }
55 
56        private InputStream loadDataFile(String filename) throws XRadarException {
57                InputStream inputStream = null;
58                if (! resourcesLoaded.containsKey(filename) && FileUtils.exists(filename) ) {
59                        inputStream = StreamUtils.fromFilenameToInputStream(filename);
60                        resourcesLoaded.put(filename,inputStream);
61                } else
62                        inputStream = resourcesLoaded.get(filename);
63                return inputStream;
64        }
65 
66        private List<Violation> addRuleToViolations(List<Violation> violations, Rule rule) {
67                for ( Violation violation : violations ) {
68                        violation.setRule(rule);
69                }
70                return violations;
71        }
72 
73        public static String findClassNameForType(String type) {
74                if ( "xpath".equals(type) )
75                        return XPathQueryAnalyser.class.getCanonicalName();
76                return type;
77        }
78 
79        public List<Violation> getViolations() {
80                return violations;
81        }
82 
83        public void setViolations(List<Violation> violations) {
84                this.violations = violations;
85        }
86 
87        /**
88         * <p>As analyser implementation are supposed to be rather 'stateless',
89         * they are only instatiate once, and this method provide access to the 
90         * already instantiated Analyser instance (or create the appropriate
91         * instance.</p>
92         *  
93         * @param type
94         * @return the instance associated with the type
95         * @throws XRadarResultsAnalyserException
96         */
97        public  Analyser getAnalyserInstance(Rule rule) throws XRadarResultsAnalyserException {
98                Analyser analyser = null;
99 
100                if ( ! this.alreadyLoaded.containsKey(rule.getType()) ) {
101                        // Maybe this a predefined rule
102                        if (!isRuleHasNameAndQueryDefined(rule)){
103                                RuleExport re = new RuleExport();
104                                alreadyLoaded.putAll(re.listRule(rule));
105                                for (int i = 0; i < alreadyLoaded.size(); i++) {
106                                        if (this.alreadyLoaded.containsKey(rule.getType())){
107                                                analyser = this.alreadyLoaded.get(rule.getType());
108                                        }
109                                }
110                        }
111                        // 
112                        String type = AnalysingProcess.findClassNameForType(rule.getType());
113                        try {
114                                analyser = (Analyser) this.getClass().getClassLoader().loadClass(type).newInstance();
115                        } catch (InstantiationException e) {
116                                throw new XRadarResultsAnalyserException(e);
117                        } catch (IllegalAccessException e) {
118                                throw new XRadarResultsAnalyserException(e);
119                        } catch (ClassNotFoundException e) {
120                                throw new XRadarResultsAnalyserException(e);
121                        }
122                }
123                else
124                        analyser = this.alreadyLoaded.get(rule.getType());
125                return analyser;
126 
127        }
128}

[all classes][org.sourceforge.xradar.results]
EMMA 2.0.5312 (C) Vladimir Roubtsov