2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.harmony.xml.dom;
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;
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.
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
35 public final class AttrImpl extends NodeImpl implements Attr {
37 // Maintained by ElementImpl.
38 ElementImpl ownerElement;
41 boolean namespaceAware;
48 AttrImpl(DocumentImpl document, String namespaceURI, String qualifiedName) {
51 setNameNS(this, namespaceURI, qualifiedName);
55 AttrImpl(DocumentImpl document, String name) {
58 this.namespaceAware = false;
60 int prefixSeparator = name.lastIndexOf(":");
61 if (prefixSeparator != -1) {
62 String prefix = name.substring(0, prefixSeparator);
63 String localName = name.substring(prefixSeparator + 1);
65 if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
66 throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
69 if (!DocumentImpl.isXMLIdentifier(name)) {
70 throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
74 this.localName = name;
78 public String getLocalName() {
79 return namespaceAware ? localName : null;
82 public String getName() {
84 ? prefix + ":" + localName
89 public String getNamespaceURI() {
94 public String getNodeName() {
98 public short getNodeType() {
99 return Node.ATTRIBUTE_NODE;
103 public String getNodeValue() {
107 public Element getOwnerElement() {
112 public String getPrefix() {
116 public boolean getSpecified() {
117 return value != null;
120 public String getValue() {
125 public void setPrefix(String prefix) {
126 this.prefix = validatePrefix(prefix, namespaceAware, namespaceURI);
129 public void setValue(String value) throws DOMException {
133 public TypeInfo getSchemaTypeInfo() {
134 // TODO: populate this when we support XML Schema
135 return NULL_TYPE_INFO;
138 public boolean isId() {