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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.stream.events;
031:
032: import javax.xml.namespace.QName;
033: import javax.xml.stream.XMLStreamException;
034: import javax.xml.stream.events.Attribute;
035: import java.io.IOException;
036: import java.io.Writer;
037:
038: public class AttributeImpl extends XMLEventImpl implements Attribute {
039: private final QName _name;
040: private final String _value;
041: private final boolean _specified;
042: private final String _dtdType;
043:
044: public AttributeImpl(QName name, String value) {
045: this (name, value, true);
046: }
047:
048: public AttributeImpl(QName name, String value, boolean specified) {
049: this (name, value, specified, "CDATA");
050: }
051:
052: public AttributeImpl(QName name, String value, boolean specified,
053: String dtdType) {
054: _name = name;
055: _value = value;
056: _specified = specified;
057: _dtdType = dtdType;
058: }
059:
060: public String getDTDType() {
061: return _dtdType;
062: }
063:
064: public QName getName() {
065: return _name;
066: }
067:
068: public String getValue() {
069: return _value;
070: }
071:
072: public boolean isSpecified() {
073: return _specified;
074: }
075:
076: public int getEventType() {
077: return ATTRIBUTE;
078: }
079:
080: public void writeAsEncodedUnicode(Writer writer)
081: throws XMLStreamException {
082: try {
083: writer.write(_name + "=\"" + _value + "\"");
084: } catch (IOException e) {
085: throw new XMLStreamException(e);
086: }
087: }
088:
089: public String toString() {
090: return _name + "=\"" + _value + "\"";
091: }
092:
093: public boolean equals(Object o) {
094: if (!(o instanceof Attribute))
095: return false;
096: if (o == null)
097: return false;
098: if (this == o)
099: return true;
100:
101: Attribute attr = (Attribute) o;
102:
103: return getName().equals(attr.getName())
104: && getDTDType().equals(attr.getDTDType())
105: && getValue().equals(attr.getValue())
106: && isSpecified() == attr.isSpecified();
107: }
108: }
|