Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 205   Methods: 20
NCLOC: 108   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AttrImpl.java 62.5% 79.6% 60% 72.7%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: AttrImpl.java 571948 2007-09-02 10:51:37Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.xml.dom;
 21   
 22    import org.w3c.dom.Attr;
 23    import org.w3c.dom.DOMException;
 24    import org.w3c.dom.Element;
 25    import org.w3c.dom.Node;
 26    import org.w3c.dom.TypeInfo;
 27    import org.w3c.dom.UserDataHandler;
 28   
 29    /**
 30    * AttrImpl
 31    *
 32    * @version $Revision: 571948 $, $Date: 2007-09-02 03:51:37 -0700 (Sun, 02 Sep 2007) $
 33    */
 34    public final class AttrImpl extends ContainerNodeImpl
 35    implements Attr {
 36   
 37    private boolean specified = true;
 38    private short symbolID = -1;
 39   
 40   
 41  0 public AttrImpl() {
 42    }
 43   
 44  0 public AttrImpl(NodeImpl parent, byte[] data, int pos, int len) {
 45  0 super(parent, data, pos, len);
 46    }
 47   
 48  80745 public AttrImpl(NodeImpl parent, String nodeName, String nsURI, short symbolID, String nodeValue) {
 49  80745 super(parent, false);
 50  80745 this.nodeName = nodeName;
 51  80745 this.nsURI = nsURI;
 52  80745 this.symbolID = symbolID;
 53  80745 this.nodeValue = nodeValue;
 54   
 55  80745 TextImpl text = new TextImpl(this, false);
 56  80745 text.nodeValue = nodeValue;
 57  80745 childNodes.add(text);
 58    }
 59   
 60  0 public AttrImpl(NodeImpl parent, boolean dirty) {
 61  0 super(parent, dirty);
 62    }
 63   
 64  137282 public AttrImpl(NodeImpl parent, String nodeName) {
 65  137282 super(parent, true);
 66  137282 this.nodeName = nodeName;
 67    }
 68   
 69  2001145 public short getNodeType() {
 70  2001146 return Node.ATTRIBUTE_NODE;
 71    }
 72   
 73    /**
 74    * Returns the name of this attribute.
 75    */
 76  279424 public String getName() {
 77  279424 return getNodeName();
 78    }
 79   
 80  0 public void setSymbolID(short symbolID) {
 81  0 this.symbolID = symbolID;
 82    }
 83   
 84  0 public short getSymbolID() {
 85  0 return symbolID;
 86    }
 87   
 88  137264 public void setNodeValue(String nodeValue) throws DOMException {
 89  137264 checkLoaded();
 90  137264 checkReadOnly();
 91   
 92  137264 childNodes.clear();
 93  137264 TextImpl text = new TextImpl(this, false);
 94  137264 text.nodeValue = nodeValue;
 95  137264 childNodes.add(text);
 96  137264 setDirty();
 97    }
 98   
 99  137264 public void setValue(String value) {
 100  137264 setNodeValue(value);
 101    }
 102   
 103  27 protected boolean isNodeTypeValid(short type) {
 104  27 return type == Node.TEXT_NODE ||
 105    type == Node.ENTITY_REFERENCE_NODE;
 106    }
 107   
 108    /**
 109    * If this attribute was explicitly given a value in the original document,
 110    * this is <code>true</code>; otherwise, it is <code>false</code>. Note
 111    * that the implementation is in charge of this attribute, not the user. If
 112    * the user changes the value of the attribute (even if it ends up having
 113    * the same value as the default value) then the <code>specified</code>
 114    * flag is automatically flipped to <code>true</code>. To re-specify the
 115    * attribute as the default value from the DTD, the user must delete the
 116    * attribute. The implementation will then make a new attribute available
 117    * with <code>specified</code> set to <code>false</code> and the default
 118    * value (if one exists).
 119    * <br>In summary: If the attribute has an assigned value in the document
 120    * then <code>specified</code> is <code>true</code>, and the value is the
 121    * assigned value. If the attribute has no assigned value in the document
 122    * and has a default value in the DTD, then <code>specified</code> is
 123    * <code>false</code>, and the value is the default value in the DTD. If
 124    * the attribute has no assigned value in the document and has a value of
 125    * #IMPLIED in the DTD, then the attribute does not appear in the
 126    * structure model of the document.
 127    */
 128  1816 public boolean getSpecified() {
 129  1816 checkLoaded();
 130  1816 return specified;
 131    }
 132   
 133  0 public void setSpecified(boolean specified) {
 134  0 checkLoaded();
 135  0 this.specified = specified;
 136    }
 137   
 138    /**
 139    * On retrieval, the value of the attribute is returned as a string.
 140    * Character and general entity references are replaced with their values.
 141    * <br>
 142    * On setting, this creates a <code>Text</code> node with the unparsed
 143    * contents of the string.
 144    */
 145  192313 public String getValue() {
 146  192313 return getNodeValue();
 147    }
 148   
 149  192627 public String getNodeValue() {
 150  192627 StringBuffer sb = new StringBuffer();
 151  192627 int size = childNodes.getLength();
 152  192627 for (int i = 0; i < size; i++) {
 153  192627 sb.append(childNodes.item(i).getNodeValue());
 154    }
 155   
 156  192627 return sb.toString();
 157    }
 158   
 159    /**
 160    * @since DOM Level 2
 161    */
 162  2 public Element getOwnerElement() {
 163  2 if (parentNode.getNodeType() == Node.ELEMENT_NODE) {
 164  2 return (Element) parentNode;
 165    } else {
 166  0 return null;
 167    }
 168    }
 169   
 170    //
 171    // DOM Level 3 Implementation
 172    //
 173   
 174    /**
 175    * @since DOM Level 3
 176    */
 177  0 public TypeInfo getSchemaTypeInfo() {
 178  0 return null;
 179    }
 180   
 181    /**
 182    * @since DOM Level 3
 183    */
 184  0 public boolean isId() {
 185  0 return false;
 186    }
 187   
 188  2 Node renameNode(String namespaceURI, String qualifiedName, String prefix) {
 189  2 checkLoaded();
 190  2 checkReadOnly();
 191   
 192  2 if ((XMLNS_PREFIX.equals(prefix) || XMLNS_PREFIX.equals(qualifiedName)) &&
 193    !XMLNS_URI.equals(namespaceURI)) {
 194  0 throw new DOMException(DOMException.NAMESPACE_ERR, XMLNS_PREFIX + " prefix is reserved.");
 195    }
 196   
 197  2 nodeName = qualifiedName;
 198  2 if (prefix != null) {
 199  2 getOwnerElement().setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, namespaceURI);
 200    }
 201   
 202  2 invokeHandlers(UserDataHandler.NODE_RENAMED, this, null);
 203  2 return this;
 204    }
 205    }