Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 113   Methods: 8
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MetricsConfigurationLoader.java 50% 80% 75% 76.2%
coverage coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.metrics;
 34   
 35    import java.io.*;
 36    import javax.xml.parsers.*;
 37   
 38    import org.apache.log4j.*;
 39    import org.xml.sax.*;
 40   
 41    public class MetricsConfigurationLoader {
 42    private static final boolean DEFAULT_VALIDATE = false;
 43   
 44    private MetricsConfigurationHandler handler;
 45    private boolean validate;
 46   
 47  8 public MetricsConfigurationLoader() {
 48  8 this(new MetricsConfiguration(), DEFAULT_VALIDATE);
 49    }
 50   
 51  0 public MetricsConfigurationLoader(MetricsConfiguration configuration) {
 52  0 this(configuration, DEFAULT_VALIDATE);
 53    }
 54   
 55  50 public MetricsConfigurationLoader(boolean validate) {
 56  50 this(new MetricsConfiguration(), validate);
 57    }
 58   
 59  67 public MetricsConfigurationLoader(MetricsConfiguration configuration, boolean validate) {
 60  67 this.handler = new MetricsConfigurationHandler(configuration);
 61  67 this.validate = validate;
 62    }
 63   
 64  58 public MetricsConfiguration load(String filename) throws IOException, SAXException, ParserConfigurationException {
 65  58 MetricsConfiguration result = null;
 66   
 67  58 FileReader in = null;
 68   
 69  58 try {
 70  58 in = new FileReader(filename);
 71  58 result = load(in);
 72    } finally {
 73  58 if (in != null) {
 74  58 in.close();
 75    }
 76    }
 77   
 78  58 return result;
 79    }
 80   
 81  0 public MetricsConfiguration load(InputStream in) throws IOException, SAXException, ParserConfigurationException {
 82  0 return load(new InputSource(in));
 83    }
 84   
 85  67 public MetricsConfiguration load(Reader in) throws IOException, SAXException, ParserConfigurationException {
 86  67 return load(new InputSource(in));
 87    }
 88   
 89  67 public MetricsConfiguration load(InputSource in) throws IOException, SAXException, ParserConfigurationException {
 90  67 XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
 91  67 reader.setDTDHandler(handler);
 92  67 reader.setContentHandler(handler);
 93  67 reader.setErrorHandler(handler);
 94   
 95  67 try {
 96  67 if (validate) {
 97  0 Logger.getLogger(getClass()).warn("XML validation turned on");
 98  0 reader.setFeature("http://xml.org/sax/features/validation", true);
 99  0 reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
 100    } else {
 101  67 Logger.getLogger(getClass()).info("XML validation turned off");
 102  67 reader.setFeature("http://xml.org/sax/features/validation", false);
 103  67 reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
 104    }
 105    } catch (Exception ex) {
 106  0 Logger.getLogger(getClass()).warn("Problem setting validation feature on XML reader",ex);
 107    }
 108   
 109  67 reader.parse(in);
 110   
 111  65 return handler.getMetricsConfiguration();
 112    }
 113    }