View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.impl.xs;
22  
23  import java.lang.ref.SoftReference;
24  import java.util.Vector;
25  
26  import com.sun.org.apache.xerces.internal.impl.Constants;
27  import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;
28  import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo;
29  import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
30  import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl;
31  import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint;
32  import com.sun.org.apache.xerces.internal.impl.xs.util.ObjectListImpl;
33  import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator;
34  import com.sun.org.apache.xerces.internal.impl.xs.util.StringListImpl;
35  import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMap4Types;
36  import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMapImpl;
37  import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;
38  import com.sun.org.apache.xerces.internal.parsers.DOMParser;
39  import com.sun.org.apache.xerces.internal.parsers.SAXParser;
40  import com.sun.org.apache.xerces.internal.parsers.XML11Configuration;
41  import com.sun.org.apache.xerces.internal.util.SymbolHash;
42  import com.sun.org.apache.xerces.internal.util.SymbolTable;
43  import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
44  import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
45  import com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar;
46  import com.sun.org.apache.xerces.internal.xs.StringList;
47  import com.sun.org.apache.xerces.internal.xs.XSAnnotation;
48  import com.sun.org.apache.xerces.internal.xs.XSAttributeDeclaration;
49  import com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinition;
50  import com.sun.org.apache.xerces.internal.xs.XSConstants;
51  import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration;
52  import com.sun.org.apache.xerces.internal.xs.XSModel;
53  import com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinition;
54  import com.sun.org.apache.xerces.internal.xs.XSNamedMap;
55  import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem;
56  import com.sun.org.apache.xerces.internal.xs.XSNotationDeclaration;
57  import com.sun.org.apache.xerces.internal.xs.XSObjectList;
58  import com.sun.org.apache.xerces.internal.xs.XSParticle;
59  import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
60  import com.sun.org.apache.xerces.internal.xs.XSWildcard;
61  import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
62  import org.xml.sax.SAXException;
63  
64  /**
65   * This class is to hold all schema component declaration that are declared
66   * within one namespace.
67   *
68   * The Grammar class this class extends contains what little
69   * commonality there is between XML Schema and DTD grammars.  It's
70   * useful to distinguish grammar objects from other kinds of object
71   * when they exist in pools or caches.
72   *
73   * @xerces.internal
74   *
75   * @author Sandy Gao, IBM
76   * @author Elena Litani, IBM
77   *
78   * @version $Id: SchemaGrammar.java,v 1.7 2010-11-01 04:39:55 joehw Exp $
79   */
80  
81  public class SchemaGrammar implements XSGrammar, XSNamespaceItem {
82  
83      // the target namespace of grammar
84      String fTargetNamespace;
85  
86      // global decls: map from decl name to decl object
87      SymbolHash fGlobalAttrDecls;
88      SymbolHash fGlobalAttrGrpDecls;
89      SymbolHash fGlobalElemDecls;
90      SymbolHash fGlobalGroupDecls;
91      SymbolHash fGlobalNotationDecls;
92      SymbolHash fGlobalIDConstraintDecls;
93      SymbolHash fGlobalTypeDecls;
94  
95      // extended global decls: map from schema location + decl name to decl object
96      // key is location,name
97      SymbolHash fGlobalAttrDeclsExt;
98      SymbolHash fGlobalAttrGrpDeclsExt;
99      SymbolHash fGlobalElemDeclsExt;
100     SymbolHash fGlobalGroupDeclsExt;
101     SymbolHash fGlobalNotationDeclsExt;
102     SymbolHash fGlobalIDConstraintDeclsExt;
103     SymbolHash fGlobalTypeDeclsExt;
104 
105     // A global map of all global element declarations - used for substitution group computation
106     // (handy when sharing components by reference, since we might end up with duplicate components
107     //  that are not added to either of the global element declarations above)
108     SymbolHash fAllGlobalElemDecls;
109 
110     // the XMLGrammarDescription member
111     XSDDescription fGrammarDescription = null;
112 
113     // annotations associated with the "root" schema of this targetNamespace
114     XSAnnotationImpl [] fAnnotations = null;
115 
116     // number of annotations declared
117     int fNumAnnotations;
118 
119     // symbol table for constructing parsers (annotation support)
120     private SymbolTable fSymbolTable = null;
121     // parsers for annotation support
122     private SoftReference fSAXParser = null;
123     private SoftReference fDOMParser = null;
124 
125     // is this grammar immutable?  (fully constructed and not changeable)
126     private boolean fIsImmutable = false;
127 
128     //
129     // Constructors
130     //
131 
132     // needed to make BuiltinSchemaGrammar work.
133     protected SchemaGrammar() {}
134 
135     /**
136      * Default constructor.
137      *
138      * @param targetNamespace
139      * @param grammarDesc the XMLGrammarDescription corresponding to this objec
140      *          at the least a systemId should always be known.
141      * @param symbolTable   needed for annotation support
142      */
143     public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc,
144                 SymbolTable symbolTable) {
145         fTargetNamespace = targetNamespace;
146         fGrammarDescription = grammarDesc;
147         fSymbolTable = symbolTable;
148 
149         // REVISIT: do we know the numbers of the following global decls
150         // when creating this grammar? If so, we can pass the numbers in,
151         // and use that number to initialize the following hashtables.
152         fGlobalAttrDecls  = new SymbolHash();
153         fGlobalAttrGrpDecls = new SymbolHash();
154         fGlobalElemDecls = new SymbolHash();
155         fGlobalGroupDecls = new SymbolHash();
156         fGlobalNotationDecls = new SymbolHash();
157         fGlobalIDConstraintDecls = new SymbolHash();
158 
159         // Extended tables
160         fGlobalAttrDeclsExt  = new SymbolHash();
161         fGlobalAttrGrpDeclsExt = new SymbolHash();
162         fGlobalElemDeclsExt = new SymbolHash();
163         fGlobalGroupDeclsExt = new SymbolHash();
164         fGlobalNotationDeclsExt = new SymbolHash();
165         fGlobalIDConstraintDeclsExt = new SymbolHash();
166         fGlobalTypeDeclsExt = new SymbolHash();
167 
168         // All global elements table
169         fAllGlobalElemDecls = new SymbolHash();
170 
171         // if we are parsing S4S, put built-in types in first
172         // they might get overwritten by the types from S4S, but that's
173         // considered what the application wants to do.
174         if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)
175             fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();
176         else
177             fGlobalTypeDecls = new SymbolHash();
178     } // <init>(String, XSDDescription)
179 
180     // Clone an existing schema grammar
181     public SchemaGrammar(SchemaGrammar grammar) {
182         fTargetNamespace = grammar.fTargetNamespace;
183         fGrammarDescription = grammar.fGrammarDescription.makeClone();
184         //fGrammarDescription.fContextType |= XSDDescription.CONTEXT_COLLISION; // REVISIT
185         fSymbolTable = grammar.fSymbolTable; // REVISIT
186 
187         fGlobalAttrDecls  = grammar.fGlobalAttrDecls.makeClone();
188         fGlobalAttrGrpDecls = grammar.fGlobalAttrGrpDecls.makeClone();
189         fGlobalElemDecls = grammar.fGlobalElemDecls.makeClone();
190         fGlobalGroupDecls = grammar.fGlobalGroupDecls.makeClone();
191         fGlobalNotationDecls = grammar.fGlobalNotationDecls.makeClone();
192         fGlobalIDConstraintDecls = grammar.fGlobalIDConstraintDecls.makeClone();
193         fGlobalTypeDecls = grammar.fGlobalTypeDecls.makeClone();
194 
195         // Extended tables
196         fGlobalAttrDeclsExt  = grammar.fGlobalAttrDeclsExt.makeClone();
197         fGlobalAttrGrpDeclsExt = grammar.fGlobalAttrGrpDeclsExt.makeClone();
198         fGlobalElemDeclsExt = grammar.fGlobalElemDeclsExt.makeClone();
199         fGlobalGroupDeclsExt = grammar.fGlobalGroupDeclsExt.makeClone();
200         fGlobalNotationDeclsExt = grammar.fGlobalNotationDeclsExt.makeClone();
201         fGlobalIDConstraintDeclsExt = grammar.fGlobalIDConstraintDeclsExt.makeClone();
202         fGlobalTypeDeclsExt = grammar.fGlobalTypeDeclsExt.makeClone();
203 
204         // All global elements table
205         fAllGlobalElemDecls = grammar.fAllGlobalElemDecls.makeClone();
206 
207         // Annotations associated with the "root" schema of this targetNamespace
208         fNumAnnotations = grammar.fNumAnnotations;
209         if (fNumAnnotations > 0) {
210             fAnnotations = new XSAnnotationImpl[grammar.fAnnotations.length];
211             System.arraycopy(grammar.fAnnotations, 0, fAnnotations, 0, fNumAnnotations);
212         }
213 
214         // All substitution group information declared in this namespace
215         fSubGroupCount = grammar.fSubGroupCount;
216         if (fSubGroupCount > 0) {
217             fSubGroups = new XSElementDecl[grammar.fSubGroups.length];
218             System.arraycopy(grammar.fSubGroups, 0, fSubGroups, 0, fSubGroupCount);
219         }
220 
221         // Array to store complex type decls for constraint checking
222         fCTCount = grammar.fCTCount;
223         if (fCTCount > 0) {
224             fComplexTypeDecls = new XSComplexTypeDecl[grammar.fComplexTypeDecls.length];
225             fCTLocators = new SimpleLocator[grammar.fCTLocators.length];
226             System.arraycopy(grammar.fComplexTypeDecls, 0, fComplexTypeDecls, 0, fCTCount);
227             System.arraycopy(grammar.fCTLocators, 0, fCTLocators, 0, fCTCount);
228         }
229 
230         // Groups being redefined by restriction
231         fRGCount = grammar.fRGCount;
232         if (fRGCount > 0) {
233             fRedefinedGroupDecls = new XSGroupDecl[grammar.fRedefinedGroupDecls.length];
234             fRGLocators = new SimpleLocator[grammar.fRGLocators.length];
235             System.arraycopy(grammar.fRedefinedGroupDecls, 0, fRedefinedGroupDecls, 0, fRGCount);
236             System.arraycopy(grammar.fRGLocators, 0, fRGLocators, 0, fRGCount);
237         }
238 
239         // List of imported grammars
240         if (grammar.fImported != null) {
241             fImported = new Vector();
242             for (int i=0; i<grammar.fImported.size(); i++) {
243                 fImported.add(grammar.fImported.elementAt(i));
244             }
245         }
246 
247         // Locations
248         if (grammar.fLocations != null) {
249             for (int k=0; k<grammar.fLocations.size(); k++) {
250                 addDocument(null, (String)grammar.fLocations.elementAt(k));
251             }
252         }
253 
254     } // <init>(String, XSDDescription)
255 
256     // number of built-in XSTypes we need to create for base and full
257     // datatype set
258     private static final int BASICSET_COUNT = 29;
259     private static final int FULLSET_COUNT  = 46;
260 
261     private static final int GRAMMAR_XS  = 1;
262     private static final int GRAMMAR_XSI = 2;
263 
264     // this class makes sure the static, built-in schema grammars
265     // are immutable.
266     public static class BuiltinSchemaGrammar extends SchemaGrammar {
267 
268         private static final String EXTENDED_SCHEMA_FACTORY_CLASS = "com.sun.org.apache.xerces.internal.impl.dv.xs.ExtendedSchemaDVFactoryImpl";
269 
270         /**
271          * Special constructor to create the grammars for the schema namespaces
272          *
273          * @param grammar
274          */
275         public BuiltinSchemaGrammar(int grammar, short schemaVersion) {
276             SchemaDVFactory schemaFactory;
277             if (schemaVersion == Constants.SCHEMA_VERSION_1_0) {
278                 schemaFactory = SchemaDVFactory.getInstance();
279             }
280             else {
281                 schemaFactory = SchemaDVFactory.getInstance(EXTENDED_SCHEMA_FACTORY_CLASS);
282             }
283 
284             if (grammar == GRAMMAR_XS) {
285                 // target namespace
286                 fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
287 
288                 // grammar description
289                 fGrammarDescription = new XSDDescription();
290                 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
291                 fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
292 
293                 // no global decls other than types
294                 fGlobalAttrDecls  = new SymbolHash(1);
295                 fGlobalAttrGrpDecls = new SymbolHash(1);
296                 fGlobalElemDecls = new SymbolHash(1);
297                 fGlobalGroupDecls = new SymbolHash(1);
298                 fGlobalNotationDecls = new SymbolHash(1);
299                 fGlobalIDConstraintDecls = new SymbolHash(1);
300 
301                 // no extended global decls
302                 fGlobalAttrDeclsExt  = new SymbolHash(1);
303                 fGlobalAttrGrpDeclsExt = new SymbolHash(1);
304                 fGlobalElemDeclsExt = new SymbolHash(1);
305                 fGlobalGroupDeclsExt = new SymbolHash(1);
306                 fGlobalNotationDeclsExt = new SymbolHash(1);
307                 fGlobalIDConstraintDeclsExt = new SymbolHash(1);
308                 fGlobalTypeDeclsExt = new SymbolHash(1);
309 
310                 // all global element decls table
311                 fAllGlobalElemDecls = new SymbolHash(1);
312 
313                 // get all built-in types
314                 fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
315 
316                 // assign the built-in schema grammar as the XSNamespaceItem
317                 // for each of the built-in simple type definitions.
318                 int length = fGlobalTypeDecls.getLength();
319                 XSTypeDefinition [] typeDefinitions = new XSTypeDefinition[length];
320                 fGlobalTypeDecls.getValues(typeDefinitions, 0);
321                 for (int i = 0; i < length; ++i) {
322                     XSTypeDefinition xtd = typeDefinitions[i];
323                     if (xtd instanceof XSSimpleTypeDecl) {
324                         ((XSSimpleTypeDecl) xtd).setNamespaceItem(this);
325                     }
326                 }
327 
328                 // add anyType
329                 fGlobalTypeDecls.put(fAnyType.getName(), fAnyType);
330             }
331             else if (grammar == GRAMMAR_XSI) {
332                 // target namespace
333                 fTargetNamespace = SchemaSymbols.URI_XSI;
334                 // grammar description
335                 fGrammarDescription = new XSDDescription();
336                 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
337                 fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);
338 
339                 // no global decls other than attributes
340                 fGlobalAttrGrpDecls = new SymbolHash(1);
341                 fGlobalElemDecls = new SymbolHash(1);
342                 fGlobalGroupDecls = new SymbolHash(1);
343                 fGlobalNotationDecls = new SymbolHash(1);
344                 fGlobalIDConstraintDecls = new SymbolHash(1);
345                 fGlobalTypeDecls = new SymbolHash(1);
346 
347                 // no extended global decls
348                 fGlobalAttrDeclsExt  = new SymbolHash(1);
349                 fGlobalAttrGrpDeclsExt = new SymbolHash(1);
350                 fGlobalElemDeclsExt = new SymbolHash(1);
351                 fGlobalGroupDeclsExt = new SymbolHash(1);
352                 fGlobalNotationDeclsExt = new SymbolHash(1);
353                 fGlobalIDConstraintDeclsExt = new SymbolHash(1);
354                 fGlobalTypeDeclsExt = new SymbolHash(1);
355 
356                 // no all global element decls
357                 fAllGlobalElemDecls = new SymbolHash(1);
358 
359                 // 4 attributes, so initialize the size as 4*2 = 8
360                 fGlobalAttrDecls  = new SymbolHash(8);
361                 String name = null;
362                 String tns = null;
363                 XSSimpleType type = null;
364                 short scope = XSConstants.SCOPE_GLOBAL;
365 
366                 // xsi:type
367                 name = SchemaSymbols.XSI_TYPE;
368                 tns = SchemaSymbols.URI_XSI;
369                 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME);
370                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
371 
372                 // xsi:nil
373                 name = SchemaSymbols.XSI_NIL;
374                 tns = SchemaSymbols.URI_XSI;
375                 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);
376                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
377 
378                 XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);
379 
380                 // xsi:schemaLocation
381                 name = SchemaSymbols.XSI_SCHEMALOCATION;
382                 tns = SchemaSymbols.URI_XSI;
383                 type = schemaFactory.createTypeList("#AnonType_schemaLocation", SchemaSymbols.URI_XSI, (short)0, anyURI, null);
384                 if (type instanceof XSSimpleTypeDecl) {
385                     ((XSSimpleTypeDecl)type).setAnonymous(true);
386                 }
387                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
388 
389                 // xsi:noNamespaceSchemaLocation
390                 name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION;
391                 tns = SchemaSymbols.URI_XSI;
392                 type = anyURI;
393                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
394             }
395         } // <init>(int)
396 
397         // return the XMLGrammarDescription corresponding to this
398         // object
399         public XMLGrammarDescription getGrammarDescription() {
400             return fGrammarDescription.makeClone();
401         } // getGrammarDescription():  XMLGrammarDescription
402 
403         // override these methods solely so that these
404         // objects cannot be modified once they're created.
405         public void setImportedGrammars(Vector importedGrammars) {
406             // ignore
407         }
408         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
409             // ignore
410         }
411         public void addGlobalAttributeDecl(XSAttributeDecl decl, String location) {
412             // ignore
413         }
414         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
415             // ignore
416         }
417         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
418             // ignore
419         }
420         public void addGlobalElementDecl(XSElementDecl decl) {
421             // ignore
422         }
423         public void addGlobalElementDecl(XSElementDecl decl, String location) {
424             // ignore
425         }
426         public void addGlobalElementDeclAll(XSElementDecl decl) {
427             // ignore
428         }
429         public void addGlobalGroupDecl(XSGroupDecl decl) {
430             // ignore
431         }
432         public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
433             // ignore
434         }
435         public void addGlobalNotationDecl(XSNotationDecl decl) {
436             // ignore
437         }
438         public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
439             // ignore
440         }
441         public void addGlobalTypeDecl(XSTypeDefinition decl) {
442             // ignore
443         }
444         public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
445             // ignore
446         }
447         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl) {
448             // ignore
449         }
450         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
451             // ignore
452         }
453         public void addGlobalSimpleTypeDecl(XSSimpleType decl) {
454             // ignore
455         }
456         public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
457             // ignore
458         }
459         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
460             // ignore
461         }
462         public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
463             // ignore
464         }
465         public synchronized void addDocument(Object document, String location) {
466             // ignore
467         }
468 
469         // annotation support
470         synchronized DOMParser getDOMParser() {
471             return null;
472         }
473         synchronized SAXParser getSAXParser() {
474             return null;
475         }
476     }
477 
478     /**
479      * <p>A partial schema for schemas for validating annotations.</p>
480      *
481      * @xerces.internal
482      *
483      * @author Michael Glavassevich, IBM
484      */
485     public static final class Schema4Annotations extends SchemaGrammar {
486 
487         /**
488          * Singleton instance.
489          */
490         public static final Schema4Annotations INSTANCE = new Schema4Annotations();
491 
492         /**
493          * Special constructor to create a schema
494          * capable of validating annotations.
495          */
496         private Schema4Annotations() {
497 
498             // target namespace
499             fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
500 
501             // grammar description
502             fGrammarDescription = new XSDDescription();
503             fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
504             fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
505 
506             // no global decls other than types and
507             // element declarations for <annotation>, <documentation> and <appinfo>.
508             fGlobalAttrDecls  = new SymbolHash(1);
509             fGlobalAttrGrpDecls = new SymbolHash(1);
510             fGlobalElemDecls = new SymbolHash(6);
511             fGlobalGroupDecls = new SymbolHash(1);
512             fGlobalNotationDecls = new SymbolHash(1);
513             fGlobalIDConstraintDecls = new SymbolHash(1);
514 
515             // no extended global decls
516             fGlobalAttrDeclsExt  = new SymbolHash(1);
517             fGlobalAttrGrpDeclsExt = new SymbolHash(1);
518             fGlobalElemDeclsExt = new SymbolHash(6);
519             fGlobalGroupDeclsExt = new SymbolHash(1);
520             fGlobalNotationDeclsExt = new SymbolHash(1);
521             fGlobalIDConstraintDeclsExt = new SymbolHash(1);
522             fGlobalTypeDeclsExt = new SymbolHash(1);
523 
524             // all global element declarations
525             fAllGlobalElemDecls = new SymbolHash(6);
526 
527             // get all built-in types
528             fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls;
529 
530             // create element declarations for <annotation>, <documentation> and <appinfo>
531             XSElementDecl annotationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_ANNOTATION);
532             XSElementDecl documentationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_DOCUMENTATION);
533             XSElementDecl appinfoDecl = createAnnotationElementDecl(SchemaSymbols.ELT_APPINFO);
534 
535             // add global element declarations
536             fGlobalElemDecls.put(annotationDecl.fName, annotationDecl);
537             fGlobalElemDecls.put(documentationDecl.fName, documentationDecl);
538             fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl);
539 
540             fGlobalElemDeclsExt.put(","+annotationDecl.fName, annotationDecl);
541             fGlobalElemDeclsExt.put(","+documentationDecl.fName, documentationDecl);
542             fGlobalElemDeclsExt.put(","+appinfoDecl.fName, appinfoDecl);
543 
544             fAllGlobalElemDecls.put(annotationDecl, annotationDecl);
545             fAllGlobalElemDecls.put(documentationDecl, documentationDecl);
546             fAllGlobalElemDecls.put(appinfoDecl, appinfoDecl);
547 
548             // create complex type declarations for <annotation>, <documentation> and <appinfo>
549             XSComplexTypeDecl annotationType = new XSComplexTypeDecl();
550             XSComplexTypeDecl documentationType = new XSComplexTypeDecl();
551             XSComplexTypeDecl appinfoType = new XSComplexTypeDecl();
552 
553             // set the types on their element declarations
554             annotationDecl.fType = annotationType;
555             documentationDecl.fType = documentationType;
556             appinfoDecl.fType = appinfoType;
557 
558             // create attribute groups for <annotation>, <documentation> and <appinfo>
559             XSAttributeGroupDecl annotationAttrs = new XSAttributeGroupDecl();
560             XSAttributeGroupDecl documentationAttrs = new XSAttributeGroupDecl();
561             XSAttributeGroupDecl appinfoAttrs = new XSAttributeGroupDecl();
562 
563             // fill in attribute groups
564             {
565                 // create and fill attribute uses for <annotation>, <documentation> and <appinfo>
566                 XSAttributeUseImpl annotationIDAttr = new XSAttributeUseImpl();
567                 annotationIDAttr.fAttrDecl = new XSAttributeDecl();
568                 annotationIDAttr.fAttrDecl.setValues(SchemaSymbols.ATT_ID, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ID),
569                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, annotationType, null);
570                 annotationIDAttr.fUse = SchemaSymbols.USE_OPTIONAL;
571                 annotationIDAttr.fConstraintType = XSConstants.VC_NONE;
572 
573                 XSAttributeUseImpl documentationSourceAttr = new XSAttributeUseImpl();
574                 documentationSourceAttr.fAttrDecl = new XSAttributeDecl();
575                 documentationSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
576                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
577                 documentationSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
578                 documentationSourceAttr.fConstraintType = XSConstants.VC_NONE;
579 
580                 XSAttributeUseImpl documentationLangAttr = new XSAttributeUseImpl();
581                 documentationLangAttr.fAttrDecl = new XSAttributeDecl();
582                 documentationLangAttr.fAttrDecl.setValues("lang".intern(), NamespaceContext.XML_URI, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_LANGUAGE),
583                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
584                 documentationLangAttr.fUse = SchemaSymbols.USE_OPTIONAL;
585                 documentationLangAttr.fConstraintType = XSConstants.VC_NONE;
586 
587                 XSAttributeUseImpl appinfoSourceAttr = new XSAttributeUseImpl();
588                 appinfoSourceAttr.fAttrDecl = new XSAttributeDecl();
589                 appinfoSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
590                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, appinfoType, null);
591                 appinfoSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
592                 appinfoSourceAttr.fConstraintType = XSConstants.VC_NONE;
593 
594                 // create lax attribute wildcard for <annotation>, <documentation> and <appinfo>
595                 XSWildcardDecl otherAttrs = new XSWildcardDecl();
596                 otherAttrs.fNamespaceList = new String [] {fTargetNamespace, null};
597                 otherAttrs.fType = XSWildcard.NSCONSTRAINT_NOT;
598                 otherAttrs.fProcessContents = XSWildcard.PC_LAX;
599 
600                 // add attribute uses and wildcards to attribute groups for <annotation>, <documentation> and <appinfo>
601                 annotationAttrs.addAttributeUse(annotationIDAttr);
602                 annotationAttrs.fAttributeWC = otherAttrs;
603 
604                 documentationAttrs.addAttributeUse(documentationSourceAttr);
605                 documentationAttrs.addAttributeUse(documentationLangAttr);
606                 documentationAttrs.fAttributeWC = otherAttrs;
607 
608                 appinfoAttrs.addAttributeUse(appinfoSourceAttr);
609                 appinfoAttrs.fAttributeWC = otherAttrs;
610             }
611 
612             // create particles for <annotation>
613             XSParticleDecl annotationParticle = createUnboundedModelGroupParticle();
614             {
615                 XSModelGroupImpl annotationChoice = new XSModelGroupImpl();
616                 annotationChoice.fCompositor = XSModelGroupImpl.MODELGROUP_CHOICE;
617                 annotationChoice.fParticleCount = 2;
618                 annotationChoice.fParticles = new XSParticleDecl[2];
619                 annotationChoice.fParticles[0] = createChoiceElementParticle(appinfoDecl);
620                 annotationChoice.fParticles[1] = createChoiceElementParticle(documentationDecl);
621                 annotationParticle.fValue = annotationChoice;
622             }
623 
624             // create wildcard particle for <documentation> and <appinfo>
625             XSParticleDecl anyWCSequenceParticle = createUnboundedAnyWildcardSequenceParticle();
626 
627             // fill complex types
628             annotationType.setValues("#AnonType_" + SchemaSymbols.ELT_ANNOTATION, fTargetNamespace, SchemaGrammar.fAnyType,
629                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
630                     XSComplexTypeDecl.CONTENTTYPE_ELEMENT, false, annotationAttrs, null, annotationParticle, new XSObjectListImpl(null, 0));
631             annotationType.setName("#AnonType_" + SchemaSymbols.ELT_ANNOTATION);
632             annotationType.setIsAnonymous();
633 
634             documentationType.setValues("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION, fTargetNamespace, SchemaGrammar.fAnyType,
635                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
636                     XSComplexTypeDecl.CONTENTTYPE_MIXED, false, documentationAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
637             documentationType.setName("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION);
638             documentationType.setIsAnonymous();
639 
640             appinfoType.setValues("#AnonType_" + SchemaSymbols.ELT_APPINFO, fTargetNamespace, SchemaGrammar.fAnyType,
641                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
642                     XSComplexTypeDecl.CONTENTTYPE_MIXED, false, appinfoAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
643             appinfoType.setName("#AnonType_" + SchemaSymbols.ELT_APPINFO);
644             appinfoType.setIsAnonymous();
645 
646         } // <init>(int)
647 
648         // return the XMLGrammarDescription corresponding to this
649         // object
650         public XMLGrammarDescription getGrammarDescription() {
651             return fGrammarDescription.makeClone();
652         } // getGrammarDescription():  XMLGrammarDescription
653 
654         // override these methods solely so that these
655         // objects cannot be modified once they're created.
656         public void setImportedGrammars(Vector importedGrammars) {
657             // ignore
658         }
659         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
660             // ignore
661         }
662         public void addGlobalAttributeDecl(XSAttributeGroupDecl decl, String location) {
663             // ignore
664         }
665         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
666             // ignore
667         }
668         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
669             // ignore
670         }
671         public void addGlobalElementDecl(XSElementDecl decl) {
672             // ignore
673         }
674         public void addGlobalElementDecl(XSElementDecl decl, String location) {
675             // ignore
676         }
677         public void addGlobalElementDeclAll(XSElementDecl decl) {
678             // ignore
679         }
680         public void addGlobalGroupDecl(XSGroupDecl decl) {
681             // ignore
682         }
683         public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
684             // ignore
685         }
686         public void addGlobalNotationDecl(XSNotationDecl decl) {
687             // ignore
688         }
689         public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
690             // ignore
691         }
692         public void addGlobalTypeDecl(XSTypeDefinition decl) {
693             // ignore
694         }
695         public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
696             // ignore
697         }
698         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl) {
699             // ignore
700         }
701         public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
702             // ignore
703         }
704         public void addGlobalSimpleTypeDecl(XSSimpleType decl) {
705             // ignore
706         }
707         public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
708             // ignore
709         }
710         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
711             // ignore
712         }
713         public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
714             // ignore
715         }
716         public synchronized void addDocument(Object document, String location) {
717             // ignore
718         }
719 
720         // annotation support
721         synchronized DOMParser getDOMParser() {
722             return null;
723         }
724         synchronized SAXParser getSAXParser() {
725             return null;
726         }
727 
728         //
729         // private helper methods
730         //
731 
732         private XSElementDecl createAnnotationElementDecl(String localName) {
733             XSElementDecl eDecl = new XSElementDecl();
734             eDecl.fName = localName;
735             eDecl.fTargetNamespace = fTargetNamespace;
736             eDecl.setIsGlobal();
737             eDecl.fBlock = (XSConstants.DERIVATION_EXTENSION |
738                     XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION);
739             eDecl.setConstraintType(XSConstants.VC_NONE);
740             return eDecl;
741         }
742 
743         private XSParticleDecl createUnboundedModelGroupParticle() {
744             XSParticleDecl particle = new XSParticleDecl();
745             particle.fMinOccurs = 0;
746             particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
747             particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
748             return particle;
749         }
750 
751         private XSParticleDecl createChoiceElementParticle(XSElementDecl ref) {
752             XSParticleDecl particle = new XSParticleDecl();
753             particle.fMinOccurs = 1;
754             particle.fMaxOccurs = 1;
755             particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
756             particle.fValue = ref;
757             return particle;
758         }
759 
760         private XSParticleDecl createUnboundedAnyWildcardSequenceParticle() {
761             XSParticleDecl particle = createUnboundedModelGroupParticle();
762             XSModelGroupImpl sequence = new XSModelGroupImpl();
763             sequence.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
764             sequence.fParticleCount = 1;
765             sequence.fParticles = new XSParticleDecl[1];
766             sequence.fParticles[0] = createAnyLaxWildcardParticle();
767             particle.fValue = sequence;
768             return particle;
769         }
770 
771         private XSParticleDecl createAnyLaxWildcardParticle() {
772             XSParticleDecl particle = new XSParticleDecl();
773             particle.fMinOccurs = 1;
774             particle.fMaxOccurs = 1;
775             particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
776 
777             XSWildcardDecl anyWC = new XSWildcardDecl();
778             anyWC.fNamespaceList = null;
779             anyWC.fType = XSWildcard.NSCONSTRAINT_ANY;
780             anyWC.fProcessContents = XSWildcard.PC_LAX;
781 
782             particle.fValue = anyWC;
783             return particle;
784         }
785     }
786 
787     // Grammar methods
788 
789     // return the XMLGrammarDescription corresponding to this
790     // object
791     public XMLGrammarDescription getGrammarDescription() {
792         return fGrammarDescription;
793     } // getGrammarDescription():  XMLGrammarDescription
794 
795     // DTDGrammar methods
796     public boolean isNamespaceAware () {
797         return true;
798     } // isNamespaceAware():boolean
799 
800     Vector fImported = null;
801 
802     public void setImportedGrammars(Vector importedGrammars) {
803         fImported = importedGrammars;
804     }
805 
806     public Vector getImportedGrammars() {
807         return fImported;
808     }
809 
810     /**
811      * Returns this grammar's target namespace.
812      */
813     public final String getTargetNamespace() {
814         return fTargetNamespace;
815     } // getTargetNamespace():String
816 
817     /**
818      * register one global attribute
819      */
820     public void addGlobalAttributeDecl(XSAttributeDecl decl) {
821         fGlobalAttrDecls.put(decl.fName, decl);
822         decl.setNamespaceItem(this);
823     }
824 
825     public void addGlobalAttributeDecl(XSAttributeDecl decl, String location) {
826         fGlobalAttrDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
827         if (decl.getNamespaceItem() == null) {
828             decl.setNamespaceItem(this);
829         }
830     }
831 
832     /**
833      * register one global attribute group
834      */
835     public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
836         fGlobalAttrGrpDecls.put(decl.fName, decl);
837         decl.setNamespaceItem(this);
838     }
839 
840     public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl, String location) {
841         fGlobalAttrGrpDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
842         if (decl.getNamespaceItem() == null) {
843             decl.setNamespaceItem(this);
844         }
845     }
846 
847     /**
848      * register one global element
849      */
850     public void addGlobalElementDeclAll(XSElementDecl decl) {
851         if (fAllGlobalElemDecls.get(decl) == null) {
852             fAllGlobalElemDecls.put(decl, decl);
853             // if there is a substitution group affiliation, store in an array,
854             // for further constraint checking: UPA, PD, EDC
855             if (decl.fSubGroup != null) {
856                if (fSubGroupCount == fSubGroups.length)
857                     fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
858                 fSubGroups[fSubGroupCount++] = decl;
859             }
860         }
861     }
862 
863     public void addGlobalElementDecl(XSElementDecl decl) {
864         fGlobalElemDecls.put(decl.fName, decl);
865         decl.setNamespaceItem(this);
866     }
867 
868     public void addGlobalElementDecl(XSElementDecl decl, String location) {
869         fGlobalElemDeclsExt.put(((location != null) ? location : "") + "," + decl.fName, decl);
870         if (decl.getNamespaceItem() == null) {
871             decl.setNamespaceItem(this);
872         }
873     }
874 
875     /**
876      * register one global group
877      */
878     public void addGlobalGroupDecl(XSGroupDecl decl) {
879         fGlobalGroupDecls.put(decl.fName, decl);
880         decl.setNamespaceItem(this);
881     }
882 
883     public void addGlobalGroupDecl(XSGroupDecl decl, String location) {
884         fGlobalGroupDeclsExt.put(((location!=null) ? location : "") + "," + decl.fName, decl);
885         if (decl.getNamespaceItem() == null) {
886             decl.setNamespaceItem(this);
887         }
888     }
889 
890     /**
891      * register one global notation
892      */
893     public void addGlobalNotationDecl(XSNotationDecl decl) {
894         fGlobalNotationDecls.put(decl.fName, decl);
895         decl.setNamespaceItem(this);
896     }
897 
898     public void addGlobalNotationDecl(XSNotationDecl decl, String location) {
899         fGlobalNotationDeclsExt.put(((location!=null) ? location : "") + "," +decl.fName, decl);
900         if (decl.getNamespaceItem() == null) {
901             decl.setNamespaceItem(this);
902         }
903     }
904 
905     /**
906      * register one global type
907      */
908     public void addGlobalTypeDecl(XSTypeDefinition decl) {
909         fGlobalTypeDecls.put(decl.getName(), decl);
910         if (decl instanceof XSComplexTypeDecl) {
911             ((XSComplexTypeDecl) decl).setNamespaceItem(this);
912         }
913         else if (decl instanceof XSSimpleTypeDecl) {
914             ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
915         }
916     }
917 
918     public void addGlobalTypeDecl(XSTypeDefinition decl, String location) {
919         fGlobalTypeDeclsExt.put(((location!=null) ? location : "") + "," + decl.getName(), decl);
920         if (decl.getNamespaceItem() == null) {
921             if (decl instanceof XSComplexTypeDecl) {
922                 ((XSComplexTypeDecl) decl).setNamespaceItem(this);
923             }
924             else if (decl instanceof XSSimpleTypeDecl) {
925                 ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
926             }
927         }
928     }
929 
930     /**
931      * register one global complex type
932      */
933     public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl) {
934         fGlobalTypeDecls.put(decl.getName(), decl);
935         decl.setNamespaceItem(this);
936     }
937 
938     public void addGlobalComplexTypeDecl(XSComplexTypeDecl decl, String location) {
939         fGlobalTypeDeclsExt.put(((location!=null) ? location : "") + "," + decl.getName(), decl);
940         if (decl.getNamespaceItem() == null) {
941             decl.setNamespaceItem(this);
942         }
943     }
944 
945     /**
946      * register one global simple type
947      */
948     public void addGlobalSimpleTypeDecl(XSSimpleType decl) {
949         fGlobalTypeDecls.put(decl.getName(), decl);
950         if (decl instanceof XSSimpleTypeDecl) {
951             ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
952         }
953     }
954 
955     public void addGlobalSimpleTypeDecl(XSSimpleType decl, String location) {
956         fGlobalTypeDeclsExt.put(((location != null) ? location : "") + "," + decl.getName(), decl);
957         if (decl.getNamespaceItem() == null && decl instanceof XSSimpleTypeDecl) {
958             ((XSSimpleTypeDecl) decl).setNamespaceItem(this);
959         }
960     }
961 
962     /**
963      * register one identity constraint
964      */
965     public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl) {
966         elmDecl.addIDConstraint(decl);
967         fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
968     }
969 
970     public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl, String location) {
971         fGlobalIDConstraintDeclsExt.put(((location != null) ? location : "") + "," + decl.getIdentityConstraintName(), decl);
972     }
973 
974     /**
975      * get one global attribute
976      */
977     public final XSAttributeDecl getGlobalAttributeDecl(String declName) {
978         return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
979     }
980 
981     public final XSAttributeDecl getGlobalAttributeDecl(String declName, String location) {
982         return(XSAttributeDecl)fGlobalAttrDeclsExt.get(((location != null) ? location : "") + "," + declName);
983     }
984 
985     /**
986      * get one global attribute group
987      */
988     public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName) {
989         return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
990     }
991 
992     public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName, String location) {
993         return(XSAttributeGroupDecl)fGlobalAttrGrpDeclsExt.get(((location != null) ? location : "") + "," + declName);
994     }
995 
996     /**
997      * get one global element
998      */
999     public final XSElementDecl getGlobalElementDecl(String declName) {
1000         return(XSElementDecl)fGlobalElemDecls.get(declName);
1001     }
1002 
1003     public final XSElementDecl getGlobalElementDecl(String declName, String location) {
1004         return(XSElementDecl)fGlobalElemDeclsExt.get(((location != null) ? location : "") + "," + declName);
1005     }
1006 
1007     /**
1008      * get one global group
1009      */
1010     public final XSGroupDecl getGlobalGroupDecl(String declName) {
1011         return(XSGroupDecl)fGlobalGroupDecls.get(declName);
1012     }
1013 
1014     public final XSGroupDecl getGlobalGroupDecl(String declName, String location) {
1015         return(XSGroupDecl)fGlobalGroupDeclsExt.get(((location != null) ? location : "") + "," + declName);
1016     }
1017 
1018     /**
1019      * get one global notation
1020      */
1021     public final XSNotationDecl getGlobalNotationDecl(String declName) {
1022         return(XSNotationDecl)fGlobalNotationDecls.get(declName);
1023     }
1024 
1025     public final XSNotationDecl getGlobalNotationDecl(String declName, String location) {
1026         return(XSNotationDecl)fGlobalNotationDeclsExt.get(((location != null) ? location : "") + "," + declName);
1027     }
1028 
1029     /**
1030      * get one global type
1031      */
1032     public final XSTypeDefinition getGlobalTypeDecl(String declName) {
1033         return(XSTypeDefinition)fGlobalTypeDecls.get(declName);
1034     }
1035 
1036     public final XSTypeDefinition getGlobalTypeDecl(String declName, String location) {
1037         return(XSTypeDefinition)fGlobalTypeDeclsExt.get(((location != null) ? location : "") + "," + declName);
1038     }
1039 
1040     /**
1041      * get one identity constraint
1042      */
1043     public final IdentityConstraint getIDConstraintDecl(String declName) {
1044         return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
1045     }
1046 
1047     public final IdentityConstraint getIDConstraintDecl(String declName, String location) {
1048         return(IdentityConstraint)fGlobalIDConstraintDeclsExt.get(((location != null) ? location : "") + "," + declName);
1049     }
1050 
1051     /**
1052      * get one identity constraint
1053      */
1054     public final boolean hasIDConstraints() {
1055         return fGlobalIDConstraintDecls.getLength() > 0;
1056     }
1057 
1058     // array to store complex type decls
1059     private static final int INITIAL_SIZE = 16;
1060     private static final int INC_SIZE     = 16;
1061 
1062     private int fCTCount = 0;
1063     private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE];
1064     private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE];
1065 
1066     // an array to store groups being redefined by restriction
1067     // even-numbered elements are the derived groups, odd-numbered ones their bases
1068     private static final int REDEFINED_GROUP_INIT_SIZE = 2;
1069     private int fRGCount = 0;
1070     private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE];
1071     private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE/2];
1072 
1073     // a flag to indicate whether we have checked the 3 constraints on this
1074     // grammar.
1075     boolean fFullChecked = false;
1076 
1077     /**
1078      * add one complex type decl: for later constraint checking
1079      */
1080     public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
1081         if (fCTCount == fComplexTypeDecls.length) {
1082             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE);
1083             fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE);
1084         }
1085         fCTLocators[fCTCount] = locator;
1086         fComplexTypeDecls[fCTCount++] = decl;
1087     }
1088 
1089     /**
1090      * add a group redefined by restriction: for later constraint checking
1091      */
1092     public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
1093         if (fRGCount == fRedefinedGroupDecls.length) {
1094             // double array size each time.
1095             fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1);
1096             fRGLocators = resize(fRGLocators, fRGCount);
1097         }
1098         fRGLocators[fRGCount/2] = locator;
1099         fRedefinedGroupDecls[fRGCount++] = derived;
1100         fRedefinedGroupDecls[fRGCount++] = base;
1101     }
1102 
1103     /**
1104      * get all complex type decls: for later constraint checking
1105      */
1106     final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() {
1107         if (fCTCount < fComplexTypeDecls.length) {
1108             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
1109             fCTLocators = resize(fCTLocators, fCTCount);
1110         }
1111         return fComplexTypeDecls;
1112     }
1113 
1114     /**
1115      * get the error locator of all complex type decls
1116      */
1117     final SimpleLocator[] getUncheckedCTLocators() {
1118         if (fCTCount < fCTLocators.length) {
1119             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
1120             fCTLocators = resize(fCTLocators, fCTCount);
1121         }
1122         return fCTLocators;
1123     }
1124 
1125     /**
1126      * get all redefined groups: for later constraint checking
1127      */
1128     final XSGroupDecl[] getRedefinedGroupDecls() {
1129         if (fRGCount < fRedefinedGroupDecls.length) {
1130             fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
1131             fRGLocators = resize(fRGLocators, fRGCount/2);
1132         }
1133         return fRedefinedGroupDecls;
1134     }
1135 
1136     /**
1137      * get the error locator of all redefined groups
1138      */
1139     final SimpleLocator[] getRGLocators() {
1140         if (fRGCount < fRedefinedGroupDecls.length) {
1141             fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
1142             fRGLocators = resize(fRGLocators, fRGCount/2);
1143         }
1144         return fRGLocators;
1145     }
1146 
1147     /**
1148      * after the first-round checking, some types don't need to be checked
1149      * against UPA again. here we trim the array to the proper size.
1150      */
1151     final void setUncheckedTypeNum(int newSize) {
1152         fCTCount = newSize;
1153         fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
1154         fCTLocators = resize(fCTLocators, fCTCount);
1155     }
1156 
1157     // used to store all substitution group information declared in
1158     // this namespace
1159     private int fSubGroupCount = 0;
1160     private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE];
1161 
1162     /**
1163      * get all substitution group information: for the 3 constraint checking
1164      */
1165     final XSElementDecl[] getSubstitutionGroups() {
1166         if (fSubGroupCount < fSubGroups.length)
1167             fSubGroups = resize(fSubGroups, fSubGroupCount);
1168         return fSubGroups;
1169     }
1170 
1171     // anyType and anySimpleType: because there are so many places where
1172     // we need direct access to these two types
1173     public final static XSComplexTypeDecl fAnyType = new XSAnyType();
1174     private static class XSAnyType extends XSComplexTypeDecl {
1175         public XSAnyType () {
1176             fName = SchemaSymbols.ATTVAL_ANYTYPE;
1177             super.fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
1178             fBaseType = this;
1179             fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
1180             fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED;
1181 
1182             fParticle = null;
1183             fAttrGrp = null;
1184         }
1185 
1186         // overridden methods
1187         public void setValues(String name, String targetNamespace,
1188                 XSTypeDefinition baseType, short derivedBy, short schemaFinal,
1189                 short block, short contentType,
1190                 boolean isAbstract, XSAttributeGroupDecl attrGrp,
1191                 XSSimpleType simpleType, XSParticleDecl particle) {
1192             // don't allow this.
1193         }
1194 
1195         public void setName(String name){
1196             // don't allow this.
1197         }
1198 
1199         public void setIsAbstractType() {
1200             // null implementation
1201         }
1202 
1203         public void setContainsTypeID() {
1204             // null implementation
1205         }
1206 
1207         public void setIsAnonymous() {
1208             // null implementation
1209         }
1210 
1211         public void reset() {
1212             // null implementation
1213         }
1214 
1215         public XSObjectList getAttributeUses() {
1216             return XSObjectListImpl.EMPTY_LIST;
1217         }
1218 
1219         public XSAttributeGroupDecl getAttrGrp() {
1220             XSWildcardDecl wildcard = new XSWildcardDecl();
1221             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
1222             XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
1223             attrGrp.fAttributeWC = wildcard;
1224             return attrGrp;
1225         }
1226 
1227         public XSWildcard getAttributeWildcard() {
1228             XSWildcardDecl wildcard = new XSWildcardDecl();
1229             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
1230             return wildcard;
1231         }
1232 
1233         public XSParticle getParticle() {
1234             // the wildcard used in anyType (content and attribute)
1235             // the spec will change strict to skip for anyType
1236             XSWildcardDecl wildcard = new XSWildcardDecl();
1237             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
1238             // the particle for the content wildcard
1239             XSParticleDecl particleW = new XSParticleDecl();
1240             particleW.fMinOccurs = 0;
1241             particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
1242             particleW.fType = XSParticleDecl.PARTICLE_WILDCARD;
1243             particleW.fValue = wildcard;
1244             // the model group of a sequence of the above particle
1245             XSModelGroupImpl group = new XSModelGroupImpl();
1246             group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
1247             group.fParticleCount = 1;
1248             group.fParticles = new XSParticleDecl[1];
1249             group.fParticles[0] = particleW;
1250             // the content of anyType: particle of the above model group
1251             XSParticleDecl particleG = new XSParticleDecl();
1252             particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP;
1253             particleG.fValue = group;
1254 
1255             return particleG;
1256         }
1257 
1258         public XSObjectList getAnnotations() {
1259             return XSObjectListImpl.EMPTY_LIST;
1260         }
1261 
1262         public XSNamespaceItem getNamespaceItem() {
1263             return SG_SchemaNS;
1264         }
1265     }
1266     private static class BuiltinAttrDecl extends XSAttributeDecl {
1267         public BuiltinAttrDecl(String name, String tns,
1268                 XSSimpleType type, short scope) {
1269             fName = name;
1270             super.fTargetNamespace = tns;
1271             fType = type;
1272             fScope = scope;
1273         }
1274 
1275         public void setValues(String name, String targetNamespace,
1276                 XSSimpleType simpleType, short constraintType, short scope,
1277                 ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT) {
1278             // ignore this call.
1279         }
1280 
1281         public void reset () {
1282             // also ignore this call.
1283         }
1284 
1285         public XSAnnotation getAnnotation() {
1286             return null;
1287         }
1288 
1289         public XSNamespaceItem getNamespaceItem() {
1290             return SG_XSI;
1291         }
1292 
1293     } // class BuiltinAttrDecl
1294 
1295     // the grammars to hold components of the schema namespace
1296     public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS, Constants.SCHEMA_VERSION_1_0);
1297     private final static BuiltinSchemaGrammar SG_SchemaNSExtended = new BuiltinSchemaGrammar(GRAMMAR_XS, Constants.SCHEMA_VERSION_1_0_EXTENDED);
1298 
1299     public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
1300 
1301     // the grammars to hold components of the schema-instance namespace
1302     public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI, Constants.SCHEMA_VERSION_1_0);
1303 
1304     public static SchemaGrammar getS4SGrammar(short schemaVersion) {
1305         if (schemaVersion == Constants.SCHEMA_VERSION_1_0) {
1306             return SG_SchemaNS;
1307         }
1308         else {
1309             return SG_SchemaNSExtended;
1310         }
1311     }
1312 
1313     static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) {
1314         XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
1315         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
1316         return newArray;
1317     }
1318 
1319     static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) {
1320         XSGroupDecl[] newArray = new XSGroupDecl[newSize];
1321         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
1322         return newArray;
1323     }
1324 
1325     static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) {
1326         XSElementDecl[] newArray = new XSElementDecl[newSize];
1327         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
1328         return newArray;
1329     }
1330 
1331     static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) {
1332         SimpleLocator[] newArray = new SimpleLocator[newSize];
1333         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
1334         return newArray;
1335     }
1336 
1337     // XSNamespaceItem methods
1338 
1339     // the max index / the max value of XSObject type
1340     private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE;
1341     private static final boolean[] GLOBAL_COMP = {false,    // null
1342                                                   true,     // attribute
1343                                                   true,     // element
1344                                                   true,     // type
1345                                                   false,    // attribute use
1346                                                   true,     // attribute group
1347                                                   true,     // group
1348                                                   false,    // model group
1349                                                   false,    // particle
1350                                                   false,    // wildcard
1351                                                   false,    // idc
1352                                                   true,     // notation
1353                                                   false,    // annotation
1354                                                   false,    // facet
1355                                                   false,    // multi value facet
1356                                                   true,     // complex type
1357                                                   true      // simple type
1358                                                  };
1359 
1360     // store a certain kind of components from all namespaces
1361     private XSNamedMap[] fComponents = null;
1362     private ObjectList[] fComponentsExt = null;
1363 
1364     // store the documents and their locations contributing to this namespace
1365     // REVISIT: use StringList and XSObjectList for there fields.
1366     private Vector fDocuments = null;
1367     private Vector fLocations = null;
1368 
1369     public synchronized void addDocument(Object document, String location) {
1370         if (fDocuments == null) {
1371             fDocuments = new Vector();
1372             fLocations = new Vector();
1373         }
1374         fDocuments.addElement(document);
1375         fLocations.addElement(location);
1376     }
1377 
1378     public synchronized void removeDocument(int index) {
1379         if (fDocuments != null &&
1380             index >= 0 &&
1381             index < fDocuments.size()) {
1382             fDocuments.removeElementAt(index);
1383             fLocations.removeElementAt(index);
1384         }
1385     }
1386 
1387     /**
1388      * [schema namespace]
1389      * @see <a href="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a>
1390      * @return The target namespace of this item.
1391      */
1392     public String getSchemaNamespace() {
1393         return fTargetNamespace;
1394     }
1395 
1396     // annotation support
1397     synchronized DOMParser getDOMParser() {
1398         if (fDOMParser != null) {
1399             DOMParser parser = (DOMParser) fDOMParser.get();
1400             if (parser != null) {
1401                 return parser;
1402             }
1403         }
1404         // REVISIT:  when schema handles XML 1.1, will need to
1405         // revisit this (and the practice of not prepending an XML decl to the annotation string
1406         XML11Configuration config = new XML11Configuration(fSymbolTable);
1407         // note that this should never produce errors or require
1408         // entity resolution, so just a barebones configuration with
1409         // a couple of feature  set will do fine
1410         config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
1411         config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
1412 
1413         DOMParser parser = new DOMParser(config);
1414         try {
1415             parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE, false);
1416         }
1417         catch (SAXException exc) {}
1418         fDOMParser = new SoftReference(parser);
1419         return parser;
1420     }
1421 
1422     synchronized SAXParser getSAXParser() {
1423         if (fSAXParser != null) {
1424             SAXParser parser = (SAXParser) fSAXParser.get();
1425             if (parser != null) {
1426                 return parser;
1427             }
1428         }
1429         // REVISIT:  when schema handles XML 1.1, will need to
1430         // revisit this (and the practice of not prepending an XML decl to the annotation string
1431         XML11Configuration config = new XML11Configuration(fSymbolTable);
1432         // note that this should never produce errors or require
1433         // entity resolution, so just a barebones configuration with
1434         // a couple of feature  set will do fine
1435         config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
1436         config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
1437         SAXParser parser = new SAXParser(config);
1438         fSAXParser = new SoftReference(parser);
1439         return parser;
1440     }
1441 
1442     /**
1443      * [schema components]: a list of top-level components, i.e. element
1444      * declarations, attribute declarations, etc.
1445      * @param objectType The type of the declaration, i.e.
1446      *   <code>ELEMENT_DECLARATION</code>. Note that
1447      *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and
1448      *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
1449      *   <code>objectType</code> to retrieve only complex types or simple
1450      *   types, instead of all types.
1451      * @return  A list of top-level definition of the specified type in
1452      *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no
1453      *   such definitions exist.
1454      */
1455     public synchronized XSNamedMap getComponents(short objectType) {
1456         if (objectType <= 0 || objectType > MAX_COMP_IDX ||
1457             !GLOBAL_COMP[objectType]) {
1458             return XSNamedMapImpl.EMPTY_MAP;
1459         }
1460 
1461         if (fComponents == null)
1462             fComponents = new XSNamedMap[MAX_COMP_IDX+1];
1463 
1464         // get the hashtable for this type of components
1465         if (fComponents[objectType] == null) {
1466             SymbolHash table = null;
1467             switch (objectType) {
1468             case XSConstants.TYPE_DEFINITION:
1469             case XSTypeDefinition.COMPLEX_TYPE:
1470             case XSTypeDefinition.SIMPLE_TYPE:
1471                 table = fGlobalTypeDecls;
1472                 break;
1473             case XSConstants.ATTRIBUTE_DECLARATION:
1474                 table = fGlobalAttrDecls;
1475                 break;
1476             case XSConstants.ELEMENT_DECLARATION:
1477                 table = fGlobalElemDecls;
1478                 break;
1479             case XSConstants.ATTRIBUTE_GROUP:
1480                 table = fGlobalAttrGrpDecls;
1481                 break;
1482             case XSConstants.MODEL_GROUP_DEFINITION:
1483                 table = fGlobalGroupDecls;
1484                 break;
1485             case XSConstants.NOTATION_DECLARATION:
1486                 table = fGlobalNotationDecls;
1487                 break;
1488             }
1489 
1490             // for complex/simple types, create a special implementation,
1491             // which take specific types out of the hash table
1492             if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
1493                 objectType == XSTypeDefinition.SIMPLE_TYPE) {
1494                 fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
1495             }
1496             else {
1497                 fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
1498             }
1499         }
1500 
1501         return fComponents[objectType];
1502     }
1503 
1504     public synchronized ObjectList getComponentsExt(short objectType) {
1505         if (objectType <= 0 || objectType > MAX_COMP_IDX ||
1506             !GLOBAL_COMP[objectType]) {
1507             return ObjectListImpl.EMPTY_LIST;
1508         }
1509 
1510         if (fComponentsExt == null)
1511             fComponentsExt = new ObjectList[MAX_COMP_IDX+1];
1512 
1513         // get the hashtable for this type of components
1514         if (fComponentsExt[objectType] == null) {
1515             SymbolHash table = null;
1516             switch (objectType) {
1517             case XSConstants.TYPE_DEFINITION:
1518             case XSTypeDefinition.COMPLEX_TYPE:
1519             case XSTypeDefinition.SIMPLE_TYPE:
1520                 table = fGlobalTypeDeclsExt;
1521                 break;
1522             case XSConstants.ATTRIBUTE_DECLARATION:
1523                 table = fGlobalAttrDeclsExt;
1524                 break;
1525             case XSConstants.ELEMENT_DECLARATION:
1526                 table = fGlobalElemDeclsExt;
1527                 break;
1528             case XSConstants.ATTRIBUTE_GROUP:
1529                 table = fGlobalAttrGrpDeclsExt;
1530                 break;
1531             case XSConstants.MODEL_GROUP_DEFINITION:
1532                 table = fGlobalGroupDeclsExt;
1533                 break;
1534             case XSConstants.NOTATION_DECLARATION:
1535                 table = fGlobalNotationDeclsExt;
1536                 break;
1537             }
1538 
1539             Object[] entries = table.getEntries();
1540             fComponentsExt[objectType] = new ObjectListImpl(entries, entries.length);
1541         }
1542 
1543         return fComponentsExt[objectType];
1544     }
1545 
1546     public synchronized void resetComponents() {
1547         fComponents = null;
1548         fComponentsExt = null;
1549     }
1550 
1551     /**
1552      * Convenience method. Returns a top-level simple or complex type
1553      * definition.
1554      * @param name The name of the definition.
1555      * @return An <code>XSTypeDefinition</code> or null if such definition
1556      *   does not exist.
1557      */
1558     public XSTypeDefinition getTypeDefinition(String name) {
1559         return getGlobalTypeDecl(name);
1560     }
1561 
1562     /**
1563      * Convenience method. Returns a top-level attribute declaration.
1564      * @param name The name of the declaration.
1565      * @return A top-level attribute declaration or null if such declaration
1566      *   does not exist.
1567      */
1568     public XSAttributeDeclaration getAttributeDeclaration(String name) {
1569         return getGlobalAttributeDecl(name);
1570     }
1571 
1572     /**
1573      * Convenience method. Returns a top-level element declaration.
1574      * @param name The name of the declaration.
1575      * @return A top-level element declaration or null if such declaration
1576      *   does not exist.
1577      */
1578     public XSElementDeclaration getElementDeclaration(String name) {
1579         return getGlobalElementDecl(name);
1580     }
1581 
1582     /**
1583      * Convenience method. Returns a top-level attribute group definition.
1584      * @param name The name of the definition.
1585      * @return A top-level attribute group definition or null if such
1586      *   definition does not exist.
1587      */
1588     public XSAttributeGroupDefinition getAttributeGroup(String name) {
1589         return getGlobalAttributeGroupDecl(name);
1590     }
1591 
1592     /**
1593      * Convenience method. Returns a top-level model group definition.
1594      *
1595      * @param name      The name of the definition.
1596      * @return A top-level model group definition definition or null if such
1597      *         definition does not exist.
1598      */
1599     public XSModelGroupDefinition getModelGroupDefinition(String name) {
1600         return getGlobalGroupDecl(name);
1601     }
1602 
1603     /**
1604      * Convenience method. Returns a top-level notation declaration.
1605      *
1606      * @param name      The name of the declaration.
1607      * @return A top-level notation declaration or null if such declaration
1608      *         does not exist.
1609      */
1610     public XSNotationDeclaration getNotationDeclaration(String name) {
1611         return getGlobalNotationDecl(name);
1612     }
1613 
1614 
1615     /**
1616      * [document location]
1617      * @see <a href="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a>
1618      * @return a list of document information item
1619      */
1620     public StringList getDocumentLocations() {
1621         return new StringListImpl(fLocations);
1622     }
1623 
1624     /**
1625      * Return an <code>XSModel</code> that represents components in this schema
1626      * grammar.
1627      *
1628      * @return  an <code>XSModel</code> representing this schema grammar
1629      */
1630     public XSModel toXSModel() {
1631         return new XSModelImpl(new SchemaGrammar[]{this});
1632     }
1633 
1634     public XSModel toXSModel(XSGrammar[] grammars) {
1635         if (grammars == null || grammars.length == 0)
1636             return toXSModel();
1637 
1638         int len = grammars.length;
1639         boolean hasSelf = false;
1640         for (int i = 0; i < len; i++) {
1641             if (grammars[i] == this) {
1642                 hasSelf = true;
1643                 break;
1644             }
1645         }
1646 
1647         SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1];
1648         for (int i = 0; i < len; i++)
1649             gs[i] = (SchemaGrammar)grammars[i];
1650         if (!hasSelf)
1651             gs[len] = this;
1652         return new XSModelImpl(gs);
1653     }
1654 
1655     /**
1656      * @see org.apache.xerces.xs.XSNamespaceItem#getAnnotations()
1657      */
1658     public XSObjectList getAnnotations() {
1659         if (fNumAnnotations == 0) {
1660             return XSObjectListImpl.EMPTY_LIST;
1661         }
1662         return new XSObjectListImpl(fAnnotations, fNumAnnotations);
1663     }
1664 
1665     public void addAnnotation(XSAnnotationImpl annotation) {
1666         if (annotation == null) {
1667             return;
1668         }
1669         if (fAnnotations == null) {
1670             fAnnotations = new XSAnnotationImpl[2];
1671         }
1672         else if (fNumAnnotations == fAnnotations.length) {
1673             XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1];
1674             System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations);
1675             fAnnotations = newArray;
1676         }
1677         fAnnotations[fNumAnnotations++] = annotation;
1678     }
1679 
1680     public void setImmutable(boolean isImmutable) {
1681         fIsImmutable = isImmutable;
1682     }
1683 
1684     public boolean isImmutable() {
1685         return fIsImmutable;
1686     }
1687 
1688 } // class SchemaGrammar