001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xml2;
030:
031: import org.w3c.dom.Attr;
032: import org.w3c.dom.Element;
033: import org.w3c.dom.Node;
034: import org.w3c.dom.TypeInfo;
035:
036: import javax.xml.namespace.QName;
037: import java.io.IOException;
038:
039: public class QAttr extends QNode implements Attr {
040: QName _name;
041: private String _value;
042: private boolean _specified = true;
043:
044: public QAttr(String name) {
045: _name = new QName(name);
046: }
047:
048: public QAttr(QName name) {
049: _name = name;
050: }
051:
052: protected QAttr(QName name, String value) {
053: _name = name;
054: _value = value;
055: }
056:
057: protected QAttr(QDocument owner, QName name) {
058: super (owner);
059:
060: _name = name;
061: }
062:
063: public Element getOwnerElement() {
064: return (Element) getParentNode();
065: }
066:
067: public short getNodeType() {
068: return ATTRIBUTE_NODE;
069: }
070:
071: /**
072: * Returns the full QName.
073: */
074: public QName getQName() {
075: return _name;
076: }
077:
078: public String getNodeName() {
079: return _name.getLocalPart();
080: }
081:
082: public boolean isId() {
083: return false;
084: }
085:
086: public String getName() {
087: return _name.getLocalPart(); // XXX:
088: }
089:
090: public String getPrefix() {
091: return _name.getPrefix();
092: }
093:
094: public String getLocalName() {
095: return _name.getLocalPart();
096: }
097:
098: public String getCanonicalName() {
099: //return _name.getCanonicalName();
100: return _name.toString(); // XXX:
101: }
102:
103: public String getNamespaceURI() {
104: return _name.getNamespaceURI();
105: }
106:
107: public String getNodeValue() {
108: return _value;
109: }
110:
111: public TypeInfo getSchemaTypeInfo() {
112: return null;
113: }
114:
115: public void setNodeValue(String value) {
116: _value = value;
117: }
118:
119: public String getValue() {
120: return _value;
121: }
122:
123: public void setValue(String value) {
124: _value = value;
125: }
126:
127: public boolean getSpecified() {
128: return _specified;
129: }
130:
131: public void setSpecified(boolean specified) {
132: _specified = specified;
133: }
134:
135: Node importNode(QDocument owner, boolean deep) {
136: QNode node = new QAttr(_name, _value);
137: node._owner = owner;
138: return node;
139: }
140:
141: public void print(XmlPrinter out) throws IOException {
142: if (!_specified)
143: return;
144:
145: out.attribute(getNamespaceURI(), getLocalName(), getNodeName(),
146: getNodeValue());
147: }
148:
149: private Object writeReplace() {
150: return new SerializedXml(this );
151: }
152:
153: public String toString() {
154: if (_value != null)
155: return "Attr[" + _name + " " + _value + "]";
156: else
157: return "Attr[" + _name + "]";
158: }
159: }
|