Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 121   Methods: 10
NCLOC: 69   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NodeLoader.java 25% 46.9% 40% 43.5%
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.dependency;
 34   
 35    import java.io.*;
 36   
 37    import javax.xml.parsers.*;
 38   
 39    import org.apache.log4j.*;
 40    import org.xml.sax.*;
 41   
 42    public class NodeLoader {
 43    private static final boolean DEFAULT_VALIDATE = false;
 44   
 45    private NodeHandler handler;
 46    private boolean validate;
 47   
 48  1 public NodeLoader() {
 49  1 this(new NodeFactory(), DEFAULT_VALIDATE);
 50    }
 51   
 52  0 public NodeLoader(NodeFactory factory) {
 53  0 this(factory, DEFAULT_VALIDATE);
 54    }
 55   
 56  0 public NodeLoader(boolean validate) {
 57  0 this(new NodeFactory(), validate);
 58    }
 59   
 60  1 public NodeLoader(NodeFactory factory, boolean validate) {
 61  1 this.handler = new NodeHandler(factory);
 62  1 this.validate = validate;
 63    }
 64   
 65  0 public NodeFactory load(String filename) throws IOException, SAXException, ParserConfigurationException {
 66  0 NodeFactory result = null;
 67   
 68  0 FileReader in = null;
 69  0 try {
 70  0 in = new FileReader(filename);
 71  0 result = load(in);
 72    } finally {
 73  0 if (in != null) {
 74  0 in.close();
 75    }
 76    }
 77   
 78  0 return result;
 79    }
 80   
 81  0 public NodeFactory load(InputStream in) throws IOException, ParserConfigurationException, SAXException {
 82  0 return load(new InputSource(in));
 83    }
 84   
 85  1 public NodeFactory load(Reader in) throws IOException, ParserConfigurationException, SAXException {
 86  1 return load(new InputSource(in));
 87    }
 88   
 89  1 public NodeFactory load(InputSource in) throws IOException, ParserConfigurationException, SAXException {
 90  1 XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
 91  1 reader.setDTDHandler(handler);
 92  1 reader.setContentHandler(handler);
 93  1 reader.setErrorHandler(handler);
 94   
 95  1 try {
 96  1 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  1 Logger.getLogger(getClass()).info("XML validation turned off");
 102  1 reader.setFeature("http://xml.org/sax/features/validation", false);
 103  1 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  1 reader.parse(in);
 110   
 111  1 return handler.getFactory();
 112    }
 113   
 114  0 public void addDependencyListener(DependencyListener listener) {
 115  0 handler.addDependencyListener(listener);
 116    }
 117   
 118  0 public void removeDependencyListener(DependencyListener listener) {
 119  0 handler.removeDependencyListener(listener);
 120    }
 121    }