KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > traversers > XSAttributeChecker


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.xs.traversers;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22 import java.util.Vector JavaDoc;
23
24 import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
25 import org.apache.xerces.impl.dv.XSSimpleType;
26 import org.apache.xerces.impl.xs.SchemaGrammar;
27 import org.apache.xerces.impl.xs.SchemaNamespaceSupport;
28 import org.apache.xerces.impl.xs.SchemaSymbols;
29 import org.apache.xerces.impl.xs.XSAttributeDecl;
30 import org.apache.xerces.impl.xs.XSGrammarBucket;
31 import org.apache.xerces.impl.xs.XSWildcardDecl;
32 import org.apache.xerces.impl.xs.util.XInt;
33 import org.apache.xerces.impl.xs.util.XIntPool;
34 import org.apache.xerces.util.DOMUtil;
35 import org.apache.xerces.util.SymbolTable;
36 import org.apache.xerces.util.XMLSymbols;
37 import org.apache.xerces.xni.QName;
38 import org.apache.xerces.xs.XSConstants;
39 import org.w3c.dom.Attr JavaDoc;
40 import org.w3c.dom.Element JavaDoc;
41
42 /**
43  * Class <code>XSAttributeCheck</code> is used to check the validity of attributes
44  * appearing in the schema document. It
45  * - reports an error for invalid element (invalid namespace, invalid name)
46  * - reports an error for invalid attribute (invalid namespace, invalid name)
47  * - reports an error for invalid attribute value
48  * - return compiled values for attriute values
49  * - provide default value for missing optional attributes
50  * - provide default value for incorrect attribute values
51  *
52  * But it's the caller's responsibility to check whether a required attribute
53  * is present.
54  *
55  * Things need revisiting:
56  * - Whether to return non-schema attributes/values
57  * - Do we need to update NamespaceScope and ErrorReporter when reset()?
58  * - Should have the datatype validators return compiled value
59  * - use symbol table instead of many hashtables
60  *
61  * @xerces.internal
62  *
63  * @author Sandy Gao, IBM
64  * @version $Id: XSAttributeChecker.java,v 1.36 2004/10/29 05:05:13 mrglavas Exp $
65  */

66
67 public class XSAttributeChecker {
68
69     // REVISIT: only local element and attribute are different from others.
70
// it's possible to have either name or ref. all the others
71
// are only allowed to have one of name or ref, or neither of them.
72
// we'd better move such checking to the traverser.
73
private static final String JavaDoc ELEMENT_N = "element_n";
74     private static final String JavaDoc ELEMENT_R = "element_r";
75     private static final String JavaDoc ATTRIBUTE_N = "attribute_n";
76     private static final String JavaDoc ATTRIBUTE_R = "attribute_r";
77
78     private static int ATTIDX_COUNT = 0;
79     public static final int ATTIDX_ABSTRACT = ATTIDX_COUNT++;
80     public static final int ATTIDX_AFORMDEFAULT = ATTIDX_COUNT++;
81     public static final int ATTIDX_BASE = ATTIDX_COUNT++;
82     public static final int ATTIDX_BLOCK = ATTIDX_COUNT++;
83     public static final int ATTIDX_BLOCKDEFAULT = ATTIDX_COUNT++;
84     public static final int ATTIDX_DEFAULT = ATTIDX_COUNT++;
85     public static final int ATTIDX_EFORMDEFAULT = ATTIDX_COUNT++;
86     public static final int ATTIDX_FINAL = ATTIDX_COUNT++;
87     public static final int ATTIDX_FINALDEFAULT = ATTIDX_COUNT++;
88     public static final int ATTIDX_FIXED = ATTIDX_COUNT++;
89     public static final int ATTIDX_FORM = ATTIDX_COUNT++;
90     public static final int ATTIDX_ID = ATTIDX_COUNT++;
91     public static final int ATTIDX_ITEMTYPE = ATTIDX_COUNT++;
92     public static final int ATTIDX_MAXOCCURS = ATTIDX_COUNT++;
93     public static final int ATTIDX_MEMBERTYPES = ATTIDX_COUNT++;
94     public static final int ATTIDX_MINOCCURS = ATTIDX_COUNT++;
95     public static final int ATTIDX_MIXED = ATTIDX_COUNT++;
96     public static final int ATTIDX_NAME = ATTIDX_COUNT++;
97     public static final int ATTIDX_NAMESPACE = ATTIDX_COUNT++;
98     public static final int ATTIDX_NAMESPACE_LIST = ATTIDX_COUNT++;
99     public static final int ATTIDX_NILLABLE = ATTIDX_COUNT++;
100     public static final int ATTIDX_NONSCHEMA = ATTIDX_COUNT++;
101     public static final int ATTIDX_PROCESSCONTENTS = ATTIDX_COUNT++;
102     public static final int ATTIDX_PUBLIC = ATTIDX_COUNT++;
103     public static final int ATTIDX_REF = ATTIDX_COUNT++;
104     public static final int ATTIDX_REFER = ATTIDX_COUNT++;
105     public static final int ATTIDX_SCHEMALOCATION = ATTIDX_COUNT++;
106     public static final int ATTIDX_SOURCE = ATTIDX_COUNT++;
107     public static final int ATTIDX_SUBSGROUP = ATTIDX_COUNT++;
108     public static final int ATTIDX_SYSTEM = ATTIDX_COUNT++;
109     public static final int ATTIDX_TARGETNAMESPACE = ATTIDX_COUNT++;
110     public static final int ATTIDX_TYPE = ATTIDX_COUNT++;
111     public static final int ATTIDX_USE = ATTIDX_COUNT++;
112     public static final int ATTIDX_VALUE = ATTIDX_COUNT++;
113     public static final int ATTIDX_ENUMNSDECLS = ATTIDX_COUNT++;
114     public static final int ATTIDX_VERSION = ATTIDX_COUNT++;
115     public static final int ATTIDX_XML_LANG = ATTIDX_COUNT++;
116     public static final int ATTIDX_XPATH = ATTIDX_COUNT++;
117     public static final int ATTIDX_FROMDEFAULT = ATTIDX_COUNT++;
118     //public static final int ATTIDX_OTHERVALUES = ATTIDX_COUNT++;
119
public static final int ATTIDX_ISRETURNED = ATTIDX_COUNT++;
120
121     private static final XIntPool fXIntPool = new XIntPool();
122     // constants to return
123
private static final XInt INT_QUALIFIED = fXIntPool.getXInt(SchemaSymbols.FORM_QUALIFIED);
124     private static final XInt INT_UNQUALIFIED = fXIntPool.getXInt(SchemaSymbols.FORM_UNQUALIFIED);
125     private static final XInt INT_EMPTY_SET = fXIntPool.getXInt(XSConstants.DERIVATION_NONE);
126     private static final XInt INT_ANY_STRICT = fXIntPool.getXInt(XSWildcardDecl.PC_STRICT);
127     private static final XInt INT_ANY_LAX = fXIntPool.getXInt(XSWildcardDecl.PC_LAX);
128     private static final XInt INT_ANY_SKIP = fXIntPool.getXInt(XSWildcardDecl.PC_SKIP);
129     private static final XInt INT_ANY_ANY = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_ANY);
130     private static final XInt INT_ANY_LIST = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_LIST);
131     private static final XInt INT_ANY_NOT = fXIntPool.getXInt(XSWildcardDecl.NSCONSTRAINT_NOT);
132     private static final XInt INT_USE_OPTIONAL = fXIntPool.getXInt(SchemaSymbols.USE_OPTIONAL);
133     private static final XInt INT_USE_REQUIRED = fXIntPool.getXInt(SchemaSymbols.USE_REQUIRED);
134     private static final XInt INT_USE_PROHIBITED = fXIntPool.getXInt(SchemaSymbols.USE_PROHIBITED);
135     private static final XInt INT_WS_PRESERVE = fXIntPool.getXInt(XSSimpleType.WS_PRESERVE);
136     private static final XInt INT_WS_REPLACE = fXIntPool.getXInt(XSSimpleType.WS_REPLACE);
137     private static final XInt INT_WS_COLLAPSE = fXIntPool.getXInt(XSSimpleType.WS_COLLAPSE);
138     private static final XInt INT_UNBOUNDED = fXIntPool.getXInt(SchemaSymbols.OCCURRENCE_UNBOUNDED);
139
140     // used to store the map from element name to attribute list
141
// for 14 global elements
142
private static final Hashtable JavaDoc fEleAttrsMapG = new Hashtable JavaDoc(29);
143     // for 39 local elememnts
144
private static final Hashtable JavaDoc fEleAttrsMapL = new Hashtable JavaDoc(79);
145
146     // used to initialize fEleAttrsMap
147
// step 1: all possible data types
148
// DT_??? >= 0 : validate using a validator, which is initialized staticly
149
// DT_??? < 0 : validate directly, which is done in "validate()"
150

