6
|
1 |
/*
|
|
2 |
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.stream.events;
|
|
27 |
|
|
28 |
import javax.xml.namespace.QName;
|
|
29 |
import javax.xml.stream.events.Attribute;
|
|
30 |
import java.io.Writer;
|
|
31 |
import javax.xml.stream.events.XMLEvent;
|
|
32 |
|
|
33 |
|
|
34 |
//xxx: AttributeEvent is not really a first order event. Should we be renaming the class to AttributeImpl for consistent
|
|
35 |
//naming convention.
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Implementation of Attribute Event.
|
|
39 |
*
|
|
40 |
*@author Neeraj Bajaj, Sun Microsystems
|
|
41 |
*@author K.Venugopal, Sun Microsystems
|
|
42 |
*
|
|
43 |
*/
|
|
44 |
|
|
45 |
public class AttributeImpl extends DummyEvent implements Attribute
|
|
46 |
|
|
47 |
{
|
|
48 |
//attribute value
|
|
49 |
private String fValue;
|
|
50 |
private String fNonNormalizedvalue;
|
|
51 |
|
|
52 |
//name of the attribute
|
|
53 |
private QName fQName;
|
|
54 |
//attribute type
|
|
55 |
private String fAttributeType = "CDATA";
|
|
56 |
|
|
57 |
|
|
58 |
//A flag indicating whether this attribute was actually specified in the start-tag
|
|
59 |
//of its element or was defaulted from the schema.
|
|
60 |
private boolean fIsSpecified;
|
|
61 |
|
|
62 |
public AttributeImpl(){
|
|
63 |
init();
|
|
64 |
}
|
|
65 |
public AttributeImpl(String name, String value) {
|
|
66 |
init();
|
|
67 |
fQName = new QName(name);
|
|
68 |
fValue = value;
|
|
69 |
}
|
|
70 |
|
|
71 |
public AttributeImpl(String prefix, String name, String value) {
|
|
72 |
this(prefix, null,name, value, null,null,false );
|
|
73 |
}
|
|
74 |
|
|
75 |
public AttributeImpl(String prefix, String uri, String localPart, String value, String type) {
|
|
76 |
this(prefix, uri, localPart, value, null, type, false);
|
|
77 |
}
|
|
78 |
|
|
79 |
public AttributeImpl(String prefix, String uri, String localPart, String value, String nonNormalizedvalue, String type, boolean isSpecified) {
|
|
80 |
this(new QName(uri, localPart, prefix), value, nonNormalizedvalue, type, isSpecified);
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
public AttributeImpl(QName qname, String value, String nonNormalizedvalue, String type, boolean isSpecified) {
|
|
85 |
init();
|
|
86 |
fQName = qname ;
|
|
87 |
fValue = value ;
|
|
88 |
if(type != null && !type.equals(""))
|
|
89 |
fAttributeType = type;
|
|
90 |
|
|
91 |
fNonNormalizedvalue = nonNormalizedvalue;
|
|
92 |
fIsSpecified = isSpecified ;
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
public String toString() {
|
|
97 |
if( fQName.getPrefix() != null && fQName.getPrefix().length() > 0 )
|
|
98 |
return fQName.getPrefix() + ":" + fQName.getLocalPart() + "='" + fValue + "'";
|
|
99 |
else
|
|
100 |
return fQName.getLocalPart() + "='" + fValue + "'";
|
|
101 |
}
|
|
102 |
|
|
103 |
public void setName(QName name){
|
|
104 |
fQName = name ;
|
|
105 |
}
|
|
106 |
|
|
107 |
public QName getName() {
|
|
108 |
return fQName;
|
|
109 |
}
|
|
110 |
|
|
111 |
public void setValue(String value){
|
|
112 |
fValue = value;
|
|
113 |
}
|
|
114 |
|
|
115 |
public String getValue() {
|
|
116 |
return fValue;
|
|
117 |
}
|
|
118 |
|
|
119 |
public void setNonNormalizedValue(String nonNormalizedvalue){
|
|
120 |
fNonNormalizedvalue = nonNormalizedvalue;
|
|
121 |
}
|
|
122 |
|
|
123 |
public String getNonNormalizedValue(){
|
|
124 |
return fNonNormalizedvalue ;
|
|
125 |
}
|
|
126 |
|
|
127 |
public void setAttributeType(String attributeType){
|
|
128 |
fAttributeType = attributeType ;
|
|
129 |
}
|
|
130 |
|
|
131 |
/** Gets the type of this attribute, default is "CDATA */
|
|
132 |
// We dont need to take care of default value.. implementation takes care of it.
|
|
133 |
public String getDTDType() {
|
|
134 |
return fAttributeType;
|
|
135 |
}
|
|
136 |
|
|
137 |
/** is this attribute is specified in the instance document */
|
|
138 |
|
|
139 |
public void setSpecified(boolean isSpecified){
|
|
140 |
fIsSpecified = isSpecified ;
|
|
141 |
}
|
|
142 |
|
|
143 |
public boolean isSpecified() {
|
|
144 |
return fIsSpecified ;
|
|
145 |
}
|
|
146 |
|
|
147 |
/** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
|
|
148 |
*
|
|
149 |
* No indentation or whitespace should be outputted.
|
|
150 |
*
|
|
151 |
*
|
|
152 |
*
|
|
153 |
* Any user defined event type SHALL have this method
|
|
154 |
*
|
|
155 |
* called when being written to on an output stream.
|
|
156 |
*
|
|
157 |
* Built in Event types MUST implement this method,
|
|
158 |
*
|
|
159 |
* but implementations MAY choose not call these methods
|
|
160 |
*
|
|
161 |
* for optimizations reasons when writing out built in
|
|
162 |
*
|
|
163 |
* Events to an output stream.
|
|
164 |
*
|
|
165 |
* The output generated MUST be equivalent in terms of the
|
|
166 |
*
|
|
167 |
* infoset expressed.
|
|
168 |
*
|
|
169 |
*
|
|
170 |
*
|
|
171 |
* @param writer The writer that will output the data
|
|
172 |
*
|
|
173 |
* @throws XMLStreamException if there is a fatal error writing the event
|
|
174 |
*
|
|
175 |
*/
|
|
176 |
|
|
177 |
public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException {
|
|
178 |
|
|
179 |
}
|
|
180 |
|
|
181 |
protected void init(){
|
|
182 |
setEventType(XMLEvent.ATTRIBUTE);
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
}//AttributeImpl
|