~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/xs/SchemaGrammar.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.xs;
 
19
 
 
20
import java.lang.ref.SoftReference;
 
21
import java.util.Vector;
 
22
 
 
23
import org.apache.xerces.impl.Constants;
 
24
import org.apache.xerces.impl.dv.SchemaDVFactory;
 
25
import org.apache.xerces.impl.dv.ValidatedInfo;
 
26
import org.apache.xerces.impl.dv.XSSimpleType;
 
27
import org.apache.xerces.impl.xs.identity.IdentityConstraint;
 
28
import org.apache.xerces.impl.xs.util.SimpleLocator;
 
29
import org.apache.xerces.impl.xs.util.StringListImpl;
 
30
import org.apache.xerces.impl.xs.util.XSNamedMap4Types;
 
31
import org.apache.xerces.impl.xs.util.XSNamedMapImpl;
 
32
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
33
import org.apache.xerces.parsers.DOMParser;
 
34
import org.apache.xerces.parsers.SAXParser;
 
35
import org.apache.xerces.parsers.XML11Configuration;
 
36
import org.apache.xerces.util.SymbolHash;
 
37
import org.apache.xerces.util.SymbolTable;
 
38
import org.apache.xerces.xni.NamespaceContext;
 
39
import org.apache.xerces.xni.grammars.XMLGrammarDescription;
 
40
import org.apache.xerces.xni.grammars.XSGrammar;
 
41
import org.apache.xerces.xs.StringList;
 
42
import org.apache.xerces.xs.XSAnnotation;
 
43
import org.apache.xerces.xs.XSAttributeDeclaration;
 
44
import org.apache.xerces.xs.XSAttributeGroupDefinition;
 
45
import org.apache.xerces.xs.XSConstants;
 
46
import org.apache.xerces.xs.XSElementDeclaration;
 
47
import org.apache.xerces.xs.XSModel;
 
48
import org.apache.xerces.xs.XSModelGroupDefinition;
 
49
import org.apache.xerces.xs.XSNamedMap;
 
50
import org.apache.xerces.xs.XSNamespaceItem;
 
51
import org.apache.xerces.xs.XSNotationDeclaration;
 
52
import org.apache.xerces.xs.XSObjectList;
 
53
import org.apache.xerces.xs.XSParticle;
 
54
import org.apache.xerces.xs.XSTypeDefinition;
 
55
import org.apache.xerces.xs.XSWildcard;
 
56
import org.xml.sax.SAXException;
 
57
 
 
58
/**
 
59
 * This class is to hold all schema component declaration that are declared
 
60
 * within one namespace.
 
61
 *
 
62
 * The Grammar class this class extends contains what little
 
63
 * commonality there is between XML Schema and DTD grammars.  It's
 
64
 * useful to distinguish grammar objects from other kinds of object
 
65
 * when they exist in pools or caches.
 
66
 *
 
67
 * @xerces.internal 
 
68
 *
 
69
 * @author Sandy Gao, IBM
 
70
 * @author Elena Litani, IBM
 
71
 *
 
72
 * @version $Id: SchemaGrammar.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
 
73
 */
 
74
 
 
75
public class SchemaGrammar implements XSGrammar, XSNamespaceItem {
 
76
 
 
77
    // the target namespace of grammar
 
78
    String fTargetNamespace;
 
79
 
 
80
    // global decls: map from decl name to decl object
 
81
    SymbolHash fGlobalAttrDecls;
 
82
    SymbolHash fGlobalAttrGrpDecls;
 
83
    SymbolHash fGlobalElemDecls;
 
84
    SymbolHash fGlobalGroupDecls;
 
85
    SymbolHash fGlobalNotationDecls;
 
86
    SymbolHash fGlobalIDConstraintDecls;
 
87
    SymbolHash fGlobalTypeDecls;
 
88
 
 
89
    // the XMLGrammarDescription member
 
90
    XSDDescription fGrammarDescription = null;
 
91
 
 
92
    // annotations associated with the "root" schema of this targetNamespace
 
93
    XSAnnotationImpl [] fAnnotations = null;
 
94
 
 
95
    // number of annotations declared
 
96
    int fNumAnnotations;
 
97
 
 
98
    // symbol table for constructing parsers (annotation support)
 
99
    private SymbolTable fSymbolTable = null;
 
100
    // parsers for annotation support
 
101
    private SoftReference fSAXParser = null;
 
102
    private SoftReference fDOMParser = null;
 
103
 
 
104
    //
 
105
    // Constructors
 
106
    //
 
107
 
 
108
    // needed to make BuiltinSchemaGrammar work.
 
109
    protected SchemaGrammar() {}
 
110
 
 
111
    /**
 
112
     * Default constructor.
 
113
     *
 
114
     * @param targetNamespace
 
115
     * @param grammarDesc the XMLGrammarDescription corresponding to this objec
 
116
     *          at the least a systemId should always be known.
 
117
     * @param symbolTable   needed for annotation support
 
118
     */
 
119
    public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc,
 
120
                SymbolTable symbolTable) {
 
121
        fTargetNamespace = targetNamespace;
 
122
        fGrammarDescription = grammarDesc;
 
123
        fSymbolTable = symbolTable;
 
124
 
 
125
        // REVISIT: do we know the numbers of the following global decls
 
126
        // when creating this grammar? If so, we can pass the numbers in,
 
127
        // and use that number to initialize the following hashtables.
 
128
        fGlobalAttrDecls  = new SymbolHash();
 
129
        fGlobalAttrGrpDecls = new SymbolHash();
 
130
        fGlobalElemDecls = new SymbolHash();
 
131
        fGlobalGroupDecls = new SymbolHash();
 
132
        fGlobalNotationDecls = new SymbolHash();
 
133
        fGlobalIDConstraintDecls = new SymbolHash();
 
134
 
 
135
        // if we are parsing S4S, put built-in types in first
 
136
        // they might get overwritten by the types from S4S, but that's
 
137
        // considered what the application wants to do.
 
138
        if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
139
            fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();
 
140
        else
 
141
            fGlobalTypeDecls = new SymbolHash();
 
142
    } // <init>(String, XSDDescription)
 
143
 
 
144
    // number of built-in XSTypes we need to create for base and full
 
145
    // datatype set
 
146
    private static final int BASICSET_COUNT = 29;
 
147
    private static final int FULLSET_COUNT  = 46;
 
