Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 349   Methods: 50
NCLOC: 210   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DOMDocument.java 33,3% 20,8% 20% 21,1%
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: DOMDocument.java,v 1.15 2004/06/25 08:03:35 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.dom;
 11   
 12    import java.util.ArrayList;
 13   
 14    import org.dom4j.DocumentFactory;
 15    import org.dom4j.QName;
 16    import org.dom4j.tree.DefaultDocument;
 17    import org.w3c.dom.DOMException;
 18    import org.w3c.dom.NamedNodeMap;
 19    import org.w3c.dom.NodeList;
 20   
 21    /** <p><code>DOMDocument</code> implements an XML document which
 22    * supports the W3C DOM API.</p>
 23    *
 24    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 25    * @version $Revision: 1.15 $
 26    */
 27    public class DOMDocument extends DefaultDocument implements org.w3c.dom.Document {
 28   
 29    /** The <code>DocumentFactory</code> instance used by default */
 30    private static final DOMDocumentFactory DOCUMENT_FACTORY = (DOMDocumentFactory) DOMDocumentFactory.getInstance();
 31   
 32   
 33  10 public DOMDocument() {
 34  10 init();
 35    }
 36   
 37  4 public DOMDocument(String name) {
 38  4 super(name);
 39  4 init();
 40    }
 41   
 42  0 public DOMDocument(DOMElement rootElement) {
 43  0 super(rootElement);
 44  0 init();
 45    }
 46   
 47  0 public DOMDocument(DOMDocumentType docType) {
 48  0 super(docType);
 49  0 init();
 50    }
 51   
 52  0 public DOMDocument(DOMElement rootElement, DOMDocumentType docType) {
 53  0 super(rootElement, docType);
 54  0 init();
 55    }
 56   
 57  0 public DOMDocument(String name, DOMElement rootElement, DOMDocumentType docType) {
 58  0 super(name, rootElement, docType);
 59  0 init();
 60    }
 61   
 62  14 private void init() {
 63  14 setDocumentFactory(DOCUMENT_FACTORY);
 64    }
 65   
 66    // org.w3c.dom.Node interface
 67    //-------------------------------------------------------------------------
 68  0 public boolean supports(String feature, String version) {
 69  0 return DOMNodeHelper.supports(this, feature, version);
 70    }
 71   
 72  0 public String getNamespaceURI() {
 73  0 return DOMNodeHelper.getNamespaceURI(this);
 74    }
 75   
 76  0 public String getPrefix() {
 77  0 return DOMNodeHelper.getPrefix(this);
 78    }
 79   
 80  0 public void setPrefix(String prefix) throws DOMException {
 81  0 DOMNodeHelper.setPrefix(this, prefix);
 82    }
 83   
 84  0 public String getLocalName() {
 85  0 return DOMNodeHelper.getLocalName(this);
 86    }
 87   
 88  0 public String getNodeName() {
 89  0 return "#document";
 90    }
 91   
 92    //already part of API
 93    //
 94    //public short getNodeType();
 95   
 96   
 97   
 98  0 public String getNodeValue() throws DOMException {
 99  0 return null;
 100    }
 101   
 102  0 public void setNodeValue(String nodeValue) throws DOMException {
 103    }
 104   
 105   
 106  0 public org.w3c.dom.Node getParentNode() {
 107  0 return DOMNodeHelper.getParentNode(this);
 108    }
 109   
 110  0 public NodeList getChildNodes() {
 111  0 return DOMNodeHelper.createNodeList( content() );
 112    }
 113   
 114  0 public org.w3c.dom.Node getFirstChild() {
 115  0 return DOMNodeHelper.asDOMNode( node(0) );
 116    }
 117   
 118  0 public org.w3c.dom.Node getLastChild() {
 119  0 return DOMNodeHelper.asDOMNode( node( nodeCount() - 1 ) );
 120    }
 121   
 122  0 public org.w3c.dom.Node getPreviousSibling() {
 123  0 return DOMNodeHelper.getPreviousSibling(this);
 124    }
 125   
 126  0 public org.w3c.dom.Node getNextSibling() {
 127  0 return DOMNodeHelper.getNextSibling(this);
 128    }
 129   
 130  0 public NamedNodeMap getAttributes() {
 131  0 return null;
 132    }
 133   
 134  0 public org.w3c.dom.Document getOwnerDocument() {
 135  0 return null;
 136    }
 137   
 138  0 public org.w3c.dom.Node insertBefore(
 139    org.w3c.dom.Node newChild,
 140    org.w3c.dom.Node refChild
 141    ) throws DOMException {
 142  0 checkNewChildNode(newChild);
 143  0 return DOMNodeHelper.insertBefore(this, newChild, refChild);
 144    }
 145   
 146  0 public org.w3c.dom.Node replaceChild(
 147    org.w3c.dom.Node newChild,
 148    org.w3c.dom.Node oldChild
 149    ) throws DOMException {
 150  0 checkNewChildNode(newChild);
 151  0 return DOMNodeHelper.replaceChild(this, newChild, oldChild);
 152    }
 153   
 154  0 public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException {
 155  0 return DOMNodeHelper.removeChild(this, oldChild);
 156    }
 157   
 158  8 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException {
 159  8 checkNewChildNode(newChild);
 160  8 return DOMNodeHelper.appendChild(this, newChild);
 161    }
 162   
 163  8 private void checkNewChildNode(org.w3c.dom.Node newChild) throws DOMException {
 164  8 final int nodeType = newChild.getNodeType();
 165  8 if (!(nodeType == org.w3c.dom.Node.ELEMENT_NODE ||
 166    nodeType == org.w3c.dom.Node.COMMENT_NODE ||
 167    nodeType == org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE ||
 168    nodeType == org.w3c.dom.Node.DOCUMENT_TYPE_NODE)) {
 169  0 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
 170    "Specified node cannot be a child of document");
 171    }
 172    }
 173   
 174   
 175  0 public boolean hasChildNodes() {
 176  0 return nodeCount() > 0;
 177    }
 178   
 179  0 public org.w3c.dom.Node cloneNode(boolean deep) {
 180  0 return DOMNodeHelper.cloneNode(this, deep);
 181    }
 182   
 183  0 public boolean isSupported(String feature, String version) {
 184  0 return DOMNodeHelper.isSupported(this, feature, version);
 185    }
 186   
 187  0 public boolean hasAttributes() {
 188  0 return DOMNodeHelper.hasAttributes(this);
 189    }
 190   
 191   
 192    // org.w3c.dom.Document interface
 193    //-------------------------------------------------------------------------
 194  0 public NodeList getElementsByTagName(String name) {
 195  0 ArrayList list = new ArrayList();
 196  0 DOMNodeHelper.appendElementsByTagName( list, this, name );
 197  0 return DOMNodeHelper.createNodeList( list );
 198    }
 199   
 200  0 public NodeList getElementsByTagNameNS(
 201    String namespaceURI, String localName
 202    ) {
 203  0 ArrayList list = new ArrayList();
 204  0 DOMNodeHelper.appendElementsByTagNameNS(list, this, namespaceURI, localName );
 205  0 return DOMNodeHelper.createNodeList( list );
 206    }
 207   
 208   
 209  0 public org.w3c.dom.DocumentType getDoctype() {
 210  0 return DOMNodeHelper.asDOMDocumentType( getDocType() );
 211    }
 212   
 213  0 public org.w3c.dom.DOMImplementation getImplementation() {
 214  0 if (getDocumentFactory() instanceof org.w3c.dom.DOMImplementation) {
 215  0 return (org.w3c.dom.DOMImplementation) getDocumentFactory();
 216    }
 217    else {
 218  0 return DOCUMENT_FACTORY;
 219    }
 220   
 221    }
 222   
 223  6 public org.w3c.dom.Element getDocumentElement() {
 224  6 return DOMNodeHelper.asDOMElement( getRootElement() );
 225    }
 226   
 227  14 public org.w3c.dom.Element createElement(String tagName) throws DOMException {
 228  14 return (org.w3c.dom.Element) getDocumentFactory().createElement(tagName);
 229    }
 230   
 231  0 public org.w3c.dom.DocumentFragment createDocumentFragment() {
 232  0 DOMNodeHelper.notSupported();
 233  0 return null;
 234    }
 235   
 236  28 public org.w3c.dom.Text createTextNode(String data) {
 237  28 return (org.w3c.dom.Text) getDocumentFactory().createText(data);
 238    }
 239   
 240  0 public org.w3c.dom.Comment createComment(String data) {
 241  0 return (org.w3c.dom.Comment) getDocumentFactory().createComment(data);
 242    }
 243   
 244  0 public org.w3c.dom.CDATASection createCDATASection(String data) throws DOMException {
 245  0 return (org.w3c.dom.CDATASection) getDocumentFactory().createCDATA(data);
 246    }
 247   
 248  0 public org.w3c.dom.ProcessingInstruction createProcessingInstruction(
 249    String target, String data
 250    ) throws DOMException {
 251  0 return (org.w3c.dom.ProcessingInstruction) getDocumentFactory().createProcessingInstruction(target, data);
 252    }
 253   
 254  0 public org.w3c.dom.Attr createAttribute(String name) throws DOMException {
 255  0 QName qname = getDocumentFactory().createQName(name);
 256  0 return (org.w3c.dom.Attr) getDocumentFactory().createAttribute(null, qname, "");
 257    }
 258   
 259  0 public org.w3c.dom.EntityReference createEntityReference(String name) throws DOMException {
 260  0 return (org.w3c.dom.EntityReference) ((DOMDocumentFactory) getDocumentFactory()).createEntity(name);
 261    }
 262   
 263  0 public org.w3c.dom.Node importNode(
 264    org.w3c.dom.Node importedNode, boolean deep
 265    ) throws DOMException {
 266  0 DOMNodeHelper.notSupported();
 267  0 return null;
 268    }
 269   
 270  20 public org.w3c.dom.Element createElementNS(
 271    String namespaceURI, String qualifiedName
 272    ) throws DOMException {
 273  20 QName qname = getDocumentFactory().createQName( qualifiedName, namespaceURI );
 274  20 return (org.w3c.dom.Element) getDocumentFactory().createElement(qname);
 275    }
 276   
 277  0 public org.w3c.dom.Attr createAttributeNS(
 278    String namespaceURI, String qualifiedName
 279    ) throws DOMException {
 280  0 QName qname = getDocumentFactory().createQName( qualifiedName, namespaceURI );
 281  0 return (org.w3c.dom.Attr) getDocumentFactory().createAttribute(null, qname, null);
 282    }
 283   
 284   
 285  0 public org.w3c.dom.Element getElementById(String elementId) {
 286  0 return DOMNodeHelper.asDOMElement( elementByID( elementId ) );
 287    }
 288   
 289   
 290   
 291    // Implementation methods
 292    //-------------------------------------------------------------------------
 293  112 protected DocumentFactory getDocumentFactory() {
 294  112 if (super.getDocumentFactory() == null) {
 295  0 return DOCUMENT_FACTORY;
 296    }
 297    else {
 298  112 return super.getDocumentFactory();
 299    }
 300    }
 301    }
 302   
 303   
 304   
 305   
 306    /*
 307    * Redistribution and use of this software and associated documentation
 308    * ("Software"), with or without modification, are permitted provided
 309    * that the following conditions are met:
 310    *
 311    * 1. Redistributions of source code must retain copyright
 312    * statements and notices. Redistributions must also contain a
 313    * copy of this document.
 314    *
 315    * 2. Redistributions in binary form must reproduce the
 316    * above copyright notice, this list of conditions and the
 317    * following disclaimer in the documentation and/or other
 318    * materials provided with the distribution.
 319    *
 320    * 3. The name "DOM4J" must not be used to endorse or promote
 321    * products derived from this Software without prior written
 322    * permission of MetaStuff, Ltd. For written permission,
 323    * please contact dom4j-info@metastuff.com.
 324    *
 325    * 4. Products derived from this Software may not be called "DOM4J"
 326    * nor may "DOM4J" appear in their names without prior written
 327    * permission of MetaStuff, Ltd. DOM4J is a registered
 328    * trademark of MetaStuff, Ltd.
 329    *
 330    * 5. Due credit should be given to the DOM4J Project -
 331    * http://www.dom4j.org
 332    *
 333    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 334    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 335    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 336    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 337    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 338    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 339    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 340    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 341    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 342    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 343    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 344    * OF THE POSSIBILITY OF SUCH DAMAGE.
 345    *
 346    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 347    *
 348    * $Id: DOMDocument.java,v 1.15 2004/06/25 08:03:35 maartenc Exp $
 349    */