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)
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
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
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
;
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
;
52 * A DOM element node implemented in libxml2.
54 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
62 * User-defined ID attributes.
66 GnomeElement(Object id
)
71 public String
getTagName()
76 public native String
getAttribute(String name
);
78 public native void setAttribute(String name
, String value
)
81 public void removeAttribute(String name
)
84 Attr attr
= getAttributeNode(name
);
87 removeAttributeNode(attr
);
91 public native Attr
getAttributeNode(String name
);
93 public native Attr
setAttributeNode(Attr newAttr
)
96 public native Attr
removeAttributeNode(Attr oldAttr
)
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
)
107 public void removeAttributeNS(String namespaceURI
, String localName
)
110 Attr attr
= getAttributeNodeNS(namespaceURI
, localName
);
113 removeAttributeNode(attr
);
117 public native Attr
getAttributeNodeNS(String namespaceURI
,
120 public native Attr
setAttributeNodeNS(Attr newAttr
)
123 public native NodeList
getElementsByTagNameNS(String namespaceURI
,
126 public native boolean hasAttribute(String name
);
128 public native boolean hasAttributeNS(String namespaceURI
,
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);
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())
168 public void setIdAttributeNS(String namespaceURI
, String localName
,
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());
181 return buffer
.toString();