148
 
 
149
    private static final int GRAMMAR_XS  = 1;
 
150
    private static final int GRAMMAR_XSI = 2;
 
151
 
 
152
    // this class makes sure the static, built-in schema grammars
 
153
    // are immutable.
 
154
    public static class BuiltinSchemaGrammar extends SchemaGrammar {
 
155
        /**
 
156
         * Special constructor to create the grammars for the schema namespaces
 
157
         *
 
158
         * @param grammar
 
159
         */
 
160
        public BuiltinSchemaGrammar(int grammar) {
 
161
            SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance();
 
162
    
 
163
            if (grammar == GRAMMAR_XS) {
 
164
                // target namespace
 
165
                fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
 
166
        
 
167
                // grammar description
 
168
                fGrammarDescription = new XSDDescription();
 
169
                fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
 
170
                fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
 
171
        
 
172
                // no global decls other than types
 
173
                fGlobalAttrDecls  = new SymbolHash(1);
 
174
                fGlobalAttrGrpDecls = new SymbolHash(1);
 
175
                fGlobalElemDecls = new SymbolHash(1);
 
176
                fGlobalGroupDecls = new SymbolHash(1);
 
177
                fGlobalNotationDecls = new SymbolHash(1);
 
178
                fGlobalIDConstraintDecls = new SymbolHash(1);
 
179
        
 
180
                // get all built-in types
 
181
                fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
 
182
                // add anyType
 
183
                fGlobalTypeDecls.put(fAnyType.getName(), fAnyType);
 
184
            }
 
185
            else if (grammar == GRAMMAR_XSI) {
 
186
                // target namespace
 
187
                fTargetNamespace = SchemaSymbols.URI_XSI;
 
188
                // grammar description
 
189
                fGrammarDescription = new XSDDescription();
 
190
                fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
 
191
                fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);
 
192
        
 
193
                // no global decls other than attributes
 
194
                fGlobalAttrGrpDecls = new SymbolHash(1);
 
195
                fGlobalElemDecls = new SymbolHash(1);
 
196
                fGlobalGroupDecls = new SymbolHash(1);
 
197
                fGlobalNotationDecls = new SymbolHash(1);
 
198
                fGlobalIDConstraintDecls = new SymbolHash(1);
 
199
                fGlobalTypeDecls = new SymbolHash(1);
 
200
    
 
201
                // 4 attributes, so initialize the size as 4*2 = 8
 
202
                fGlobalAttrDecls  = new SymbolHash(8);
 
203
                String name = null;
 
204
                String tns = null;
 
205
                XSSimpleType type = null;
 
206
                short scope = XSConstants.SCOPE_GLOBAL;
 
207
                
 
208
                // xsi:type
 
209
                name = SchemaSymbols.XSI_TYPE;
 
210
                tns = SchemaSymbols.URI_XSI;
 
211
                type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME);
 
212
                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
 
213
                
 
214
                // xsi:nil
 
215
                name = SchemaSymbols.XSI_NIL;
 
216
                tns = SchemaSymbols.URI_XSI;
 
217
                type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);
 
218
                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
 
219
                
 
220
                XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);
 
221
    
 
222
                // xsi:schemaLocation
 
223
                name = SchemaSymbols.XSI_SCHEMALOCATION;
 
224
                tns = SchemaSymbols.URI_XSI;
 
225
                type = schemaFactory.createTypeList(null, SchemaSymbols.URI_XSI, (short)0, anyURI, null);
 
226
                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
 
227
                
 
228
                // xsi:noNamespaceSchemaLocation
 
229
                name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION;
 
230
                tns = SchemaSymbols.URI_XSI;
 
231
                type = anyURI;
 
232
                fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
 
233
            }
 
234
        } // <init>(int)
 
235
 
 
236
        // return the XMLGrammarDescription corresponding to this
 
237
        // object
 
238
        public XMLGrammarDescription getGrammarDescription() {
 
239
            return fGrammarDescription.makeClone();
 
240
        } // getGrammarDescription():  XMLGrammarDescription
 
241
 
 
242
        // override these methods solely so that these
 
243
        // objects cannot be modified once they're created.
 
244
        public void setImportedGrammars(Vector importedGrammars) {
 
245
            // ignore
 
246
        }
 
247
        public void addGlobalAttributeDecl(XSAttributeDecl decl) {
 
248
            // ignore
 
249
        }
 
250
        public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
 
251
            // ignore
 
252
        }
 
253
        public void addGlobalElementDecl(XSElementDecl decl) {
 
254
            // ignore
 
255
        }
 
256
        public void addGlobalGroupDecl(XSGroupDecl decl) {
 
257
            // ignore
 
258
        }
 
259
        public void addGlobalNotationDecl(XSNotationDecl decl) {
 
260
            // ignore
 
261
        }
 
262
        public void addGlobalTypeDecl(XSTypeDefinition decl) {
 
263
            // ignore
 
264
        }
 
265
        public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
 
266
            // ignore
 
267
        }
 
268
        public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
 
269
            // ignore
 
270
        }
 
271
        public synchronized void addDocument(Object document, String location) {
 
272
            // ignore
 
273
        }
 
274
 
 
275
        // annotation support
 
276
        synchronized DOMParser getDOMParser() {
 
277
            return null;
 
278
        }
 
279
        synchronized SAXParser getSAXParser() {
 
280
            return null;
 
281
        }
 
282
    }
 
283
    
 
284
    /**
 
285
     * <p>A partial schema for schemas for validating annotations.</p>
 
286
     * 
 
287
     * @xerces.internal 
 
288
     * 
 
289
     * @author Michael Glavassevich, IBM
 
290
     */
 
291
    public static final class Schema4Annotations extends SchemaGrammar {
 
292
 
 
293
        /**
 
294
         * Special constructor to create a schema 
 
295
         * capable of validating annotations.
 
296
         */
 
297
        public Schema4Annotations() {
 
298
            
 
299
            // target namespace
 
300
            fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
 
301
            
 
302
            // grammar description
 
303
            fGrammarDescription = new XSDDescription();
 
304
            fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
 
305
            fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
 
306
            
 
307
            // no global decls other than types and
 
308
            // element declarations for <annotation>, <documentation> and <appinfo>.
 
309
            fGlobalAttrDecls  = new SymbolHash(1);
 
310
            fGlobalAttrGrpDecls = new SymbolHash(1);
 
311
            fGlobalElemDecls = new SymbolHash(6);
 
312
            fGlobalGroupDecls = new SymbolHash(1);
 
313
            fGlobalNotationDecls = new SymbolHash(1);
 
314
            fGlobalIDConstraintDecls = new SymbolHash(1);
 
315
            
 
316
            // get all built-in types
 
317
            fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls;
 
318
            
 
319
            // create element declarations for <annotation>, <documentation> and <appinfo>
 
320
            XSElementDecl annotationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_ANNOTATION);
 
321
            XSElementDecl documentationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_DOCUMENTATION);
 
