OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / gnu / xml / libxmlj / dom / GnomeElement.java
1 /* GnomeElement.java - 
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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.
20
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.
25
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. */
37
38 package gnu.xml.libxmlj.dom;
39
40 import gnu.java.lang.CPStringBuilder;
41
42 import java.util.HashSet;
43 import java.util.Set;
44
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;
50
51 /**
52  * A DOM element node implemented in libxml2.
53  *
54  * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
55  */
56 class GnomeElement
57   extends GnomeNode
58   implements Element
59 {
60
61   /**
62    * User-defined ID attributes.
63    */
64   Set userIdAttrs;
65
66   GnomeElement(Object id)
67   {
68     super(id);
69   }
70   
71   public String getTagName()
72   {
73     return getNodeName();
74   }
75
76   public native String getAttribute(String name);
77
78   public native void setAttribute(String name, String value)
79     throws DOMException;
80   
81   public void removeAttribute(String name)
82     throws DOMException
83   {
84     Attr attr = getAttributeNode(name);
85     if (attr != null)
86       {
87         removeAttributeNode(attr);
88       }
89   }
90
91   public native Attr getAttributeNode(String name);
92   
93   public native Attr setAttributeNode(Attr newAttr)
94     throws DOMException;
95
96   public native Attr removeAttributeNode(Attr oldAttr)
97     throws DOMException;
98
99   public native NodeList getElementsByTagName(String name);
100   
101   public native String getAttributeNS(String namespaceURI, String localName);
102   
103   public native void setAttributeNS(String namespaceURI, String
104                                     qualifiedName, String value)
105     throws DOMException;
106
107   public void removeAttributeNS(String namespaceURI, String localName)
108     throws DOMException
109   {
110     Attr attr = getAttributeNodeNS(namespaceURI, localName);
111     if (attr != null)
112       {
113         removeAttributeNode(attr);
114       }
115   }
116   
117   public native Attr getAttributeNodeNS(String namespaceURI,
118                                         String localName);
119
120   public native Attr setAttributeNodeNS(Attr newAttr)
121     throws DOMException;
122
123   public native NodeList getElementsByTagNameNS(String namespaceURI,
124                                                 String localName);
125   
126   public native boolean hasAttribute(String name);
127
128   public native boolean hasAttributeNS(String namespaceURI,
129                                        String localName);
130
131   // DOM Level 3 methods
132
133   public TypeInfo getSchemaTypeInfo()
134   {
135     return new GnomeTypeInfo(id);
136   }
137
138   public void setIdAttribute(String name, boolean isId)
139   {
140     Attr attr = getAttributeNode(name);
141     setIdAttributeNode(attr, isId);
142   }
143
144   public void setIdAttributeNode(Attr attr, boolean isId)
145   {
146     if (attr == null)// FIXME || !attr.getOwnerElement().equals(this))
147       {
148         throw new GnomeDOMException(DOMException.NOT_FOUND_ERR, null);
149       }
150     if (isId)
151       {
152         if (userIdAttrs == null)
153           {
154             userIdAttrs = new HashSet();
155           }
156         userIdAttrs.add(attr);
157       }
158     else if (userIdAttrs != null)
159       {
160         userIdAttrs.remove(attr);
161         if (userIdAttrs.isEmpty())
162           {
163             userIdAttrs = null;
164           }
165       }
166   }
167
168   public void setIdAttributeNS(String namespaceURI, String localName,
169                                boolean isId)
170   {
171     Attr attr = getAttributeNodeNS(namespaceURI, localName);
172     setIdAttributeNode(attr, isId);
173   }
174
175   public String toString()
176   {
177     CPStringBuilder buffer = new CPStringBuilder(getClass().getName());
178     buffer.append("[tagName=");
179     buffer.append(getTagName());
180     buffer.append("]");
181     return buffer.toString();
182   }
183
184 }