151     protected static final int DT_ANYURI = 0;
152     protected static final int DT_ID = 1;
153     protected static final int DT_QNAME = 2;
154     protected static final int DT_STRING = 3;
155     protected static final int DT_TOKEN = 4;
156     protected static final int DT_NCNAME = 5;
157     protected static final int DT_XPATH = 6;
158     protected static final int DT_XPATH1 = 7;
159     protected static final int DT_LANGUAGE = 8;
160
161     // used to store extra datatype validators
162
protected static final int DT_COUNT = DT_LANGUAGE + 1;
163     private static final XSSimpleType[] fExtraDVs = new XSSimpleType[DT_COUNT];
164     static {
165         // step 5: register all datatype validators for new types
166
SchemaGrammar grammar = SchemaGrammar.SG_SchemaNS;
167         // anyURI
168
fExtraDVs[DT_ANYURI] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYURI);
169         // ID
170
fExtraDVs[DT_ID] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ID);
171         // QName
172
fExtraDVs[DT_QNAME] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME);
173         // string
174
fExtraDVs[DT_STRING] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_STRING);
175         // token
176
fExtraDVs[DT_TOKEN] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_TOKEN);
177         // NCName
178
fExtraDVs[DT_NCNAME] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_NCNAME);
179         // xpath = a subset of XPath expression
180
fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
181         // xpath = a subset of XPath expression
182
fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
183         // language
184
fExtraDVs[DT_LANGUAGE] = (XSSimpleType)grammar.getGlobalTypeDecl(SchemaSymbols.ATTVAL_LANGUAGE);
185     }
186
187     protected static final int DT_BLOCK = -1;
188     protected static final int DT_BLOCK1 = -2;
189     protected static final int DT_FINAL = -3;
190     protected static final int DT_FINAL1 = -4;
191     protected static final int DT_FINAL2 = -5;
192     protected static final int DT_FORM = -6;
193     protected static final int DT_MAXOCCURS = -7;
194     protected static final int DT_MAXOCCURS1 = -8;
195     protected static final int DT_MEMBERTYPES = -9;
196     protected static final int DT_MINOCCURS1 = -10;
197     protected static final int DT_NAMESPACE = -11;
198     protected static final int DT_PROCESSCONTENTS = -12;
199     protected static final int DT_USE = -13;
200     protected static final int DT_WHITESPACE = -14;
201     protected static final int DT_BOOLEAN = -15;
202     protected static final int DT_NONNEGINT = -16;
203     protected static final int DT_POSINT = -17;
204
205     static {
206         // step 2: all possible attributes for all elements
207
int attCount = 0;
208         int ATT_ABSTRACT_D = attCount++;
209         int ATT_ATTRIBUTE_FD_D = attCount++;
210         int ATT_BASE_R = attCount++;
211         int ATT_BASE_N = attCount++;
212         int ATT_BLOCK_N = attCount++;
213         int ATT_BLOCK1_N = attCount++;
214         int ATT_BLOCK_D_D = attCount++;
215         int ATT_DEFAULT_N = attCount++;
216         int ATT_ELEMENT_FD_D = attCount++;
217         int ATT_FINAL_N = attCount++;
218         int ATT_FINAL1_N = attCount++;
219         int ATT_FINAL_D_D = attCount++;
220         int ATT_FIXED_N = attCount++;
221         int ATT_FIXED_D = attCount++;
222         int ATT_FORM_N = attCount++;
223         int ATT_ID_N = attCount++;
224         int ATT_ITEMTYPE_N = attCount++;
225         int ATT_MAXOCCURS_D = attCount++;
226         int ATT_MAXOCCURS1_D = attCount++;
227         int ATT_MEMBER_T_N = attCount++;
228         int ATT_MINOCCURS_D = attCount++;
229         int ATT_MINOCCURS1_D = attCount++;
230         int ATT_MIXED_D = attCount++;
231         int ATT_MIXED_N = attCount++;
232         int ATT_NAME_R = attCount++;
233         int ATT_NAMESPACE_D = attCount++;
234         int ATT_NAMESPACE_N = attCount++;
235         int ATT_NILLABLE_D = attCount++;
236         int ATT_PROCESS_C_D = attCount++;
237         int ATT_PUBLIC_R = attCount++;
238         int ATT_REF_R = attCount++;
239         int ATT_REFER_R = attCount++;
240         int ATT_SCHEMA_L_R = attCount++;
241         int ATT_SCHEMA_L_N = attCount++;
242         int ATT_SOURCE_N = attCount++;
243         int ATT_SUBSTITUTION_G_N = attCount++;
244         int ATT_SYSTEM_N = attCount++;
245         int ATT_TARGET_N_N = attCount++;
246         int ATT_TYPE_N = attCount++;
247         int ATT_USE_D = attCount++;
248         int ATT_VALUE_NNI_N = attCount++;
249         int ATT_VALUE_PI_N = attCount++;
250         int ATT_VALUE_STR_N = attCount++;
251         int ATT_VALUE_WS_N = attCount++;
252         int ATT_VERSION_N = attCount++;
253         int ATT_XML_LANG = attCount++;
254         int ATT_XPATH_R = attCount++;
255         int ATT_XPATH1_R = attCount++;
256
257         // step 3: store all these attributes in an array
258
OneAttr[] allAttrs = new OneAttr[attCount];
259         allAttrs[ATT_ABSTRACT_D] = new OneAttr(SchemaSymbols.ATT_ABSTRACT,
260                                                         DT_BOOLEAN,
261                                                         ATTIDX_ABSTRACT,
262                                                         Boolean.FALSE);
263         allAttrs[ATT_ATTRIBUTE_FD_D] = new OneAttr(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT,
264                                                         DT_FORM,
265                                                         ATTIDX_AFORMDEFAULT,
266                                                         INT_UNQUALIFIED);
267         allAttrs[ATT_BASE_R] = new OneAttr(SchemaSymbols.ATT_BASE,
268                                                         DT_QNAME,
269                                                         ATTIDX_BASE,
270                                                         null);
271         allAttrs[ATT_BASE_N] = new OneAttr(SchemaSymbols.ATT_BASE,
272                                                         DT_QNAME,
273                                                         ATTIDX_BASE,
274                                                         null);
275         allAttrs[ATT_BLOCK_N] = new OneAttr(SchemaSymbols.ATT_BLOCK,
276                                                         DT_BLOCK,
277                                                         ATTIDX_BLOCK,
278                                                         null);
279         allAttrs[ATT_BLOCK1_N] = new OneAttr(SchemaSymbols.ATT_BLOCK,
280                                                         DT_BLOCK1,
281                                                         ATTIDX_BLOCK,
282                                                         null);
283         allAttrs[ATT_BLOCK_D_D] = new OneAttr(SchemaSymbols.ATT_BLOCKDEFAULT,
284                                                         DT_BLOCK,
285                                                         ATTIDX_BLOCKDEFAULT,
286                                                         INT_EMPTY_SET);
287         allAttrs[ATT_DEFAULT_N] = new OneAttr(SchemaSymbols.ATT_DEFAULT,
288                                                         DT_STRING,
289                                                         ATTIDX_DEFAULT,
290                                                         null);
291         allAttrs[ATT_ELEMENT_FD_D] = new OneAttr(SchemaSymbols.ATT_ELEMENTFORMDEFAULT,
292                                                         DT_FORM,
293                                                         ATTIDX_EFORMDEFAULT,
294                                                         INT_UNQUALIFIED);
295         allAttrs[ATT_FINAL_N] = new OneAttr(SchemaSymbols.ATT_FINAL,
296                                                         DT_FINAL,
297                                                         ATTIDX_FINAL,
298                                                         null);
299         allAttrs[ATT_FINAL1_N] = new OneAttr(SchemaSymbols.ATT_FINAL,
300                                                         DT_FINAL1,
301                                                         ATTIDX_FINAL,
302                                                         null);
303         allAttrs[ATT_FINAL_D_D] = new OneAttr(SchemaSymbols.ATT_FINALDEFAULT,
304                                                         DT_FINAL2,
305                                                         ATTIDX_FINALDEFAULT,
306                                                         INT_EMPTY_SET);
307         allAttrs[ATT_FIXED_N] = new OneAttr(SchemaSymbols.ATT_FIXED,
308                                                         DT_STRING,
309                                                         ATTIDX_FIXED,
310                                                         null);
311         allAttrs[ATT_FIXED_D] = new OneAttr(SchemaSymbols.ATT_FIXED,
312                                                         DT_BOOLEAN,
313                                                         ATTIDX_FIXED,
314                                                         Boolean.FALSE);
315         allAttrs[ATT_FORM_N] = new OneAttr(SchemaSymbols.ATT_FORM,
316                                                         DT_FORM,
317                                                         ATTIDX_FORM,
318                                                         null);
319         allAttrs[ATT_ID_N] = new OneAttr(SchemaSymbols.ATT_ID,
320                                                         DT_ID,
321                                                         ATTIDX_ID,
322                                                         null);
323         allAttrs[ATT_ITEMTYPE_N] = new OneAttr(SchemaSymbols.ATT_ITEMTYPE,
324                                                         DT_QNAME,
325                                                         ATTIDX_ITEMTYPE,
326                                                         null);
327         allAttrs[ATT_MAXOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS,
328                                                         DT_MAXOCCURS,
329                                                         ATTIDX_MAXOCCURS,
330                                                         fXIntPool.getXInt(1));
331         allAttrs[ATT_MAXOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS,
332                                                         DT_MAXOCCURS1,
333                                                         ATTIDX_MAXOCCURS,
334                                                         fXIntPool.getXInt(1));
335         allAttrs[ATT_MEMBER_T_N] = new OneAttr(SchemaSymbols.ATT_MEMBERTYPES,
336                                                         DT_MEMBERTYPES,
337                                                         ATTIDX_MEMBERTYPES,
338                                                         null);
339         allAttrs[ATT_MINOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS,
340                                                         DT_NONNEGINT,
341                                                         ATTIDX_MINOCCURS,
342                                                         fXIntPool.getXInt(1));
343         allAttrs[ATT_MINOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS,
344                                                         DT_MINOCCURS1,
345                                                         ATTIDX_MINOCCURS,
346                                                         fXIntPool.getXInt(1));
347         allAttrs[ATT_MIXED_D] = new OneAttr(SchemaSymbols.ATT_MIXED,
348                                                         DT_BOOLEAN,
349                                                         ATTIDX_MIXED,
350                                                         Boolean.FALSE);
351         allAttrs[ATT_MIXED_N] = new OneAttr(SchemaSymbols.ATT_MIXED,
352                                                         DT_BOOLEAN,
353                                                         ATTIDX_MIXED,
354                                                         null);
355         allAttrs[ATT_NAME_R] = new OneAttr(SchemaSymbols.ATT_NAME,
356                                                         DT_NCNAME,
357                                                         ATTIDX_NAME,
358                                                         null);
359         allAttrs[ATT_NAMESPACE_D] = new OneAttr(SchemaSymbols.ATT_NAMESPACE,
360                                                         DT_NAMESPACE,
361                                                         ATTIDX_NAMESPACE,
362                                                         INT_ANY_ANY);
363         allAttrs[ATT_NAMESPACE_N] = new OneAttr(SchemaSymbols.ATT_NAMESPACE,
364                                                         DT_ANYURI,
365                                                         ATTIDX_NAMESPACE,
366                                                         null);
367         allAttrs[ATT_NILLABLE_D] = new OneAttr(SchemaSymbols.ATT_NILLABLE,
368                                                         DT_BOOLEAN,
369                                                         ATTIDX_NILLABLE,
370                                                         Boolean.FALSE);
371         allAttrs[ATT_PROCESS_C_D] = new OneAttr(SchemaSymbols.ATT_PROCESSCONTENTS,
372                                                         DT_PROCESSCONTENTS,
373                                                         ATTIDX_PROCESSCONTENTS,
374                                                         INT_ANY_STRICT);
375         allAttrs[ATT_PUBLIC_R] = new OneAttr(SchemaSymbols.ATT_PUBLIC,
376                                                         DT_TOKEN,
377                                                         ATTIDX_PUBLIC,
378                                                         null);
379         allAttrs[ATT_REF_R] = new OneAttr(SchemaSymbols.ATT_REF,
380                                                         DT_QNAME,
381                                                         ATTIDX_REF,
382                                                         null);
383         allAttrs[ATT_REFER_R] = new OneAttr(SchemaSymbols.ATT_REFER,
384                                                         DT_QNAME,
385                                                         ATTIDX_REFER,
386                                                         null);
387         allAttrs[ATT_SCHEMA_L_R] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION,
388                                                         DT_ANYURI,
389                                                         ATTIDX_SCHEMALOCATION,
390                                                         null);
391         allAttrs[ATT_SCHEMA_L_N] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION,
392                                                         DT_ANYURI,
393                                                         ATTIDX_SCHEMALOCATION,
394                                                         null);
395         allAttrs[ATT_SOURCE_N] = new OneAttr(SchemaSymbols.ATT_SOURCE,
396                                                         DT_ANYURI,
397                                                         ATTIDX_SOURCE,
398                                                         null);
399         allAttrs[ATT_SUBSTITUTION_G_N] = new OneAttr(SchemaSymbols.ATT_SUBSTITUTIONGROUP,
400                                                         DT_QNAME,
401                                                         ATTIDX_SUBSGROUP,
402                                                         null);
403         allAttrs[ATT_SYSTEM_N] = new OneAttr(SchemaSymbols.ATT_SYSTEM,
404                                                         DT_ANYURI,
405                                                         ATTIDX_SYSTEM,
406                                                         null);
407         allAttrs[ATT_TARGET_N_N] = new OneAttr(SchemaSymbols.ATT_TARGETNAMESPACE,
408                                                         DT_ANYURI,
409                                                         ATTIDX_TARGETNAMESPACE,
410                                                         null);
411         allAttrs[ATT_TYPE_N] = new OneAttr(SchemaSymbols.ATT_TYPE,
412                                                         DT_QNAME,
413                                                         ATTIDX_TYPE,
414                                                         null);
415         allAttrs[ATT_USE_D] = new OneAttr(SchemaSymbols.ATT_USE,
416                                                         DT_USE,
417                                                         ATTIDX_USE,
418                                                         INT_USE_OPTIONAL);
419         allAttrs[ATT_VALUE_NNI_N] = new OneAttr(SchemaSymbols.ATT_VALUE,
420                                                         DT_NONNEGINT,
421                                                         ATTIDX_VALUE,
422                                                         null);
423         allAttrs[ATT_VALUE_PI_N] = new OneAttr(SchemaSymbols.ATT_VALUE,
424                                                         DT_POSINT,
425                                                         ATTIDX_VALUE,
426                                                         null);
427         allAttrs[ATT_VALUE_STR_N] = new OneAttr(SchemaSymbols.ATT_VALUE,
428                                                         DT_STRING,
429                                                         ATTIDX_VALUE,
430                                                         null);
431         allAttrs[ATT_VALUE_WS_N] = new OneAttr(SchemaSymbols.ATT_VALUE,
432                                                         DT_WHITESPACE,
433                                                         ATTIDX_VALUE,
434                                                         null);
435         allAttrs[ATT_VERSION_N] = new OneAttr(SchemaSymbols.ATT_VERSION,
436                                                         DT_TOKEN,
437                                                         ATTIDX_VERSION,
438                                                         null);
439         allAttrs[ATT_XML_LANG] = new OneAttr(SchemaSymbols.ATT_XML_LANG,
440                                                         DT_LANGUAGE,
441                                                         ATTIDX_XML_LANG,
442                                                         null);
443         allAttrs[ATT_XPATH_R] = new OneAttr(SchemaSymbols.ATT_XPATH,
444                                                         DT_XPATH,
445                                                         ATTIDX_XPATH,
446                                                         null);
447         allAttrs[ATT_XPATH1_R] = new OneAttr(SchemaSymbols.ATT_XPATH,
448                                                         DT_XPATH1,
449                                                         ATTIDX_XPATH,
450                                                         null);
451
452         // step 4: for each element, make a list of possible attributes
453
Container attrList;
454         OneElement oneEle;
455
456         // for element "attribute" - global
457
attrList = Container.getContainer(5);
458         // default = string
459
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]);
460         // fixed = string
461
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]);
462         // id = ID
463
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
464         // name = NCName
465
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
466         // type = QName
467
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]);
468         oneEle = new OneElement (attrList);
469         fEleAttrsMapG.put(SchemaSymbols.ELT_ATTRIBUTE, oneEle);
470
471         // for element "attribute" - local name
472
attrList = Container.getContainer(7);
473         // default = string
474
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]);
475         // fixed = string
476
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]);
477         // form = (qualified | unqualified)
478
attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]);
479         // id = ID
480
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
481         // name = NCName
482
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
483         // type = QName
484
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]);
485         // use = (optional | prohibited | required) : optional
486
attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]);
487         oneEle = new OneElement (attrList);
488         fEleAttrsMapL.put(ATTRIBUTE_N, oneEle);
489
490         // for element "attribute" - local ref
491
attrList = Container.getContainer(5);
492         // default = string
493
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]);
494         // fixed = string
495
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]);
496         // id = ID
497
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
498         // ref = QName
499
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]);
500         // use = (optional | prohibited | required) : optional
501
attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]);
502         oneEle = new OneElement (attrList);
503         fEleAttrsMapL.put(ATTRIBUTE_R, oneEle);
504
505         // for element "element" - global
506
attrList = Container.getContainer(10);
507         // abstract = boolean : false
508
attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]);
509         // block = (#all | List of (substitution | extension | restriction | list | union))
510
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]);
511         // default = string
512
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]);
513         // final = (#all | List of (extension | restriction))
514
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]);
515         // fixed = string
516
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]);
517         // id = ID
518
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
519         // name = NCName
520
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
521         // nillable = boolean : false
522
attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]);
523         // substitutionGroup = QName
524
attrList.put(SchemaSymbols.ATT_SUBSTITUTIONGROUP, allAttrs[ATT_SUBSTITUTION_G_N]);
525         // type = QName
526
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]);
527         oneEle = new OneElement (attrList);
528         fEleAttrsMapG.put(SchemaSymbols.ELT_ELEMENT, oneEle);
529
530         // for element "element" - local name
531
attrList = Container.getContainer(10);
532         // block = (#all | List of (substitution | extension | restriction | list | union))
533
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]);
534         // default = string
535
attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]);
536         // fixed = string
537
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]);
538         // form = (qualified | unqualified)
539
attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]);
540         // id = ID
541
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
542         // maxOccurs = (nonNegativeInteger | unbounded) : 1
543
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]);
544         // minOccurs = nonNegativeInteger : 1
545
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]);
546         // name = NCName
547
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
548         // nillable = boolean : false
549
attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]);
550         // type = QName
551
attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]);
552         oneEle = new OneElement (attrList);
553         fEleAttrsMapL.put(ELEMENT_N, oneEle);
554
555         // for element "element" - local ref
556
attrList = Container.getContainer(4);
557         // id = ID
558
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
559         // maxOccurs = (nonNegativeInteger | unbounded) : 1
560
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]);
561         // minOccurs = nonNegativeInteger : 1
562
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]);
563         // ref = QName
564
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]);
565         oneEle = new OneElement (attrList);
566         fEleAttrsMapL.put(ELEMENT_R, oneEle);
567
568         // for element "complexType" - global
569
attrList = Container.getContainer(6);
570         // abstract = boolean : false
571
attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]);
572         // block = (#all | List of (extension | restriction))
573
attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK1_N]);
574         // final = (#all | List of (extension | restriction))
575
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]);
576         // id = ID
577
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
578         // mixed = boolean : false
579
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]);
580         // name = NCName
581
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
582         oneEle = new OneElement (attrList);
583         fEleAttrsMapG.put(SchemaSymbols.ELT_COMPLEXTYPE, oneEle);
584
585         // for element "notation" - global
586
attrList = Container.getContainer(4);
587         // id = ID
588
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
589         // name = NCName
590
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
591         // public = A public identifier, per ISO 8879
592
attrList.put(SchemaSymbols.ATT_PUBLIC, allAttrs[ATT_PUBLIC_R]);
593         // system = anyURI
594
attrList.put(SchemaSymbols.ATT_SYSTEM, allAttrs[ATT_SYSTEM_N]);
595         oneEle = new OneElement (attrList);
596         fEleAttrsMapG.put(SchemaSymbols.ELT_NOTATION, oneEle);
597
598
599         // for element "complexType" - local
600
attrList = Container.getContainer(2);
601         // id = ID
602
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
603         // mixed = boolean : false
604
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]);
605         oneEle = new OneElement (attrList);
606         fEleAttrsMapL.put(SchemaSymbols.ELT_COMPLEXTYPE, oneEle);
607
608         // for element "simpleContent" - local
609
attrList = Container.getContainer(1);
610         // id = ID
611
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
612         oneEle = new OneElement (attrList);
613         fEleAttrsMapL.put(SchemaSymbols.ELT_SIMPLECONTENT, oneEle);
614
615         // for element "restriction" - local
616
attrList = Container.getContainer(2);
617         // base = QName
618
attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_N]);
619         // id = ID
620
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
621         oneEle = new OneElement (attrList);
622         fEleAttrsMapL.put(SchemaSymbols.ELT_RESTRICTION, oneEle);
623
624         // for element "extension" - local
625
attrList = Container.getContainer(2);
626         // base = QName
627
attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_R]);
628         // id = ID
629
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
630         oneEle = new OneElement (attrList);
631         fEleAttrsMapL.put(SchemaSymbols.ELT_EXTENSION, oneEle);
632
633         // for element "attributeGroup" - local ref
634
attrList = Container.getContainer(2);
635         // id = ID
636
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
637         // ref = QName
638
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]);
639         oneEle = new OneElement (attrList);
640         fEleAttrsMapL.put(SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle);
641
642         // for element "anyAttribute" - local
643
attrList = Container.getContainer(3);
644         // id = ID
645
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
646         // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
647
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]);
648         // processContents = (lax | skip | strict) : strict
649
attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]);
650         oneEle = new OneElement (attrList);
651         fEleAttrsMapL.put(SchemaSymbols.ELT_ANYATTRIBUTE, oneEle);
652
653         // for element "complexContent" - local
654
attrList = Container.getContainer(2);
655         // id = ID
656
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
657         // mixed = boolean
658
attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_N]);
659         oneEle = new OneElement (attrList);
660         fEleAttrsMapL.put(SchemaSymbols.ELT_COMPLEXCONTENT, oneEle);
661
662         // for element "attributeGroup" - global
663
attrList = Container.getContainer(2);
664         // id = ID
665
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
666         // name = NCName
667
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
668         oneEle = new OneElement (attrList);
669         fEleAttrsMapG.put(SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle);
670
671         // for element "group" - global
672
attrList = Container.getContainer(2);
673         // id = ID
674
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
675         // name = NCName
676
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
677         oneEle = new OneElement (attrList);
678         fEleAttrsMapG.put(SchemaSymbols.ELT_GROUP, oneEle);
679
680         // for element "group" - local ref
681
attrList = Container.getContainer(4);
682         // id = ID
683
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
684         // maxOccurs = (nonNegativeInteger | unbounded) : 1
685
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]);
686         // minOccurs = nonNegativeInteger : 1
687
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]);
688         // ref = QName
689
attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]);
690         oneEle = new OneElement (attrList);
691         fEleAttrsMapL.put(SchemaSymbols.ELT_GROUP, oneEle);
692
693         // for element "all" - local
694
attrList = Container.getContainer(3);
695         // id = ID
696
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
697         // maxOccurs = 1 : 1
698
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS1_D]);
699         // minOccurs = (0 | 1) : 1
700
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS1_D]);
701         oneEle = new OneElement (attrList);
702         fEleAttrsMapL.put(SchemaSymbols.ELT_ALL, oneEle);
703
704         // for element "choice" - local
705
attrList = Container.getContainer(3);
706         // id = ID
707
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
708         // maxOccurs = (nonNegativeInteger | unbounded) : 1
709
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]);
710         // minOccurs = nonNegativeInteger : 1
711
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]);
712         oneEle = new OneElement (attrList);
713         fEleAttrsMapL.put(SchemaSymbols.ELT_CHOICE, oneEle);
714         // for element "sequence" - local
715
fEleAttrsMapL.put(SchemaSymbols.ELT_SEQUENCE, oneEle);
716
717         // for element "any" - local
718
attrList = Container.getContainer(5);
719         // id = ID
720
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
721         // maxOccurs = (nonNegativeInteger | unbounded) : 1
722
attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]);
723         // minOccurs = nonNegativeInteger : 1
724
attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]);
725         // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
726
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]);
727         // processContents = (lax | skip | strict) : strict
728
attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]);
729         oneEle = new OneElement (attrList);
730         fEleAttrsMapL.put(SchemaSymbols.ELT_ANY, oneEle);
731
732         // for element "unique" - local
733
attrList = Container.getContainer(2);
734         // id = ID
735
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
736         // name = NCName
737
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
738         oneEle = new OneElement (attrList);
739         fEleAttrsMapL.put(SchemaSymbols.ELT_UNIQUE, oneEle);
740         // for element "key" - local
741
fEleAttrsMapL.put(SchemaSymbols.ELT_KEY, oneEle);
742
743         // for element "keyref" - local
744
attrList = Container.getContainer(3);
745         // id = ID
746
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
747         // name = NCName
748
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
749         // refer = QName
750
attrList.put(SchemaSymbols.ATT_REFER, allAttrs[ATT_REFER_R]);
751         oneEle = new OneElement (attrList);
752         fEleAttrsMapL.put(SchemaSymbols.ELT_KEYREF, oneEle);
753
754         // for element "selector" - local
755
attrList = Container.getContainer(2);
756         // id = ID
757
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
758         // xpath = a subset of XPath expression
759
attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH_R]);
760         oneEle = new OneElement (attrList);
761         fEleAttrsMapL.put(SchemaSymbols.ELT_SELECTOR, oneEle);
762
763         // for element "field" - local
764
attrList = Container.getContainer(2);
765         // id = ID
766
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
767         // xpath = a subset of XPath expression
768
attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH1_R]);
769         oneEle = new OneElement (attrList);
770         fEleAttrsMapL.put(SchemaSymbols.ELT_FIELD, oneEle);
771
772         // for element "annotation" - global
773
attrList = Container.getContainer(1);
774         // id = ID
775
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
776         oneEle = new OneElement (attrList);
777         fEleAttrsMapG.put(SchemaSymbols.ELT_ANNOTATION, oneEle);
778         // for element "annotation" - local
779
fEleAttrsMapL.put(SchemaSymbols.ELT_ANNOTATION, oneEle);
780
781         // for element "appinfo" - local
782
attrList = Container.getContainer(1);
783         // source = anyURI
784
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]);
785         oneEle = new OneElement (attrList);
786         fEleAttrsMapG.put(SchemaSymbols.ELT_APPINFO, oneEle);
787         fEleAttrsMapL.put(SchemaSymbols.ELT_APPINFO, oneEle);
788
789         // for element "documentation" - local
790
attrList = Container.getContainer(2);
791         // source = anyURI
792
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]);
793         // xml:lang = language
794
attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]);
795         oneEle = new OneElement (attrList);
796         fEleAttrsMapG.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle);
797         fEleAttrsMapL.put(SchemaSymbols.ELT_DOCUMENTATION, oneEle);
798
799         // for element "simpleType" - global
800
attrList = Container.getContainer(3);
801         // final = (#all | List of (list | union | restriction))
802
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]);
803         // id = ID
804
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
805         // name = NCName
806
attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]);
807         oneEle = new OneElement (attrList);
808         fEleAttrsMapG.put(SchemaSymbols.ELT_SIMPLETYPE, oneEle);
809
810         // for element "simpleType" - local
811
attrList = Container.getContainer(2);
812         // final = (#all | List of (list | union | restriction))
813
attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]);
814         // id = ID
815
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
816         oneEle = new OneElement (attrList);
817         fEleAttrsMapL.put(SchemaSymbols.ELT_SIMPLETYPE, oneEle);
818
819         // for element "restriction" - local
820
// already registered for complexType
821