322
            XSElementDecl appinfoDecl = createAnnotationElementDecl(SchemaSymbols.ELT_APPINFO);
 
323
            
 
324
            // add global element declarations
 
325
            fGlobalElemDecls.put(annotationDecl.fName, annotationDecl);
 
326
            fGlobalElemDecls.put(documentationDecl.fName, documentationDecl);
 
327
            fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl);
 
328
            
 
329
            // create complex type declarations for <annotation>, <documentation> and <appinfo>
 
330
            XSComplexTypeDecl annotationType = new XSComplexTypeDecl();
 
331
            XSComplexTypeDecl documentationType = new XSComplexTypeDecl();
 
332
            XSComplexTypeDecl appinfoType = new XSComplexTypeDecl();
 
333
            
 
334
            // set the types on their element declarations
 
335
            annotationDecl.fType = annotationType;
 
336
            documentationDecl.fType = documentationType;
 
337
            appinfoDecl.fType = appinfoType;
 
338
            
 
339
            // create attribute groups for <annotation>, <documentation> and <appinfo>
 
340
            XSAttributeGroupDecl annotationAttrs = new XSAttributeGroupDecl();
 
341
            XSAttributeGroupDecl documentationAttrs = new XSAttributeGroupDecl();
 
342
            XSAttributeGroupDecl appinfoAttrs = new XSAttributeGroupDecl();
 
343
            
 
344
            // fill in attribute groups
 
345
            {
 
346
                // create and fill attribute uses for <annotation>, <documentation> and <appinfo>
 
347
                XSAttributeUseImpl annotationIDAttr = new XSAttributeUseImpl();
 
348
                annotationIDAttr.fAttrDecl = new XSAttributeDecl();
 
349
                annotationIDAttr.fAttrDecl.setValues(SchemaSymbols.ATT_ID, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ID),
 
350
                        XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, annotationType, null);
 
351
                annotationIDAttr.fUse = SchemaSymbols.USE_OPTIONAL;
 
352
                annotationIDAttr.fConstraintType = XSConstants.VC_NONE;
 
353
                
 
354
                XSAttributeUseImpl documentationSourceAttr = new XSAttributeUseImpl();
 
355
                documentationSourceAttr.fAttrDecl = new XSAttributeDecl();
 
356
                documentationSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
 
357
                        XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
 
358
                documentationSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
 
359
                documentationSourceAttr.fConstraintType = XSConstants.VC_NONE;
 
360
                
 
361
                XSAttributeUseImpl documentationLangAttr = new XSAttributeUseImpl();
 
362
                documentationLangAttr.fAttrDecl = new XSAttributeDecl();
 
363
                documentationLangAttr.fAttrDecl.setValues("lang".intern(), NamespaceContext.XML_URI, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_LANGUAGE),
 
364
                        XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
 
365
                documentationLangAttr.fUse = SchemaSymbols.USE_OPTIONAL;
 
366
                documentationLangAttr.fConstraintType = XSConstants.VC_NONE;
 
367
                
 
368
                XSAttributeUseImpl appinfoSourceAttr = new XSAttributeUseImpl();
 
369
                appinfoSourceAttr.fAttrDecl = new XSAttributeDecl();
 
370
                appinfoSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
 
371
                        XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, appinfoType, null);
 
372
                appinfoSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
 
373
                appinfoSourceAttr.fConstraintType = XSConstants.VC_NONE;
 
374
                
 
375
                // create lax attribute wildcard for <annotation>, <documentation> and <appinfo>
 
376
                XSWildcardDecl otherAttrs = new XSWildcardDecl();
 
377
                otherAttrs.fNamespaceList = new String [] {fTargetNamespace, null};
 
378
                otherAttrs.fType = XSWildcard.NSCONSTRAINT_NOT;
 
379
                otherAttrs.fProcessContents = XSWildcard.PC_LAX;
 
380
                
 
381
                // add attribute uses and wildcards to attribute groups for <annotation>, <documentation> and <appinfo>
 
382
                annotationAttrs.addAttributeUse(annotationIDAttr);
 
383
                annotationAttrs.fAttributeWC = otherAttrs;
 
384
                
 
385
                documentationAttrs.addAttributeUse(documentationSourceAttr);
 
386
                documentationAttrs.addAttributeUse(documentationLangAttr);
 
387
                documentationAttrs.fAttributeWC = otherAttrs;
 
388
                
 
389
                appinfoAttrs.addAttributeUse(appinfoSourceAttr);
 
390
                appinfoAttrs.fAttributeWC = otherAttrs;
 
391
            }
 
392
            
 
393
            // create particles for <annotation>
 
394
            XSParticleDecl annotationParticle = createUnboundedModelGroupParticle();
 
395
            {
 
396
                XSModelGroupImpl annotationChoice = new XSModelGroupImpl();
 
397
                annotationChoice.fCompositor = XSModelGroupImpl.MODELGROUP_CHOICE;
 
398
                annotationChoice.fParticleCount = 2;
 
399
                annotationChoice.fParticles = new XSParticleDecl[2];
 
400
                annotationChoice.fParticles[0] = createChoiceElementParticle(appinfoDecl);
 
401
                annotationChoice.fParticles[1] = createChoiceElementParticle(documentationDecl);
 
402
                annotationParticle.fValue = annotationChoice;
 
403
            }
 
404
            
 
405
            // create wildcard particle for <documentation> and <appinfo>
 
406
            XSParticleDecl anyWCSequenceParticle = createUnboundedAnyWildcardSequenceParticle();
 
407
            
 
408
            // fill complex types
 
409
            annotationType.setValues("#AnonType_" + SchemaSymbols.ELT_ANNOTATION, fTargetNamespace, SchemaGrammar.fAnyType,
 
410
                    XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
 
411
                    XSComplexTypeDecl.CONTENTTYPE_ELEMENT, false, annotationAttrs, null, annotationParticle, new XSObjectListImpl(null, 0));
 
