001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.tax.dom;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.tax.*;
046:
047: /**
048: *
049: * @author Petr Kuzel
050: */
051: class AttrImpl extends NodeImpl implements Attr {
052:
053: private final TreeAttribute peer;
054:
055: /** Creates a new instance of AttrImpl */
056: public AttrImpl(TreeAttribute peer) {
057: this .peer = peer;
058: }
059:
060: /** The name of this node, depending on its type; see the table above.
061: *
062: */
063: public String getNodeName() {
064: return getName();
065: }
066:
067: /** A code representing the type of the underlying object, as defined above.
068: *
069: */
070: public short getNodeType() {
071: return Node.ATTRIBUTE_NODE;
072: }
073:
074: /** The value of this node, depending on its type; see the table above.
075: * When it is defined to be <code>null</code>, setting it has no effect.
076: * @exception DOMException
077: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
078: * @exception DOMException
079: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
080: * fit in a <code>DOMString</code> variable on the implementation
081: * platform.
082: *
083: */
084: public String getNodeValue() throws DOMException {
085: return getValue();
086: }
087:
088: /** The parent of this node. All nodes, except <code>Attr</code>,
089: * <code>Document</code>, <code>DocumentFragment</code>,
090: * <code>Entity</code>, and <code>Notation</code> may have a parent.
091: * However, if a node has just been created and not yet added to the
092: * tree, or if it has been removed from the tree, this is
093: * <code>null</code>.
094: *
095: */
096: public Node getParentNode() {
097: return null;
098: }
099:
100: /** Returns the name of this attribute.
101: *
102: */
103: public String getName() {
104: return peer.getQName();
105: }
106:
107: /** The <code>Element</code> node this attribute is attached to or
108: * <code>null</code> if this attribute is not in use.
109: * @since DOM Level 2
110: *
111: */
112: public Element getOwnerElement() {
113: return Wrapper.wrap(peer.getOwnerElement());
114: }
115:
116: /** If this attribute was explicitly given a value in the original
117: * document, this is <code>true</code>; otherwise, it is
118: * <code>false</code>. Note that the implementation is in charge of this
119: * attribute, not the user. If the user changes the value of the
120: * attribute (even if it ends up having the same value as the default
121: * value) then the <code>specified</code> flag is automatically flipped
122: * to <code>true</code>. To re-specify the attribute as the default
123: * value from the DTD, the user must delete the attribute. The
124: * implementation will then make a new attribute available with
125: * <code>specified</code> set to <code>false</code> and the default
126: * value (if one exists).
127: * <br>In summary: If the attribute has an assigned value in the document
128: * then <code>specified</code> is <code>true</code>, and the value is
129: * the assigned value.If the attribute has no assigned value in the
130: * document and has a default value in the DTD, then
131: * <code>specified</code> is <code>false</code>, and the value is the
132: * default value in the DTD.If the attribute has no assigned value in
133: * the document and has a value of #IMPLIED in the DTD, then the
134: * attribute does not appear in the structure model of the document.If
135: * the <code>ownerElement</code> attribute is <code>null</code> (i.e.
136: * because it was just created or was set to <code>null</code> by the
137: * various removal and cloning operations) <code>specified</code> is
138: * <code>true</code>.
139: *
140: */
141: public boolean getSpecified() {
142: return peer.isSpecified();
143: }
144:
145: /** On retrieval, the value of the attribute is returned as a string.
146: * Character and general entity references are replaced with their
147: * values. See also the method <code>getAttribute</code> on the
148: * <code>Element</code> interface.
149: * <br>On setting, this creates a <code>Text</code> node with the unparsed
150: * contents of the string. I.e. any characters that an XML processor
151: * would recognize as markup are instead treated as literal text. See
152: * also the method <code>setAttribute</code> on the <code>Element</code>
153: * interface.
154: * @exception DOMException
155: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
156: *
157: */
158: public String getValue() {
159: return peer.getValue();
160: }
161:
162: /** On retrieval, the value of the attribute is returned as a string.
163: * Character and general entity references are replaced with their
164: * values. See also the method <code>getAttribute</code> on the
165: * <code>Element</code> interface.
166: * <br>On setting, this creates a <code>Text</code> node with the unparsed
167: * contents of the string. I.e. any characters that an XML processor
168: * would recognize as markup are instead treated as literal text. See
169: * also the method <code>setAttribute</code> on the <code>Element</code>
170: * interface.
171: * @exception DOMException
172: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
173: *
174: */
175: public void setValue(String value) throws DOMException {
176: throw new ROException();
177: }
178:
179: }
|