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