412
            annotationType.setName("#AnonType_" + SchemaSymbols.ELT_ANNOTATION);
 
413
            annotationType.setIsAnonymous();
 
414
            
 
415
            documentationType.setValues("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION, fTargetNamespace, SchemaGrammar.fAnyType,
 
416
                    XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
 
417
                    XSComplexTypeDecl.CONTENTTYPE_MIXED, false, documentationAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
 
418
            documentationType.setName("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION);
 
419
            documentationType.setIsAnonymous();
 
420
            
 
421
            appinfoType.setValues("#AnonType_" + SchemaSymbols.ELT_APPINFO, fTargetNamespace, SchemaGrammar.fAnyType,
 
422
                    XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
 
423
                    XSComplexTypeDecl.CONTENTTYPE_MIXED, false, appinfoAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
 
424
            appinfoType.setName("#AnonType_" + SchemaSymbols.ELT_APPINFO);
 
425
            appinfoType.setIsAnonymous();
 
426
            
 
427
        } // <init>(int)
 
428
        
 
429
        // return the XMLGrammarDescription corresponding to this
 
430
        // object
 
431
        public XMLGrammarDescription getGrammarDescription() {
 
432
            return fGrammarDescription.makeClone();
 
433
        } // getGrammarDescription():  XMLGrammarDescription
 
434
 
 
435
        // override these methods solely so that these
 
436
        // objects cannot be modified once they're created.
 
437
        public void setImportedGrammars(Vector importedGrammars) {
 
438
            // ignore
 
439
        }
 
440
        public void addGlobalAttributeDecl(XSAttributeDecl decl) {
 
441
            // ignore
 
442
        }
 
443
        public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
 
444
            // ignore
 
445
        }
 
446
        public void addGlobalElementDecl(XSElementDecl decl) {
 
447
            // ignore
 
448
        }
 
449
        public void addGlobalGroupDecl(XSGroupDecl decl) {
 
450
            // ignore
 
451
        }
 
452
        public void addGlobalNotationDecl(XSNotationDecl decl) {
 
453
            // ignore
 
454
        }
 
455
        public void addGlobalTypeDecl(XSTypeDefinition decl) {
 
456
            // ignore
 
457
        }
 
458
        public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
 
459
            // ignore
 
460
        }
 
461
        public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
 
462
            // ignore
 
463
        }
 
464
        public synchronized void addDocument(Object document, String location) {
 
465
            // ignore
 
466
        }
 
467
 
 
468
        // annotation support
 
469
        synchronized DOMParser getDOMParser() {
 
470
            return null;
 
471
        }
 
472
        synchronized SAXParser getSAXParser() {
 
473
            return null;
 
474
        }
 
475
        
 
476
        //
 
477
        // private helper methods
 
478
        //
 
479
        
 
480
        private XSElementDecl createAnnotationElementDecl(String localName) {
 
481
            XSElementDecl eDecl = new XSElementDecl();
 
482
            eDecl.fName = localName;
 
483
            eDecl.fTargetNamespace = fTargetNamespace;
 
484
            eDecl.setIsGlobal();
 
485
            eDecl.fBlock = (XSConstants.DERIVATION_EXTENSION | 
 
486
                    XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION);
 
487
            eDecl.setConstraintType(XSConstants.VC_NONE);
 
488
            return eDecl;
 
489
        }
 
490
        
 
491
        private XSParticleDecl createUnboundedModelGroupParticle() {
 
492
            XSParticleDecl particle = new XSParticleDecl();
 
493
            particle.fMinOccurs = 0;
 
494
            particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
 
495
            particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
 
496
            return particle;
 
497
        }
 
498
        
 
499
        private XSParticleDecl createChoiceElementParticle(XSElementDecl ref) {
 
500
            XSParticleDecl particle = new XSParticleDecl();
 
501
            particle.fMinOccurs = 1;
 
502
            particle.fMaxOccurs = 1;
 
503
            particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
 
504
            particle.fValue = ref;
 
505
            return particle;
 
506
        }
 
507
        
 
508
        private XSParticleDecl createUnboundedAnyWildcardSequenceParticle() {
 
509
            XSParticleDecl particle = createUnboundedModelGroupParticle();
 
510
            XSModelGroupImpl sequence = new XSModelGroupImpl();
 
511
            sequence.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
 
512
            sequence.fParticleCount = 1;
 
513
            sequence.fParticles = new XSParticleDecl[1];
 
514
            sequence.fParticles[0] = createAnyLaxWildcardParticle();
 
515
            particle.fValue = sequence;
 
516
            return particle;
 
517
        }
 
518
        
 
519
        private XSParticleDecl createAnyLaxWildcardParticle() {
 
520
            XSParticleDecl particle = new XSParticleDecl();
 
521
            particle.fMinOccurs = 1;
 
522
            particle.fMaxOccurs = 1;
 
523
            particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
 
524
            
 
525
            XSWildcardDecl anyWC = new XSWildcardDecl();
 
526
            anyWC.fNamespaceList = null;
 
527
            anyWC.fType = XSWildcard.NSCONSTRAINT_ANY;
 
528
            anyWC.fProcessContents = XSWildcard.PC_LAX;
 
529
            
 
530
            particle.fValue = anyWC;
 
531
            return particle;
 
532
        }
 
533
    }
 
534
 
 
535
    // Grammar methods
 
536
 
 
537
    // return the XMLGrammarDescription corresponding to this
 
538
    // object
 
539
    public XMLGrammarDescription getGrammarDescription() {
 
540
        return fGrammarDescription;
 
541
    } // getGrammarDescription():  XMLGrammarDescription
 
542
 
 
543
    // DTDGrammar methods
 
544
    public boolean isNamespaceAware () {
 
545
        return true;
 
546
    } // isNamespaceAware():boolean
 
547
 
 
548
    Vector fImported = null;
 
549
 
 
550
    public void setImportedGrammars(Vector importedGrammars) {
 
551
        fImported = importedGrammars;
 
552
    }
 
553
 
 
554
    public Vector getImportedGrammars() {
 
555
        return fImported;
 
556
    }
 
557
 
 
558
    /**
 
559
     * Returns this grammar's target namespace.
 
560
     */
 