822         // for element "list" - local
823
attrList = Container.getContainer(2);
824         // id = ID
825
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
826         // itemType = QName
827
attrList.put(SchemaSymbols.ATT_ITEMTYPE, allAttrs[ATT_ITEMTYPE_N]);
828         oneEle = new OneElement (attrList);
829         fEleAttrsMapL.put(SchemaSymbols.ELT_LIST, oneEle);
830
831         // for element "union" - local
832
attrList = Container.getContainer(2);
833         // id = ID
834
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
835         // memberTypes = List of QName
836
attrList.put(SchemaSymbols.ATT_MEMBERTYPES, allAttrs[ATT_MEMBER_T_N]);
837         oneEle = new OneElement (attrList);
838         fEleAttrsMapL.put(SchemaSymbols.ELT_UNION, oneEle);
839
840         // for element "schema" - global
841
attrList = Container.getContainer(8);
842         // attributeFormDefault = (qualified | unqualified) : unqualified
843
attrList.put(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, allAttrs[ATT_ATTRIBUTE_FD_D]);
844         // blockDefault = (#all | List of (substitution | extension | restriction | list | union)) : ''
845
attrList.put(SchemaSymbols.ATT_BLOCKDEFAULT, allAttrs[ATT_BLOCK_D_D]);
846         // elementFormDefault = (qualified | unqualified) : unqualified
847
attrList.put(SchemaSymbols.ATT_ELEMENTFORMDEFAULT, allAttrs[ATT_ELEMENT_FD_D]);
848         // finalDefault = (#all | List of (extension | restriction | list | union)) : ''
849
attrList.put(SchemaSymbols.ATT_FINALDEFAULT, allAttrs[ATT_FINAL_D_D]);
850         // id = ID
851
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
852         // targetNamespace = anyURI
853
attrList.put(SchemaSymbols.ATT_TARGETNAMESPACE, allAttrs[ATT_TARGET_N_N]);
854         // version = token
855
attrList.put(SchemaSymbols.ATT_VERSION, allAttrs[ATT_VERSION_N]);
856         // xml:lang = language
857
attrList.put(SchemaSymbols.ATT_XML_LANG, allAttrs[ATT_XML_LANG]);
858         oneEle = new OneElement (attrList);
859         fEleAttrsMapG.put(SchemaSymbols.ELT_SCHEMA, oneEle);
860
861         // for element "include" - global
862
attrList = Container.getContainer(2);
863         // id = ID
864
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
865         // schemaLocation = anyURI
866
attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_R]);
867         oneEle = new OneElement (attrList);
868         fEleAttrsMapG.put(SchemaSymbols.ELT_INCLUDE, oneEle);
869         // for element "redefine" - global
870
fEleAttrsMapG.put(SchemaSymbols.ELT_REDEFINE, oneEle);
871
872         // for element "import" - global
873
attrList = Container.getContainer(3);
874         // id = ID
875
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
876         // namespace = anyURI
877
attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_N]);
878         // schemaLocation = anyURI
879
attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_N]);
880         oneEle = new OneElement (attrList);
881         fEleAttrsMapG.put(SchemaSymbols.ELT_IMPORT, oneEle);
882
883         // for element "length" - local
884
attrList = Container.getContainer(3);
885         // id = ID
886
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
887         // value = nonNegativeInteger
888
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_NNI_N]);
889         // fixed = boolean : false
890
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]);
891         oneEle = new OneElement (attrList);
892         fEleAttrsMapL.put(SchemaSymbols.ELT_LENGTH, oneEle);
893         // for element "minLength" - local
894
fEleAttrsMapL.put(SchemaSymbols.ELT_MINLENGTH, oneEle);
895         // for element "maxLength" - local
896
fEleAttrsMapL.put(SchemaSymbols.ELT_MAXLENGTH, oneEle);
897         // for element "fractionDigits" - local
898
fEleAttrsMapL.put(SchemaSymbols.ELT_FRACTIONDIGITS, oneEle);
899
900         // for element "totalDigits" - local
901
attrList = Container.getContainer(3);
902         // id = ID
903
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
904         // value = positiveInteger
905
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_PI_N]);
906         // fixed = boolean : false
907
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]);
908         oneEle = new OneElement (attrList);
909         fEleAttrsMapL.put(SchemaSymbols.ELT_TOTALDIGITS, oneEle);
910
911         // for element "pattern" - local
912
attrList = Container.getContainer(2);
913         // id = ID
914
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
915         // value = string
916
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]);
917         oneEle = new OneElement (attrList);
918         fEleAttrsMapL.put(SchemaSymbols.ELT_PATTERN, oneEle);
919
920         // for element "enumeration" - local
921
attrList = Container.getContainer(2);
922         // id = ID
923
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
924         // value = anySimpleType
925
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]);
926         oneEle = new OneElement (attrList);
927         fEleAttrsMapL.put(SchemaSymbols.ELT_ENUMERATION, oneEle);
928
929         // for element "whiteSpace" - local
930
attrList = Container.getContainer(3);
931         // id = ID
932
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
933         // value = preserve | replace | collapse
934
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_WS_N]);
935         // fixed = boolean : false
936
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]);
937         oneEle = new OneElement (attrList);
938         fEleAttrsMapL.put(SchemaSymbols.ELT_WHITESPACE, oneEle);
939
940         // for element "maxInclusive" - local
941
attrList = Container.getContainer(3);
942         // id = ID
943
attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]);
944         // value = anySimpleType
945
attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]);
946         // fixed = boolean : false
947
attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]);
948         oneEle = new OneElement (attrList);
949         fEleAttrsMapL.put(SchemaSymbols.ELT_MAXINCLUSIVE, oneEle);
950         // for element "maxExclusive" - local
951
fEleAttrsMapL.put(SchemaSymbols.ELT_MAXEXCLUSIVE, oneEle);
952         // for element "minInclusive" - local
953
fEleAttrsMapL.put(SchemaSymbols.ELT_MININCLUSIVE, oneEle);
954         // for element "minExclusive" - local
955
fEleAttrsMapL.put(SchemaSymbols.ELT_MINEXCLUSIVE, oneEle);
956     }
957
958     // used to resolver namespace prefixes
959
protected XSDHandler fSchemaHandler = null;
960
961     // used to store symbols.
962
protected SymbolTable fSymbolTable = null;
963
964     // used to store the mapping from processed element to attributes
965
protected Hashtable JavaDoc fNonSchemaAttrs = new Hashtable JavaDoc();
966
967     // temprory vector, used to hold the namespace list
968
protected Vector JavaDoc fNamespaceList = new Vector JavaDoc();
969
970     // whether this attribute appeared in the current element
971
protected boolean[] fSeen = new boolean[ATTIDX_COUNT];
972     private static boolean[] fSeenTemp = new boolean[ATTIDX_COUNT];
973
974     // constructor. Sets fErrorReproter and get datatype validators
975
public XSAttributeChecker(XSDHandler schemaHandler) {
976         fSchemaHandler = schemaHandler;
977     }
978
979     public void reset(SymbolTable symbolTable) {
980         fSymbolTable = symbolTable;
981         fNonSchemaAttrs.clear();
982     }
983
984     /**
985      * Check whether the specified element conforms to the attributes restriction
986      * an array of attribute values is returned. the caller must call
987      * <code>returnAttrArray</code> to return that array.
988      *
989      * @param element which element to check
990      * @param isGlobal whether a child of &lt;schema&gt; or &lt;redefine&gt;
991      * @param schemaDoc the document where the element lives in
992      * @return an array containing attribute values
993      */

