Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 280   Methods: 34
NCLOC: 168   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractNode.java 75% 73,3% 67,6% 71,7%
coverage coverage
 1    /*
 2    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 3    *
 4    * This software is open source.
 5    * See the bottom of this file for the licence.
 6    *
 7    * $Id: AbstractNode.java,v 1.29 2004/08/05 10:16:48 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.tree;
 11   
 12    import java.io.IOException;
 13    import java.io.Serializable;
 14    import java.io.Writer;
 15    import java.util.List;
 16   
 17    import org.dom4j.Document;
 18    import org.dom4j.DocumentFactory;
 19    import org.dom4j.Element;
 20    import org.dom4j.Node;
 21    import org.dom4j.NodeFilter;
 22    import org.dom4j.XPath;
 23    import org.dom4j.rule.Pattern;
 24   
 25    /** <p><code>AbstractNode</code> is an abstract base class for
 26    * tree implementors to use for implementation inheritence.</p>
 27    *
 28    * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
 29    * @version $Revision: 1.29 $
 30    */
 31    public abstract class AbstractNode implements Node, Cloneable, Serializable {
 32   
 33    protected static final String[] NODE_TYPE_NAMES ={
 34    "Node", "Element", "Attribute", "Text", "CDATA", "Entity", "Entity", "ProcessingInstruction",
 35    "Comment", "Document", "DocumentType", "DocumentFragment", "Notation", "Namespace","Unknown"
 36    };
 37   
 38    /** The <code>DocumentFactory</code> instance used by default */
 39    private static final DocumentFactory DOCUMENT_FACTORY = DocumentFactory.getInstance();
 40   
 41   
 42  457236 public AbstractNode() {
 43    }
 44   
 45  0 public short getNodeType() {
 46  0 return UNKNOWN_NODE;
 47    }
 48   
 49  224 public String getNodeTypeName() {
 50  224 int type = getNodeType();
 51  224 if ( type < 0 || type >= NODE_TYPE_NAMES.length ) {
 52  0 return "Unknown";
 53    }
 54  224 return NODE_TYPE_NAMES[type];
 55    }
 56   
 57  106 public Document getDocument() {
 58  106 Element element = getParent();
 59  106 return ( element != null ) ? element.getDocument() : null;
 60    }
 61   
 62  4220 public void setDocument(Document document) {
 63    }
 64   
 65  11860 public Element getParent() {
 66  11860 return null;
 67    }
 68   
 69  11888 public void setParent(Element parent) {
 70    }
 71   
 72  152 public boolean supportsParent() {
 73  152 return false;
 74    }
 75   
 76  12 public boolean isReadOnly() {
 77  12 return true;
 78    }
 79   
 80  0 public boolean hasContent() {
 81  0 return false;
 82    }
 83   
 84  36 public String getPath() {
 85  36 return getPath(null);
 86    }
 87   
 88  40 public String getUniquePath() {
 89  40 return getUniquePath(null);
 90    }
 91   
 92   
 93  666 public Object clone() {
 94  666 if ( isReadOnly() ) {
 95  12 return this;
 96    }
 97    else {
 98  654 try {
 99  654 Node answer = (Node) super.clone();
 100  654 answer.setParent( null );
 101  654 answer.setDocument( null );
 102  654 return answer;
 103    }
 104    catch (CloneNotSupportedException e) {
 105    // should never happen
 106  0 throw new RuntimeException( "This should never happen. Caught: " + e );
 107    }
 108    }
 109    }
 110   
 111  3034 public Node detach() {
 112  3034 Element parent = getParent();
 113  3034 if ( parent != null ) {
 114  3030 parent.remove( this );
 115    }
 116    else {
 117  4 Document document = getDocument();
 118  4 if ( document != null ) {
 119  4 document.remove( this );
 120    }
 121    }
 122  3034 setParent(null);
 123  3034 setDocument(null);
 124  3034 return this;
 125    }
 126   
 127  0 public String getName() {
 128  0 return null;
 129    }
 130   
 131  0 public void setName(String name) {
 132  0 throw new UnsupportedOperationException( "This node cannot be modified" );
 133    }
 134   
 135  0 public String getText() {
 136  0 return null;
 137    }
 138   
 139  3026 public String getStringValue() {
 140  3026 return getText();
 141    }
 142   
 143  0 public void setText(String text) {
 144  0 throw new UnsupportedOperationException( "This node cannot be modified" );
 145    }
 146   
 147   
 148  0 public void write(Writer writer) throws IOException {
 149  0 writer.write( asXML() );
 150    }
 151   
 152   
 153    // XPath methods
 154   
 155  4 public Object selectObject(String xpathExpression) {
 156  4 XPath xpath = createXPath(xpathExpression);
 157  0 return xpath.selectObject(this);
 158    }
 159   
 160  456 public List selectNodes(String xpathExpression) {
 161  456 XPath xpath = createXPath(xpathExpression);
 162  456 return xpath.selectNodes(this);
 163    }
 164   
 165  2 public List selectNodes(
 166    String xpathExpression,
 167    String comparisonXPathExpression
 168    ) {
 169  2 return selectNodes(
 170    xpathExpression, comparisonXPathExpression, false
 171    );
 172    }
 173   
 174  4 public List selectNodes(
 175    String xpathExpression,
 176    String comparisonXPathExpression,
 177    boolean removeDuplicates
 178    ) {
 179  4 XPath xpath = createXPath(xpathExpression);
 180  4 XPath sortBy = createXPath(comparisonXPathExpression);
 181  4 return xpath.selectNodes(this, sortBy, removeDuplicates);
 182    }
 183   
 184  128 public Node selectSingleNode(String xpathExpression) {
 185  128 XPath xpath = createXPath(xpathExpression);
 186  128 return xpath.selectSingleNode(this);
 187    }
 188   
 189  168 public String valueOf(String xpathExpression) {
 190  168 XPath xpath = createXPath(xpathExpression);
 191  168 return xpath.valueOf(this);
 192    }
 193   
 194  0 public Number numberValueOf(String xpathExpression) {
 195  0 XPath xpath = createXPath(xpathExpression);
 196  0 return xpath.numberValueOf(this);
 197    }
 198   
 199  18 public boolean matches(String patternText) {
 200  18 NodeFilter filter = createXPathFilter(patternText);
 201  18 return filter.matches(this);
 202    }
 203   
 204  1448 public XPath createXPath(String xpathExpression) {
 205  1448 return getDocumentFactory().createXPath(xpathExpression);
 206    }
 207   
 208  18 public NodeFilter createXPathFilter(String patternText) {
 209  18 return getDocumentFactory().createXPathFilter(patternText);
 210    }
 211   
 212  0 public Pattern createPattern(String patternText) {
 213  0 return getDocumentFactory().createPattern(patternText);
 214    }
 215   
 216   
 217  152 public Node asXPathResult(Element parent) {
 218  152 if (supportsParent()) {
 219  0 return this;
 220    }
 221  152 return createXPathResult(parent);
 222    }
 223   
 224  0 protected DocumentFactory getDocumentFactory() {
 225  0 return DOCUMENT_FACTORY;
 226    }
 227   
 228  0 protected Node createXPathResult(Element parent) {
 229  0 throw new RuntimeException("asXPathResult() not yet implemented fully for: " + this );
 230    }
 231   
 232    }
 233   
 234   
 235   
 236   
 237    /*
 238    * Redistribution and use of this software and associated documentation
 239    * ("Software"), with or without modification, are permitted provided
 240    * that the following conditions are met:
 241    *
 242    * 1. Redistributions of source code must retain copyright
 243    * statements and notices. Redistributions must also contain a
 244    * copy of this document.
 245    *
 246    * 2. Redistributions in binary form must reproduce the
 247    * above copyright notice, this list of conditions and the
 248    * following disclaimer in the documentation and/or other
 249    * materials provided with the distribution.
 250    *
 251    * 3. The name "DOM4J" must not be used to endorse or promote
 252    * products derived from this Software without prior written
 253    * permission of MetaStuff, Ltd. For written permission,
 254    * please contact dom4j-info@metastuff.com.
 255    *
 256    * 4. Products derived from this Software may not be called "DOM4J"
 257    * nor may "DOM4J" appear in their names without prior written
 258    * permission of MetaStuff, Ltd. DOM4J is a registered
 259    * trademark of MetaStuff, Ltd.
 260    *
 261    * 5. Due credit should be given to the DOM4J Project -
 262    * http://www.dom4j.org
 263    *
 264    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 265    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 266    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 267    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 268    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 269    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 270    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 271    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 272    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 273    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 274    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 275    * OF THE POSSIBILITY OF SUCH DAMAGE.
 276    *
 277    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 278    *
 279    * $Id: AbstractNode.java,v 1.29 2004/08/05 10:16:48 maartenc Exp $
 280    */