561
    public final String getTargetNamespace() {
 
562
        return fTargetNamespace;
 
563
    } // getTargetNamespace():String
 
564
 
 
565
    /**
 
566
     * register one global attribute
 
567
     */
 
568
    public void addGlobalAttributeDecl(XSAttributeDecl decl) {
 
569
        fGlobalAttrDecls.put(decl.fName, decl);
 
570
    }
 
571
 
 
572
    /**
 
573
     * register one global attribute group
 
574
     */
 
575
    public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
 
576
        fGlobalAttrGrpDecls.put(decl.fName, decl);
 
577
    }
 
578
 
 
579
    /**
 
580
     * register one global element
 
581
     */
 
582
    public void addGlobalElementDecl(XSElementDecl decl) {
 
583
        fGlobalElemDecls.put(decl.fName, decl);
 
584
 
 
585
        // if there is a substitution group affiliation, store in an array,
 
586
        // for further constraint checking: UPA, PD, EDC
 
587
        if (decl.fSubGroup != null) {
 
588
            if (fSubGroupCount == fSubGroups.length)
 
589
                fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
 
590
            fSubGroups[fSubGroupCount++] = decl;
 
591
        }
 
592
    }
 
593
 
 
594
    /**
 
595
     * register one global group
 
596
     */
 
597
    public void addGlobalGroupDecl(XSGroupDecl decl) {
 
598
        fGlobalGroupDecls.put(decl.fName, decl);
 
599
    }
 
600
 
 
601
    /**
 
602
     * register one global notation
 
603
     */
 
604
    public void addGlobalNotationDecl(XSNotationDecl decl) {
 
605
        fGlobalNotationDecls.put(decl.fName, decl);
 
606
    }
 
607
 
 
608
    /**
 
609
     * register one global type
 
610
     */
 
611
    public void addGlobalTypeDecl(XSTypeDefinition decl) {
 
612
        fGlobalTypeDecls.put(decl.getName(), decl);
 
613
    }
 
614
 
 
615
    /**
 
616
     * register one identity constraint
 
617
     */
 
618
    public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl) {
 
619
        elmDecl.addIDConstraint(decl);
 
620
        fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
 
621
    }
 
622
 
 
623
    /**
 
624
     * get one global attribute
 
625
     */
 
626
    public final XSAttributeDecl getGlobalAttributeDecl(String declName) {
 
627
        return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
 
628
    }
 
629
 
 
630
    /**
 
631
     * get one global attribute group
 
632
     */
 
633
    public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String declName) {
 
634
        return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
 
635
    }
 
636
 
 
637
    /**
 
638
     * get one global element
 
639
     */
 
640
    public final XSElementDecl getGlobalElementDecl(String declName) {
 
641
        return(XSElementDecl)fGlobalElemDecls.get(declName);
 
642
    }
 
643
 
 
644
    /**
 
645
     * get one global group
 
646
     */
 
647
    public final XSGroupDecl getGlobalGroupDecl(String declName) {
 
648
        return(XSGroupDecl)fGlobalGroupDecls.get(declName);
 
649
    }
 
650
 
 
651
    /**
 
652
     * get one global notation
 
653
     */
 
654
    public final XSNotationDecl getGlobalNotationDecl(String declName) {
 
655
        return(XSNotationDecl)fGlobalNotationDecls.get(declName);
 
656
    }
 
657
 
 
658
    /**
 
659
     * get one global type
 
660
     */
 
661
    public final XSTypeDefinition getGlobalTypeDecl(String declName) {
 
662
        return(XSTypeDefinition)fGlobalTypeDecls.get(declName);
 
663
    }
 
664
 
 
665
    /**
 
666
     * get one identity constraint
 
667
     */
 
668
    public final IdentityConstraint getIDConstraintDecl(String declName) {
 
669
        return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
 
670
    }
 
671
 
 
672
    /**
 
673
     * get one identity constraint
 
674
     */
 
675
    public final boolean hasIDConstraints() {
 
676
        return fGlobalIDConstraintDecls.getLength() > 0;
 
677
    }
 
678
 
 
679
    // array to store complex type decls
 
680
    private static final int INITIAL_SIZE = 16;
 
681
    private static final int INC_SIZE     = 16;
 
682
 
 
683
    private int fCTCount = 0;
 
684
    private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE];
 
685
    private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE];
 
686
 
 
687
    // an array to store groups being redefined by restriction
 
688
    // even-numbered elements are the derived groups, odd-numbered ones their bases
 
689
    private static final int REDEFINED_GROUP_INIT_SIZE = 2;
 
690
    private int fRGCount = 0;
 
691
    private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE];
 
692
    private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE/2];
 
693
 
 
694
    // a flag to indicate whether we have checked the 3 constraints on this
 
695
    // grammar.
 
696
    boolean fFullChecked = false;
 
697
 
 
698
    /**
 
699
     * add one complex type decl: for later constraint checking
 
700
     */
 
701
    public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
 
702
        if (fCTCount == fComplexTypeDecls.length) {
 
703
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE);
 
704
            fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE);
 
705
        }
 
706
        fCTLocators[fCTCount] = locator;
 
707
        fComplexTypeDecls[fCTCount++] = decl;
 
708
    }
 
709
 
 
710
    /**
 
711
     * add a group redefined by restriction: for later constraint checking
 
712
     */
 
713
    public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
 
714
        if (fRGCount == fRedefinedGroupDecls.length) {
 
715
            // double array size each time.
 
716
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1);
 
717
            fRGLocators = resize(fRGLocators, fRGCount);
 
718
        }
 
719
        fRGLocators[fRGCount/2] = locator;
 
720
        fRedefinedGroupDecls[fRGCount++] = derived;
 
721
        fRedefinedGroupDecls[fRGCount++] = base;
 
722
    }
 
723
 
 
724
    /**
 
725
     * get all complex type decls: for later constraint checking
 
726
     */
 
727
    final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() {
 
728
        if (fCTCount < fComplexTypeDecls.length) {
 
729
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
 
730
            fCTLocators = resize(fCTLocators, fCTCount);
 
731
        }
 
732
        return fComplexTypeDecls;
 
733
    }
 
734
 
 
735
    /**
 
736
     * get the error locator of all complex type decls
 
737
     */
 
738
    final SimpleLocator[] getUncheckedCTLocators() {
 
739
        if (fCTCount < fCTLocators.length) {
 
740
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
 
741
            fCTLocators = resize(fCTLocators, fCTCount);
 
742
        }
 
743
        return fCTLocators;
 
744
    }
 