994     public Object JavaDoc[] checkAttributes(Element JavaDoc element, boolean isGlobal,
995                                     XSDocumentInfo schemaDoc) {
996         return checkAttributes(element, isGlobal, schemaDoc, false);
997     }
998
999     /**
1000     * Check whether the specified element conforms to the attributes restriction
1001     * an array of attribute values is returned. the caller must call
1002     * <code>returnAttrArray</code> to return that array. This method also takes
1003     * an extra parameter: if the element is "enumeration", whether to make a
1004     * copy of the namespace context, so that the value can be resolved as a
1005     * QName later.
1006     *
1007     * @param element which element to check
1008     * @param isGlobal whether a child of &lt;schema&gt; or &lt;redefine&gt;
1009     * @param schemaDoc the document where the element lives in
1010     * @param enumAsQName whether to tread enumeration value as QName
1011     * @return an array containing attribute values
1012     */

1013    public Object JavaDoc[] checkAttributes(Element JavaDoc element, boolean isGlobal,
1014                                    XSDocumentInfo schemaDoc, boolean enumAsQName) {
1015        if (element == null)
1016            return null;
1017
1018        // get all attributes
1019
Attr JavaDoc[] attrs = DOMUtil.getAttrs(element);
1020
1021        // update NamespaceSupport
1022
resolveNamespace(element, attrs, schemaDoc.fNamespaceSupport);
1023
1024        String JavaDoc uri = DOMUtil.getNamespaceURI(element);
1025        String JavaDoc elName = DOMUtil.getLocalName(element);
1026
1027        if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(uri)) {
1028            reportSchemaError("s4s-elt-schema-ns", new Object JavaDoc[] {elName}, element);
1029        }
1030
1031        Hashtable JavaDoc eleAttrsMap = fEleAttrsMapG;
1032        String JavaDoc lookupName = elName;
1033
1034        // REVISIT: only local element and attribute are different from others.
1035
// it's possible to have either name or ref. all the others
1036
// are only allowed to have one of name or ref, or neither of them.
1037
// we'd better move such checking to the traverser.
1038
if (!isGlobal) {
1039            eleAttrsMap = fEleAttrsMapL;
1040            if (elName.equals(SchemaSymbols.ELT_ELEMENT)) {
1041                if (DOMUtil.getAttr(element, SchemaSymbols.ATT_REF) != null)
1042                    lookupName = ELEMENT_R;
1043                else
1044                    lookupName = ELEMENT_N;
1045            } else if (elName.equals(SchemaSymbols.ELT_ATTRIBUTE)) {
1046                if (DOMUtil.getAttr(element, SchemaSymbols.ATT_REF) != null)
1047                    lookupName = ATTRIBUTE_R;
1048                else
1049                    lookupName = ATTRIBUTE_N;
1050            }
1051        }
1052
1053        // get desired attribute list of this element
1054
OneElement oneEle = (OneElement)eleAttrsMap.get(lookupName);
1055        if (oneEle == null) {
1056            // should never gets here.
1057
// when this method is called, the call already knows that
1058
// the element can appear.
1059
reportSchemaError ("s4s-elt-invalid", new Object JavaDoc[] {elName}, element);
1060            return null;
1061        }
1062
1063        //Hashtable attrValues = new Hashtable();
1064
Object JavaDoc[] attrValues = getAvailableArray();
1065        //Hashtable otherValues = new Hashtable();
1066
long fromDefault = 0;
1067        Container attrList = oneEle.attrList;
1068
1069        // clear the "seen" flag.
1070
System.arraycopy(fSeenTemp, 0, fSeen, 0, ATTIDX_COUNT);
1071
1072        // traverse all attributes
1073
int length = attrs.length;
1074        Attr JavaDoc sattr = null;
1075        for (int i = 0; i < length; i++) {
1076            sattr = attrs[i];
1077            // get the attribute name/value
1078
//String attrName = DOMUtil.getLocalName(sattr);
1079
String JavaDoc attrName = sattr.getName();
1080            String JavaDoc attrURI = DOMUtil.getNamespaceURI(sattr);
1081            String JavaDoc attrVal = DOMUtil.getValue(sattr);
1082            
1083            if (attrName.startsWith("xml")) {
1084                String JavaDoc attrPrefix = DOMUtil.getPrefix(sattr);
1085                // we don't want to add namespace declarations to the non-schema attributes
1086
if ("xmlns".equals(attrPrefix) || "xmlns".equals(attrName)) {
1087                    continue;
1088                }
1089                // Both <schema> and <documentation> may have an xml:lang attribute.
1090
// Set the URI for this attribute to null so that we process it
1091
// like any other schema attribute.
1092
else if (SchemaSymbols.ATT_XML_LANG.equals(attrName) &&
1093                        (SchemaSymbols.ELT_SCHEMA.equals(elName) ||
1094                                SchemaSymbols.ELT_DOCUMENTATION.equals(elName))) {
1095                    attrURI = null;
1096                }
1097            }
1098
1099            // for attributes with namespace prefix
1100
//
1101
if (attrURI != null && attrURI.length() != 0) {
1102                // attributes with schema namespace are not allowed
1103
// and not allowed on "document" and "appInfo"
1104
if (attrURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) ||
1105                    !oneEle.allowNonSchemaAttr) {
1106                    reportSchemaError ("s4s-att-not-allowed", new Object JavaDoc[] {elName, attrName}, element);
1107                }
1108                else {
1109                    if(attrValues[ATTIDX_NONSCHEMA] == null) {
1110                        // these are usually small
1111
attrValues[ATTIDX_NONSCHEMA] = new Vector JavaDoc(4,2);
1112                    }
1113                    ((Vector JavaDoc)attrValues[ATTIDX_NONSCHEMA]).addElement(attrName);
1114                    ((Vector JavaDoc)attrValues[ATTIDX_NONSCHEMA]).addElement(attrVal);
1115                    // for attributes from other namespace
1116
// store them in a list, and TRY to validate them after
1117
// schema traversal (because it's "lax")
1118
//otherValues.put(attrName, attrVal);
1119
// REVISIT: actually use this some day...
1120
// String attrRName = attrURI + "," + attrName;
1121
// Vector values = (Vector)fNonSchemaAttrs.get(attrRName);
1122
// if (values == null) {
1123
// values = new Vector();
1124
// values.addElement(attrName);
1125
// values.addElement(elName);
1126
// values.addElement(attrVal);
1127
// fNonSchemaAttrs.put(attrRName, values);
1128
// }
1129
// else {
1130
// values.addElement(elName);
1131
// values.addElement(attrVal);
1132
// }
1133
}
1134                continue;
1135            }
1136
1137            // check whether this attribute is allowed
1138
OneAttr oneAttr = (OneAttr)attrList.get(attrName);
1139            if (oneAttr == null) {
1140                reportSchemaError ("s4s-att-not-allowed",
1141                                   new Object JavaDoc[] {elName, attrName},
1142                                   element);
1143                continue;
1144            }
1145
1146            // we've seen this attribute
1147
fSeen[oneAttr.valueIndex] = true;
1148
1149            // check the value against the datatype
1150
try {
1151                // no checking on string needs to be done here.
1152
// no checking on xpath needs to be done here.
1153
// xpath values are validated in xpath parser
1154
if (oneAttr.dvIndex >= 0) {
1155                    if (oneAttr.dvIndex != DT_STRING &&
1156                        oneAttr.dvIndex != DT_XPATH &&
1157                        oneAttr.dvIndex != DT_XPATH1) {
1158                        XSSimpleType dv = fExtraDVs[oneAttr.dvIndex];
1159                        Object JavaDoc avalue = dv.validate(attrVal, schemaDoc.fValidationContext, null);
1160                        // kludge to handle chameleon includes/redefines...
1161
if (oneAttr.dvIndex == DT_QNAME) {
1162                            QName qname = (QName)avalue;
1163                            if(qname.prefix == XMLSymbols.EMPTY_STRING && qname.uri == null && schemaDoc.fIsChameleonSchema)
1164                                qname.uri = schemaDoc.fTargetNamespace;
1165                        }
1166                        attrValues[oneAttr.valueIndex] = avalue;
1167                    } else {
1168                        attrValues[oneAttr.valueIndex] = attrVal;
1169                    }
1170                }
1171                else {
1172                    attrValues[oneAttr.valueIndex] = validate(attrValues, attrName, attrVal, oneAttr.dvIndex, schemaDoc);
1173                }
1174            } catch (InvalidDatatypeValueException ide) {
1175                reportSchemaError ("s4s-att-invalid-value",
1176                                   new Object JavaDoc[] {elName, attrName, ide.getMessage()},
1177                                   element);
1178                if (oneAttr.dfltValue != null)
1179                    //attrValues.put(attrName, oneAttr.dfltValue);
1180
attrValues[oneAttr.valueIndex] = oneAttr.dfltValue;
1181            }
1182
1183            // For "enumeration", and type is possible to be a QName, we need
1184
// to return namespace context for later QName resolution.
1185
if (elName.equals(SchemaSymbols.ELT_ENUMERATION) && enumAsQName) {
1186                attrValues[ATTIDX_ENUMNSDECLS] = new SchemaNamespaceSupport(schemaDoc.fNamespaceSupport);
1187            }
1188        }
1189
1190        // apply default values
1191
OneAttr[] reqAttrs = oneEle.attrList.values;
1192        for (int i = 0; i < reqAttrs.length; i++) {
1193            OneAttr oneAttr = reqAttrs[i];
1194
1195            // if the attribute didn't apprear, and
1196
// if the attribute is optional with default value, apply it
1197
if (oneAttr.dfltValue != null && !fSeen[oneAttr.valueIndex]) {
1198                //attrValues.put(oneAttr.name, oneAttr.dfltValue);
1199
attrValues[oneAttr.valueIndex] = oneAttr.dfltValue;
1200                fromDefault |= (1<<oneAttr.valueIndex);
1201            }
1202        }
1203
1204        attrValues[ATTIDX_FROMDEFAULT] = new Long JavaDoc(fromDefault);
1205        //attrValues[ATTIDX_OTHERVALUES] = otherValues;
1206

