author | tbell |
Mon, 20 Apr 2009 22:50:16 -0700 | |
changeset 2669 | 15024792697e |
parent 6 | 7f561c08de6b |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
6 |
* Copyright 2001-2004 The Apache Software Foundation. |
|
7 |
* |
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
||
21 |
package com.sun.org.apache.xerces.internal.impl.xs.traversers; |
|
22 |
||
23 |
import java.util.Enumeration; |
|
24 |
import java.util.Hashtable; |
|
25 |
import java.util.StringTokenizer; |
|
26 |
import java.util.Vector; |
|
27 |
||
28 |
import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; |
|
29 |
import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; |
|
30 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; |
|
31 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaNamespaceSupport; |
|
32 |
import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; |
|
33 |
import com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl; |
|
34 |
import com.sun.org.apache.xerces.internal.impl.xs.XSGrammarBucket; |
|
35 |
import com.sun.org.apache.xerces.internal.impl.xs.XSWildcardDecl; |
|
36 |
import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; |
|
37 |
import com.sun.org.apache.xerces.internal.impl.xs.util.XIntPool; |
|
38 |
import com.sun.org.apache.xerces.internal.util.DOMUtil; |
|
39 |
import com.sun.org.apache.xerces.internal.util.SymbolTable; |
|
40 |
import com.sun.org.apache.xerces.internal.util.XMLSymbols; |
|
41 |
import com.sun.org.apache.xerces.internal.xni.QName; |
|
42 |
import com.sun.org.apache.xerces.internal.xs.XSConstants; |
|
43 |
import org.w3c.dom.Attr; |
|
44 |
import org.w3c.dom.Element; |
|
45 |
||
46 |
/** |
|
47 |
* Class <code>XSAttributeCheck</code> is used to check the validity of attributes |
|
48 |
* appearing in the schema document. It |
|
49 |
* - reports an error for invalid element (invalid namespace, invalid name) |
|
50 |
* - reports an error for invalid attribute (invalid namespace, invalid name) |
|
51 |
* - reports an error for invalid attribute value |
|
52 |
* - return compiled values for attriute values |
|
53 |
* - provide default value for missing optional attributes |
|
54 |
* - provide default value for incorrect attribute values |
|
55 |
* |
|
56 |
* But it's the caller's responsibility to check whether a required attribute |
|
57 |
* is present. |
|
58 |
* |
|
59 |
* Things need revisiting: |
|
60 |
* - Whether to return non-schema attributes/values |
|
61 |
* - Do we need to update NamespaceScope and ErrorReporter when reset()? |
|
62 |
* - Should have the datatype validators return compiled value |
|
63 |
* - use symbol table instead of many hashtables |
|
64 |
* |
|
65 |
* @xerces.internal |
|
66 |
* |
|
67 |
* @author Sandy Gao, IBM |
|
68 |
*/ |
|
69 |
||
70 |
public class XSAttributeChecker { |
|
71 |
||
72 |
// REVISIT: only local element and attribute are different from others. |
|
73 |
// it's possible to have either name or ref. all the others |
|
74 |
// are only allowed to have one of name or ref, or neither of them. |
|
75 |
// we'd better move such checking to the traverser. |
|
76 |
private static final String ELEMENT_N = "element_n"; |
|
77 |
private static final String ELEMENT_R = "element_r"; |
|
78 |
private static final String ATTRIBUTE_N = "attribute_n"; |
|
79 |
private static final String ATTRIBUTE_R = "attribute_r"; |
|
80 |
||
81 |
private static int ATTIDX_COUNT = 0; |
|
82 |
public static final int ATTIDX_ABSTRACT = ATTIDX_COUNT++; |
|
83 |
public static final int ATTIDX_AFORMDEFAULT = ATTIDX_COUNT++; |
|
84 |
public static final int ATTIDX_BASE = ATTIDX_COUNT++; |
|
85 |
public static final int ATTIDX_BLOCK = ATTIDX_COUNT++; |
|
86 |
public static final int ATTIDX_BLOCKDEFAULT = ATTIDX_COUNT++; |
|
87 |
public static final int ATTIDX_DEFAULT = ATTIDX_COUNT++; |
|
88 |
public static final int ATTIDX_EFORMDEFAULT = ATTIDX_COUNT++; |
|
89 |
public static final int ATTIDX_FINAL = ATTIDX_COUNT++; |
|
90 |
public static final int ATTIDX_FINALDEFAULT = ATTIDX_COUNT++; |
|
91 |
public static final int ATTIDX_FIXED = ATTIDX_COUNT++; |
|
92 |
public static final int ATTIDX_FORM = ATTIDX_COUNT++; |
|
93 |
public static final int ATTIDX_ID = ATTIDX_COUNT++; |
|
94 |
public static final int ATTIDX_ITEMTYPE = ATTIDX_COUNT++; |
|
95 |
public static final int ATTIDX_MAXOCCURS = ATTIDX_COUNT++; |
|
96 |
public static final int ATTIDX_MEMBERTYPES = ATTIDX_COUNT++; |
|
97 |
public static final int ATTIDX_MINOCCURS = ATTIDX_COUNT++; |
|
98 |
public static final int ATTIDX_MIXED = ATTIDX_COUNT++; |
|
99 |
public static final int ATTIDX_NAME = ATTIDX_COUNT++; |
|
100 |
public static final int ATTIDX_NAMESPACE = ATTIDX_COUNT++; |
|
101 |
public static final int ATTIDX_NAMESPACE_LIST = ATTIDX_COUNT++; |
|
102 |
public static final int ATTIDX_NILLABLE = ATTIDX_COUNT++; |
|
103 |
public static final int ATTIDX_NONSCHEMA = ATTIDX_COUNT++; |
|
104 |
public static final int ATTIDX_PROCESSCONTENTS = ATTIDX_COUNT++; |
|
105 |
public static final int ATTIDX_PUBLIC = ATTIDX_COUNT++; |
|
106 |
public static final int ATTIDX_REF = ATTIDX_COUNT++; |
|
107 |
public static final int ATTIDX_REFER = ATTIDX_COUNT++; |
|
108 |
public static final int ATTIDX_SCHEMALOCATION = ATTIDX_COUNT++; |
|
109 |
public static final int ATTIDX_SOURCE = ATTIDX_COUNT++; |
|
110 |
public static final int ATTIDX_SUBSGROUP = ATTIDX_COUNT++; |
|
111 |
public static final int ATTIDX_SYSTEM = ATTIDX_COUNT++; |
|
112 |
public static final int ATTIDX_TARGETNAMESPACE = ATTIDX_COUNT++; |
|
113 |
public static final int ATTIDX_TYPE = ATTIDX_COUNT++; |
|
114 |
public static final int ATTIDX_USE = ATTIDX_COUNT++; |
|
115 |
public static final int ATTIDX_VALUE = ATTIDX_COUNT++; |
|
116 |
public static final int ATTIDX_ENUMNSDECLS = ATTIDX_COUNT++; |
|
117 |
public static final int ATTIDX_VERSION = ATTIDX_COUNT++; |
|
118 |
public static final int ATTIDX_XML_LANG = ATTIDX_COUNT++; |
|
119 |
public static final int ATTIDX_XPATH = ATTIDX_COUNT++; |
|
120 |
public static final int ATTIDX_FROMDEFAULT = ATTIDX_COUNT++; |
|
121 |
//public static final int ATTIDX_OTHERVALUES = ATTIDX_COUNT++; |
|
122 |
public static final int ATTIDX_ISRETURNED = ATTIDX_COUNT++; |
|
123 |
||
124 |
private static final XIntPool fXIntPool = new XIntPool(); |
|
125 |
// constants to return |
|
126 |
private static final XInt INT_QUALIFIED = fXIntPool.getXInt(SchemaSymbols.FORM_QUALIFIED); |
|
127 |
private static final XInt INT_UNQUALIFIED = fXIntPool.getXInt(SchemaSymbols.FORM_UNQUALIFIED); |
|
128 |
private static final XInt INT_EMPTY_SET = fXIntPool.getXInt(XSConstants.DERIVATION_NONE); |
|
129 |
private static final XInt INT_ANY_STRICT = fXIntPool.getXInt(XSWildcardDecl.PC_STRICT); |
|
130 |
private static final XInt INT_ANY_LAX = fXIntPool.getXInt(XSWildcardDecl.PC_LAX); |
|
131 |
private static final XInt INT_ANY_SKIP = fXIntPool.getXInt(XSWildcardDecl.PC_SKIP); |
|
132 |
private static final XInt INT_ANY_ANY = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_ANY); |
|
133 |
private static final XInt INT_ANY_LIST = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_LIST); |
|
134 |
private static final XInt INT_ANY_NOT = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_NOT); |
|
135 |
private static final XInt INT_USE_OPTIONAL = fXIntPool.getXInt(SchemaSymbols.USE_OPTIONAL); |
|
136 |
private static final XInt INT_USE_REQUIRED = fXIntPool.getXInt(SchemaSymbols.USE_REQUIRED); |
|
137 |
private static final XInt INT_USE_PROHIBITED = fXIntPool.getXInt(SchemaSymbols.USE_PROHIBITED); |
|
138 |
private static final XInt INT_WS_PRESERVE = fXIntPool.getXInt(XSSimpleType.WS_PRESERVE); |
|
139 |
private static final XInt INT_WS_REPLACE = fXIntPool.getXInt(XSSimpleType.WS_REPLACE); |
|
140 |
private static final XInt INT_WS_COLLAPSE = fXIntPool.getXInt(XSSimpleType.WS_COLLAPSE); |
|
141 |
private static final XInt INT_UNBOUNDED = fXIntPool.getXInt(SchemaSymbols.OCCURRENCE_UNBOUNDED); |
|
142 |
||
143 |
// used to store the map from element name to attribute list |
|
144 |
// for 14 global elements |
|
145 |
private static final Hashtable fEleAttrsMapG = new Hashtable(29); |
|
146 |
// for 39 local elememnts |
|
147 |
private static final Hashtable fEleAttrsMapL = new Hashtable(79); |
|
148 |
||
149 |
// used to initialize fEleAttrsMap |
|
150 |
// step 1: all possible data types |
|
151 |
// DT_??? >= 0 : validate using a validator, which is initialized staticly |
|
152 |
// DT_??? < 0 : validate directly, which is done in "validate()" |
|
153 |
||
154 |
protected static final int DT_ANYURI = 0; |
|
155 |
protected static final int DT_ID = 1; |
|
156 |
protected static final int DT_QNAME = 2; |
|
157 |
protected static final int DT_STRING = 3; |
|
158 |
protected static final int DT_TOKEN = 4; |
|
159 |
protected static final int DT_NCNAME = 5; |
|
160 |
protected static final int DT_XPATH = 6; |
|
161 |
protected static final int DT_XPATH1 = 7; |
|
162 |
protected static final int DT_LANGUAGE = 8; |
|
163 |
||
164 |
// used to store extra datatype validators |
|
165 |
protected static final int DT_COUNT = DT_LANGUAGE + 1; |
|
166 |
private static final XSSimpleType[] fExtraDVs = new XSSimpleType[DT_COUNT]; |
|
167 |
static { |
|
168 |
// step 5: register all datatype validators for new types |
|
169 |
SchemaGrammar grammar = SchemaGrammar.SG_SchemaNS; |
|
170 |
// anyURI |
|
171 |
fExtraDVs[DT_ANYURI] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYURI); |
|
172 |
// ID |
|
173 |
fExtraDVs[DT_ID] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ID); |
|
174 |
// QName |
|
175 |
fExtraDVs[DT_QNAME] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME); |
|
176 |
// string |
|
177 |
fExtraDVs[DT_STRING] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_STRING); |
|
178 |
// token |
|
179 |
fExtraDVs[DT_TOKEN] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_TOKEN); |
|
180 |
// NCName |
|
181 |
fExtraDVs[DT_NCNAME] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_NCNAME); |
|
182 |
// xpath = a subset of XPath expression |
|
183 |
fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; |
|
184 |
// xpath = a subset of XPath expression |
|
185 |
fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; |
|
186 |
// language |
|
187 |
fExtraDVs[DT_LANGUAGE] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_LANGUAGE); |
|
188 |
} |
|
189 |
||
190 |
protected static final int DT_BLOCK = -1; |
|
191 |
protected static final int DT_BLOCK1 = -2; |
|
192 |
protected static final int DT_FINAL = -3; |
|
193 |
protected static final int DT_FINAL1 = -4; |
|
194 |
protected static final int DT_FINAL2 = -5; |
|
195 |
protected static final int DT_FORM = -6; |
|
196 |
protected static final int DT_MAXOCCURS = -7; |
|
197 |
protected static final int DT_MAXOCCURS1 = -8; |
|
198 |
protected static final int DT_MEMBERTYPES = -9; |
|
199 |
protected static final int DT_MINOCCURS1 = -10; |
|
200 |
protected static final int DT_NAMESPACE = -11; |
|
201 |
protected static final int DT_PROCESSCONTENTS = -12; |
|
202 |
protected static final int DT_USE = -13; |
|
203 |
protected static final int DT_WHITESPACE = -14; |
|
204 |
protected static final int DT_BOOLEAN = -15; |
|
205 |
protected static final int DT_NONNEGINT = -16; |
|
206 |
protected static final int DT_POSINT = -17; |
|
207 |
||
208 |
static { |
|
209 |
// step 2: all possible attributes for all elements |
|
210 |
int attCount = 0; |
|
211 |
int ATT_ABSTRACT_D = attCount++; |
|
212 |
int ATT_ATTRIBUTE_FD_D = attCount++; |
|
213 |
int ATT_BASE_R = attCount++; |
|
214 |
int ATT_BASE_N = attCount++; |
|
215 |
int ATT_BLOCK_N = attCount++; |
|
216 |
int ATT_BLOCK1_N = attCount++; |
|
217 |
int ATT_BLOCK_D_D = attCount++; |
|
218 |
int ATT_DEFAULT_N = attCount++; |
|
219 |
int ATT_ELEMENT_FD_D = attCount++; |
|
220 |
int ATT_FINAL_N = attCount++; |
|
221 |
int ATT_FINAL1_N = attCount++; |
|
222 |
int ATT_FINAL_D_D = attCount++; |
|
223 |
int ATT_FIXED_N = attCount++; |
|
224 |
int ATT_FIXED_D = attCount++; |
|
225 |
int ATT_FORM_N = attCount++; |
|
226 |
int ATT_ID_N = attCount++; |
|
227 |
int ATT_ITEMTYPE_N = attCount++; |
|
228 |
int ATT_MAXOCCURS_D = attCount++; |
|
229 |
int ATT_MAXOCCURS1_D = attCount++; |
|
230 |
int ATT_MEMBER_T_N = attCount++; |
|
231 |
int ATT_MINOCCURS_D = attCount++; |
|
232 |
int ATT_MINOCCURS1_D = attCount++; |
|
233 |
int ATT_MIXED_D = attCount++; |
|
234 |
int ATT_MIXED_N = attCount++; |
|
235 |
int ATT_NAME_R = attCount++; |
|
236 |
int ATT_NAMESPACE_D = attCount++; |
|
237 |
int ATT_NAMESPACE_N = attCount++; |
|
238 |
int ATT_NILLABLE_D = attCount++; |
|
239 |
int ATT_PROCESS_C_D = attCount++; |
|
240 |
int ATT_PUBLIC_R = attCount++; |
|
241 |
int ATT_REF_R = attCount++; |
|
242 |
int ATT_REFER_R = attCount++; |
|
243 |
int ATT_SCHEMA_L_R = attCount++; |
|
244 |
int ATT_SCHEMA_L_N = attCount++; |
|
245 |
int ATT_SOURCE_N = attCount++; |
|
246 |
int ATT_SUBSTITUTION_G_N = attCount++; |
|
247 |
int ATT_SYSTEM_N = attCount++; |
|
248 |
int ATT_TARGET_N_N = attCount++; |
|
249 |
int ATT_TYPE_N = attCount++; |
|
250 |
int ATT_USE_D = attCount++; |
|
251 |
int ATT_VALUE_NNI_N = attCount++; |
|
252 |
int ATT_VALUE_PI_N = attCount++; |
|
253 |
int ATT_VALUE_STR_N = attCount++; |
|
254 |
int ATT_VALUE_WS_N = attCount++; |
|
255 |
int ATT_VERSION_N = attCount++; |
|
256 |
int ATT_XML_LANG = attCount++; |
|
257 |
int ATT_XPATH_R = attCount++; |
|
258 |
int ATT_XPATH1_R = attCount++; |
|
259 |
||
260 |
// step 3: store all these attributes in an array |
|
261 |
OneAttr[] allAttrs = new OneAttr[attCount]; |
|
262 |
allAttrs[ATT_ABSTRACT_D] = new OneAttr(SchemaSymbols.ATT_ABSTRACT, |
|
263 |
DT_BOOLEAN, |
|
264 |
ATTIDX_ABSTRACT, |
|
265 |
Boolean.FALSE); |
|
266 |
allAttrs[ATT_ATTRIBUTE_FD_D] = new OneAttr(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, |
|
267 |
DT_FORM, |
|
268 |
ATTIDX_AFORMDEFAULT, |
|
269 |
INT_UNQUALIFIED); |
|
270 |
allAttrs[ATT_BASE_R] = new OneAttr(SchemaSymbols.ATT_BASE, |
|
271 |
DT_QNAME, |
|
272 |
ATTIDX_BASE, |
|
273 |
null); |
|
274 |
allAttrs[ATT_BASE_N] = new OneAttr(SchemaSymbols.ATT_BASE, |
|
275 |
DT_QNAME, |
|
276 |
ATTIDX_BASE, |
|
277 |
null); |
|
278 |
allAttrs[ATT_BLOCK_N] = new OneAttr(SchemaSymbols.ATT_BLOCK, |
|
279 |
DT_BLOCK, |
|
280 |
ATTIDX_BLOCK, |
|
281 |
null); |
|
282 |
allAttrs[ATT_BLOCK1_N] = new OneAttr(SchemaSymbols.ATT_BLOCK, |
|
283 |
DT_BLOCK1, |
|
284 |
ATTIDX_BLOCK, |
|
285 |
null); |
|
286 |
allAttrs[ATT_BLOCK_D_D] = new OneAttr(SchemaSymbols.ATT_BLOCKDEFAULT, |
|
287 |
DT_BLOCK, |
|
288 |
ATTIDX_BLOCKDEFAULT, |
|
289 |
INT_EMPTY_SET); |
|
290 |
allAttrs[ATT_DEFAULT_N] = new OneAttr(SchemaSymbols.ATT_DEFAULT, |
|
291 |
DT_STRING, |
|
292 |
ATTIDX_DEFAULT, |
|
293 |
null); |
|
294 |
allAttrs[ATT_ELEMENT_FD_D] = new OneAttr(SchemaSymbols.ATT_ELEMENTFORMDEFAULT, |
|
295 |
DT_FORM, |
|
296 |
ATTIDX_EFORMDEFAULT, |
|
297 |
INT_UNQUALIFIED); |
|
298 |
allAttrs[ATT_FINAL_N] = new OneAttr(SchemaSymbols.ATT_FINAL, |
|
299 |
DT_FINAL, |
|
300 |
ATTIDX_FINAL, |
|
301 |
null); |
|
302 |
allAttrs[ATT_FINAL1_N] = new OneAttr(SchemaSymbols.ATT_FINAL, |
|
303 |
DT_FINAL1, |
|
304 |
ATTIDX_FINAL, |
|
305 |
null); |
|
306 |
allAttrs[ATT_FINAL_D_D] = new OneAttr(SchemaSymbols.ATT_FINALDEFAULT, |
|
307 |
DT_FINAL2, |
|
308 |
ATTIDX_FINALDEFAULT, |
|
309 |
INT_EMPTY_SET); |
|
310 |
allAttrs[ATT_FIXED_N] = new OneAttr(SchemaSymbols.ATT_FIXED, |
|
311 |
DT_STRING, |
|
312 |
ATTIDX_FIXED, |
|
313 |
null); |
|
314 |
allAttrs[ATT_FIXED_D] = new OneAttr(SchemaSymbols.ATT_FIXED, |
|
315 |
DT_BOOLEAN, |
|
316 |
ATTIDX_FIXED, |
|
317 |
Boolean.FALSE); |
|
318 |
allAttrs[ATT_FORM_N] = new OneAttr(SchemaSymbols.ATT_FORM, |
|
319 |
DT_FORM, |
|
320 |
ATTIDX_FORM, |
|
321 |
null); |
|
322 |
allAttrs[ATT_ID_N] = new OneAttr(SchemaSymbols.ATT_ID, |
|
323 |
DT_ID, |
|
324 |
ATTIDX_ID, |
|
325 |
null); |
|
326 |
allAttrs[ATT_ITEMTYPE_N] = new OneAttr(SchemaSymbols.ATT_ITEMTYPE, |
|
327 |
DT_QNAME, |
|
328 |
ATTIDX_ITEMTYPE, |
|
329 |
null); |
|
330 |
allAttrs[ATT_MAXOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS, |
|
331 |
DT_MAXOCCURS, |
|
332 |
ATTIDX_MAXOCCURS, |
|
333 |
fXIntPool.getXInt(1)); |
|
334 |
allAttrs[ATT_MAXOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS, |
|
335 |
DT_MAXOCCURS1, |
|
336 |
ATTIDX_MAXOCCURS, |
|
337 |
fXIntPool.getXInt(1)); |
|
338 |
allAttrs[ATT_MEMBER_T_N] = new OneAttr(SchemaSymbols.ATT_MEMBERTYPES, |
|
339 |
DT_MEMBERTYPES, |
|
340 |
ATTIDX_MEMBERTYPES, |
|
341 |
null); |
|
342 |
allAttrs[ATT_MINOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS, |
|
343 |
DT_NONNEGINT, |
|
344 |
ATTIDX_MINOCCURS, |
|
345 |
fXIntPool.getXInt(1)); |
|
346 |
allAttrs[ATT_MINOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS, |
|
347 |
DT_MINOCCURS1, |
|
348 |
ATTIDX_MINOCCURS, |
|
349 |
fXIntPool.getXInt(1)); |
|
350 |
allAttrs[ATT_MIXED_D] = new OneAttr(SchemaSymbols.ATT_MIXED, |
|
351 |
DT_BOOLEAN, |
|
352 |
ATTIDX_MIXED, |
|
353 |
Boolean.FALSE); |
|
354 |
allAttrs[ATT_MIXED_N] = new OneAttr(SchemaSymbols.ATT_MIXED, |
|
355 |
DT_BOOLEAN, |
|
356 |
ATTIDX_MIXED, |
|
357 |
null); |
|
358 |
allAttrs[ATT_NAME_R] = new OneAttr(SchemaSymbols.ATT_NAME, |
|
359 |
DT_NCNAME, |
|
360 |
ATTIDX_NAME, |
|
361 |
null); |
|
362 |
allAttrs[ATT_NAMESPACE_D] = new OneAttr(SchemaSymbols.ATT_NAMESPACE, |
|
363 |
DT_NAMESPACE, |
|
364 |
ATTIDX_NAMESPACE, |
|
365 |
INT_ANY_ANY); |
|
366 |
allAttrs[ATT_NAMESPACE_N] = new OneAttr(SchemaSymbols.ATT_NAMESPACE, |
|
367 |
DT_ANYURI, |
|
368 |
ATTIDX_NAMESPACE, |
|
369 |
null); |
|
370 |
allAttrs[ATT_NILLABLE_D] = new OneAttr(SchemaSymbols.ATT_NILLABLE, |
|
371 |
DT_BOOLEAN, |
|
372 |
ATTIDX_NILLABLE, |
|
373 |
Boolean.FALSE); |
|
374 |
allAttrs[ATT_PROCESS_C_D] = new OneAttr(SchemaSymbols.ATT_PROCESSCONTENTS, |
|
375 |
DT_PROCESSCONTENTS, |
|
376 |
ATTIDX_PROCESSCONTENTS, |
|
377 |
INT_ANY_STRICT); |
|
378 |
allAttrs[ATT_PUBLIC_R] = new OneAttr(SchemaSymbols.ATT_PUBLIC, |
|
379 |
DT_TOKEN, |
|
380 |
ATTIDX_PUBLIC, |
|
381 |
null); |
|
382 |
allAttrs[ATT_REF_R] = new OneAttr(SchemaSymbols.ATT_REF, |
|
383 |
DT_QNAME, |
|
384 |
ATTIDX_REF, |
|
385 |
null); |
|
386 |
allAttrs[ATT_REFER_R] = new OneAttr(SchemaSymbols.ATT_REFER, |
|
387 |
DT_QNAME, |
|
388 |
ATTIDX_REFER, |
|
389 |
null); |
|
390 |
allAttrs[ATT_SCHEMA_L_R] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION, |
|
391 |
DT_ANYURI, |
|
392 |
ATTIDX_SCHEMALOCATION, |
|
393 |
null); |
|
394 |
allAttrs[ATT_SCHEMA_L_N] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION, |
|
395 |
DT_ANYURI, |
|
396 |
ATTIDX_SCHEMALOCATION, |
|
397 |
null); |
|
398 |
allAttrs[ATT_SOURCE_N] = new OneAttr(SchemaSymbols.ATT_SOURCE, |
|
399 |
DT_ANYURI, |
|
400 |
ATTIDX_SOURCE, |
|
401 |
null); |
|
402 |
allAttrs[ATT_SUBSTITUTION_G_N] = new OneAttr(SchemaSymbols.ATT_SUBSTITUTIONGROUP, |
|
403 |
DT_QNAME, |
|
404 |
ATTIDX_SUBSGROUP, |
|
405 |
null); |
|
406 |
allAttrs[ATT_SYSTEM_N] = new OneAttr(SchemaSymbols.ATT_SYSTEM, |
|
407 |
DT_ANYURI, |
|
408 |
ATTIDX_SYSTEM, |
|
409 |
null); |
|
410 |
allAttrs[ATT_TARGET_N_N] = new OneAttr(SchemaSymbols.ATT_TARGETNAMESPACE, |
|
411 |
DT_ANYURI, |
|
412 |
ATTIDX_TARGETNAMESPACE, |
|
413 |
null); |
|
414 |
allAttrs[ATT_TYPE_N] = new OneAttr(SchemaSymbols.ATT_TYPE, |
|
415 |
DT_QNAME, |
|
416 |
ATTIDX_TYPE, |
|
417 |
null); |
|
418 |
allAttrs[ATT_USE_D] = new OneAttr(SchemaSymbols.ATT_USE, |
|
419 |
DT_USE, |
|
420 |
ATTIDX_USE, |
|
421 |
INT_USE_OPTIONAL); |
|
422 |
allAttrs[ATT_VALUE_NNI_N] = new OneAttr(SchemaSymbols.ATT_VALUE, |
|
423 |
DT_NONNEGINT, |
|
424 |
ATTIDX_VALUE, |
|
425 |
null); |
|
426 |
allAttrs[ATT_VALUE_PI_N] = new OneAttr(SchemaSymbols.ATT_VALUE, |
|
427 |
DT_POSINT, |
|
428 |
ATTIDX_VALUE, |
|
429 |
null); |
|
430 |
allAttrs[ATT_VALUE_STR_N] = new OneAttr(SchemaSymbols.ATT_VALUE, |
|
431 |
DT_STRING, |
|
432 |
ATTIDX_VALUE, |
|
433 |
null); |
|
434 |
allAttrs[ATT_VALUE_WS_N] = new OneAttr(SchemaSymbols.ATT_VALUE, |
|
435 |
DT_WHITESPACE, |
|
436 |
ATTIDX_VALUE, |
|
437 |
null); |
|
438 |
allAttrs[ATT_VERSION_N] = new OneAttr(SchemaSymbols.ATT_VERSION, |
|
439 |
DT_TOKEN, |
|
440 |
ATTIDX_VERSION, |
|
441 |
null); |
|
442 |
allAttrs[ATT_XML_LANG] = new OneAttr(SchemaSymbols.ATT_XML_LANG, |
|
443 |
DT_LANGUAGE, |
|
444 |
ATTIDX_XML_LANG, |
|
445 |
null); |
|
446 |
allAttrs[ATT_XPATH_R] = new OneAttr(SchemaSymbols.ATT_XPATH, |
|
447 |
DT_XPATH, |
|
448 |
ATTIDX_XPATH, |
|
449 |
null); |
|
450 |
allAttrs[ATT_XPATH1_R] = new OneAttr(SchemaSymbols.ATT_XPATH, |
|
451 |
DT_XPATH1, |
|
452 |
ATTIDX_XPATH, |
|
453 |
null); |
|
454 |
||
455 |
// step 4: for each element, make a list of possible attributes |
|
456 |
Container attrList; |
|
457 |
OneElement oneEle; |
|
458 |
||
459 |
// for element "attribute" - global |
|
460 |
attrList = Container.getContainer(5); |
|
461 |
// default = string |
|
462 |
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); |
|
463 |
// fixed = string |
|
464 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); |
|
465 |
// id = ID |
|
466 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
467 |
// name = NCName |
|
468 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
469 |
// type = QName |
|
470 |
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); |
|
471 |
oneEle = new OneElement (attrList); |
|
472 |
fEleAttrsMapG.put(SchemaSymbols.ELT_ATTRIBUTE, oneEle); |
|
473 |
||
474 |
// for element "attribute" - local name |
|
475 |
attrList = Container.getContainer(7); |
|
476 |
// default = string |
|
477 |
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); |
|
478 |
// fixed = string |
|
479 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); |
|
480 |
// form = (qualified | unqualified) |
|
481 |
attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]); |
|
482 |
// id = ID |
|
483 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
484 |
// name = NCName |
|
485 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
486 |
// type = QName |
|
487 |
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); |
|
488 |
// use = (optional | prohibited | required) : optional |
|
489 |
attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]); |
|
490 |
oneEle = new OneElement (attrList); |
|
491 |
fEleAttrsMapL.put(ATTRIBUTE_N, oneEle); |
|
492 |
||
493 |
// for element "attribute" - local ref |
|
494 |
attrList = Container.getContainer(5); |
|
495 |
// default = string |
|
496 |
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); |
|
497 |
// fixed = string |
|
498 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); |
|
499 |
// id = ID |
|
500 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
501 |
// ref = QName |
|
502 |
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); |
|
503 |
// use = (optional | prohibited | required) : optional |
|
504 |
attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]); |
|
505 |
oneEle = new OneElement (attrList); |
|
506 |
fEleAttrsMapL.put(ATTRIBUTE_R, oneEle); |
|
507 |
||
508 |
// for element "element" - global |
|
509 |
attrList = Container.getContainer(10); |
|
510 |
// abstract = boolean : false |
|
511 |
attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]); |
|
512 |
// block = (#all | List of (substitution | extension | restriction | list | union)) |
|
513 |
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]); |
|
514 |
// default = string |
|
515 |
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); |
|
516 |
// final = (#all | List of (extension | restriction)) |
|
517 |
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]); |
|
518 |
// fixed = string |
|
519 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); |
|
520 |
// id = ID |
|
521 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
522 |
// name = NCName |
|
523 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
524 |
// nillable = boolean : false |
|
525 |
attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]); |
|
526 |
// substitutionGroup = QName |
|
527 |
attrList.put(SchemaSymbols.ATT_SUBSTITUTIONGROUP, allAttrs[ATT_SUBSTITUTION_G_N]); |
|
528 |
// type = QName |
|
529 |
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); |
|
530 |
oneEle = new OneElement (attrList); |
|
531 |
fEleAttrsMapG.put(SchemaSymbols.ELT_ELEMENT, oneEle); |
|
532 |
||
533 |
// for element "element" - local name |
|
534 |
attrList = Container.getContainer(10); |
|
535 |
// block = (#all | List of (substitution | extension | restriction | list | union)) |
|
536 |
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]); |
|
537 |
// default = string |
|
538 |
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); |
|
539 |
// fixed = string |
|
540 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); |
|
541 |
// form = (qualified | unqualified) |
|
542 |
attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]); |
|
543 |
// id = ID |
|
544 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
545 |
// maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
546 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); |
|
547 |
// minOccurs = nonNegativeInteger : 1 |
|
548 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); |
|
549 |
// name = NCName |
|
550 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
551 |
// nillable = boolean : false |
|
552 |
attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]); |
|
553 |
// type = QName |
|
554 |
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); |
|
555 |
oneEle = new OneElement (attrList); |
|
556 |
fEleAttrsMapL.put(ELEMENT_N, oneEle); |
|
557 |
||
558 |
// for element "element" - local ref |
|
559 |
attrList = Container.getContainer(4); |
|
560 |
// id = ID |
|
561 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
562 |
// maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
563 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); |
|
564 |
// minOccurs = nonNegativeInteger : 1 |
|
565 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); |
|
566 |
// ref = QName |
|
567 |
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); |
|
568 |
oneEle = new OneElement (attrList); |
|
569 |
fEleAttrsMapL.put(ELEMENT_R, oneEle); |
|
570 |
||
571 |
// for element "complexType" - global |
|
572 |
attrList = Container.getContainer(6); |
|
573 |
// abstract = boolean : false |
|
574 |
attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]); |
|
575 |
// block = (#all | List of (extension | restriction)) |
|
576 |
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK1_N]); |
|
577 |
// final = (#all | List of (extension | restriction)) |
|
578 |
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]); |
|
579 |
// id = ID |
|
580 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
581 |
// mixed = boolean : false |
|
582 |
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]); |
|
583 |
// name = NCName |
|
584 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
585 |
oneEle = new OneElement (attrList); |
|
586 |
fEleAttrsMapG.put(SchemaSymbols.ELT_COMPLEXTYPE, oneEle); |
|
587 |
||
588 |
// for element "notation" - global |
|
589 |
attrList = Container.getContainer(4); |
|
590 |
// id = ID |
|
591 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
592 |
// name = NCName |
|
593 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
594 |
// public = A public identifier, per ISO 8879 |
|
595 |
attrList.put(SchemaSymbols.ATT_PUBLIC, allAttrs[ATT_PUBLIC_R]); |
|
596 |
// system = anyURI |
|
597 |
attrList.put(SchemaSymbols.ATT_SYSTEM, allAttrs[ATT_SYSTEM_N]); |
|
598 |
oneEle = new OneElement (attrList); |
|
599 |
fEleAttrsMapG.put(SchemaSymbols.ELT_NOTATION, oneEle); |
|
600 |
||
601 |
||
602 |
// for element "complexType" - local |
|
603 |
attrList = Container.getContainer(2); |
|
604 |
// id = ID |
|
605 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
606 |
// mixed = boolean : false |
|
607 |
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]); |
|
608 |
oneEle = new OneElement (attrList); |
|
609 |
fEleAttrsMapL.put(SchemaSymbols.ELT_COMPLEXTYPE, oneEle); |
|
610 |
||
611 |
// for element "simpleContent" - local |
|
612 |
attrList = Container.getContainer(1); |
|
613 |
// id = ID |
|
614 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
615 |
oneEle = new OneElement (attrList); |
|
616 |
fEleAttrsMapL.put(SchemaSymbols.ELT_SIMPLECONTENT, oneEle); |
|
617 |
||
618 |
// for element "restriction" - local |
|
619 |
attrList = Container.getContainer(2); |
|
620 |
// base = QName |
|
621 |
attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_N]); |
|
622 |
// id = ID |
|
623 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
624 |
oneEle = new OneElement (attrList); |
|
625 |
fEleAttrsMapL.put(SchemaSymbols.ELT_RESTRICTION, oneEle); |
|
626 |
||
627 |
// for element "extension" - local |
|
628 |
attrList = Container.getContainer(2); |
|
629 |
// base = QName |
|
630 |
attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_R]); |
|
631 |
// id = ID |
|
632 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
633 |
oneEle = new OneElement (attrList); |
|
634 |
fEleAttrsMapL.put(SchemaSymbols.ELT_EXTENSION, oneEle); |
|
635 |
||
636 |
// for element "attributeGroup" - local ref |
|
637 |
attrList = Container.getContainer(2); |
|
638 |
// id = ID |
|
639 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
640 |
// ref = QName |
|
641 |
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); |
|
642 |
oneEle = new OneElement (attrList); |
|
643 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle); |
|
644 |
||
645 |
// for element "anyAttribute" - local |
|
646 |
attrList = Container.getContainer(3); |
|
647 |
// id = ID |
|
648 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
649 |
// namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any |
|
650 |
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]); |
|
651 |
// processContents = (lax | skip | strict) : strict |
|
652 |
attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]); |
|
653 |
oneEle = new OneElement (attrList); |
|
654 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ANYATTRIBUTE, oneEle); |
|
655 |
||
656 |
// for element "complexContent" - local |
|
657 |
attrList = Container.getContainer(2); |
|
658 |
// id = ID |
|
659 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
660 |
// mixed = boolean |
|
661 |
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_N]); |
|
662 |
oneEle = new OneElement (attrList); |
|
663 |
fEleAttrsMapL.put(SchemaSymbols.ELT_COMPLEXCONTENT, oneEle); |
|
664 |
||
665 |
// for element "attributeGroup" - global |
|
666 |
attrList = Container.getContainer(2); |
|
667 |
// id = ID |
|
668 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
669 |
// name = NCName |
|
670 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
671 |
oneEle = new OneElement (attrList); |
|
672 |
fEleAttrsMapG.put(SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle); |
|
673 |
||
674 |
// for element "group" - global |
|
675 |
attrList = Container.getContainer(2); |
|
676 |
// id = ID |
|
677 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
678 |
// name = NCName |
|
679 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
680 |
oneEle = new OneElement (attrList); |
|
681 |
fEleAttrsMapG.put(SchemaSymbols.ELT_GROUP, oneEle); |
|
682 |
||
683 |
// for element "group" - local ref |
|
684 |
attrList = Container.getContainer(4); |
|
685 |
// id = ID |
|
686 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
687 |
// maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
688 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); |
|
689 |
// minOccurs = nonNegativeInteger : 1 |
|
690 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); |
|
691 |
// ref = QName |
|
692 |
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); |
|
693 |
oneEle = new OneElement (attrList); |
|
694 |
fEleAttrsMapL.put(SchemaSymbols.ELT_GROUP, oneEle); |
|
695 |
||
696 |
// for element "all" - local |
|
697 |
attrList = Container.getContainer(3); |
|
698 |
// id = ID |
|
699 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
700 |
// maxOccurs = 1 : 1 |
|
701 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS1_D]); |
|
702 |
// minOccurs = (0 | 1) : 1 |
|
703 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS1_D]); |
|
704 |
oneEle = new OneElement (attrList); |
|
705 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ALL, oneEle); |
|
706 |
||
707 |
// for element "choice" - local |
|
708 |
attrList = Container.getContainer(3); |
|
709 |
// id = ID |
|
710 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
711 |
// maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
712 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); |
|
713 |
// minOccurs = nonNegativeInteger : 1 |
|
714 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); |
|
715 |
oneEle = new OneElement (attrList); |
|
716 |
fEleAttrsMapL.put(SchemaSymbols.ELT_CHOICE, oneEle); |
|
717 |
// for element "sequence" - local |
|
718 |
fEleAttrsMapL.put(SchemaSymbols.ELT_SEQUENCE, oneEle); |
|
719 |
||
720 |
// for element "any" - local |
|
721 |
attrList = Container.getContainer(5); |
|
722 |
// id = ID |
|
723 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
724 |
// maxOccurs = (nonNegativeInteger | unbounded) : 1 |
|
725 |
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); |
|
726 |
// minOccurs = nonNegativeInteger : 1 |
|
727 |
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); |
|
728 |
// namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any |
|
729 |
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]); |
|
730 |
// processContents = (lax | skip | strict) : strict |
|
731 |
attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]); |
|
732 |
oneEle = new OneElement (attrList); |
|
733 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ANY, oneEle); |
|
734 |
||
735 |
// for element "unique" - local |
|
736 |
attrList = Container.getContainer(2); |
|
737 |
// id = ID |
|
738 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
739 |
// name = NCName |
|
740 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
741 |
oneEle = new OneElement (attrList); |
|
742 |
fEleAttrsMapL.put(SchemaSymbols.ELT_UNIQUE, oneEle); |
|
743 |
// for element "key" - local |
|
744 |
fEleAttrsMapL.put(SchemaSymbols.ELT_KEY, oneEle); |
|
745 |
||
746 |
// for element "keyref" - local |
|
747 |
attrList = Container.getContainer(3); |
|
748 |
// id = ID |
|
749 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
750 |
// name = NCName |
|
751 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
752 |
// refer = QName |
|
753 |
attrList.put(SchemaSymbols.ATT_REFER, allAttrs[ATT_REFER_R]); |
|
754 |
oneEle = new OneElement (attrList); |
|
755 |
fEleAttrsMapL.put(SchemaSymbols.ELT_KEYREF, oneEle); |
|
756 |
||
757 |
// for element "selector" - local |
|
758 |
attrList = Container.getContainer(2); |
|
759 |
// id = ID |
|
760 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
761 |
// xpath = a subset of XPath expression |
|
762 |
attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH_R]); |
|
763 |
oneEle = new OneElement (attrList); |
|
764 |
fEleAttrsMapL.put(SchemaSymbols.ELT_SELECTOR, oneEle); |
|
765 |
||
766 |
// for element "field" - local |
|
767 |
attrList = Container.getContainer(2); |
|
768 |
// id = ID |
|
769 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
770 |
// xpath = a subset of XPath expression |
|
771 |
attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH1_R]); |
|
772 |
oneEle = new OneElement (attrList); |
|
773 |
fEleAttrsMapL.put(SchemaSymbols.ELT_FIELD, oneEle); |
|
774 |
||
775 |
// for element "annotation" - global |
|
776 |
attrList = Container.getContainer(1); |
|
777 |
// id = ID |
|
778 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
779 |
oneEle = new OneElement (attrList); |
|
780 |
fEleAttrsMapG.put(SchemaSymbols.ELT_ANNOTATION, oneEle); |
|
781 |
// for element "annotation" - local |
|
782 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ANNOTATION, oneEle); |
|
783 |
||
784 |
// for element "appinfo" - local |
|
785 |
attrList = Container.getContainer(1); |
|
786 |
// source = anyURI |
|
787 |
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]); |
|
788 |
oneEle = new OneElement (attrList); |
|
789 |
fEleAttrsMapG.put(SchemaSymbols.ELT_APPINFO, oneEle); |
|
790 |
fEleAttrsMapL.put(SchemaSymbols.ELT_APPINFO, oneEle); |
|
791 |
||
792 |
// for element "documentation" - local |
|
793 |
attrList = Container.getContainer(2); |
|
794 |
// source = anyURI |
|
795 |
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]); |
|
796 |
// xml:lang = language |
|
797 |
attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]); |
|
798 |
oneEle = new OneElement (attrList); |
|
799 |
fEleAttrsMapG.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle); |
|
800 |
fEleAttrsMapL.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle); |
|
801 |
||
802 |
// for element "simpleType" - global |
|
803 |
attrList = Container.getContainer(3); |
|
804 |
// final = (#all | List of (list | union | restriction)) |
|
805 |
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]); |
|
806 |
// id = ID |
|
807 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
808 |
// name = NCName |
|
809 |
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); |
|
810 |
oneEle = new OneElement (attrList); |
|
811 |
fEleAttrsMapG.put(SchemaSymbols.ELT_SIMPLETYPE, oneEle); |
|
812 |
||
813 |
// for element "simpleType" - local |
|
814 |
attrList = Container.getContainer(2); |
|
815 |
// final = (#all | List of (list | union | restriction)) |
|
816 |
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]); |
|
817 |
// id = ID |
|
818 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
819 |
oneEle = new OneElement (attrList); |
|
820 |
fEleAttrsMapL.put(SchemaSymbols.ELT_SIMPLETYPE, oneEle); |
|
821 |
||
822 |
// for element "restriction" - local |
|
823 |
// already registered for complexType |
|
824 |
||
825 |
// for element "list" - local |
|
826 |
attrList = Container.getContainer(2); |
|
827 |
// id = ID |
|
828 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
829 |
// itemType = QName |
|
830 |
attrList.put(SchemaSymbols.ATT_ITEMTYPE, allAttrs[ATT_ITEMTYPE_N]); |
|
831 |
oneEle = new OneElement (attrList); |
|
832 |
fEleAttrsMapL.put(SchemaSymbols.ELT_LIST, oneEle); |
|
833 |
||
834 |
// for element "union" - local |
|
835 |
attrList = Container.getContainer(2); |
|
836 |
// id = ID |
|
837 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
838 |
// memberTypes = List of QName |
|
839 |
attrList.put(SchemaSymbols.ATT_MEMBERTYPES, allAttrs[ATT_MEMBER_T_N]); |
|
840 |
oneEle = new OneElement (attrList); |
|
841 |
fEleAttrsMapL.put(SchemaSymbols.ELT_UNION, oneEle); |
|
842 |
||
843 |
// for element "schema" - global |
|
844 |
attrList = Container.getContainer(8); |
|
845 |
// attributeFormDefault = (qualified | unqualified) : unqualified |
|
846 |
attrList.put(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, allAttrs[ATT_ATTRIBUTE_FD_D]); |
|
847 |
// blockDefault = (#all | List of (substitution | extension | restriction | list | union)) : '' |
|
848 |
attrList.put(SchemaSymbols.ATT_BLOCKDEFAULT, allAttrs[ATT_BLOCK_D_D]); |
|
849 |
// elementFormDefault = (qualified | unqualified) : unqualified |
|
850 |
attrList.put(SchemaSymbols.ATT_ELEMENTFORMDEFAULT, allAttrs[ATT_ELEMENT_FD_D]); |
|
851 |
// finalDefault = (#all | List of (extension | restriction | list | union)) : '' |
|
852 |
attrList.put(SchemaSymbols.ATT_FINALDEFAULT, allAttrs[ATT_FINAL_D_D]); |
|
853 |
// id = ID |
|
854 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
855 |
// targetNamespace = anyURI |
|
856 |
attrList.put(SchemaSymbols.ATT_TARGETNAMESPACE, allAttrs[ATT_TARGET_N_N]); |
|
857 |
// version = token |
|
858 |
attrList.put(SchemaSymbols.ATT_VERSION, allAttrs[ATT_VERSION_N]); |
|
859 |
// xml:lang = language |
|
860 |
attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]); |
|
861 |
oneEle = new OneElement (attrList); |
|
862 |
fEleAttrsMapG.put(SchemaSymbols.ELT_SCHEMA, oneEle); |
|
863 |
||
864 |
// for element "include" - global |
|
865 |
attrList = Container.getContainer(2); |
|
866 |
// id = ID |
|
867 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
868 |
// schemaLocation = anyURI |
|
869 |
attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_R]); |
|
870 |
oneEle = new OneElement (attrList); |
|
871 |
fEleAttrsMapG.put(SchemaSymbols.ELT_INCLUDE, oneEle); |
|
872 |
// for element "redefine" - global |
|
873 |
fEleAttrsMapG.put(SchemaSymbols.ELT_REDEFINE, oneEle); |
|
874 |
||
875 |
// for element "import" - global |
|
876 |
attrList = Container.getContainer(3); |
|
877 |
// id = ID |
|
878 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
879 |
// namespace = anyURI |
|
880 |
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_N]); |
|
881 |
// schemaLocation = anyURI |
|
882 |
attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_N]); |
|
883 |
oneEle = new OneElement (attrList); |
|
884 |
fEleAttrsMapG.put(SchemaSymbols.ELT_IMPORT, oneEle); |
|
885 |
||
886 |
// for element "length" - local |
|
887 |
attrList = Container.getContainer(3); |
|
888 |
// id = ID |
|
889 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
890 |
// value = nonNegativeInteger |
|
891 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_NNI_N]); |
|
892 |
// fixed = boolean : false |
|
893 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); |
|
894 |
oneEle = new OneElement (attrList); |
|
895 |
fEleAttrsMapL.put(SchemaSymbols.ELT_LENGTH, oneEle); |
|
896 |
// for element "minLength" - local |
|
897 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MINLENGTH, oneEle); |
|
898 |
// for element "maxLength" - local |
|
899 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MAXLENGTH, oneEle); |
|
900 |
// for element "fractionDigits" - local |
|
901 |
fEleAttrsMapL.put(SchemaSymbols.ELT_FRACTIONDIGITS, oneEle); |
|
902 |
||
903 |
// for element "totalDigits" - local |
|
904 |
attrList = Container.getContainer(3); |
|
905 |
// id = ID |
|
906 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
907 |
// value = positiveInteger |
|
908 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_PI_N]); |
|
909 |
// fixed = boolean : false |
|
910 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); |
|
911 |
oneEle = new OneElement (attrList); |
|
912 |
fEleAttrsMapL.put(SchemaSymbols.ELT_TOTALDIGITS, oneEle); |
|
913 |
||
914 |
// for element "pattern" - local |
|
915 |
attrList = Container.getContainer(2); |
|
916 |
// id = ID |
|
917 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
918 |
// value = string |
|
919 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); |
|
920 |
oneEle = new OneElement (attrList); |
|
921 |
fEleAttrsMapL.put(SchemaSymbols.ELT_PATTERN, oneEle); |
|
922 |
||
923 |
// for element "enumeration" - local |
|
924 |
attrList = Container.getContainer(2); |
|
925 |
// id = ID |
|
926 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
927 |
// value = anySimpleType |
|
928 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); |
|
929 |
oneEle = new OneElement (attrList); |
|
930 |
fEleAttrsMapL.put(SchemaSymbols.ELT_ENUMERATION, oneEle); |
|
931 |
||
932 |
// for element "whiteSpace" - local |
|
933 |
attrList = Container.getContainer(3); |
|
934 |
// id = ID |
|
935 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
936 |
// value = preserve | replace | collapse |
|
937 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_WS_N]); |
|
938 |
// fixed = boolean : false |
|
939 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); |
|
940 |
oneEle = new OneElement (attrList); |
|
941 |
fEleAttrsMapL.put(SchemaSymbols.ELT_WHITESPACE, oneEle); |
|
942 |
||
943 |
// for element "maxInclusive" - local |
|
944 |
attrList = Container.getContainer(3); |
|
945 |
// id = ID |
|
946 |
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); |
|
947 |
// value = anySimpleType |
|
948 |
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); |
|
949 |
// fixed = boolean : false |
|
950 |
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); |
|
951 |
oneEle = new OneElement (attrList); |
|
952 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MAXINCLUSIVE, oneEle); |
|
953 |
// for element "maxExclusive" - local |
|
954 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MAXEXCLUSIVE, oneEle); |
|
955 |
// for element "minInclusive" - local |
|
956 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MININCLUSIVE, oneEle); |
|
957 |
// for element "minExclusive" - local |
|
958 |
fEleAttrsMapL.put(SchemaSymbols.ELT_MINEXCLUSIVE, oneEle); |
|
959 |
} |
|
960 |
||
961 |
// used to resolver namespace prefixes |
|
962 |
protected XSDHandler fSchemaHandler = null; |
|
963 |
||
964 |
// used to store symbols. |
|
965 |
protected SymbolTable fSymbolTable = null; |
|
966 |
||
967 |
// used to store the mapping from processed element to attributes |
|
968 |
protected Hashtable fNonSchemaAttrs = new Hashtable(); |
|
969 |
||
970 |
// temprory vector, used to hold the namespace list |
|
971 |
protected Vector fNamespaceList = new Vector(); |
|
972 |
||
973 |
// whether this attribute appeared in the current element |
|
974 |
protected boolean[] fSeen = new boolean[ATTIDX_COUNT]; |
|
975 |
private static boolean[] fSeenTemp = new boolean[ATTIDX_COUNT]; |
|
976 |
||
977 |
// constructor. Sets fErrorReproter and get datatype validators |
|
978 |
public XSAttributeChecker(XSDHandler schemaHandler) { |
|
979 |
fSchemaHandler = schemaHandler; |
|
980 |
} |
|
981 |
||
982 |
public void reset(SymbolTable symbolTable) { |
|
983 |
fSymbolTable = symbolTable; |
|
984 |
fNonSchemaAttrs.clear(); |
|
985 |
} |
|
986 |
||
987 |
/** |
|
988 |
* Check whether the specified element conforms to the attributes restriction |
|
989 |
* an array of attribute values is returned. the caller must call |
|
990 |
* <code>returnAttrArray</code> to return that array. |
|
991 |
* |
|
992 |
* @param element which element to check |
|
993 |
* @param isGlobal whether a child of <schema> or <redefine> |
|
994 |
* @param schemaDoc the document where the element lives in |
|
995 |
* @return an array containing attribute values |
|
996 |
*/ |
|
997 |
public Object[] checkAttributes(Element element, boolean isGlobal, |
|
998 |
XSDocumentInfo schemaDoc) { |
|
999 |
return checkAttributes(element, isGlobal, schemaDoc, false); |
|
1000 |
} |
|
1001 |
||
1002 |
/** |
|
1003 |
* Check whether the specified element conforms to the attributes restriction |
|
1004 |
* an array of attribute values is returned. the caller must call |
|
1005 |
* <code>returnAttrArray</code> to return that array. This method also takes |
|
1006 |
* an extra parameter: if the element is "enumeration", whether to make a |
|
1007 |
* copy of the namespace context, so that the value can be resolved as a |
|
1008 |
* QName later. |
|
1009 |
* |
|
1010 |
* @param element which element to check |
|
1011 |
* @param isGlobal whether a child of <schema> or <redefine> |
|
1012 |
* @param schemaDoc the document where the element lives in |
|
1013 |
* @param enumAsQName whether to tread enumeration value as QName |
|
1014 |
* @return an array containing attribute values |
|
1015 |
*/ |
|
1016 |
public Object[] checkAttributes(Element element, boolean isGlobal, |
|
1017 |
XSDocumentInfo schemaDoc, boolean enumAsQName) { |
|
1018 |
if (element == null) |
|
1019 |
return null; |
|
1020 |
||
1021 |
// get all attributes |
|
1022 |
Attr[] attrs = DOMUtil.getAttrs(element); |
|
1023 |
||
1024 |
// update NamespaceSupport |
|
1025 |
resolveNamespace(element, attrs, schemaDoc.fNamespaceSupport); |
|
1026 |
||
1027 |
String uri = DOMUtil.getNamespaceURI(element); |
|
1028 |
String elName = DOMUtil.getLocalName(element); |
|
1029 |
||
1030 |
if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(uri)) { |
|
1031 |
reportSchemaError("s4s-elt-schema-ns", new Object[] {elName}, element); |
|
1032 |
} |
|
1033 |
||
1034 |
Hashtable eleAttrsMap = fEleAttrsMapG; |
|
1035 |
String lookupName = elName; |
|
1036 |
||
1037 |
// REVISIT: only local element and attribute are different from others. |
|
1038 |
// it's possible to have either name or ref. all the others |
|
1039 |
// are only allowed to have one of name or ref, or neither of them. |
|
1040 |
// we'd better move such checking to the traverser. |
|
1041 |
if (!isGlobal) { |
|
1042 |
eleAttrsMap = fEleAttrsMapL; |
|
1043 |
if (elName.equals(SchemaSymbols.ELT_ELEMENT)) { |
|
1044 |
if (DOMUtil.getAttr(element, SchemaSymbols.ATT_REF) != null) |
|
1045 |
lookupName = ELEMENT_R; |
|
1046 |
else |
|
1047 |
lookupName = ELEMENT_N; |
|
1048 |
} else if (elName.equals(SchemaSymbols.ELT_ATTRIBUTE)) { |
|
1049 |
if (DOMUtil.getAttr(element, SchemaSymbols.ATT_REF) != null) |
|
1050 |
lookupName = ATTRIBUTE_R; |
|
1051 |
else |
|
1052 |
lookupName = ATTRIBUTE_N; |
|
1053 |
} |
|
1054 |
} |
|
1055 |
||
1056 |
// get desired attribute list of this element |
|
1057 |
OneElement oneEle = (OneElement)eleAttrsMap.get(lookupName); |
|
1058 |
if (oneEle == null) { |
|
1059 |
// should never gets here. |
|
1060 |
// when this method is called, the call already knows that |
|
1061 |
// the element can appear. |
|
1062 |
reportSchemaError ("s4s-elt-invalid", new Object[] {elName}, element); |
|
1063 |
return null; |
|
1064 |
} |
|
1065 |
||
1066 |
//Hashtable attrValues = new Hashtable(); |
|
1067 |
Object[] attrValues = getAvailableArray(); |
|
1068 |
//Hashtable otherValues = new Hashtable(); |
|
1069 |
long fromDefault = 0; |
|
1070 |
Container attrList = oneEle.attrList; |
|
1071 |
||
1072 |
// clear the "seen" flag. |
|
1073 |
System.arraycopy(fSeenTemp, 0, fSeen, 0, ATTIDX_COUNT); |
|
1074 |
||
1075 |
// traverse all attributes |
|
1076 |
int length = attrs.length; |
|
1077 |
Attr sattr = null; |
|
1078 |
for (int i = 0; i < length; i++) { |
|
1079 |
sattr = attrs[i]; |
|
1080 |
// get the attribute name/value |
|
1081 |
//String attrName = DOMUtil.getLocalName(sattr); |
|
1082 |
String attrName = sattr.getName(); |
|
1083 |
String attrURI = DOMUtil.getNamespaceURI(sattr); |
|
1084 |
String attrVal = DOMUtil.getValue(sattr); |
|
1085 |
||
1086 |
if (attrName.startsWith("xml")) { |
|
1087 |
String attrPrefix = DOMUtil.getPrefix(sattr); |
|
1088 |
// we don't want to add namespace declarations to the non-schema attributes |
|
1089 |
if ("xmlns".equals(attrPrefix) || "xmlns".equals(attrName)) { |
|
1090 |
continue; |
|
1091 |
} |
|
1092 |
// Both <schema> and <documentation> may have an xml:lang attribute. |
|
1093 |
// Set the URI for this attribute to null so that we process it |
|
1094 |
// like any other schema attribute. |
|
1095 |
else if (SchemaSymbols.ATT_XML_LANG.equals(attrName) && |
|
1096 |
(SchemaSymbols.ELT_SCHEMA.equals(elName) || |
|
1097 |
SchemaSymbols.ELT_DOCUMENTATION.equals(elName))) { |
|
1098 |
attrURI = null; |
|
1099 |
} |
|
1100 |
} |
|
1101 |
||
1102 |
// for attributes with namespace prefix |
|
1103 |
// |
|
1104 |
if (attrURI != null && attrURI.length() != 0) { |
|
1105 |
// attributes with schema namespace are not allowed |
|
1106 |
// and not allowed on "document" and "appInfo" |
|
1107 |
if (attrURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) || |
|
1108 |
!oneEle.allowNonSchemaAttr) { |
|
1109 |
reportSchemaError ("s4s-att-not-allowed", new Object[] {elName, attrName}, element); |
|
1110 |
} |
|
1111 |
else { |
|
1112 |
if(attrValues[ATTIDX_NONSCHEMA] == null) { |
|
1113 |
// these are usually small |
|
1114 |
attrValues[ATTIDX_NONSCHEMA] = new Vector(4,2); |
|
1115 |
} |
|
1116 |
((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrName); |
|
1117 |
((Vector)attrValues[ATTIDX_NONSCHEMA]).addElement(attrVal); |
|
1118 |
// for attributes from other namespace |
|
1119 |
// store them in a list, and TRY to validate them after |
|
1120 |
// schema traversal (because it's "lax") |
|
1121 |
//otherValues.put(attrName, attrVal); |
|
1122 |
// REVISIT: actually use this some day... |
|
1123 |
// String attrRName = attrURI + "," + attrName; |
|
1124 |
// Vector values = (Vector)fNonSchemaAttrs.get(attrRName); |
|
1125 |
// if (values == null) { |
|
1126 |
// values = new Vector(); |
|
1127 |
// values.addElement(attrName); |
|
1128 |
// values.addElement(elName); |
|
1129 |
// values.addElement(attrVal); |
|
1130 |
// fNonSchemaAttrs.put(attrRName, values); |
|
1131 |
// } |
|
1132 |
// else { |
|
1133 |
// values.addElement(elName); |
|
1134 |
// values.addElement(attrVal); |
|
1135 |
// } |
|
1136 |
} |
|
1137 |
continue; |
|
1138 |
} |
|
1139 |
||
1140 |
// check whether this attribute is allowed |
|
1141 |
OneAttr oneAttr = (OneAttr)attrList.get(attrName); |
|
1142 |
if (oneAttr == null) { |
|
1143 |
reportSchemaError ("s4s-att-not-allowed", |
|
1144 |
new Object[] {elName, attrName}, |
|
1145 |
element); |
|
1146 |
continue; |
|
1147 |
} |
|
1148 |
||
1149 |
// we've seen this attribute |
|
1150 |
fSeen[oneAttr.valueIndex] = true; |
|
1151 |
||
1152 |
// check the value against the datatype |
|
1153 |
try { |
|
1154 |
// no checking on string needs to be done here. |
|
1155 |
// no checking on xpath needs to be done here. |
|
1156 |
// xpath values are validated in xpath parser |
|
1157 |
if (oneAttr.dvIndex >= 0) { |
|
1158 |
if (oneAttr.dvIndex != DT_STRING && |
|
1159 |
oneAttr.dvIndex != DT_XPATH && |
|
1160 |
oneAttr.dvIndex != DT_XPATH1) { |
|
1161 |
XSSimpleType dv = fExtraDVs[oneAttr.dvIndex]; |
|
1162 |
Object avalue = dv.validate(attrVal, schemaDoc.fValidationContext, null); |
|
1163 |
// kludge to handle chameleon includes/redefines... |
|
1164 |
if (oneAttr.dvIndex == DT_QNAME) { |
|
1165 |
QName qname = (QName)avalue; |
|
1166 |
if(qname.prefix == XMLSymbols.EMPTY_STRING && qname.uri == null && schemaDoc.fIsChameleonSchema) |
|
1167 |
qname.uri = schemaDoc.fTargetNamespace; |
|
1168 |
} |
|
1169 |
attrValues[oneAttr.valueIndex] = avalue; |
|
1170 |
} else { |
|
1171 |
attrValues[oneAttr.valueIndex] = attrVal; |
|
1172 |
} |
|
1173 |
} |
|
1174 |
else { |
|
1175 |
attrValues[oneAttr.valueIndex] = validate(attrValues, attrName, attrVal, oneAttr.dvIndex, schemaDoc); |
|
1176 |
} |
|
1177 |
} catch (InvalidDatatypeValueException ide) { |
|
1178 |
reportSchemaError ("s4s-att-invalid-value", |
|
1179 |
new Object[] {elName, attrName, ide.getMessage()}, |
|
1180 |
element); |
|
1181 |
if (oneAttr.dfltValue != null) |
|
1182 |
//attrValues.put(attrName, oneAttr.dfltValue); |
|
1183 |
attrValues[oneAttr.valueIndex] = oneAttr.dfltValue; |
|
1184 |
} |
|
1185 |
||
1186 |
// For "enumeration", and type is possible to be a QName, we need |
|
1187 |
// to return namespace context for later QName resolution. |
|
1188 |
if (elName.equals(SchemaSymbols.ELT_ENUMERATION) && enumAsQName) { |
|
1189 |
attrValues[ATTIDX_ENUMNSDECLS] = new SchemaNamespaceSupport(schemaDoc.fNamespaceSupport); |
|
1190 |
} |
|
1191 |
} |
|
1192 |
||
1193 |
// apply default values |
|
1194 |
OneAttr[] reqAttrs = oneEle.attrList.values; |
|
1195 |
for (int i = 0; i < reqAttrs.length; i++) { |
|
1196 |
OneAttr oneAttr = reqAttrs[i]; |
|
1197 |
||
1198 |
// if the attribute didn't apprear, and |
|
1199 |
// if the attribute is optional with default value, apply it |
|
1200 |
if (oneAttr.dfltValue != null && !fSeen[oneAttr.valueIndex]) { |
|
1201 |
//attrValues.put(oneAttr.name, oneAttr.dfltValue); |
|
1202 |
attrValues[oneAttr.valueIndex] = oneAttr.dfltValue; |
|
1203 |
fromDefault |= (1<<oneAttr.valueIndex); |
|
1204 |
} |
|
1205 |
} |
|
1206 |
||
1207 |
attrValues[ATTIDX_FROMDEFAULT] = new Long(fromDefault); |
|
1208 |
//attrValues[ATTIDX_OTHERVALUES] = otherValues; |
|
1209 |
||
1210 |
// Check that minOccurs isn't greater than maxOccurs. |
|
1211 |
// p-props-correct 2.1 |
|
1212 |
if (attrValues[ATTIDX_MAXOCCURS] != null) { |
|
1213 |
int min = ((XInt)attrValues[ATTIDX_MINOCCURS]).intValue(); |
|
1214 |
int max = ((XInt)attrValues[ATTIDX_MAXOCCURS]).intValue(); |
|
1215 |
if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) { |
|
1216 |
||
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1217 |
// maxOccurLimit is only check in secure mode |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1218 |
if (fSchemaHandler.fSecureProcessing != null) { |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1219 |
String localName = element.getLocalName(); |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1220 |
|
6 | 1221 |
// The maxOccurs restriction no longer applies to elements |
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1222 |
// and wildcards in a sequence in which they are the only |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1223 |
// particle. These are now validated using a constant |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1224 |
// space algorithm. The restriction still applies to all |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1225 |
// other cases. |
6 | 1226 |
|
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1227 |
// Determine if constant-space algorithm can be applied |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1228 |
final boolean optimize = |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1229 |
(localName.equals("element") || localName.equals("any")) && |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1230 |
(element.getNextSibling() == null) && |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1231 |
(element.getPreviousSibling() == null) && |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1232 |
(element.getParentNode().getLocalName().equals("sequence")); |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1233 |
|
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1234 |
if (!optimize) { |
6 | 1235 |
//Revisit :: IMO this is not right place to check |
1236 |
// maxOccurNodeLimit. |
|
1237 |
int maxOccurNodeLimit = fSchemaHandler.fSecureProcessing.getMaxOccurNodeLimit(); |
|
1238 |
if (max > maxOccurNodeLimit) { |
|
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1239 |
reportSchemaFatalError("maxOccurLimit", new Object[] {new Integer(maxOccurNodeLimit)}, element); |
6 | 1240 |
|
1241 |
// reset max values in case processing continues on error |
|
1242 |
attrValues[ATTIDX_MAXOCCURS] = fXIntPool.getXInt(maxOccurNodeLimit); |
|
1243 |
//new Integer(maxOccurNodeLimit); |
|
1244 |
max = maxOccurNodeLimit; |
|
1245 |
} |
|
1246 |
} |
|
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1247 |
} |
6 | 1248 |
|
1249 |
if (min > max) { |
|
1250 |
reportSchemaError ("p-props-correct.2.1", |
|
1251 |
new Object[] {elName, attrValues[ATTIDX_MINOCCURS], attrValues[ATTIDX_MAXOCCURS]}, |
|
1252 |
element); |
|
1253 |
attrValues[ATTIDX_MINOCCURS] = attrValues[ATTIDX_MAXOCCURS]; |
|
1254 |
} |
|
1255 |
} |
|
1256 |
} |
|
1257 |
||
1258 |
return attrValues; |
|
1259 |
} |
|
1260 |
||
1261 |
private Object validate(Object[] attrValues, String attr, String ivalue, int dvIndex, |
|
1262 |
XSDocumentInfo schemaDoc) throws InvalidDatatypeValueException { |
|
1263 |
if (ivalue == null) |
|
1264 |
return null; |
|
1265 |
||
1266 |
// To validate these types, we don't actually need to normalize the |
|
1267 |
// strings. We only need to remove the whitespace from both ends. |
|
1268 |
// In some special cases (list types), StringTokenizer can correctly |
|
1269 |
// process the un-normalized whitespace. |
|
1270 |
/** |
|
1271 |
* REVISIT: Trim removes all leading and trailing characters less |
|
1272 |
* than or equal to U+0020. This is okay for XML 1.0 since all |
|
1273 |
* of the valid characters in that range are white space but |
|
1274 |
* in XML 1.1 control chars are allowed. We shouldn't be trimming |
|
1275 |
* those. -- mrglavas |
|
1276 |
*/ |
|
1277 |
String value = ivalue.trim(); |
|
1278 |
Object retValue = null; |
|
1279 |
Vector memberType; |
|
1280 |
int choice; |
|
1281 |
||
1282 |
switch (dvIndex) { |
|
1283 |
case DT_BOOLEAN: |
|
1284 |
if (value.equals(SchemaSymbols.ATTVAL_FALSE) || |
|
1285 |
value.equals(SchemaSymbols.ATTVAL_FALSE_0)) { |
|
1286 |
retValue = Boolean.FALSE; |
|
1287 |
} else if (value.equals(SchemaSymbols.ATTVAL_TRUE) || |
|
1288 |
value.equals(SchemaSymbols.ATTVAL_TRUE_1)) { |
|
1289 |
retValue = Boolean.TRUE; |
|
1290 |
} else { |
|
1291 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{value, "boolean"}); |
|
1292 |
} |
|
1293 |
break; |
|
1294 |
case DT_NONNEGINT: |
|
1295 |
try { |
|
1296 |
if (value.length() > 0 && value.charAt(0) == '+') |
|
1297 |
value = value.substring(1); |
|
1298 |
retValue = fXIntPool.getXInt(Integer.parseInt(value)); |
|
1299 |
} catch (NumberFormatException e) { |
|
1300 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{value, "nonNegativeInteger"}); |
|
1301 |
} |
|
1302 |
if (((XInt)retValue).intValue() < 0) |
|
1303 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{value, "nonNegativeInteger"}); |
|
1304 |
break; |
|
1305 |
case DT_POSINT: |
|
1306 |
try { |
|
1307 |
if (value.length() > 0 && value.charAt(0) == '+') |
|
1308 |
value = value.substring(1); |
|
1309 |
retValue = fXIntPool.getXInt(Integer.parseInt(value)); |
|
1310 |
} catch (NumberFormatException e) { |
|
1311 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{value, "positiveInteger"}); |
|
1312 |
} |
|
1313 |
if (((XInt)retValue).intValue() <= 0) |
|
1314 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{value, "positiveInteger"}); |
|
1315 |
break; |
|
1316 |
case DT_BLOCK: |
|
1317 |
// block = (#all | List of (substitution | extension | restriction | list | union)) |
|
1318 |
choice = 0; |
|
1319 |
if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { |
|
1320 |
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION| |
|
1321 |
XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST| |
|
1322 |
XSConstants.DERIVATION_UNION; |
|
1323 |
} |
|
1324 |
else { |
|
1325 |
// use the default \t\r\n\f delimiters |
|
1326 |
StringTokenizer t = new StringTokenizer(value); |
|
1327 |
while (t.hasMoreTokens()) { |
|
1328 |
String token = t.nextToken (); |
|
1329 |
||
1330 |
if (token.equals (SchemaSymbols.ATTVAL_SUBSTITUTION)) { |
|
1331 |
choice |= XSConstants.DERIVATION_SUBSTITUTION; |
|
1332 |
} |
|
1333 |
else if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) { |
|
1334 |
choice |= XSConstants.DERIVATION_EXTENSION; |
|
1335 |
} |
|
1336 |
else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { |
|
1337 |
choice |= XSConstants.DERIVATION_RESTRICTION; |
|
1338 |
} |
|
1339 |
else if (token.equals (SchemaSymbols.ATTVAL_LIST)) { |
|
1340 |
choice |= XSConstants.DERIVATION_LIST; |
|
1341 |
} |
|
1342 |
else if (token.equals (SchemaSymbols.ATTVAL_UNION)) { |
|
1343 |
choice |= XSConstants.DERIVATION_UNION; |
|
1344 |
} |
|
1345 |
else { |
|
1346 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "(#all | List of (substitution | extension | restriction | list | union))"}); |
|
1347 |
} |
|
1348 |
} |
|
1349 |
} |
|
1350 |
retValue = fXIntPool.getXInt(choice); |
|
1351 |
break; |
|
1352 |
case DT_BLOCK1: |
|
1353 |
case DT_FINAL: |
|
1354 |
// block = (#all | List of (extension | restriction)) |
|
1355 |
// final = (#all | List of (extension | restriction)) |
|
1356 |
choice = 0; |
|
1357 |
if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { |
|
1358 |
//choice = SchemaSymbols.EXTENSION|SchemaSymbols.RESTRICTION; |
|
1359 |
// REVISIT: if #all, then make the result the combination of |
|
1360 |
// everything: substitution/externsion/restriction/list/union. |
|
1361 |
// would this be a problem? |
|
1362 |
// the reason doing so is that when final/blockFinal on <schema> |
|
1363 |
// is #all, it's not always the same as the conbination of those |
|
1364 |
// values allowed by final/blockFinal. |
|
1365 |
// for example, finalDefault="#all" is not always the same as |
|
1366 |
// finalDefault="extension restriction". |
|
1367 |
// if finalDefault="#all", final on any simple type would be |
|
1368 |
// "extension restriction list union". |
|
1369 |
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION| |
|
1370 |
XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST| |
|
1371 |
XSConstants.DERIVATION_UNION; |
|
1372 |
} |
|
1373 |
else { |
|
1374 |
// use the default \t\r\n\f delimiters |
|
1375 |
StringTokenizer t = new StringTokenizer(value); |
|
1376 |
while (t.hasMoreTokens()) { |
|
1377 |
String token = t.nextToken (); |
|
1378 |
||
1379 |
if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) { |
|
1380 |
choice |= XSConstants.DERIVATION_EXTENSION; |
|
1381 |
} |
|
1382 |
else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { |
|
1383 |
choice |= XSConstants.DERIVATION_RESTRICTION; |
|
1384 |
} |
|
1385 |
else { |
|
1386 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "(#all | List of (extension | restriction))"}); |
|
1387 |
} |
|
1388 |
} |
|
1389 |
} |
|
1390 |
retValue = fXIntPool.getXInt(choice); |
|
1391 |
break; |
|
1392 |
case DT_FINAL1: |
|
1393 |
// final = (#all | List of (list | union | restriction)) |
|
1394 |
choice = 0; |
|
1395 |
if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { |
|
1396 |
//choice = SchemaSymbols.RESTRICTION|SchemaSymbols.LIST| |
|
1397 |
// SchemaSymbols.UNION; |
|
1398 |
// REVISIT: if #all, then make the result the combination of |
|
1399 |
// everything: substitution/externsion/restriction/list/union. |
|
1400 |
// would this be a problem? |
|
1401 |
// same reason as above DT_BLOCK1/DT_FINAL |
|
1402 |
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION| |
|
1403 |
XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST| |
|
1404 |
XSConstants.DERIVATION_UNION; |
|
1405 |
} |
|
1406 |
else { |
|
1407 |
// use the default \t\r\n\f delimiters |
|
1408 |
StringTokenizer t = new StringTokenizer(value); |
|
1409 |
while (t.hasMoreTokens()) { |
|
1410 |
String token = t.nextToken (); |
|
1411 |
||
1412 |
if (token.equals (SchemaSymbols.ATTVAL_LIST)) { |
|
1413 |
choice |= XSConstants.DERIVATION_LIST; |
|
1414 |
} |
|
1415 |
else if (token.equals (SchemaSymbols.ATTVAL_UNION)) { |
|
1416 |
choice |= XSConstants.DERIVATION_UNION; |
|
1417 |
} |
|
1418 |
else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { |
|
1419 |
choice |= XSConstants.DERIVATION_RESTRICTION; |
|
1420 |
} |
|
1421 |
else { |
|
1422 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "(#all | List of (list | union | restriction))"}); |
|
1423 |
} |
|
1424 |
} |
|
1425 |
} |
|
1426 |
retValue = fXIntPool.getXInt(choice); |
|
1427 |
break; |
|
1428 |
case DT_FINAL2: |
|
1429 |
// finalDefault = (#all | List of (extension | restriction | list | union)) |
|
1430 |
choice = 0; |
|
1431 |
if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { |
|
1432 |
//choice = SchemaSymbols.RESTRICTION|SchemaSymbols.LIST| |
|
1433 |
// SchemaSymbols.UNION; |
|
1434 |
// REVISIT: if #all, then make the result the combination of |
|
1435 |
// everything: substitution/externsion/restriction/list/union. |
|
1436 |
// would this be a problem? |
|
1437 |
// same reason as above DT_BLOCK1/DT_FINAL |
|
1438 |
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION| |
|
1439 |
XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST| |
|
1440 |
XSConstants.DERIVATION_UNION; |
|
1441 |
} |
|
1442 |
else { |
|
1443 |
// use the default \t\r\n\f delimiters |
|
1444 |
StringTokenizer t = new StringTokenizer(value); |
|
1445 |
while (t.hasMoreTokens()) { |
|
1446 |
String token = t.nextToken (); |
|
1447 |
||
1448 |
if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) { |
|
1449 |
choice |= XSConstants.DERIVATION_EXTENSION; |
|
1450 |
} |
|
1451 |
else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { |
|
1452 |
choice |= XSConstants.DERIVATION_RESTRICTION; |
|
1453 |
} |
|
1454 |
else if (token.equals (SchemaSymbols.ATTVAL_LIST)) { |
|
1455 |
choice |= XSConstants.DERIVATION_LIST; |
|
1456 |
} |
|
1457 |
else if (token.equals (SchemaSymbols.ATTVAL_UNION)) { |
|
1458 |
choice |= XSConstants.DERIVATION_UNION; |
|
1459 |
} |
|
1460 |
else { |
|
1461 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "(#all | List of (extension | restriction | list | union))"}); |
|
1462 |
} |
|
1463 |
} |
|
1464 |
} |
|
1465 |
retValue = fXIntPool.getXInt(choice); |
|
1466 |
break; |
|
1467 |
case DT_FORM: |
|
1468 |
// form = (qualified | unqualified) |
|
1469 |
if (value.equals (SchemaSymbols.ATTVAL_QUALIFIED)) |
|
1470 |
retValue = INT_QUALIFIED; |
|
1471 |
else if (value.equals (SchemaSymbols.ATTVAL_UNQUALIFIED)) |
|
1472 |
retValue = INT_UNQUALIFIED; |
|
1473 |
else |
|
1474 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1475 |
new Object[]{value, "(qualified | unqualified)"}); |
|
1476 |
break; |
|
1477 |
case DT_MAXOCCURS: |
|
1478 |
// maxOccurs = (nonNegativeInteger | unbounded) |
|
1479 |
if (value.equals(SchemaSymbols.ATTVAL_UNBOUNDED)) { |
|
1480 |
retValue = INT_UNBOUNDED; |
|
1481 |
} else { |
|
1482 |
try { |
|
1483 |
retValue = validate(attrValues, attr, value, DT_NONNEGINT, schemaDoc); |
|
1484 |
} catch (NumberFormatException e) { |
|
1485 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "(nonNegativeInteger | unbounded)"}); |
|
1486 |
} |
|
1487 |
} |
|
1488 |
break; |
|
1489 |
case DT_MAXOCCURS1: |
|
1490 |
// maxOccurs = 1 |
|
1491 |
if (value.equals("1")) |
|
1492 |
retValue = fXIntPool.getXInt(1); |
|
1493 |
else |
|
1494 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1495 |
new Object[]{value, "(1)"}); |
|
1496 |
break; |
|
1497 |
case DT_MEMBERTYPES: |
|
1498 |
// memberTypes = List of QName |
|
1499 |
memberType = new Vector(); |
|
1500 |
try { |
|
1501 |
// use the default \t\r\n\f delimiters |
|
1502 |
StringTokenizer t = new StringTokenizer(value); |
|
1503 |
while (t.hasMoreTokens()) { |
|
1504 |
String token = t.nextToken (); |
|
1505 |
QName qname = (QName)fExtraDVs[DT_QNAME].validate(token, schemaDoc.fValidationContext, null); |
|
1506 |
// kludge to handle chameleon includes/redefines... |
|
1507 |
if(qname.prefix == XMLSymbols.EMPTY_STRING && qname.uri == null && schemaDoc.fIsChameleonSchema) |
|
1508 |
qname.uri = schemaDoc.fTargetNamespace; |
|
1509 |
memberType.addElement(qname); |
|
1510 |
} |
|
1511 |
retValue = memberType; |
|
1512 |
} |
|
1513 |
catch (InvalidDatatypeValueException ide) { |
|
1514 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.2", new Object[]{value, "(List of QName)"}); |
|
1515 |
} |
|
1516 |
break; |
|
1517 |
case DT_MINOCCURS1: |
|
1518 |
// minOccurs = (0 | 1) |
|
1519 |
if (value.equals("0")) |
|
1520 |
retValue = fXIntPool.getXInt(0); |
|
1521 |
else if (value.equals("1")) |
|
1522 |
retValue = fXIntPool.getXInt(1); |
|
1523 |
else |
|
1524 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1525 |
new Object[]{value, "(0 | 1)"}); |
|
1526 |
break; |
|
1527 |
case DT_NAMESPACE: |
|
1528 |
// namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) |
|
1529 |
if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDANY)) { |
|
1530 |
// ##any |
|
1531 |
retValue = INT_ANY_ANY; |
|
1532 |
} else if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDOTHER)) { |
|
1533 |
// ##other |
|
1534 |
retValue = INT_ANY_NOT; |
|
1535 |
String[] list = new String[2]; |
|
1536 |
list[0] = schemaDoc.fTargetNamespace; |
|
1537 |
list[1] = null; |
|
1538 |
attrValues[ATTIDX_NAMESPACE_LIST] = list; |
|
1539 |
} else { |
|
1540 |
// list |
|
1541 |
retValue = INT_ANY_LIST; |
|
1542 |
||
1543 |
fNamespaceList.removeAllElements(); |
|
1544 |
||
1545 |
// tokenize |
|
1546 |
// use the default \t\r\n\f delimiters |
|
1547 |
StringTokenizer tokens = new StringTokenizer(value); |
|
1548 |
String token; |
|
1549 |
String tempNamespace; |
|
1550 |
try { |
|
1551 |
while (tokens.hasMoreTokens()) { |
|
1552 |
token = tokens.nextToken(); |
|
1553 |
if (token.equals(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL)) { |
|
1554 |
tempNamespace = null; |
|
1555 |
} else if (token.equals(SchemaSymbols.ATTVAL_TWOPOUNDTARGETNS)) { |
|
1556 |
tempNamespace = schemaDoc.fTargetNamespace; |
|
1557 |
} else { |
|
1558 |
// we have found namespace URI here |
|
1559 |
// need to add it to the symbol table |
|
1560 |
fExtraDVs[DT_ANYURI].validate(token, schemaDoc.fValidationContext, null); |
|
1561 |
tempNamespace = fSymbolTable.addSymbol(token); |
|
1562 |
} |
|
1563 |
||
1564 |
//check for duplicate namespaces in the list |
|
1565 |
if (!fNamespaceList.contains(tempNamespace)) { |
|
1566 |
fNamespaceList.addElement(tempNamespace); |
|
1567 |
} |
|
1568 |
} |
|
1569 |
} catch (InvalidDatatypeValueException ide) { |
|
1570 |
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object[]{value, "((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )"}); |
|
1571 |
} |
|
1572 |
||
1573 |
// convert the vector to an array |
|
1574 |
int num = fNamespaceList.size(); |
|
1575 |
String[] list = new String[num]; |
|
1576 |
fNamespaceList.copyInto(list); |
|
1577 |
attrValues[ATTIDX_NAMESPACE_LIST] = list; |
|
1578 |
} |
|
1579 |
break; |
|
1580 |
case DT_PROCESSCONTENTS: |
|
1581 |
// processContents = (lax | skip | strict) |
|
1582 |
if (value.equals (SchemaSymbols.ATTVAL_STRICT)) |
|
1583 |
retValue = INT_ANY_STRICT; |
|
1584 |
else if (value.equals (SchemaSymbols.ATTVAL_LAX)) |
|
1585 |
retValue = INT_ANY_LAX; |
|
1586 |
else if (value.equals (SchemaSymbols.ATTVAL_SKIP)) |
|
1587 |
retValue = INT_ANY_SKIP; |
|
1588 |
else |
|
1589 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1590 |
new Object[]{value, "(lax | skip | strict)"}); |
|
1591 |
break; |
|
1592 |
case DT_USE: |
|
1593 |
// use = (optional | prohibited | required) |
|
1594 |
if (value.equals (SchemaSymbols.ATTVAL_OPTIONAL)) |
|
1595 |
retValue = INT_USE_OPTIONAL; |
|
1596 |
else if (value.equals (SchemaSymbols.ATTVAL_REQUIRED)) |
|
1597 |
retValue = INT_USE_REQUIRED; |
|
1598 |
else if (value.equals (SchemaSymbols.ATTVAL_PROHIBITED)) |
|
1599 |
retValue = INT_USE_PROHIBITED; |
|
1600 |
else |
|
1601 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1602 |
new Object[]{value, "(optional | prohibited | required)"}); |
|
1603 |
break; |
|
1604 |
case DT_WHITESPACE: |
|
1605 |
// value = preserve | replace | collapse |
|
1606 |
if (value.equals (SchemaSymbols.ATTVAL_PRESERVE)) |
|
1607 |
retValue = INT_WS_PRESERVE; |
|
1608 |
else if (value.equals (SchemaSymbols.ATTVAL_REPLACE)) |
|
1609 |
retValue = INT_WS_REPLACE; |
|
1610 |
else if (value.equals (SchemaSymbols.ATTVAL_COLLAPSE)) |
|
1611 |
retValue = INT_WS_COLLAPSE; |
|
1612 |
else |
|
1613 |
throw new InvalidDatatypeValueException("cvc-enumeration-valid", |
|
1614 |
new Object[]{value, "(preserve | replace | collapse)"}); |
|
1615 |
break; |
|
1616 |
} |
|
1617 |
||
1618 |
return retValue; |
|
1619 |
} |
|
1620 |
||
2669
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1621 |
void reportSchemaFatalError (String key, Object[] args, Element ele) { |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1622 |
fSchemaHandler.reportSchemaFatalError(key, args, ele); |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1623 |
} |
15024792697e
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents:
6
diff
changeset
|
1624 |
|
6 | 1625 |
void reportSchemaError (String key, Object[] args, Element ele) { |
1626 |
fSchemaHandler.reportSchemaError(key, args, ele); |
|
1627 |
} |
|
1628 |
||
1629 |
// validate attriubtes from non-schema namespaces |
|
1630 |
// REVISIT: why we store the attributes in this way? why not just a list |
|
1631 |
// of structure {element node, attr name/qname, attr value)? |
|
1632 |
// REVISIT: pass the proper element node to reportSchemaError |
|
1633 |
public void checkNonSchemaAttributes(XSGrammarBucket grammarBucket) { |
|
1634 |
// for all attributes |
|
1635 |
Enumeration keys = fNonSchemaAttrs.keys(); |
|
1636 |
XSAttributeDecl attrDecl; |
|
1637 |
while (keys.hasMoreElements()) { |
|
1638 |
// get name, uri, localpart |
|
1639 |
String attrRName = (String)keys.nextElement(); |
|
1640 |
String attrURI = attrRName.substring(0,attrRName.indexOf(',')); |
|
1641 |
String attrLocal = attrRName.substring(attrRName.indexOf(',')+1); |
|
1642 |
// find associated grammar |
|
1643 |
SchemaGrammar sGrammar = grammarBucket.getGrammar(attrURI); |
|
1644 |
if (sGrammar == null) |
|
1645 |
continue; |
|
1646 |
// and get the datatype validator, if there is one |
|
1647 |
attrDecl = sGrammar.getGlobalAttributeDecl(attrLocal); |
|
1648 |
if (attrDecl == null) |
|
1649 |
continue; |
|
1650 |
XSSimpleType dv = (XSSimpleType)attrDecl.getTypeDefinition(); |
|
1651 |
if (dv == null) |
|
1652 |
continue; |
|
1653 |
||
1654 |
// get all values appeared with this attribute name |
|
1655 |
Vector values = (Vector)fNonSchemaAttrs.get(attrRName); |
|
1656 |
String elName, attrVal; |
|
1657 |
String attrName = (String)values.elementAt(0); |
|
1658 |
// for each of the values |
|
1659 |
int count = values.size(); |
|
1660 |
for (int i = 1; i < count; i += 2) { |
|
1661 |
elName = (String)values.elementAt(i); |
|
1662 |
try { |
|
1663 |
// and validate it using the XSSimpleType |
|
1664 |
// REVISIT: what would be the proper validation context? |
|
1665 |
// guess we need to save that in the vectors too. |
|
1666 |
dv.validate((String)values.elementAt(i+1), null, null); |
|
1667 |
} catch(InvalidDatatypeValueException ide) { |
|
1668 |
reportSchemaError ("s4s-att-invalid-value", |
|
1669 |
new Object[] {elName, attrName, ide.getMessage()}, |
|
1670 |
null); |
|
1671 |
} |
|
1672 |
} |
|
1673 |
} |
|
1674 |
} |
|
1675 |
||
1676 |
// normalize the string according to the whiteSpace facet |
|
1677 |
public static String normalize(String content, short ws) { |
|
1678 |
int len = content == null ? 0 : content.length(); |
|
1679 |
if (len == 0 || ws == XSSimpleType.WS_PRESERVE) |
|
1680 |
return content; |
|
1681 |
||
1682 |
StringBuffer sb = new StringBuffer(); |
|
1683 |
if (ws == XSSimpleType.WS_REPLACE) { |
|
1684 |
char ch; |
|
1685 |
// when it's replace, just replace #x9, #xa, #xd by #x20 |
|
1686 |
for (int i = 0; i < len; i++) { |
|
1687 |
ch = content.charAt(i); |
|
1688 |
if (ch != 0x9 && ch != 0xa && ch != 0xd) |
|
1689 |
sb.append(ch); |
|
1690 |
else |
|
1691 |
sb.append((char)0x20); |
|
1692 |
} |
|
1693 |
} else { |
|
1694 |
char ch; |
|
1695 |
int i; |
|
1696 |
boolean isLeading = true; |
|
1697 |
// when it's collapse |
|
1698 |
for (i = 0; i < len; i++) { |
|
1699 |
ch = content.charAt(i); |
|
1700 |
// append real characters, so we passed leading ws |
|
1701 |
if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { |
|
1702 |
sb.append(ch); |
|
1703 |
isLeading = false; |
|
1704 |
} |
|
1705 |
else { |
|
1706 |
// for whitespaces, we skip all following ws |
|
1707 |
for (; i < len-1; i++) { |
|
1708 |
ch = content.charAt(i+1); |
|
1709 |
if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) |
|
1710 |
break; |
|
1711 |
} |
|
1712 |
// if it's not a leading or tailing ws, then append a space |
|
1713 |
if (i < len - 1 && !isLeading) |
|
1714 |
sb.append((char)0x20); |
|
1715 |
} |
|
1716 |
} |
|
1717 |
} |
|
1718 |
||
1719 |
return sb.toString(); |
|
1720 |
} |
|
1721 |
||
1722 |
// the following part implements an attribute-value-array pool. |
|
1723 |
// when checkAttribute is called, it calls getAvailableArray to get |
|
1724 |
// an array from the pool; when the caller is done with the array, |
|
1725 |
// it calls returnAttrArray to return that array to the pool. |
|
1726 |
||
1727 |
// initial size of the array pool. 10 is big enough |
|
1728 |
static final int INIT_POOL_SIZE = 10; |
|
1729 |
// the incremental size of the array pool |
|
1730 |
static final int INC_POOL_SIZE = 10; |
|
1731 |
// the array pool |
|
1732 |
Object[][] fArrayPool = new Object[INIT_POOL_SIZE][ATTIDX_COUNT]; |
|
1733 |
// used to clear the returned array |
|
1734 |
// I think System.arrayCopy is more efficient than setting 35 fields to null |
|
1735 |
private static Object[] fTempArray = new Object[ATTIDX_COUNT]; |
|
1736 |
// current position of the array pool (# of arrays not returned) |
|
1737 |
int fPoolPos = 0; |
|
1738 |
||
1739 |
// get the next available array |
|
1740 |
protected Object[] getAvailableArray() { |
|
1741 |
// if no array left in the pool, increase the pool size |
|
1742 |
if (fArrayPool.length == fPoolPos) { |
|
1743 |
// increase size |
|
1744 |
fArrayPool = new Object[fPoolPos+INC_POOL_SIZE][]; |
|
1745 |
// initialize each *new* array |
|
1746 |
for (int i = fPoolPos; i < fArrayPool.length; i++) |
|
1747 |
fArrayPool[i] = new Object[ATTIDX_COUNT]; |
|
1748 |
} |
|
1749 |
// get the next available one |
|
1750 |
Object[] retArray = fArrayPool[fPoolPos]; |
|
1751 |
// clear it from the pool. this is for GC: if a caller forget to |
|
1752 |
// return the array, we want that array to be GCed. |
|
1753 |
fArrayPool[fPoolPos++] = null; |
|
1754 |
// to make sure that one array is not returned twice, we use |
|
1755 |
// the last entry to indicate whether an array is already returned |
|
1756 |
// now set it to false. |
|
1757 |
System.arraycopy(fTempArray, 0, retArray, 0, ATTIDX_COUNT-1); |
|
1758 |
retArray[ATTIDX_ISRETURNED] = Boolean.FALSE; |
|
1759 |
||
1760 |
return retArray; |
|
1761 |
} |
|
1762 |
||
1763 |
// return an array back to the pool |
|
1764 |
public void returnAttrArray(Object[] attrArray, XSDocumentInfo schemaDoc) { |
|
1765 |
// pop the namespace context |
|
1766 |
if (schemaDoc != null) |
|
1767 |
schemaDoc.fNamespaceSupport.popContext(); |
|
1768 |
||
1769 |
// if 1. the pool is full; 2. the array is null; |
|
1770 |
// 3. the array is of wrong size; 4. the array is already returned |
|
1771 |
// then we can't accept this array to be returned |
|
1772 |
if (fPoolPos == 0 || |
|
1773 |
attrArray == null || |
|
1774 |
attrArray.length != ATTIDX_COUNT || |
|
1775 |
((Boolean)attrArray[ATTIDX_ISRETURNED]).booleanValue()) { |
|
1776 |
return; |
|
1777 |
} |
|
1778 |
||
1779 |
// mark this array as returned |
|
1780 |
attrArray[ATTIDX_ISRETURNED] = Boolean.TRUE; |
|
1781 |
// better clear nonschema vector |
|
1782 |
if(attrArray[ATTIDX_NONSCHEMA] != null) |
|
1783 |
((Vector)attrArray[ATTIDX_NONSCHEMA]).clear(); |
|
1784 |
// and put it into the pool |
|
1785 |
fArrayPool[--fPoolPos] = attrArray; |
|
1786 |
} |
|
1787 |
||
1788 |
public void resolveNamespace(Element element, Attr[] attrs, |
|
1789 |
SchemaNamespaceSupport nsSupport) { |
|
1790 |
// push the namespace context |
|
1791 |
nsSupport.pushContext(); |
|
1792 |
||
1793 |
// search for new namespace bindings |
|
1794 |
int length = attrs.length; |
|
1795 |
Attr sattr = null; |
|
1796 |
String rawname, prefix, uri; |
|
1797 |
for (int i = 0; i < length; i++) { |
|
1798 |
sattr = attrs[i]; |
|
1799 |
rawname = DOMUtil.getName(sattr); |
|
1800 |
prefix = null; |
|
1801 |
if (rawname.equals(XMLSymbols.PREFIX_XMLNS)) |
|
1802 |
prefix = XMLSymbols.EMPTY_STRING; |
|
1803 |
else if (rawname.startsWith("xmlns:")) |
|
1804 |
prefix = fSymbolTable.addSymbol(DOMUtil.getLocalName(sattr)); |
|
1805 |
if (prefix != null) { |
|
1806 |
uri = fSymbolTable.addSymbol(DOMUtil.getValue(sattr)); |
|
1807 |
nsSupport.declarePrefix(prefix, uri.length()!=0 ? uri : null); |
|
1808 |
} |
|
1809 |
} |
|
1810 |
} |
|
1811 |
} |
|
1812 |
||
1813 |
class OneAttr { |
|
1814 |
// name of the attribute |
|
1815 |
public String name; |
|
1816 |
// index of the datatype validator |
|
1817 |
public int dvIndex; |
|
1818 |
// whether it's optional, and has default value |
|
1819 |
public int valueIndex; |
|
1820 |
// the default value of this attribute |
|
1821 |
public Object dfltValue; |
|
1822 |
||
1823 |
public OneAttr(String name, int dvIndex, int valueIndex, Object dfltValue) { |
|
1824 |
this.name = name; |
|
1825 |
this.dvIndex = dvIndex; |
|
1826 |
this.valueIndex = valueIndex; |
|
1827 |
this.dfltValue = dfltValue; |
|
1828 |
} |
|
1829 |
} |
|
1830 |
||
1831 |
class OneElement { |
|
1832 |
// the list of attributes that can appear in one element |
|
1833 |
public Container attrList; |
|
1834 |
// does this element allow attributes from non-schema namespace |
|
1835 |
public boolean allowNonSchemaAttr; |
|
1836 |
||
1837 |
public OneElement (Container attrList) { |
|
1838 |
this(attrList, true); |
|
1839 |
} |
|
1840 |
||
1841 |
public OneElement (Container attrList, boolean allowNonSchemaAttr) { |
|
1842 |
this.attrList = attrList; |
|
1843 |
this.allowNonSchemaAttr = allowNonSchemaAttr; |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
abstract class Container { |
|
1848 |
static final int THRESHOLD = 5; |
|
1849 |
static Container getContainer(int size) { |
|
1850 |
if (size > THRESHOLD) |
|
1851 |
return new LargeContainer(size); |
|
1852 |
else |
|
1853 |
return new SmallContainer(size); |
|
1854 |
} |
|
1855 |
abstract void put(String key, OneAttr value); |
|
1856 |
abstract OneAttr get(String key); |
|
1857 |
||
1858 |
OneAttr[] values; |
|
1859 |
int pos = 0; |
|
1860 |
} |
|
1861 |
||
1862 |
class SmallContainer extends Container { |
|
1863 |
String[] keys; |
|
1864 |
SmallContainer(int size) { |
|
1865 |
keys = new String[size]; |
|
1866 |
values = new OneAttr[size]; |
|
1867 |
} |
|
1868 |
void put(String key, OneAttr value) { |
|
1869 |
keys[pos] = key; |
|
1870 |
values[pos++] = value; |
|
1871 |
} |
|
1872 |
OneAttr get(String key) { |
|
1873 |
for (int i = 0; i < pos; i++) { |
|
1874 |
if (keys[i].equals(key)) { |
|
1875 |
return values[i]; |
|
1876 |
} |
|
1877 |
} |
|
1878 |
return null; |
|
1879 |
} |
|
1880 |
} |
|
1881 |
||
1882 |
class LargeContainer extends Container { |
|
1883 |
Hashtable items; |
|
1884 |
LargeContainer(int size) { |
|
1885 |
items = new Hashtable(size*2+1); |
|
1886 |
values = new OneAttr[size]; |
|
1887 |
} |
|
1888 |
void put(String key, OneAttr value) { |
|
1889 |
items.put(key, value); |
|
1890 |
values[pos++] = value; |
|
1891 |
} |
|
1892 |
OneAttr get(String key) { |
|
1893 |
OneAttr ret = (OneAttr)items.get(key); |
|
1894 |
return ret; |
|
1895 |
} |
|
1896 |
} |