001: /*
002: * $Id: AttributeImpl.java,v 1.2 2006/04/01 06:01:35 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import javax.xml.namespace.QName;
032: import javax.xml.stream.events.Attribute;
033: import java.io.Writer;
034: import javax.xml.stream.events.XMLEvent;
035:
036: //xxx: AttributeEvent is not really a first order event. Should we be renaming the class to AttributeImpl for consistent
037: //naming convention.
038:
039: /**
040: * Implementation of Attribute Event.
041: *
042: *@author Neeraj Bajaj, Sun Microsystems
043: *@author K.Venugopal, Sun Microsystems
044: *
045: */
046:
047: public class AttributeImpl extends DummyEvent implements Attribute
048:
049: {
050: //attribute value
051: private String fValue;
052: private String fNonNormalizedvalue;
053:
054: //name of the attribute
055: private QName fQName;
056: //attribute type
057: private String fAttributeType = "CDATA";
058:
059: //A flag indicating whether this attribute was actually specified in the start-tag
060: //of its element or was defaulted from the schema.
061: private boolean fIsSpecified;
062:
063: public AttributeImpl() {
064: init();
065: }
066:
067: public AttributeImpl(String name, String value) {
068: init();
069: fQName = new QName(name);
070: fValue = value;
071: }
072:
073: public AttributeImpl(String prefix, String name, String value) {
074: this (prefix, null, name, value, null, null, false);
075: }
076:
077: public AttributeImpl(String prefix, String uri, String localPart,
078: String value, String type) {
079: this (prefix, uri, localPart, value, null, type, false);
080: }
081:
082: public AttributeImpl(String prefix, String uri, String localPart,
083: String value, String nonNormalizedvalue, String type,
084: boolean isSpecified) {
085: this (new QName(uri, localPart, prefix), value,
086: nonNormalizedvalue, type, isSpecified);
087: }
088:
089: public AttributeImpl(QName qname, String value,
090: String nonNormalizedvalue, String type, boolean isSpecified) {
091: init();
092: fQName = qname;
093: fValue = value;
094: if (type != null && !type.equals(""))
095: fAttributeType = type;
096:
097: fNonNormalizedvalue = nonNormalizedvalue;
098: fIsSpecified = isSpecified;
099:
100: }
101:
102: public String toString() {
103: if (fQName.getPrefix() != null
104: && fQName.getPrefix().length() > 0)
105: return fQName.getPrefix() + ":" + fQName.getLocalPart()
106: + "='" + fValue + "'";
107: else
108: return fQName.getLocalPart() + "='" + fValue + "'";
109: }
110:
111: public void setName(QName name) {
112: fQName = name;
113: }
114:
115: public QName getName() {
116: return fQName;
117: }
118:
119: public void setValue(String value) {
120: fValue = value;
121: }
122:
123: public String getValue() {
124: return fValue;
125: }
126:
127: public void setNonNormalizedValue(String nonNormalizedvalue) {
128: fNonNormalizedvalue = nonNormalizedvalue;
129: }
130:
131: public String getNonNormalizedValue() {
132: return fNonNormalizedvalue;
133: }
134:
135: public void setAttributeType(String attributeType) {
136: fAttributeType = attributeType;
137: }
138:
139: /** Gets the type of this attribute, default is "CDATA */
140: // We dont need to take care of default value.. implementation takes care of it.
141: public String getDTDType() {
142: return fAttributeType;
143: }
144:
145: /** is this attribute is specified in the instance document */
146:
147: public void setSpecified(boolean isSpecified) {
148: fIsSpecified = isSpecified;
149: }
150:
151: public boolean isSpecified() {
152: return fIsSpecified;
153: }
154:
155: /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
156: *
157: * No indentation or whitespace should be outputted.
158: *
159: *
160: *
161: * Any user defined event type SHALL have this method
162: *
163: * called when being written to on an output stream.
164: *
165: * Built in Event types MUST implement this method,
166: *
167: * but implementations MAY choose not call these methods
168: *
169: * for optimizations reasons when writing out built in
170: *
171: * Events to an output stream.
172: *
173: * The output generated MUST be equivalent in terms of the
174: *
175: * infoset expressed.
176: *
177: *
178: *
179: * @param writer The writer that will output the data
180: *
181: * @throws XMLStreamException if there is a fatal error writing the event
182: *
183: */
184:
185: public void writeAsEncodedUnicode(Writer writer)
186: throws javax.xml.stream.XMLStreamException {
187:
188: }
189:
190: protected void init() {
191: setEventType(XMLEvent.ATTRIBUTE);
192: }
193:
194: }//AttributeImpl
|