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.xml;
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 java.io.IOException;
037:
038: public class QAttr extends QNode implements Attr {
039: QName _name;
040: private String _value;
041: private boolean _specified = true;
042:
043: public QAttr(String name) {
044: _name = new QName(name);
045: }
046:
047: public QAttr(QName name) {
048: _name = name;
049: }
050:
051: protected QAttr(QName name, String value) {
052: _name = name;
053: _value = value;
054: }
055:
056: protected QAttr(QDocument owner, QName name) {
057: super (owner);
058:
059: _name = name;
060: }
061:
062: public Element getOwnerElement() {
063: return (Element) getParentNode();
064: }
065:
066: public short getNodeType() {
067: return ATTRIBUTE_NODE;
068: }
069:
070: /**
071: * Returns the full QName.
072: */
073: public QName getQName() {
074: return _name;
075: }
076:
077: public String getNodeName() {
078: return _name.getName();
079: }
080:
081: public boolean isId() {
082: return false;
083: }
084:
085: public String getName() {
086: return _name.getName();
087: }
088:
089: public String getPrefix() {
090: return _name.getPrefix();
091: }
092:
093: public String getLocalName() {
094: return _name.getLocalName();
095: }
096:
097: public String getCanonicalName() {
098: return _name.getCanonicalName();
099: }
100:
101: public String getNamespaceURI() {
102: return _name.getNamespace();
103: }
104:
105: public String getNodeValue() {
106: return _value;
107: }
108:
109: public TypeInfo getSchemaTypeInfo() {
110: return null;
111: }
112:
113: public void setNodeValue(String value) {
114: _value = value;
115: }
116:
117: public String getValue() {
118: return _value;
119: }
120:
121: public void setValue(String value) {
122: _value = value;
123: }
124:
125: public boolean getSpecified() {
126: return _specified;
127: }
128:
129: public void setSpecified(boolean specified) {
130: _specified = specified;
131: }
132:
133: Node importNode(QDocument owner, boolean deep) {
134: QNode node = new QAttr(_name, _value);
135: node._owner = owner;
136: return node;
137: }
138:
139: public void print(XmlPrinter out) throws IOException {
140: if (!_specified)
141: return;
142:
143: out.attribute(getNamespaceURI(), getLocalName(), getNodeName(),
144: getNodeValue());
145: }
146:
147: private Object writeReplace() {
148: return new SerializedXml(this );
149: }
150:
151: public String toString() {
152: if (_value != null)
153: return "Attr[" + _name + " " + _value + "]";
154: else
155: return "Attr[" + _name + "]";
156: }
157: }
|