KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > dom > AttrOverNodeInfo


1 package net.sf.saxon.dom;
2
3 import net.sf.saxon.om.NodeInfo;
4 import net.sf.saxon.type.Type;
5 import org.w3c.dom.Attr JavaDoc;
6 import org.w3c.dom.DOMException JavaDoc;
7 import org.w3c.dom.Element JavaDoc;
8 import org.w3c.dom.TypeInfo JavaDoc;
9
10 /**
11  * This class is an implementation of the DOM Element class that wraps a Saxon NodeInfo
12  * representation of an attribute node.
13  */

14
15 public class AttrOverNodeInfo extends NodeOverNodeInfo implements Attr JavaDoc {
16
17      /**
18     * Get the name of an attribute node (the QName) (DOM method)
19     */

20
21     public String JavaDoc getName() {
22         return node.getDisplayName();
23     }
24
25     /**
26     * Return the character value of an attribute node (DOM method)
27     * @return the attribute value
28     */

29
30     public String JavaDoc getValue() {
31         return node.getStringValue();
32     }
33
34     /**
35      * If this attribute was explicitly given a value in the original
36      * document, this is <code>true</code> ; otherwise, it is
37      * <code>false</code>. (DOM method)
38      * @return Always true in this implementation.
39      */

40
41     public boolean getSpecified() {
42         return true;
43     }
44
45     /**
46     * Set the value of an attribute node. (DOM method).
47     * Always fails (because tree is readonly)
48     */

49
50     public void setValue(String JavaDoc value) throws DOMException JavaDoc {
51         disallowUpdate();
52     }
53
54     /**
55      * The <code>Element</code> node this attribute is attached to or
56      * <code>null</code> if this attribute is not in use.
57      * @since DOM Level 2
58      */

59
60     public Element JavaDoc getOwnerElement() {
61         if (node.getNodeKind()!=Type.ATTRIBUTE) {
62             throw new UnsupportedOperationException JavaDoc(
63                         "This method is defined only on attribute nodes");
64         }
65         return (Element JavaDoc)wrap(node.getParent());
66     }
67     /**
68      * Get the schema type information for this node. Returns null for an untyped node.
69      */

70
71     public TypeInfo JavaDoc getSchemaTypeInfo() {
72         int annotation = node.getTypeAnnotation();
73         if (annotation == -1 || ((annotation & NodeInfo.IS_DTD_TYPE) != 0)) {
74             return null;
75         }
76         return new TypeInfoImpl(node.getConfiguration(),
77                 node.getConfiguration().getSchemaType(annotation));
78     }
79
80 }
81
82 //
83
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
84
// you may not use this file except in compliance with the License. You may obtain a copy of the
85
// License at http://www.mozilla.org/MPL/
86
//
87
// Software distributed under the License is distributed on an "AS IS" basis,
88
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
89
// See the License for the specific language governing rights and limitations under the License.
90
//
91
// The Original Code is: all this file.
92
//
93
// The Initial Developer of the Original Code is Michael H. Kay.
94
//
95
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
96
//
97
// Contributor(s): none.
98
//
Popular Tags