libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / gnu / xml / libxmlj / dom / GnomeElement.java
blobe87e3adfe1c1b6b85e87dac61902c26426afe6bd
1 /* GnomeElement.java -
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.xml.libxmlj.dom;
40 import gnu.java.lang.CPStringBuilder;
42 import java.util.HashSet;
43 import java.util.Set;
45 import org.w3c.dom.Attr;
46 import org.w3c.dom.DOMException;
47 import org.w3c.dom.Element;
48 import org.w3c.dom.NodeList;
49 import org.w3c.dom.TypeInfo;
51 /**
52 * A DOM element node implemented in libxml2.
54 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
56 class GnomeElement
57 extends GnomeNode
58 implements Element
61 /**
62 * User-defined ID attributes.
64 Set userIdAttrs;
66 GnomeElement(Object id)
68 super(id);
71 public String getTagName()
73 return getNodeName();
76 public native String getAttribute(String name);
78 public native void setAttribute(String name, String value)
79 throws DOMException;
81 public void removeAttribute(String name)
82 throws DOMException
84 Attr attr = getAttributeNode(name);
85 if (attr != null)
87 removeAttributeNode(attr);
91 public native Attr getAttributeNode(String name);
93 public native Attr setAttributeNode(Attr newAttr)
94 throws DOMException;
96 public native Attr removeAttributeNode(Attr oldAttr)
97 throws DOMException;
99 public native NodeList getElementsByTagName(String name);
101 public native String getAttributeNS(String namespaceURI, String localName);
103 public native void setAttributeNS(String namespaceURI, String
104 qualifiedName, String value)
105 throws DOMException;
107 public void removeAttributeNS(String namespaceURI, String localName)
108 throws DOMException
110 Attr attr = getAttributeNodeNS(namespaceURI, localName);
111 if (attr != null)
113 removeAttributeNode(attr);
117 public native Attr getAttributeNodeNS(String namespaceURI,
118 String localName);
120 public native Attr setAttributeNodeNS(Attr newAttr)
121 throws DOMException;
123 public native NodeList getElementsByTagNameNS(String namespaceURI,
124 String localName);
126 public native boolean hasAttribute(String name);
128 public native boolean hasAttributeNS(String namespaceURI,
129 String localName);
131 // DOM Level 3 methods
133 public TypeInfo getSchemaTypeInfo()
135 return new GnomeTypeInfo(id);
138 public void setIdAttribute(String name, boolean isId)
140 Attr attr = getAttributeNode(name);
141 setIdAttributeNode(attr, isId);
144 public void setIdAttributeNode(Attr attr, boolean isId)
146 if (attr == null)// FIXME || !attr.getOwnerElement().equals(this))
148 throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
150 if (isId)
152 if (userIdAttrs == null)
154 userIdAttrs = new HashSet();
156 userIdAttrs.add(attr);
158 else if (userIdAttrs != null)
160 userIdAttrs.remove(attr);
161 if (userIdAttrs.isEmpty())
163 userIdAttrs = null;
168 public void setIdAttributeNS(String namespaceURI, String localName,
169 boolean isId)
171 Attr attr = getAttributeNodeNS(namespaceURI, localName);
172 setIdAttributeNode(attr, isId);
175 public String toString()
177 CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
178 buffer.append("[tagName=");
179 buffer.append(getTagName());
180 buffer.append("]");
181 return buffer.toString();