• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.apache.harmony.xml.dom;
18 
19 import org.w3c.dom.Attr;
20 import org.w3c.dom.DOMException;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.Node;
23 import org.w3c.dom.TypeInfo;
24 
25 /**
26  * Provides a straightforward implementation of the corresponding W3C DOM
27  * interface. The class is used internally only, thus only notable members that
28  * are not in the original interface are documented (the W3C docs are quite
29  * extensive). Hope that's ok.
30  * <p>
31  * Some of the fields may have package visibility, so other classes belonging to
32  * the DOM implementation can easily access them while maintaining the DOM tree
33  * structure.
34  */
35 public final class AttrImpl extends NodeImpl implements Attr {
36 
37     // Maintained by ElementImpl.
38     ElementImpl ownerElement;
39     boolean isId;
40 
41     boolean namespaceAware;
42     String namespaceURI;
43     String prefix;
44     String localName;
45 
46     private String value = "";
47 
AttrImpl(DocumentImpl document, String namespaceURI, String qualifiedName)48     AttrImpl(DocumentImpl document, String namespaceURI, String qualifiedName) {
49         super(document);
50         setNameNS(this, namespaceURI, qualifiedName);
51     }
52 
AttrImpl(DocumentImpl document, String name)53     AttrImpl(DocumentImpl document, String name) {
54         super(document);
55         setName(this, name);
56     }
57 
58     @Override
getLocalName()59     public String getLocalName() {
60         return namespaceAware ? localName : null;
61     }
62 
getName()63     public String getName() {
64         return prefix != null
65                 ? prefix + ":" + localName
66                 : localName;
67     }
68 
69     @Override
getNamespaceURI()70     public String getNamespaceURI() {
71         return namespaceURI;
72     }
73 
74     @Override
getNodeName()75     public String getNodeName() {
76         return getName();
77     }
78 
getNodeType()79     public short getNodeType() {
80         return Node.ATTRIBUTE_NODE;
81     }
82 
83     @Override
getNodeValue()84     public String getNodeValue() {
85         return getValue();
86     }
87 
getOwnerElement()88     public Element getOwnerElement() {
89         return ownerElement;
90     }
91 
92     @Override
getPrefix()93     public String getPrefix() {
94         return prefix;
95     }
96 
getSpecified()97     public boolean getSpecified() {
98         return value != null;
99     }
100 
getValue()101     public String getValue() {
102         return value;
103     }
104 
105     @Override
setPrefix(String prefix)106     public void setPrefix(String prefix) {
107         this.prefix = validatePrefix(prefix, namespaceAware, namespaceURI);
108     }
109 
setValue(String value)110     public void setValue(String value) throws DOMException {
111         this.value = value;
112     }
113 
getSchemaTypeInfo()114     public TypeInfo getSchemaTypeInfo() {
115         // TODO: populate this when we support XML Schema
116         return NULL_TYPE_INFO;
117     }
118 
isId()119     public boolean isId() {
120         return isId;
121     }
122 }
123