author | rriggs |
Fri, 07 Dec 2018 11:51:17 -0500 | |
changeset 52902 | e3398b2e1ab0 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12005 | 1 |
/* |
2 |
* Copyright (c) 2005, Oracle and/or its affiliates. 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* 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 ; |
|
52902
e3398b2e1ab0
8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents:
47216
diff
changeset
|
88 |
if(type != null && !type.isEmpty()) |
12005 | 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 |
protected void writeAsEncodedUnicodeEx(java.io.Writer writer) |
|
148 |
throws java.io.IOException |
|
149 |
{ |
|
150 |
writer.write(toString()); |
|
151 |
} |
|
152 |
||
153 |
||
154 |
protected void init(){ |
|
155 |
setEventType(XMLEvent.ATTRIBUTE); |
|
156 |
} |
|
157 |
||
158 |
||
159 |
||
160 |
||
161 |
}//AttributeImpl |