1207        // Check that minOccurs isn't greater than maxOccurs.
1208
// p-props-correct 2.1
1209
if (attrValues[ATTIDX_MAXOCCURS] != null) {
1210            int min = ((XInt)attrValues[ATTIDX_MINOCCURS]).intValue();
1211            int max = ((XInt)attrValues[ATTIDX_MAXOCCURS]).intValue();
1212            if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) {
1213                if (min > max) {
1214                    reportSchemaError ("p-props-correct.2.1",
1215                                       new Object JavaDoc[] {elName, attrValues[ATTIDX_MINOCCURS], attrValues[ATTIDX_MAXOCCURS]},
1216                                       element);
1217                    attrValues[ATTIDX_MINOCCURS] = attrValues[ATTIDX_MAXOCCURS];
1218                }
1219            }
1220        }
1221
1222        return attrValues;
1223    }
1224
1225    private Object JavaDoc validate(Object JavaDoc[] attrValues, String JavaDoc attr, String JavaDoc ivalue, int dvIndex,
1226                            XSDocumentInfo schemaDoc) throws InvalidDatatypeValueException {
1227        if (ivalue == null)
1228            return null;
1229
1230        // To validate these types, we don't actually need to normalize the
1231
// strings. We only need to remove the whitespace from both ends.
1232
// In some special cases (list types), StringTokenizer can correctly
1233
// process the un-normalized whitespace.
1234
/**
1235         * REVISIT: Trim removes all leading and trailing characters less
1236         * than or equal to U+0020. This is okay for XML 1.0 since all
1237         * of the valid characters in that range are white space but
1238         * in XML 1.1 control chars are allowed. We shouldn't be trimming
1239         * those. -- mrglavas
1240         */

1241        String JavaDoc value = ivalue.trim();
1242        Object JavaDoc retValue = null;
1243        Vector JavaDoc memberType;
1244        int choice;
1245
1246        switch (dvIndex) {
1247        case DT_BOOLEAN:
1248            if (value.equals(SchemaSymbols.ATTVAL_FALSE) ||
1249                value.equals(SchemaSymbols.ATTVAL_FALSE_0)) {
1250                retValue = Boolean.FALSE;
1251            } else if (value.equals(SchemaSymbols.ATTVAL_TRUE) ||
1252                       value.equals(SchemaSymbols.ATTVAL_TRUE_1)) {
1253                retValue = Boolean.TRUE;
1254            } else {
1255                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{value, "boolean"});
1256            }
1257            break;
1258        case DT_NONNEGINT:
1259            try {
1260                if (value.length() > 0 && value.charAt(0) == '+')
1261                    value = value.substring(1);
1262                retValue = fXIntPool.getXInt(Integer.parseInt(value));
1263            } catch (NumberFormatException JavaDoc e) {
1264                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{value, "nonNegativeInteger"});
1265            }
1266            if (((XInt)retValue).intValue() < 0)
1267                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{value, "nonNegativeInteger"});
1268            break;
1269        case DT_POSINT:
1270            try {
1271                if (value.length() > 0 && value.charAt(0) == '+')
1272                    value = value.substring(1);
1273                retValue = fXIntPool.getXInt(Integer.parseInt(value));
1274            } catch (NumberFormatException JavaDoc e) {
1275                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{value, "positiveInteger"});
1276            }
1277            if (((XInt)retValue).intValue() <= 0)
1278                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object JavaDoc[]{value, "positiveInteger"});
1279            break;
1280        case DT_BLOCK:
1281            // block = (#all | List of (substitution | extension | restriction | list | union))
1282
choice = 0;
1283            if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) {
1284                choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION|
1285                         XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST|
1286                         XSConstants.DERIVATION_UNION;
1287            }
1288            else {
1289                // use the default \t\r\n\f delimiters
1290
StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(value);
1291                while (t.hasMoreTokens()) {
1292                    String JavaDoc token = t.nextToken ();
1293
1294                    if (token.equals (SchemaSymbols.ATTVAL_SUBSTITUTION)) {
1295                        choice |= XSConstants.DERIVATION_SUBSTITUTION;
1296                    }
1297                    else if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) {
1298                        choice |= XSConstants.DERIVATION_EXTENSION;
1299                    }
1300                    else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) {
1301                        choice |= XSConstants.DERIVATION_RESTRICTION;
1302                    }
1303                    else if (token.equals (SchemaSymbols.ATTVAL_LIST)) {
1304                        choice |= XSConstants.DERIVATION_LIST;
1305                    }
1306                    else if (token.equals (SchemaSymbols.ATTVAL_UNION)) {
1307                        choice |= XSConstants.DERIVATION_RESTRICTION;
1308                    }
1309                    else {
1310                        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object JavaDoc[]{value, "(#all | List of (substitution | extension | restriction | list | union))"});
1311                    }
1312                }
1313            }
1314            retValue = fXIntPool.getXInt(choice);
1315            break;
1316        case DT_BLOCK1:
1317        case DT_FINAL:
1318            // block = (#all | List of (extension | restriction))
1319
// final = (#all | List of (extension | restriction))
1320
choice = 0;
1321            if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) {
1322                //choice = SchemaSymbols.EXTENSION|SchemaSymbols.RESTRICTION;
1323
// REVISIT: if #all, then make the result the combination of
1324
// everything: substitution/externsion/restriction/list/union.
1325
// would this be a problem?
1326
// the reason doing so is that when final/blockFinal on <schema>
1327
// is #all, it's not always the same as the conbination of those
1328
// values allowed by final/blockFinal.
1329
// for example, finalDefault="#all" is not always the same as
1330
// finalDefault="extension restriction".
1331
// if finalDefault="#all", final on any simple type would be
1332
// "extension restriction list union".
1333
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION|
1334                         XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST|
1335                         XSConstants.DERIVATION_UNION;
1336            }
1337            else {
1338                // use the default \t\r\n\f delimiters
1339
StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(value);
1340                while (t.hasMoreTokens()) {
1341                    String JavaDoc token = t.nextToken ();
1342
1343                    if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) {
1344                        choice |= XSConstants.DERIVATION_EXTENSION;
1345                    }
1346                    else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) {
1347                        choice |= XSConstants.DERIVATION_RESTRICTION;
1348                    }
1349                    else {
1350                        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object JavaDoc[]{value, "(#all | List of (extension | restriction))"});
1351                    }
1352                }
1353            }
1354            retValue = fXIntPool.getXInt(choice);
1355            break;
1356        case DT_FINAL1:
1357            // final = (#all | List of (list | union | restriction))
1358
choice = 0;
1359            if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) {
1360                //choice = SchemaSymbols.RESTRICTION|SchemaSymbols.LIST|
1361
// SchemaSymbols.UNION;
1362
// REVISIT: if #all, then make the result the combination of
1363
// everything: substitution/externsion/restriction/list/union.
1364
// would this be a problem?
1365
// same reason as above DT_BLOCK1/DT_FINAL
1366
choice = XSConstants.DERIVATION_SUBSTITUTION|XSConstants.DERIVATION_EXTENSION|
1367                         XSConstants.DERIVATION_RESTRICTION|XSConstants.DERIVATION_LIST|
1368                         XSConstants.DERIVATION_UNION;
1369            }
1370            else {
1371                // use the default \t\r\n\f delimiters
1372
StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(value);
1373                while (t.hasMoreTokens()) {
1374                    String JavaDoc token = t.nextToken ();
1375
1376                    if (token.equals (SchemaSymbols.ATTVAL_LIST)) {
1377                        choice |= XSConstants.DERIVATION_LIST;
1378                    }
1379                    else if (token.equals (SchemaSymbols.ATTVAL_UNION)) {
1380                        choice |= XSConstants.DERIVATION_UNION;
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 JavaDoc[]{value, "(#all | List of (list | union | restriction))"});
1387                    }
1388                }
1389            }
1390            retValue = fXIntPool.getXInt(choice);
1391            break;
1392        case DT_FINAL2:
1393            // finalDefault = (#all | List of (extension | restriction | list | union))
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 JavaDoc t = new StringTokenizer JavaDoc(value);
1409                while (t.hasMoreTokens()) {
1410                    String JavaDoc token = t.nextToken ();
1411
1412                    if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) {
1413                        choice |= XSConstants.DERIVATION_EXTENSION;
1414                    }
1415                    else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) {
1416                        choice |= XSConstants.DERIVATION_RESTRICTION;
1417                    }
1418                    else if (token.equals (SchemaSymbols.ATTVAL_LIST)) {
1419                        choice |= XSConstants.DERIVATION_LIST;
1420                    }
1421                    else if (token.equals (SchemaSymbols.ATTVAL_UNION)) {
1422                        choice |= XSConstants.DERIVATION_UNION;
1423                    }
1424                    else {
1425                        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object JavaDoc[]{value, "(#all | List of (extension | restriction | list | union))"});
1426                    }
1427                }
1428            }
1429            retValue = fXIntPool.getXInt(choice);
1430            break;
1431        case DT_FORM:
1432            // form = (qualified | unqualified)
1433
if (value.equals (SchemaSymbols.ATTVAL_QUALIFIED))
1434                retValue = INT_QUALIFIED;
1435            else if (value.equals (SchemaSymbols.ATTVAL_UNQUALIFIED))
1436                retValue = INT_UNQUALIFIED;
1437            else
1438                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1439                                                        new Object JavaDoc[]{value, "(qualified | unqualified)"});
1440            break;
1441        case DT_MAXOCCURS:
1442            // maxOccurs = (nonNegativeInteger | unbounded)
1443
if (value.equals(SchemaSymbols.ATTVAL_UNBOUNDED)) {
1444                retValue = INT_UNBOUNDED;
1445            } else {
1446                try {
1447                    retValue = validate(attrValues, attr, value, DT_NONNEGINT, schemaDoc);
1448                } catch (NumberFormatException JavaDoc e) {
1449                    throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object JavaDoc[]{value, "(nonNegativeInteger | unbounded)"});
1450                }
1451            }
1452            break;
1453        case DT_MAXOCCURS1:
1454            // maxOccurs = 1
1455
if (value.equals("1"))
1456                retValue = fXIntPool.getXInt(1);
1457            else
1458                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1459                                                        new Object JavaDoc[]{value, "(1)"});
1460            break;
1461        case DT_MEMBERTYPES:
1462            // memberTypes = List of QName
1463
memberType = new Vector JavaDoc();
1464            try {
1465                // use the default \t\r\n\f delimiters
1466
StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(value);
1467                while (t.hasMoreTokens()) {
1468                    String JavaDoc token = t.nextToken ();
1469                    QName qname = (QName)fExtraDVs[DT_QNAME].validate(token, schemaDoc.fValidationContext, null);
1470                    // kludge to handle chameleon includes/redefines...
1471
if(qname.prefix == XMLSymbols.EMPTY_STRING && qname.uri == null && schemaDoc.fIsChameleonSchema)
1472                        qname.uri = schemaDoc.fTargetNamespace;
1473                    memberType.addElement(qname);
1474                }
1475                retValue = memberType;
1476            }
1477            catch (InvalidDatatypeValueException ide) {
1478                throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.2", new Object JavaDoc[]{value, "(List of QName)"});
1479            }
1480            break;
1481        case DT_MINOCCURS1:
1482            // minOccurs = (0 | 1)
1483
if (value.equals("0"))
1484                retValue = fXIntPool.getXInt(0);
1485            else if (value.equals("1"))
1486                retValue = fXIntPool.getXInt(1);
1487            else
1488                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1489                                                        new Object JavaDoc[]{value, "(0 | 1)"});
1490            break;
1491        case DT_NAMESPACE:
1492            // namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )
1493
if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDANY)) {
1494                // ##any
1495
retValue = INT_ANY_ANY;
1496            } else if (value.equals(SchemaSymbols.ATTVAL_TWOPOUNDOTHER)) {
1497                // ##other
1498
retValue = INT_ANY_NOT;
1499                String JavaDoc[] list = new String JavaDoc[2];
1500                list[0] = schemaDoc.fTargetNamespace;
1501                list[1] = null;
1502                attrValues[ATTIDX_NAMESPACE_LIST] = list;
1503            } else {
1504                // list
1505
retValue = INT_ANY_LIST;
1506
1507                fNamespaceList.removeAllElements();
1508
1509                // tokenize
1510
// use the default \t\r\n\f delimiters
1511
StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(value);
1512                String JavaDoc token;
1513                String JavaDoc tempNamespace;
1514                try {
1515                    while (tokens.hasMoreTokens()) {
1516                        token = tokens.nextToken();
1517                        if (token.equals(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL)) {
1518                            tempNamespace = null;
1519                        } else if (token.equals(SchemaSymbols.ATTVAL_TWOPOUNDTARGETNS)) {
1520                            tempNamespace = schemaDoc.fTargetNamespace;
1521                        } else {
1522                            // we have found namespace URI here
1523
// need to add it to the symbol table
1524
fExtraDVs[DT_ANYURI].validate(token, schemaDoc.fValidationContext, null);
1525                            tempNamespace = fSymbolTable.addSymbol(token);
1526                        }
1527
1528                        //check for duplicate namespaces in the list
1529
if (!fNamespaceList.contains(tempNamespace)) {
1530                            fNamespaceList.addElement(tempNamespace);
1531                        }
1532                    }
1533                } catch (InvalidDatatypeValueException ide) {
1534                    throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.3", new Object JavaDoc[]{value, "((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )"});
1535                }
1536
1537                // convert the vector to an array
1538
int num = fNamespaceList.size();
1539                String JavaDoc[] list = new String JavaDoc[num];
1540                fNamespaceList.copyInto(list);
1541                attrValues[ATTIDX_NAMESPACE_LIST] = list;
1542            }
1543            break;
1544        case DT_PROCESSCONTENTS:
1545            // processContents = (lax | skip | strict)
1546
if (value.equals (SchemaSymbols.ATTVAL_STRICT))
1547                retValue = INT_ANY_STRICT;
1548            else if (value.equals (SchemaSymbols.ATTVAL_LAX))
1549                retValue = INT_ANY_LAX;
1550            else if (value.equals (SchemaSymbols.ATTVAL_SKIP))
1551                retValue = INT_ANY_SKIP;
1552            else
1553                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1554                                                        new Object JavaDoc[]{value, "(lax | skip | strict)"});
1555            break;
1556        case DT_USE:
1557            // use = (optional | prohibited | required)
1558
if (value.equals (SchemaSymbols.ATTVAL_OPTIONAL))
1559                retValue = INT_USE_OPTIONAL;
1560            else if (value.equals (SchemaSymbols.ATTVAL_REQUIRED))
1561                retValue = INT_USE_REQUIRED;
1562            else if (value.equals (SchemaSymbols.ATTVAL_PROHIBITED))
1563                retValue = INT_USE_PROHIBITED;
1564            else
1565                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1566                                                        new Object JavaDoc[]{value, "(optional | prohibited | required)"});
1567            break;
1568        case DT_WHITESPACE:
1569            // value = preserve | replace | collapse
1570
if (value.equals (SchemaSymbols.ATTVAL_PRESERVE))
1571                retValue = INT_WS_PRESERVE;
1572            else if (value.equals (SchemaSymbols.ATTVAL_REPLACE))
1573                retValue = INT_WS_REPLACE;
1574            else if (value.equals (SchemaSymbols.ATTVAL_COLLAPSE))
1575                retValue = INT_WS_COLLAPSE;
1576            else
1577                throw new InvalidDatatypeValueException("cvc-enumeration-valid",
1578                                                        new Object JavaDoc[]{value, "(preserve | replace | collapse)"});
1579            break;
1580        }
1581
1582        return retValue;
1583    }
1584
1585    void reportSchemaError (String JavaDoc key, Object JavaDoc[] args, Element JavaDoc ele) {
1586        fSchemaHandler.reportSchemaError(key, args, ele);
1587    }
1588
1589    // validate attriubtes from non-schema namespaces
1590
// REVISIT: why we store the attributes in this way? why not just a list
1591
// of structure {element node, attr name/qname, attr value)?
1592
// REVISIT: pass the proper element node to reportSchemaError
1593
public void checkNonSchemaAttributes(XSGrammarBucket grammarBucket) {
1594        // for all attributes
1595
Enumeration JavaDoc keys = fNonSchemaAttrs.keys();
1596        XSAttributeDecl attrDecl;
1597        while (keys.hasMoreElements()) {
1598            // get name, uri, localpart
1599
String JavaDoc attrRName = (String JavaDoc)keys.nextElement();
1600            String JavaDoc attrURI = attrRName.substring(0,attrRName.indexOf(','));
1601            String JavaDoc attrLocal = attrRName.substring(attrRName.indexOf(',')+1);
1602            // find associated grammar
1603
SchemaGrammar sGrammar = grammarBucket.getGrammar(attrURI);
1604            if (sGrammar == null)
1605                continue;
1606            // and get the datatype validator, if there is one
1607
attrDecl = sGrammar.getGlobalAttributeDecl(attrLocal);
1608            if (attrDecl == null)
1609                continue;
1610            XSSimpleType dv = (XSSimpleType)attrDecl.getTypeDefinition();
1611            if (dv == null)
1612                continue;
1613
1614            // get all values appeared with this attribute name
1615
Vector JavaDoc values = (Vector JavaDoc)fNonSchemaAttrs.get(attrRName);
1616            String JavaDoc elName, attrVal;
1617            String JavaDoc attrName = (String JavaDoc)values.elementAt(0);
1618            // for each of the values
1619
int count = values.size();
1620            for (int i = 1; i < count; i += 2) {
1621                elName = (String JavaDoc)values.elementAt(i);
1622                try {
1623                    // and validate it using the XSSimpleType
1624
// REVISIT: what would be the proper validation context?
1625
// guess we need to save that in the vectors too.
1626
dv.validate((String JavaDoc)values.elementAt(i+1), null, null);
1627                } catch(InvalidDatatypeValueException ide) {
1628                    reportSchemaError ("s4s-att-invalid-value",
1629                                       new Object JavaDoc[] {elName, attrName, ide.getMessage()},
1630                                       null);
1631                }
1632            }
1633        }
1634    }
1635
1636    // normalize the string according to the whiteSpace facet
1637
public static String JavaDoc normalize(String JavaDoc content, short ws) {
1638        int len = content == null ? 0 : content.length();
1639        if (len == 0 || ws == XSSimpleType.WS_PRESERVE)
1640            return content;
1641
1642        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1643        if (ws == XSSimpleType.WS_REPLACE) {
1644            char ch;
1645            // when it's replace, just replace #x9, #xa, #xd by #x20
1646
for (int i = 0; i < len; i++) {
1647                ch = content.charAt(i);
1648                if (ch != 0x9 && ch != 0xa && ch != 0xd)
1649                    sb.append(ch);
1650                else
1651                    sb.append((char)0x20);
1652            }
1653        } else {
1654            char ch;
1655            int i;
1656            boolean isLeading = true;
1657            // when it's collapse
1658
for (i = 0; i < len; i++) {
1659                ch = content.charAt(i);
1660                // append real characters, so we passed leading ws
1661
if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) {
1662                    sb.append(ch);
1663                    isLeading = false;
1664                }
1665                else {
1666                    // for whitespaces, we skip all following ws
1667
for (; i < len-1; i++) {
1668                        ch = content.charAt(i+1);
1669                        if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20)
1670                            break;
1671                    }
1672                    // if it's not a leading or tailing ws, then append a space
1673
if (i < len - 1 && !isLeading)
1674                        sb.append((char)0x20);
1675                }
1676            }
1677        }
1678
1679        return sb.toString();
1680    }
1681
1682    // the following part implements an attribute-value-array pool.
1683
// when checkAttribute is called, it calls getAvailableArray to get
1684
// an array from the pool; when the caller is done with the array,
1685
// it calls returnAttrArray to return that array to the pool.
1686