745
 
 
746
    /**
 
747
     * get all redefined groups: for later constraint checking
 
748
     */
 
749
    final XSGroupDecl[] getRedefinedGroupDecls() {
 
750
        if (fRGCount < fRedefinedGroupDecls.length) {
 
751
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
 
752
            fRGLocators = resize(fRGLocators, fRGCount/2);
 
753
        }
 
754
        return fRedefinedGroupDecls;
 
755
    }
 
756
 
 
757
    /**
 
758
     * get the error locator of all redefined groups
 
759
     */
 
760
    final SimpleLocator[] getRGLocators() {
 
761
        if (fRGCount < fRedefinedGroupDecls.length) {
 
762
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
 
763
            fRGLocators = resize(fRGLocators, fRGCount/2);
 
764
        }
 
765
        return fRGLocators;
 
766
    }
 
767
 
 
768
    /**
 
769
     * after the first-round checking, some types don't need to be checked
 
770
     * against UPA again. here we trim the array to the proper size.
 
771
     */
 
772
    final void setUncheckedTypeNum(int newSize) {
 
773
        fCTCount = newSize;
 
774
        fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
 
775
        fCTLocators = resize(fCTLocators, fCTCount);
 
776
    }
 
777
 
 
778
    // used to store all substitution group information declared in
 
779
    // this namespace
 
780
    private int fSubGroupCount = 0;
 
781
    private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE];
 
782
 
 
783
    /**
 
784
     * get all substitution group information: for the 3 constraint checking
 
785
     */
 
786
    final XSElementDecl[] getSubstitutionGroups() {
 
787
        if (fSubGroupCount < fSubGroups.length)
 
788
            fSubGroups = resize(fSubGroups, fSubGroupCount);
 
789
        return fSubGroups;
 
790
    }
 
791
 
 
792
    // anyType and anySimpleType: because there are so many places where
 
793
    // we need direct access to these two types
 
794
    public final static XSComplexTypeDecl fAnyType = new XSAnyType();
 
795
    private static class XSAnyType extends XSComplexTypeDecl {
 
796
        public XSAnyType () {
 
797
            fName = SchemaSymbols.ATTVAL_ANYTYPE;
 
798
            super.fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
 
799
            fBaseType = this;
 
800
            fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
 
801
            fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED;
 
802
 
 
803
            fParticle = null;
 
804
            fAttrGrp = null;
 
805
        }
 
806
 
 
807
        // overridden methods
 
808
        public void setValues(String name, String targetNamespace,
 
809
                XSTypeDefinition baseType, short derivedBy, short schemaFinal, 
 
810
                short block, short contentType,
 
811
                boolean isAbstract, XSAttributeGroupDecl attrGrp, 
 
812
                XSSimpleType simpleType, XSParticleDecl particle) {
 
813
            // don't allow this.
 
814
        }
 
815
 
 
816
        public void setName(String name){
 
817
            // don't allow this.
 
818
        }
 
819
 
 
820
        public void setIsAbstractType() {
 
821
            // null implementation
 
822
        }
 
823
 
 
824
        public void setContainsTypeID() {
 
825
            // null implementation
 
826
        }
 
827
 
 
828
        public void setIsAnonymous() {
 
829
            // null implementation
 
830
        }
 
831
 
 
832
        public void reset() {
 
833
            // null implementation
 
834
        }
 
835
 
 
836
        public XSObjectList getAttributeUses() {
 
837
            return new XSObjectListImpl(null, 0);
 
838
        }
 
839
 
 
840
        public XSAttributeGroupDecl getAttrGrp() {
 
841
            XSWildcardDecl wildcard = new XSWildcardDecl();
 
842
            wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
 
843
            XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
 
844
            attrGrp.fAttributeWC = wildcard;
 
845
            return attrGrp;
 
846
        }
 
847
 
 
848
        public XSWildcard getAttributeWildcard() {
 
849
            XSWildcardDecl wildcard = new XSWildcardDecl();
 
850
            wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
 
851
            return wildcard;
 
852
        }
 
853
 
 
854
        public XSParticle getParticle() {
 
855
            // the wildcard used in anyType (content and attribute)
 
856
            // the spec will change strict to skip for anyType
 
857
            XSWildcardDecl wildcard = new XSWildcardDecl();
 
858
            wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
 
859
            // the particle for the content wildcard
 
860
            XSParticleDecl particleW = new XSParticleDecl();
 
861
            particleW.fMinOccurs = 0;
 
862
            particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
 
863
            particleW.fType = XSParticleDecl.PARTICLE_WILDCARD;
 
864
            particleW.fValue = wildcard;
 
865
            // the model group of a sequence of the above particle
 
866
            XSModelGroupImpl group = new XSModelGroupImpl();
 
867
            group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
 
868
            group.fParticleCount = 1;
 
869
            group.fParticles = new XSParticleDecl[1];
 
870
            group.fParticles[0] = particleW;
 
871
            // the content of anyType: particle of the above model group
 
872
            XSParticleDecl particleG = new XSParticleDecl();
 
873
            particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP;
 
874
            particleG.fValue = group;
 
875
        
 
876
            return particleG;
 
877
        }
 
878
 
 
879
        public XSObjectList getAnnotations() {
 
880
            return null;
 
881
        }
 
882
    }
 
883
    private static class BuiltinAttrDecl extends XSAttributeDecl {
 
884
        public BuiltinAttrDecl(String name, String tns, 
 
885
                XSSimpleType type, short scope) {
 
886
            fName = name;
 
887
            super.fTargetNamespace = tns;
 
888
            fType = type;
 
889
            fScope = scope;
 
890
        }
 
891
 
 
892
        public void setValues(String name, String targetNamespace,
 
893
                XSSimpleType simpleType, short constraintType, short scope,
 
894
                ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT) { 
 
895
            // ignore this call.
 
896
        }
 
897
 
 
898
        public void reset () {
 
899
            // also ignore this call.
 
900
        }
 
901
        public XSAnnotation getAnnotation() {
 
902
            return null;
 
903
        }
 
904
    } // class BuiltinAttrDecl
 
905
 
 
906
    // the grammars to hold components of the schema namespace
 
907
    public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS);
 
