Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 193   Methods: 17
NCLOC: 91   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseElement.java 10% 23,5% 23,5% 19,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: BaseElement.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.tree;
 11   
 12    import java.util.List;
 13   
 14    import org.dom4j.Branch;
 15    import org.dom4j.Document;
 16    import org.dom4j.Element;
 17    import org.dom4j.Namespace;
 18    import org.dom4j.QName;
 19   
 20    /** <p><code>BaseElement</code> is a useful base class for implemementation
 21    * inheritence of an XML element.</p>
 22    *
 23    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 24    * @version $Revision: 1.7 $
 25    */
 26    public class BaseElement extends AbstractElement {
 27   
 28    /** The <code>QName</code> for this element */
 29    private QName qname;
 30   
 31    /** Stores the parent branch of this node which is either a Document
 32    * if this element is the root element in a document, or another Element
 33    * if it is a child of the root document, or null if it has not been added
 34    * to a document yet.
 35    */
 36    private Branch parentBranch;
 37   
 38    /** List of content nodes. */
 39    protected List content;
 40   
 41    /** list of attributes */
 42    protected List attributes;
 43   
 44   
 45   
 46  2 public BaseElement(String name) {
 47  2 this.qname = getDocumentFactory().createQName(name);
 48    }
 49   
 50  0 public BaseElement(QName qname) {
 51  0 this.qname = qname;
 52    }
 53   
 54  0 public BaseElement(String name,Namespace namespace) {
 55  0 this.qname = getDocumentFactory().createQName(name, namespace);
 56    }
 57   
 58  0 public Element getParent() {
 59  0 return ( parentBranch instanceof Element )
 60    ? (Element) parentBranch : null;
 61    }
 62   
 63  0 public void setParent(Element parent) {
 64  0 if ( parentBranch instanceof Element || parent != null ) {
 65  0 parentBranch = parent;
 66    }
 67    }
 68   
 69  0 public Document getDocument() {
 70  0 if ( parentBranch instanceof Document ) {
 71  0 return (Document) parentBranch;
 72    }
 73  0 else if ( parentBranch instanceof Element ) {
 74  0 Element parent = (Element) parentBranch;
 75  0 return parent.getDocument();
 76    }
 77  0 return null;
 78    }
 79   
 80  0 public void setDocument(Document document) {
 81  0 if ( parentBranch instanceof Document || document != null ) {
 82  0 parentBranch = document;
 83    }
 84    }
 85   
 86  0 public boolean supportsParent() {
 87  0 return true;
 88    }
 89   
 90  6 public QName getQName() {
 91  6 return qname;
 92    }
 93   
 94  0 public void setQName(QName qname) {
 95  0 this.qname = qname;
 96    }
 97   
 98  0 public void clearContent() {
 99  0 contentList().clear();
 100    }
 101   
 102  0 public void setContent(List content) {
 103  0 this.content = content;
 104  0 if ( content instanceof ContentListFacade ) {
 105  0 this.content = ((ContentListFacade) content).getBackingList();
 106    }
 107    }
 108   
 109  0 public void setAttributes(List attributes) {
 110  0 this.attributes = attributes;
 111  0 if ( attributes instanceof ContentListFacade ) {
 112  0 this.attributes = ((ContentListFacade) attributes).getBackingList();
 113    }
 114    }
 115   
 116   
 117    // Implementation methods
 118    //-------------------------------------------------------------------------
 119   
 120  2 protected List contentList() {
 121  2 if ( content == null ) {
 122  2 content = createContentList();
 123    }
 124  2 return content;
 125    }
 126   
 127  2 protected List attributeList() {
 128  2 if ( attributes == null ) {
 129  2 attributes = createAttributeList();
 130    }
 131  2 return attributes;
 132    }
 133   
 134  0 protected List attributeList(int size) {
 135  0 if ( attributes == null ) {
 136  0 attributes = createAttributeList(size);
 137    }
 138  0 return attributes;
 139    }
 140   
 141  0 protected void setAttributeList(List attributes) {
 142  0 this.attributes = attributes;
 143    }
 144   
 145    }
 146   
 147   
 148   
 149   
 150    /*
 151    * Redistribution and use of this software and associated documentation
 152    * ("Software"), with or without modification, are permitted provided
 153    * that the following conditions are met:
 154    *
 155    * 1. Redistributions of source code must retain copyright
 156    * statements and notices. Redistributions must also contain a
 157    * copy of this document.
 158    *
 159    * 2. Redistributions in binary form must reproduce the
 160    * above copyright notice, this list of conditions and the
 161    * following disclaimer in the documentation and/or other
 162    * materials provided with the distribution.
 163    *
 164    * 3. The name "DOM4J" must not be used to endorse or promote
 165    * products derived from this Software without prior written
 166    * permission of MetaStuff, Ltd. For written permission,
 167    * please contact dom4j-info@metastuff.com.
 168    *
 169    * 4. Products derived from this Software may not be called "DOM4J"
 170    * nor may "DOM4J" appear in their names without prior written
 171    * permission of MetaStuff, Ltd. DOM4J is a registered
 172    * trademark of MetaStuff, Ltd.
 173    *
 174    * 5. Due credit should be given to the DOM4J Project -
 175    * http://www.dom4j.org
 176    *
 177    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 178    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 179    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 180    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 181    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 182    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 183    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 184    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 185    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 186    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 187    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 188    * OF THE POSSIBILITY OF SUCH DAMAGE.
 189    *
 190    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 191    *
 192    * $Id: BaseElement.java,v 1.7 2004/06/25 08:03:41 maartenc Exp $
 193    */