Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 188   Methods: 14
NCLOC: 92   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
DomAttrOrElm.java 0% 0% 0% 0%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.dom3.core;
 11   
 
 12   
 import org.jbind.xml.base.INamespaces;
 13   
 import org.jbind.xml.base.StringUtil;
 14   
 import org.jbind.xml.core.data.IAnyTypeData;
 15   
 import org.jbind.xml.dom3.types.IDomAttrOrElm;
 16   
 import org.jbind.xml.dom3.types.IDomDocument;
 17   
 import org.jbind.xml.dom3.types.IDomNode;
 18   
 
 19   
 public abstract class DomAttrOrElm extends DomNode implements IDomAttrOrElm {
 20   
 
 21   
   /**
 22   
    * The namespace URI of this node, or <code>null</code> if it is
 23   
    * unspecified.
 24   
    * <br>This is not a computed value that is the result of a namespace
 25   
    * lookup based on an examination of the namespace declarations in
 26   
    * scope. It is merely the namespace URI given at creation time.
 27   
    * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
 28   
    * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
 29   
    * method, such as <code>createElement</code> from the
 30   
    * <code>Document</code> interface, this is always <code>null</code>.Per
 31   
    * the Namespaces in XML Specification  an attribute does not inherit
 32   
    * its namespace from the element it is attached to. If an attribute is
 33   
    * not explicitly given a namespace, it simply has no namespace.
 34   
    * @since DOM Level 2
 35   
    */
 36   
   private String myNamespaceUri = null;
 37   
 
 38   
   /**
 39   
    * The namespace prefix of this node, or <code>null</code> if it is
 40   
    * unspecified.
 41   
    * <br>Note that setting this attribute, when permitted, changes the
 42   
    * <code>nodeName</code> attribute, which holds the qualified name, as
 43   
    * well as the <code>tagName</code> and <code>name</code> attributes of
 44   
    * the <code>Element</code> and <code>Attr</code> interfaces, when
 45   
    * applicable.
 46   
    * <br>Note also that changing the prefix of an attribute that is known to
 47   
    * have a default value, does not make a new attribute with the default
 48   
    * value and the original prefix appear, since the
 49   
    * <code>namespaceURI</code> and <code>localName</code> do not change.
 50   
    * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
 51   
    * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
 52   
    * method, such as <code>createElement</code> from the
 53   
    * <code>Document</code> interface, this is always <code>null</code>.
 54   
    * @exception DOMException
 55   
    *  INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
 56   
    *  illegal character.
 57   
    *  <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
 58   
    *  <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
 59   
    *  malformed, if the <code>namespaceURI</code> of this node is
 60   
    *  <code>null</code>, if the specified prefix is "xml" and the
 61   
    *  <code>namespaceURI</code> of this node is different from "
 62   
    *  http://www.w3.org/XML/1998/namespace", if this node is an attribute
 63   
    *  and the specified prefix is "xmlns" and the
 64   
    *  <code>namespaceURI</code> of this node is different from "
 65   
    *  http://www.w3.org/2000/xmlns/", or if this node is an attribute and
 66   
    *  the <code>qualifiedName</code> of this node is "xmlns" .
 67   
    * @since DOM Level 2
 68   
    */
 69   
   private String myPrefix = null;
 70   
 
 71   
   /**
 72   
    * Only set for nodes that are namespace aware.
 73   
    */
 74   
   private String myLocalName = null;
 75   
 
 76   
   /**
 77   
    * Either the qname for nodes that are namespace aware or the specified name
 78   
    * otherwise.
 79   
    */
 80   
   private String myName = null;
 81   
 
 82   
   private IAnyTypeData myData = null;
 83   
 
 84   
   /**
 85   
    * Creates a 'namespaced' attribute or element.
 86   
    */
 87  0
   public DomAttrOrElm(IDomDocument aDocument, String aNamespaceUri, String aQName) throws DomException {
 88  0
     super(aDocument);
 89  0
     myNamespaceUri = aNamespaceUri;
 90  0
     if (!StringUtil.isValidQName(aQName)) {
 91  0
       throw new DomException(DomException.INVALID_CHARACTER_ERR, "invalid qname '" + aQName + "'");
 92   
     }
 93  0
     int idx = aQName.indexOf(':');
 94  0
     if (idx >= 0) {
 95  0
       setPrefix(aQName.substring(0, idx));
 96  0
       myLocalName = aQName.substring(idx + 1);
 97   
     } else {
 98  0
       myLocalName = aQName;
 99   
     }
 100  0
     myName = aQName;
 101   
   }
 102   
 
 103   
   /**
 104   
    * Creates an attribute or element that is not namespace aware.
 105   
    */
 106  0
   public DomAttrOrElm(IDomDocument aDocument, String aName) {
 107  0
     super(aDocument);
 108  0
     if (!StringUtil.isValidName(aName)) {
 109  0
       throw new DomException(DomException.INVALID_CHARACTER_ERR, "invalid name '" + aName + "'");
 110   
     }
 111  0
     myName = aName;
 112   
   }
 113   
 
 114  0
   public DomAttrOrElm(IDomNode aDomNode, boolean aDeep) {
 115  0
     super(aDomNode, aDeep);
 116  0
     myName = aDomNode.getNodeName();
 117  0
     myNamespaceUri = aDomNode.getNamespaceURI();
 118  0
     myPrefix = aDomNode.getPrefix();
 119  0
     myLocalName = aDomNode.getLocalName();
 120   
   }
 121   
 
 122  0
   public String getPrefix() {
 123  0
     return myPrefix;
 124   
   }
 125   
 
 126  0
   public void setPrefix(String aPrefix) throws DomException {
 127  0
     if (isReadOnly()) {
 128  0
       throw new DomException(DomException.NO_MODIFICATION_ALLOWED_ERR);
 129   
     }
 130   
 
 131  0
     if (!StringUtil.isValidNamespacePrefix(aPrefix)) {
 132  0
       throw new DomException(DomException.NAMESPACE_ERR, "invalid prefix '" + aPrefix + "'");
 133   
     }
 134   
 
 135  0
     String uri = getNamespaceURI();
 136  0
     if (null == uri) {
 137  0
       throw new DomException(DomException.NAMESPACE_ERR, "namespace URI is null");
 138   
     }
 139   
 
 140  0
     if ("xml".equals(aPrefix) && !INamespaces.XML.equals(uri)) {
 141  0
       throw new DomException(DomException.NAMESPACE_ERR, "'xml' prefix must not be used for namespace uri: " + uri);
 142   
     }
 143   
 
 144  0
     if ("xmlns".equals(aPrefix) && !INamespaces.XML_NAMESPACE.equals(uri) && (getNodeType() == ATTRIBUTE_NODE)) {
 145  0
       throw new DomException(DomException.NAMESPACE_ERR, "'xmlns' prefix must not be used for namespace uri: " + uri);
 146   
     }
 147   
 
 148  0
     myPrefix = aPrefix;
 149   
   }
 150   
 
 151  0
   public String getNamespaceURI() {
 152  0
     return myNamespaceUri;
 153   
   }
 154  0
   public String getNamespace() {
 155  0
     return myNamespaceUri;
 156   
   }
 157  0
   public String getLocalName() {
 158  0
     return myLocalName;
 159   
   }
 160  0
   public String getNodeName() {
 161  0
     return myName;
 162   
   }
 163   
 
 164  0
   public String getTextContent() {
 165  0
     return collectTextContent(myChildNodes);
 166   
   }
 167   
 
 168   
   //
 169   
   // Implementation of IDataImpl
 170   
   //
 171   
 
 172  0
   public IAnyTypeData getData() {
 173  0
     return myData;
 174   
   }
 175  0
   public void setData(IAnyTypeData aData) {
 176  0
     myData = aData;
 177   
   }
 178   
 
 179  0
   public String getPartName() {
 180  0
     return getLocalName();
 181   
   }
 182   
 
 183  0
   public boolean isDefault() {
 184  0
     return myChildNodes.isDefault();
 185   
   }
 186   
 
 187   
 }
 188