908
    
 
909
    public final static Schema4Annotations SG_Schema4Annotations = new Schema4Annotations();
 
910
 
 
911
    public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
 
912
 
 
913
    // the grammars to hold components of the schema-instance namespace
 
914
    public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI);
 
915
 
 
916
    static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) {
 
917
        XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
 
918
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
 
919
        return newArray;
 
920
    }
 
921
 
 
922
    static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) {
 
923
        XSGroupDecl[] newArray = new XSGroupDecl[newSize];
 
924
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
 
925
        return newArray;
 
926
    }
 
927
 
 
928
    static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) {
 
929
        XSElementDecl[] newArray = new XSElementDecl[newSize];
 
930
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
 
931
        return newArray;
 
932
    }
 
933
 
 
934
    static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) {
 
935
        SimpleLocator[] newArray = new SimpleLocator[newSize];
 
936
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
 
937
        return newArray;
 
938
    }
 
939
 
 
940
    // XSNamespaceItem methods
 
941
    
 
942
    // the max index / the max value of XSObject type
 
943
    private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE;
 
944
    private static final boolean[] GLOBAL_COMP = {false,    // null
 
945
                                                  true,     // attribute
 
946
                                                  true,     // element
 
947
                                                  true,     // type
 
948
                                                  false,    // attribute use
 
949
                                                  true,     // attribute group
 
950
                                                  true,     // group
 
951
                                                  false,    // model group
 
952
                                                  false,    // particle
 
953
                                                  false,    // wildcard
 
954
                                                  false,    // idc
 
955
                                                  true,     // notation
 
956
                                                  false,    // annotation
 
957
                                                  false,    // facet
 
958
                                                  false,    // multi value facet
 
959
                                                  true,     // complex type
 
960
                                                  true      // simple type
 
961
                                                 };
 
962
                                                 
 
963
    // store a certain kind of components from all namespaces
 
964
    private XSNamedMap[] fComponents = null;
 
965
 
 
966
    // store the documents and their locations contributing to this namespace
 
967
    // REVISIT: use StringList and XSObjectList for there fields.
 
968
    private Vector fDocuments = null;
 
969
    private Vector fLocations = null;
 
970
    
 
971
    public synchronized void addDocument(Object document, String location) {
 
972
        if (fDocuments == null) {
 
973
            fDocuments = new Vector();
 
974
            fLocations = new Vector();
 
975
        }
 
976
        fDocuments.addElement(document);
 
977
        fLocations.addElement(location);
 
978
    }
 
979
    
 
980
    /**
 
981
     * [schema namespace]
 
982
     * @see <a href="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a>
 
983
     * @return The target namespace of this item.
 
984
     */
 
985
    public String getSchemaNamespace() {
 
986
        return fTargetNamespace;
 
987
    }
 
988
 
 
989
    // annotation support
 
990
    synchronized DOMParser getDOMParser() {
 
991
        if (fDOMParser != null) {
 
992
            DOMParser parser = (DOMParser) fDOMParser.get();
 
993
            if (parser != null) {
 
994
                return parser;
 
995
            }
 
996
        }
 
997
        // REVISIT:  when schema handles XML 1.1, will need to 
 
998
        // revisit this (and the practice of not prepending an XML decl to the annotation string
 
999
        XML11Configuration config = new XML11Configuration(fSymbolTable);
 
1000
        // note that this should never produce errors or require
 
1001
        // entity resolution, so just a barebones configuration with
 
1002
        // a couple of feature  set will do fine
 
1003
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
 
1004
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
 
1005
        
 
1006
        DOMParser parser = new DOMParser(config);
 
1007
        try {
 
1008
            parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE, false);
 
1009
        }
 
1010
        catch (SAXException exc) {}
 
1011
        fDOMParser = new SoftReference(parser);
 
1012
        return parser;
 
1013
    }
 
1014
 
 
1015
    synchronized SAXParser getSAXParser() {
 
1016
        if (fSAXParser != null) {
 
1017
            SAXParser parser = (SAXParser) fSAXParser.get();
 
1018
            if (parser != null) {
 
1019
                return parser;
 
1020
            }
 
1021
        }
 
1022
        // REVISIT:  when schema handles XML 1.1, will need to 
 
1023
        // revisit this (and the practice of not prepending an XML decl to the annotation string
 
1024
        XML11Configuration config = new XML11Configuration(fSymbolTable);
 
1025
        // note that this should never produce errors or require
 
1026
        // entity resolution, so just a barebones configuration with
 
1027
        // a couple of feature  set will do fine
 
1028
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
 
1029
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
 
1030
        SAXParser parser = new SAXParser(config);
 
1031
        fSAXParser = new SoftReference(parser);
 
1032
        return parser;
 
1033
    }
 
1034
 
 
1035
    /**
 
1036
     * [schema components]: a list of top-level components, i.e. element 
 
1037
     * declarations, attribute declarations, etc. 
 
1038
     * @param objectType The type of the declaration, i.e. 
 
1039
     *   <code>ELEMENT_DECLARATION</code>. Note that 
 
1040
     *   <code>XSTypeDefinition.SIMPLE_TYPE</code> and 
 
1041
     *   <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the 
 
1042
     *   <code>objectType</code> to retrieve only complex types or simple 
 
1043
     *   types, instead of all types.
 
1044
     * @return  A list of top-level definition of the specified type in 
 
1045
     *   <code>objectType</code> or an empty <code>XSNamedMap</code> if no 
 
1046
     *   such definitions exist. 
 
1047
     */
 
