001: /*
002: * $Id: AttributeEvent.java,v 1.3 2004/07/15 02:11:01 cniles Exp $
003: *
004: * Copyright (c) 2004, Christian Niles, unit12.net
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions are met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * * Neither the name of Christian Niles, Unit12, nor the names of its
018: * contributors may be used to endorse or promote products derived from
019: * this software without specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
022: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
023: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
024: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
025: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
026: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
027: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
028: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
029: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
030: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
031: * POSSIBILITY OF SUCH DAMAGE.
032: *
033: */
034: package javanet.staxutils.events;
035:
036: import javax.xml.namespace.QName;
037: import javax.xml.stream.Location;
038: import javax.xml.stream.events.Attribute;
039:
040: /**
041: * {@link Attribute} event implementation.
042: *
043: * @author Christian Niles
044: * @version $Revision: 1.3 $
045: */
046: public class AttributeEvent extends AbstractXMLEvent implements
047: Attribute {
048:
049: /**
050: * Whether the attribute was specified in the document. Defaults to
051: * <code>true</code>.
052: */
053: private boolean specified = true;
054:
055: /** The qualified attribute name. */
056: private QName name;
057:
058: /** The normalized attribute value. */
059: private String value;
060:
061: /** Type of attribute as specified in the DTD. Defaults to <code>CDATA</code>. */
062: private String dtdType = "CDATA";
063:
064: /**
065: * Constructs an <code>AttributeEvent</code> with the specified name and value.
066: *
067: * @param name The qualified attribute name.
068: * @param value The attribute value.
069: */
070: public AttributeEvent(QName name, String value) {
071:
072: this .name = name;
073: this .value = value;
074:
075: }
076:
077: /**
078: * Constructs a new <code>AttributeEvent</code>.
079: *
080: * @param name The qualified attribute name.
081: * @param value The attribute value.
082: * @param specified Whether the attribute was specified in the document
083: * (<code>true</code), or inherited from a DTD or schema
084: * (<code>false</code>).
085: */
086: public AttributeEvent(QName name, String value, boolean specified) {
087:
088: this .name = name;
089: this .value = value;
090: this .specified = specified;
091:
092: }
093:
094: /**
095: * Constructs a new <code>AttributeEvent</code>.
096: *
097: * @param name The qualified attribute name.
098: * @param value The attribute value.
099: * @param location The {@link Location} of the attribute.
100: */
101: public AttributeEvent(QName name, String value, Location location) {
102:
103: super (location);
104: this .name = name;
105: this .value = value;
106:
107: }
108:
109: /**
110: * Constructs a new <code>AttributeEvent</code>.
111: *
112: * @param name The qualified attribute name.
113: * @param value The attribute value.
114: * @param location The {@link Location} of the attribute.
115: * @param schemaType The attribute type as specified in the schema.
116: */
117: public AttributeEvent(QName name, String value, Location location,
118: QName schemaType) {
119:
120: super (location, schemaType);
121: this .name = name;
122: this .value = value;
123:
124: }
125:
126: /**
127: * Constructs a new <code>AttributeEvent</code>.
128: *
129: * @param name The qualified attribute name.
130: * @param value The attribute value.
131: * @param specified Whether the attribute was specified in the document
132: * (<code>true</code), or inherited from a DTD or schema
133: * (<code>false</code>).
134: * @param location The {@link Location} of the attribute.
135: * @param dtdType The attribute type as specified in the DTD.
136: * @param schemaType The attribute type as specified in the schema.
137: */
138: public AttributeEvent(QName name, String value, boolean specified,
139: String dtdType, Location location, QName schemaType) {
140:
141: super (location, schemaType);
142: this .name = name;
143: this .value = value;
144: this .specified = specified;
145: this .dtdType = dtdType;
146:
147: }
148:
149: /**
150: * Copy constructor that optionally allows the name and/or value to be changed.
151: *
152: * @param name The new attribute name, or <code>null</code> to use the name from
153: * the provided attribute.
154: * @param value The new attribute value, or <code>null</code> to use the value
155: * from the provided attribute.
156: * @param that The {@link Attribute} event to copy.
157: */
158: public AttributeEvent(QName name, String value, Attribute that) {
159:
160: super (that);
161: this .specified = that.isSpecified();
162: this .name = (name == null ? that.getName() : name);
163: this .value = (value == null ? that.getValue() : value);
164: this .dtdType = that.getDTDType();
165:
166: }
167:
168: /**
169: * Copy constructor.
170: *
171: * @param that The {@link Attribute} event to copy.
172: */
173: public AttributeEvent(Attribute that) {
174:
175: super (that);
176: this .specified = that.isSpecified();
177: this .name = that.getName();
178: this .value = that.getValue();
179: this .dtdType = that.getDTDType();
180:
181: }
182:
183: /** Returns {@link #ATTRIBUTE}. */
184: public int getEventType() {
185:
186: return ATTRIBUTE;
187:
188: }
189:
190: public QName getName() {
191:
192: return name;
193:
194: }
195:
196: public String getValue() {
197:
198: return value;
199:
200: }
201:
202: public boolean isSpecified() {
203:
204: return specified;
205:
206: }
207:
208: public String getDTDType() {
209:
210: return dtdType;
211:
212: }
213:
214: }
|