001: package net.sf.saxon.dom;
002:
003: import net.sf.saxon.om.NodeInfo;
004: import net.sf.saxon.type.Type;
005: import org.w3c.dom.Attr;
006: import org.w3c.dom.DOMException;
007: import org.w3c.dom.Element;
008: import org.w3c.dom.TypeInfo;
009:
010: /**
011: * This class is an implementation of the DOM Element class that wraps a Saxon NodeInfo
012: * representation of an attribute node.
013: */
014:
015: public class AttrOverNodeInfo extends NodeOverNodeInfo implements Attr {
016:
017: /**
018: * Get the name of an attribute node (the QName) (DOM method)
019: */
020:
021: public String getName() {
022: return node.getDisplayName();
023: }
024:
025: /**
026: * Return the character value of an attribute node (DOM method)
027: * @return the attribute value
028: */
029:
030: public String getValue() {
031: return node.getStringValue();
032: }
033:
034: /**
035: * If this attribute was explicitly given a value in the original
036: * document, this is <code>true</code> ; otherwise, it is
037: * <code>false</code>. (DOM method)
038: * @return Always true in this implementation.
039: */
040:
041: public boolean getSpecified() {
042: return true;
043: }
044:
045: /**
046: * Set the value of an attribute node. (DOM method).
047: * Always fails (because tree is readonly)
048: */
049:
050: public void setValue(String value) throws DOMException {
051: disallowUpdate();
052: }
053:
054: /**
055: * The <code>Element</code> node this attribute is attached to or
056: * <code>null</code> if this attribute is not in use.
057: * @since DOM Level 2
058: */
059:
060: public Element getOwnerElement() {
061: if (node.getNodeKind() != Type.ATTRIBUTE) {
062: throw new UnsupportedOperationException(
063: "This method is defined only on attribute nodes");
064: }
065: return (Element) wrap(node.getParent());
066: }
067:
068: /**
069: * Get the schema type information for this node. Returns null for an untyped node.
070: */
071:
072: public TypeInfo getSchemaTypeInfo() {
073: int annotation = node.getTypeAnnotation();
074: if (annotation == -1
075: || ((annotation & NodeInfo.IS_DTD_TYPE) != 0)) {
076: return null;
077: }
078: return new TypeInfoImpl(node.getConfiguration(), node
079: .getConfiguration().getSchemaType(annotation));
080: }
081:
082: }
083:
084: //
085: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
086: // you may not use this file except in compliance with the License. You may obtain a copy of the
087: // License at http://www.mozilla.org/MPL/
088: //
089: // Software distributed under the License is distributed on an "AS IS" basis,
090: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
091: // See the License for the specific language governing rights and limitations under the License.
092: //
093: // The Original Code is: all this file.
094: //
095: // The Initial Developer of the Original Code is Michael H. Kay.
096: //
097: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
098: //
099: // Contributor(s): none.
100: //
|