1048
    public synchronized XSNamedMap getComponents(short objectType) {
 
1049
        if (objectType <= 0 || objectType > MAX_COMP_IDX ||
 
1050
            !GLOBAL_COMP[objectType]) {
 
1051
            return XSNamedMapImpl.EMPTY_MAP;
 
1052
        }
 
1053
        
 
1054
        if (fComponents == null)
 
1055
            fComponents = new XSNamedMap[MAX_COMP_IDX+1];
 
1056
 
 
1057
        // get the hashtable for this type of components
 
1058
        if (fComponents[objectType] == null) {
 
1059
            SymbolHash table = null;
 
1060
            switch (objectType) {
 
1061
            case XSConstants.TYPE_DEFINITION:
 
1062
            case XSTypeDefinition.COMPLEX_TYPE:
 
1063
            case XSTypeDefinition.SIMPLE_TYPE:
 
1064
                table = fGlobalTypeDecls;
 
1065
                break;
 
1066
            case XSConstants.ATTRIBUTE_DECLARATION:
 
1067
                table = fGlobalAttrDecls;
 
1068
                break;
 
1069
            case XSConstants.ELEMENT_DECLARATION:
 
1070
                table = fGlobalElemDecls;
 
1071
                break;
 
1072
            case XSConstants.ATTRIBUTE_GROUP:
 
1073
                table = fGlobalAttrGrpDecls;
 
1074
                break;
 
1075
            case XSConstants.MODEL_GROUP_DEFINITION:
 
1076
                table = fGlobalGroupDecls;
 
1077
                break;
 
1078
            case XSConstants.NOTATION_DECLARATION:
 
1079
                table = fGlobalNotationDecls;
 
1080
                break;
 
1081
            }
 
1082
            
 
1083
            // for complex/simple types, create a special implementation,
 
1084
            // which take specific types out of the hash table
 
1085
            if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
 
1086
                objectType == XSTypeDefinition.SIMPLE_TYPE) {
 
1087
                fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
 
1088
            }
 
1089
            else {
 
1090
                fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
 
1091
            }
 
1092
        }
 
1093
        
 
1094
        return fComponents[objectType];
 
1095
    }
 
1096
 
 
1097
    /**
 
1098
     * Convenience method. Returns a top-level simple or complex type
 
1099
     * definition.
 
1100
     * @param name The name of the definition.
 
1101
     * @return An <code>XSTypeDefinition</code> or null if such definition
 
1102
     *   does not exist.
 
1103
     */
 
1104
    public XSTypeDefinition getTypeDefinition(String name) {
 
1105
        return getGlobalTypeDecl(name);
 
1106
    }
 
1107
 
 
1108
    /**
 
1109
     * Convenience method. Returns a top-level attribute declaration.
 
1110
     * @param name The name of the declaration.
 
1111
     * @return A top-level attribute declaration or null if such declaration
 
1112
     *   does not exist.
 
1113
     */
 
1114
    public XSAttributeDeclaration getAttributeDeclaration(String name) {
 
1115
        return getGlobalAttributeDecl(name);
 
1116
    }
 
1117
 
 
1118
    /**
 
1119
     * Convenience method. Returns a top-level element declaration.
 
1120
     * @param name The name of the declaration.
 
1121
     * @return A top-level element declaration or null if such declaration
 
1122
     *   does not exist.
 
1123
     */
 
1124
    public XSElementDeclaration getElementDeclaration(String name) {
 
1125
        return getGlobalElementDecl(name);
 
1126
    }
 
1127
 
 
1128
    /**
 
1129
     * Convenience method. Returns a top-level attribute group definition.
 
1130
     * @param name The name of the definition.
 
1131
     * @return A top-level attribute group definition or null if such
 
1132
     *   definition does not exist.
 
1133
     */
 
1134
    public XSAttributeGroupDefinition getAttributeGroup(String name) {
 
1135
        return getGlobalAttributeGroupDecl(name);
 
1136
    }
 
1137
 
 
1138
    /**
 
1139
     * Convenience method. Returns a top-level model group definition.
 
1140
     *
 
1141
     * @param name      The name of the definition.
 
1142
     * @return A top-level model group definition definition or null if such
 
1143
     *         definition does not exist.
 
1144
     */
 
1145
    public XSModelGroupDefinition getModelGroupDefinition(String name) {
 
1146
        return getGlobalGroupDecl(name);
 
1147
    }
 
1148
 
 
1149
    /**
 
1150
     * Convenience method. Returns a top-level notation declaration.
 
1151
     *
 
1152
     * @param name      The name of the declaration.
 
1153
     * @return A top-level notation declaration or null if such declaration
 
1154
     *         does not exist.
 
1155
     */
 
1156
    public XSNotationDeclaration getNotationDeclaration(String name) {
 
1157
        return getGlobalNotationDecl(name);
 
1158
    }
 
1159
 
 
1160
 
 
1161
    /**
 
1162
     * [document location]
 
1163
     * @see <a href="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a>
 
1164
     * @return a list of document information item
 
1165
     */
 
1166
    public StringList getDocumentLocations() {
 
1167
        return new StringListImpl(fLocations);
 
1168
    }
 
1169
    
 
1170
    /**
 
1171
     * Return an <code>XSModel</code> that represents components in this schema
 
1172
     * grammar.
 
1173
     * 
 
1174
     * @return  an <code>XSModel</code> representing this schema grammar
 
1175
     */
 
1176
    public XSModel toXSModel() {
 
1177
        return new XSModelImpl(new SchemaGrammar[]{this});
 
1178
    }
 
1179
 
 
1180
    public XSModel toXSModel(XSGrammar[] grammars) {
 
1181
        if (grammars == null || grammars.length == 0)
 
1182
            return toXSModel();
 
1183
 
 
1184
        int len = grammars.length;
 
1185
        boolean hasSelf = false;
 
1186
        for (int i = 0; i < len; i++) {
 
1187
            if (grammars[i] == this) {
 
1188
                hasSelf = true;
 
1189
                break;
 
1190
            }
 
1191
        }
 
1192
 
 
1193
        SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1];
 
1194
        for (int i = 0; i < len; i++)
 
1195
            gs[i] = (SchemaGrammar)grammars[i];
 
1196
        if (!hasSelf)
 
1197
            gs[len] = this;
 
1198
        return new XSModelImpl(gs);
 
1199
    }
 
1200
 
 
1201
    /**
 
1202
     * @see org.apache.xerces.xs.XSNamespaceItem#getAnnotations()
 
1203
     */
 
1204
    public XSObjectList getAnnotations() {
 
1205
        return new XSObjectListImpl(fAnnotations, fNumAnnotations);
 
1206
    }
 
1207
 
 
1208
    public void addAnnotation(XSAnnotationImpl annotation) {
 
1209
        if(annotation == null)
 
1210
            return;
 
1211
        if(fAnnotations == null) {
 
1212
            fAnnotations = new XSAnnotationImpl[2];
 
1213
        } else if(fNumAnnotations == fAnnotations.length) {
 
1214
            XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1];
 
1215
            System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations);
 
1216
            fAnnotations = newArray;
 
1217
        }
 
1218
        fAnnotations[fNumAnnotations++] = annotation;
 
1219
    }
 
1220
 
 
1221
} // class SchemaGrammar