1687    // initial size of the array pool. 10 is big enough
1688
static final int INIT_POOL_SIZE = 10;
1689    // the incremental size of the array pool
1690
static final int INC_POOL_SIZE = 10;
1691    // the array pool
1692
Object JavaDoc[][] fArrayPool = new Object JavaDoc[INIT_POOL_SIZE][ATTIDX_COUNT];
1693    // used to clear the returned array
1694
// I think System.arrayCopy is more efficient than setting 35 fields to null
1695
private static Object JavaDoc[] fTempArray = new Object JavaDoc[ATTIDX_COUNT];
1696    // current position of the array pool (# of arrays not returned)
1697
int fPoolPos = 0;
1698
1699    // get the next available array
1700
protected Object JavaDoc[] getAvailableArray() {
1701        // if no array left in the pool, increase the pool size
1702
if (fArrayPool.length == fPoolPos) {
1703            // increase size
1704
fArrayPool = new Object JavaDoc[fPoolPos+INC_POOL_SIZE][];
1705            // initialize each *new* array
1706
for (int i = fPoolPos; i < fArrayPool.length; i++)
1707                fArrayPool[i] = new Object JavaDoc[ATTIDX_COUNT];
1708        }
1709        // get the next available one
1710
Object JavaDoc[] retArray = fArrayPool[fPoolPos];
1711        // clear it from the pool. this is for GC: if a caller forget to
1712
// return the array, we want that array to be GCed.
1713
fArrayPool[fPoolPos++] = null;
1714        // to make sure that one array is not returned twice, we use
1715
// the last entry to indicate whether an array is already returned
1716
// now set it to false.
1717
System.arraycopy(fTempArray, 0, retArray, 0, ATTIDX_COUNT-1);
1718        retArray[ATTIDX_ISRETURNED] = Boolean.FALSE;
1719
1720        return retArray;
1721    }
1722
1723    // return an array back to the pool
1724
public void returnAttrArray(Object JavaDoc[] attrArray, XSDocumentInfo schemaDoc) {
1725        // pop the namespace context
1726
if (schemaDoc != null)
1727            schemaDoc.fNamespaceSupport.popContext();
1728
1729        // if 1. the pool is full; 2. the array is null;
1730
// 3. the array is of wrong size; 4. the array is already returned
1731
// then we can't accept this array to be returned
1732
if (fPoolPos == 0 ||
1733            attrArray == null ||
1734            attrArray.length != ATTIDX_COUNT ||
1735            ((Boolean JavaDoc)attrArray[ATTIDX_ISRETURNED]).booleanValue()) {
1736            return;
1737        }
1738
1739        // mark this array as returned
1740
attrArray[ATTIDX_ISRETURNED] = Boolean.TRUE;
1741        // better clear nonschema vector
1742
if(attrArray[ATTIDX_NONSCHEMA] != null)
1743            ((Vector JavaDoc)attrArray[ATTIDX_NONSCHEMA]).clear();
1744        // and put it into the pool
1745
fArrayPool[--fPoolPos] = attrArray;
1746    }
1747
1748    public void resolveNamespace(Element JavaDoc element, Attr JavaDoc[] attrs,
1749                                 SchemaNamespaceSupport nsSupport) {
1750        // push the namespace context
1751
nsSupport.pushContext();
1752
1753        // search for new namespace bindings
1754
int length = attrs.length;
1755        Attr JavaDoc sattr = null;
1756        String JavaDoc rawname, prefix, uri;
1757        for (int i = 0; i < length; i++) {
1758            sattr = attrs[i];
1759            rawname = DOMUtil.getName(sattr);
1760            prefix = null;
1761            if (rawname.equals(XMLSymbols.PREFIX_XMLNS))
1762                prefix = XMLSymbols.EMPTY_STRING;
1763            else if (rawname.startsWith("xmlns:"))
1764                prefix = fSymbolTable.addSymbol(DOMUtil.getLocalName(sattr));
1765            if (prefix != null) {
1766                uri = fSymbolTable.addSymbol(DOMUtil.getValue(sattr));
1767                nsSupport.declarePrefix(prefix, uri.length()!=0 ? uri : null);
1768            }
1769        }
1770    }
1771}
1772
1773class OneAttr {
1774    // name of the attribute
1775
public String JavaDoc name;
1776    // index of the datatype validator
1777
public int dvIndex;
1778    // whether it's optional, and has default value
1779
public int valueIndex;
1780    // the default value of this attribute
1781
public Object JavaDoc dfltValue;
1782
1783    public OneAttr(String JavaDoc name, int dvIndex, int valueIndex, Object JavaDoc dfltValue) {
1784        this.name = name;
1785        this.dvIndex = dvIndex;
1786        this.valueIndex = valueIndex;
1787        this.dfltValue = dfltValue;
1788    }
1789}
1790
1791class OneElement {
1792    // the list of attributes that can appear in one element
1793
public Container attrList;
1794    // does this element allow attributes from non-schema namespace
1795
public boolean allowNonSchemaAttr;
1796
1797    public OneElement (Container attrList) {
1798        this(attrList, true);
1799    }
1800
1801    public OneElement (Container attrList, boolean allowNonSchemaAttr) {
1802        this.attrList = attrList;
1803        this.allowNonSchemaAttr = allowNonSchemaAttr;
1804    }
1805}
1806
1807abstract class Container {
1808    static final int THRESHOLD = 5;
1809    static Container getContainer(int size) {
1810        if (size > THRESHOLD)
1811            return new LargeContainer(size);
1812        else
1813            return new SmallContainer(size);
1814    }
1815    abstract void put(String JavaDoc key, OneAttr value);
1816    abstract OneAttr get(String JavaDoc key);
1817
1818    OneAttr[] values;
1819    int pos = 0;
1820}
1821
1822class SmallContainer extends Container {
1823    String JavaDoc[] keys;
1824    SmallContainer(int size) {
1825        keys = new String JavaDoc[size];
1826        values = new OneAttr[size];
1827    }
1828    void put(String JavaDoc key, OneAttr value) {
1829        keys[pos] = key;
1830        values[pos++] = value;
1831    }
1832    OneAttr get(String JavaDoc key) {
1833        for (int i = 0; i < pos; i++) {
1834            if (keys[i].equals(key)) {
1835                return values[i];
1836            }
1837        }
1838        return null;
1839    }
1840}
1841
1842class LargeContainer extends Container {
1843    Hashtable JavaDoc items;
1844    LargeContainer(int size) {
1845        items = new Hashtable JavaDoc(size*2+1);
1846        values = new OneAttr[size];
1847    }
1848    void put(String JavaDoc key, OneAttr value) {
1849        items.put(key, value);
1850        values[pos++] = value;
1851    }
1852    OneAttr get(String JavaDoc key) {
1853        OneAttr ret = (OneAttr)items.get(key);
1854        return ret;
1855    }
1856}
1857
Popular Tags