KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > SchemaGrammar


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

16
17 package org.apache.xerces.impl.xs;
18
19 import java.util.Vector JavaDoc;
20
21 import org.apache.xerces.impl.Constants;
22 import org.apache.xerces.impl.dv.SchemaDVFactory;
23 import org.apache.xerces.impl.dv.ValidatedInfo;
24 import org.apache.xerces.impl.dv.XSSimpleType;
25 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
26 import org.apache.xerces.impl.xs.util.SimpleLocator;
27 import org.apache.xerces.impl.xs.util.StringListImpl;
28 import org.apache.xerces.impl.xs.util.XSNamedMap4Types;
29 import org.apache.xerces.impl.xs.util.XSNamedMapImpl;
30 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
31 import org.apache.xerces.parsers.DOMParser;
32 import org.apache.xerces.parsers.IntegratedParserConfiguration;
33 import org.apache.xerces.parsers.SAXParser;
34 import org.apache.xerces.util.SymbolHash;
35 import org.apache.xerces.util.SymbolTable;
36 import org.apache.xerces.xni.NamespaceContext;
37 import org.apache.xerces.xni.grammars.XMLGrammarDescription;
38 import org.apache.xerces.xni.grammars.XSGrammar;
39 import org.apache.xerces.xs.StringList;
40 import org.apache.xerces.xs.XSAnnotation;
41 import org.apache.xerces.xs.XSAttributeDeclaration;
42 import org.apache.xerces.xs.XSAttributeGroupDefinition;
43 import org.apache.xerces.xs.XSConstants;
44 import org.apache.xerces.xs.XSElementDeclaration;
45 import org.apache.xerces.xs.XSModel;
46 import org.apache.xerces.xs.XSModelGroupDefinition;
47 import org.apache.xerces.xs.XSNamedMap;
48 import org.apache.xerces.xs.XSNamespaceItem;
49 import org.apache.xerces.xs.XSNotationDeclaration;
50 import org.apache.xerces.xs.XSObjectList;
51 import org.apache.xerces.xs.XSParticle;
52 import org.apache.xerces.xs.XSTypeDefinition;
53 import org.apache.xerces.xs.XSWildcard;
54
55 /**
56  * This class is to hold all schema component declaration that are declared
57  * within one namespace.
58  *
59  * The Grammar class this class extends contains what little
60  * commonality there is between XML Schema and DTD grammars. It's
61  * useful to distinguish grammar objects from other kinds of object
62  * when they exist in pools or caches.
63  *
64  * @xerces.internal
65  *
66  * @author Sandy Gao, IBM
67  * @author Elena Litani, IBM
68  *
69  * @version $Id: SchemaGrammar.java,v 1.42 2004/12/15 23:48:48 mrglavas Exp $
70  */

71
72 public class SchemaGrammar implements XSGrammar, XSNamespaceItem {
73
74     // the target namespace of grammar
75
String JavaDoc fTargetNamespace;
76
77     // global decls: map from decl name to decl object
78
SymbolHash fGlobalAttrDecls;
79     SymbolHash fGlobalAttrGrpDecls;
80     SymbolHash fGlobalElemDecls;
81     SymbolHash fGlobalGroupDecls;
82     SymbolHash fGlobalNotationDecls;
83     SymbolHash fGlobalIDConstraintDecls;
84     SymbolHash fGlobalTypeDecls;
85
86     // the XMLGrammarDescription member
87
XSDDescription fGrammarDescription = null;
88
89     // annotations associated with the "root" schema of this targetNamespace
90
XSAnnotationImpl [] fAnnotations = null;
91
92     // number of annotations declared
93
int fNumAnnotations;
94
95     // symbol table for constructing parsers (annotation support)
96
private SymbolTable fSymbolTable = null;
97     // parsers for annotation support
98
private SAXParser fSAXParser = null;
99     private DOMParser fDOMParser = null;
100
101     //
102
// Constructors
103
//
104

105     // needed to make BuiltinSchemaGrammar work.
106
protected SchemaGrammar() {}
107
108     /**
109      * Default constructor.
110      *
111      * @param targetNamespace
112      * @param grammarDesc the XMLGrammarDescription corresponding to this objec
113      * at the least a systemId should always be known.
114      * @param symbolTable needed for annotation support
115      */

116     public SchemaGrammar(String JavaDoc targetNamespace, XSDDescription grammarDesc,
117                 SymbolTable symbolTable) {
118         fTargetNamespace = targetNamespace;
119         fGrammarDescription = grammarDesc;
120         fSymbolTable = symbolTable;
121
122         // REVISIT: do we know the numbers of the following global decls
123
// when creating this grammar? If so, we can pass the numbers in,
124
// and use that number to initialize the following hashtables.
125
fGlobalAttrDecls = new SymbolHash();
126         fGlobalAttrGrpDecls = new SymbolHash();
127         fGlobalElemDecls = new SymbolHash();
128         fGlobalGroupDecls = new SymbolHash();
129         fGlobalNotationDecls = new SymbolHash();
130         fGlobalIDConstraintDecls = new SymbolHash();
131
132         // if we are parsing S4S, put built-in types in first
133
// they might get overwritten by the types from S4S, but that's
134
// considered what the application wants to do.
135
if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)
136             fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();
137         else
138             fGlobalTypeDecls = new SymbolHash();
139     } // <init>(String, XSDDescription)
140

141     // number of built-in XSTypes we need to create for base and full
142
// datatype set
143
private static final int BASICSET_COUNT = 29;
144     private static final int FULLSET_COUNT = 46;
145
146     private static final int GRAMMAR_XS = 1;
147     private static final int GRAMMAR_XSI = 2;
148
149     // this class makes sure the static, built-in schema grammars
150
// are immutable.
151
public static class BuiltinSchemaGrammar extends SchemaGrammar {
152         /**
153          * Special constructor to create the grammars for the schema namespaces
154          *
155          * @param grammar
156          */

157         public BuiltinSchemaGrammar(int grammar) {
158             SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance();
159     
160             if (grammar == GRAMMAR_XS) {
161                 // target namespace
162
fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
163         
164                 // grammar description
165
fGrammarDescription = new XSDDescription();
166                 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
167                 fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
168         
169                 // no global decls other than types
170
fGlobalAttrDecls = new SymbolHash(1);
171                 fGlobalAttrGrpDecls = new SymbolHash(1);
172                 fGlobalElemDecls = new SymbolHash(1);
173                 fGlobalGroupDecls = new SymbolHash(1);
174                 fGlobalNotationDecls = new SymbolHash(1);
175                 fGlobalIDConstraintDecls = new SymbolHash(1);
176         
177                 // get all built-in types
178
fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
179                 // add anyType
180
fGlobalTypeDecls.put(fAnyType.getName(), fAnyType);
181             }
182             else if (grammar == GRAMMAR_XSI) {
183                 // target namespace
184
fTargetNamespace = SchemaSymbols.URI_XSI;
185                 // grammar description
186
fGrammarDescription = new XSDDescription();
187                 fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
188                 fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);
189         
190                 // no global decls other than attributes
191
fGlobalAttrGrpDecls = new SymbolHash(1);
192                 fGlobalElemDecls = new SymbolHash(1);
193                 fGlobalGroupDecls = new SymbolHash(1);
194                 fGlobalNotationDecls = new SymbolHash(1);
195                 fGlobalIDConstraintDecls = new SymbolHash(1);
196                 fGlobalTypeDecls = new SymbolHash(1);
197     
198                 // 4 attributes, so initialize the size as 4*2 = 8
199
fGlobalAttrDecls = new SymbolHash(8);
200                 String JavaDoc name = null;
201                 String JavaDoc tns = null;
202                 XSSimpleType type = null;
203                 short scope = XSConstants.SCOPE_GLOBAL;
204                 
205                 // xsi:type
206
name = SchemaSymbols.XSI_TYPE;
207                 tns = SchemaSymbols.URI_XSI;
208                 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME);
209                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
210                 
211                 // xsi:nil
212
name = SchemaSymbols.XSI_NIL;
213                 tns = SchemaSymbols.URI_XSI;
214                 type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);
215                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
216                 
217                 XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);
218     
219                 // xsi:schemaLocation
220
name = SchemaSymbols.XSI_SCHEMALOCATION;
221                 tns = SchemaSymbols.URI_XSI;
222                 type = schemaFactory.createTypeList(null, SchemaSymbols.URI_XSI, (short)0, anyURI, null);
223                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
224                 
225                 // xsi:noNamespaceSchemaLocation
226
name = SchemaSymbols.XSI_NONAMESPACESCHEMALOCATION;
227                 tns = SchemaSymbols.URI_XSI;
228                 type = anyURI;
229                 fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
230             }
231         } // <init>(int)
232

233         // return the XMLGrammarDescription corresponding to this
234
// object
235
public XMLGrammarDescription getGrammarDescription() {
236             return fGrammarDescription.makeClone();
237         } // getGrammarDescription(): XMLGrammarDescription
238

239         // override these methods solely so that these
240
// objects cannot be modified once they're created.
241
public void setImportedGrammars(Vector JavaDoc importedGrammars) {
242             // ignore
243
}
244         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
245             // ignore
246
}
247         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
248             // ignore
249
}
250         public void addGlobalElementDecl(XSElementDecl decl) {
251             // ignore
252
}
253         public void addGlobalGroupDecl(XSGroupDecl decl) {
254             // ignore
255
}
256         public void addGlobalNotationDecl(XSNotationDecl decl) {
257             // ignore
258
}
259         public void addGlobalTypeDecl(XSTypeDefinition decl) {
260             // ignore
261
}
262         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
263             // ignore
264
}
265         public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
266             // ignore
267
}
268         public synchronized void addDocument(Object JavaDoc document, String JavaDoc location) {
269             // ignore
270
}
271
272         // annotation support
273
synchronized DOMParser getDOMParser() {
274             return null;
275         }
276         synchronized SAXParser getSAXParser() {
277             return null;
278         }
279     }
280     
281     /**
282      * <p>A partial schema for schemas for validating annotations.</p>
283      *
284      * @xerces.internal
285      *
286      * @author Michael Glavassevich, IBM
287      */

288     public static final class Schema4Annotations extends SchemaGrammar {
289
290         /**
291          * Special constructor to create a schema
292          * capable of validating annotations.
293          */

294         public Schema4Annotations() {
295             
296             // target namespace
297
fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
298             
299             // grammar description
300
fGrammarDescription = new XSDDescription();
301             fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
302             fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
303             
304             // no global decls other than types and
305
// element declarations for <annotation>, <documentation> and <appinfo>.
306
fGlobalAttrDecls = new SymbolHash(1);
307             fGlobalAttrGrpDecls = new SymbolHash(1);
308             fGlobalElemDecls = new SymbolHash(6);
309             fGlobalGroupDecls = new SymbolHash(1);
310             fGlobalNotationDecls = new SymbolHash(1);
311             fGlobalIDConstraintDecls = new SymbolHash(1);
312             
313             // get all built-in types
314
fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls;
315             
316             // create element declarations for <annotation>, <documentation> and <appinfo>
317
XSElementDecl annotationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_ANNOTATION);
318             XSElementDecl documentationDecl = createAnnotationElementDecl(SchemaSymbols.ELT_DOCUMENTATION);
319             XSElementDecl appinfoDecl = createAnnotationElementDecl(SchemaSymbols.ELT_APPINFO);
320             
321             // add global element declarations
322
fGlobalElemDecls.put(annotationDecl.fName, annotationDecl);
323             fGlobalElemDecls.put(documentationDecl.fName, documentationDecl);
324             fGlobalElemDecls.put(appinfoDecl.fName, appinfoDecl);
325             
326             // create complex type declarations for <annotation>, <documentation> and <appinfo>
327
XSComplexTypeDecl annotationType = new XSComplexTypeDecl();
328             XSComplexTypeDecl documentationType = new XSComplexTypeDecl();
329             XSComplexTypeDecl appinfoType = new XSComplexTypeDecl();
330             
331             // set the types on their element declarations
332
annotationDecl.fType = annotationType;
333             documentationDecl.fType = documentationType;
334             appinfoDecl.fType = appinfoType;
335             
336             // create attribute groups for <annotation>, <documentation> and <appinfo>
337
XSAttributeGroupDecl annotationAttrs = new XSAttributeGroupDecl();
338             XSAttributeGroupDecl documentationAttrs = new XSAttributeGroupDecl();
339             XSAttributeGroupDecl appinfoAttrs = new XSAttributeGroupDecl();
340             
341             // fill in attribute groups
342
{
343                 // create and fill attribute uses for <annotation>, <documentation> and <appinfo>
344
XSAttributeUseImpl annotationIDAttr = new XSAttributeUseImpl();
345                 annotationIDAttr.fAttrDecl = new XSAttributeDecl();
346                 annotationIDAttr.fAttrDecl.setValues(SchemaSymbols.ATT_ID, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ID),
347                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, annotationType, null);
348                 annotationIDAttr.fUse = SchemaSymbols.USE_OPTIONAL;
349                 annotationIDAttr.fConstraintType = XSConstants.VC_NONE;
350                 
351                 XSAttributeUseImpl documentationSourceAttr = new XSAttributeUseImpl();
352                 documentationSourceAttr.fAttrDecl = new XSAttributeDecl();
353                 documentationSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
354                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
355                 documentationSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
356                 documentationSourceAttr.fConstraintType = XSConstants.VC_NONE;
357                 
358                 XSAttributeUseImpl documentationLangAttr = new XSAttributeUseImpl();
359                 documentationLangAttr.fAttrDecl = new XSAttributeDecl();
360                 documentationLangAttr.fAttrDecl.setValues("lang".intern(), NamespaceContext.XML_URI, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_LANGUAGE),
361                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, documentationType, null);
362                 documentationLangAttr.fUse = SchemaSymbols.USE_OPTIONAL;
363                 documentationLangAttr.fConstraintType = XSConstants.VC_NONE;
364                 
365                 XSAttributeUseImpl appinfoSourceAttr = new XSAttributeUseImpl();
366                 appinfoSourceAttr.fAttrDecl = new XSAttributeDecl();
367                 appinfoSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
368                         XSConstants.VC_NONE, XSConstants.SCOPE_LOCAL, null, appinfoType, null);
369                 appinfoSourceAttr.fUse = SchemaSymbols.USE_OPTIONAL;
370                 appinfoSourceAttr.fConstraintType = XSConstants.VC_NONE;
371                 
372                 // create lax attribute wildcard for <annotation>, <documentation> and <appinfo>
373
XSWildcardDecl otherAttrs = new XSWildcardDecl();
374                 otherAttrs.fNamespaceList = new String JavaDoc [] {fTargetNamespace, null};
375                 otherAttrs.fType = XSWildcard.NSCONSTRAINT_NOT;
376                 otherAttrs.fProcessContents = XSWildcard.PC_LAX;
377                 
378                 // add attribute uses and wildcards to attribute groups for <annotation>, <documentation> and <appinfo>
379
annotationAttrs.addAttributeUse(annotationIDAttr);
380                 annotationAttrs.fAttributeWC = otherAttrs;
381                 
382                 documentationAttrs.addAttributeUse(documentationSourceAttr);
383                 documentationAttrs.addAttributeUse(documentationLangAttr);
384                 documentationAttrs.fAttributeWC = otherAttrs;
385                 
386                 appinfoAttrs.addAttributeUse(appinfoSourceAttr);
387                 appinfoAttrs.fAttributeWC = otherAttrs;
388             }
389             
390             // create particles for <annotation>
391
XSParticleDecl annotationParticle = createUnboundedModelGroupParticle();
392             {
393                 XSModelGroupImpl annotationChoice = new XSModelGroupImpl();
394                 annotationChoice.fCompositor = XSModelGroupImpl.MODELGROUP_CHOICE;
395                 annotationChoice.fParticleCount = 2;
396                 annotationChoice.fParticles = new XSParticleDecl[2];
397                 annotationChoice.fParticles[0] = createChoiceElementParticle(appinfoDecl);
398                 annotationChoice.fParticles[1] = createChoiceElementParticle(documentationDecl);
399                 annotationParticle.fValue = annotationChoice;
400             }
401             
402             // create wildcard particle for <documentation> and <appinfo>
403
XSParticleDecl anyWCSequenceParticle = createUnboundedAnyWildcardSequenceParticle();
404             
405             // fill complex types
406
annotationType.setValues("#AnonType_" + SchemaSymbols.ELT_ANNOTATION, fTargetNamespace, SchemaGrammar.fAnyType,
407                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
408                     XSComplexTypeDecl.CONTENTTYPE_ELEMENT, false, annotationAttrs, null, annotationParticle, new XSObjectListImpl(null, 0));
409             annotationType.setName("#AnonType_" + SchemaSymbols.ELT_ANNOTATION);
410             annotationType.setIsAnonymous();
411             
412             documentationType.setValues("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION, fTargetNamespace, SchemaGrammar.fAnyType,
413                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
414                     XSComplexTypeDecl.CONTENTTYPE_MIXED, false, documentationAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
415             documentationType.setName("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION);
416             documentationType.setIsAnonymous();
417             
418             appinfoType.setValues("#AnonType_" + SchemaSymbols.ELT_APPINFO, fTargetNamespace, SchemaGrammar.fAnyType,
419                     XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
420                     XSComplexTypeDecl.CONTENTTYPE_MIXED, false, appinfoAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
421             appinfoType.setName("#AnonType_" + SchemaSymbols.ELT_APPINFO);
422             appinfoType.setIsAnonymous();
423             
424         } // <init>(int)
425

426         // return the XMLGrammarDescription corresponding to this
427
// object
428
public XMLGrammarDescription getGrammarDescription() {
429             return fGrammarDescription.makeClone();
430         } // getGrammarDescription(): XMLGrammarDescription
431

432         // override these methods solely so that these
433
// objects cannot be modified once they're created.
434
public void setImportedGrammars(Vector JavaDoc importedGrammars) {
435             // ignore
436
}
437         public void addGlobalAttributeDecl(XSAttributeDecl decl) {
438             // ignore
439
}
440         public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
441             // ignore
442
}
443         public void addGlobalElementDecl(XSElementDecl decl) {
444             // ignore
445
}
446         public void addGlobalGroupDecl(XSGroupDecl decl) {
447             // ignore
448
}
449         public void addGlobalNotationDecl(XSNotationDecl decl) {
450             // ignore
451
}
452         public void addGlobalTypeDecl(XSTypeDefinition decl) {
453             // ignore
454
}
455         public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
456             // ignore
457
}
458         public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
459             // ignore
460
}
461         public synchronized void addDocument(Object JavaDoc document, String JavaDoc location) {
462             // ignore
463
}
464
465         // annotation support
466
synchronized DOMParser getDOMParser() {
467             return null;
468         }
469         synchronized SAXParser getSAXParser() {
470             return null;
471         }
472         
473         //
474
// private helper methods
475
//
476

477         private XSElementDecl createAnnotationElementDecl(String JavaDoc localName) {
478             XSElementDecl eDecl = new XSElementDecl();
479             eDecl.fName = localName;
480             eDecl.fTargetNamespace = fTargetNamespace;
481             eDecl.setIsGlobal();
482             eDecl.fBlock = (XSConstants.DERIVATION_EXTENSION |
483                     XSConstants.DERIVATION_RESTRICTION | XSConstants.DERIVATION_SUBSTITUTION);
484             eDecl.setConstraintType(XSConstants.VC_NONE);
485             return eDecl;
486         }
487         
488         private XSParticleDecl createUnboundedModelGroupParticle() {
489             XSParticleDecl particle = new XSParticleDecl();
490             particle.fMinOccurs = 0;
491             particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
492             particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
493             return particle;
494         }
495         
496         private XSParticleDecl createChoiceElementParticle(XSElementDecl ref) {
497             XSParticleDecl particle = new XSParticleDecl();
498             particle.fMinOccurs = 1;
499             particle.fMaxOccurs = 1;
500             particle.fType = XSParticleDecl.PARTICLE_ELEMENT;
501             particle.fValue = ref;
502             return particle;
503         }
504         
505         private XSParticleDecl createUnboundedAnyWildcardSequenceParticle() {
506             XSParticleDecl particle = createUnboundedModelGroupParticle();
507             XSModelGroupImpl sequence = new XSModelGroupImpl();
508             sequence.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
509             sequence.fParticleCount = 1;
510             sequence.fParticles = new XSParticleDecl[1];
511             sequence.fParticles[0] = createAnyLaxWildcardParticle();
512             particle.fValue = sequence;
513             return particle;
514         }
515         
516         private XSParticleDecl createAnyLaxWildcardParticle() {
517             XSParticleDecl particle = new XSParticleDecl();
518             particle.fMinOccurs = 1;
519             particle.fMaxOccurs = 1;
520             particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
521             
522             XSWildcardDecl anyWC = new XSWildcardDecl();
523             anyWC.fNamespaceList = null;
524             anyWC.fType = XSWildcard.NSCONSTRAINT_ANY;
525             anyWC.fProcessContents = XSWildcard.PC_LAX;
526             
527             particle.fValue = anyWC;
528             return particle;
529         }
530     }
531
532     // Grammar methods
533

534     // return the XMLGrammarDescription corresponding to this
535
// object
536
public XMLGrammarDescription getGrammarDescription() {
537         return fGrammarDescription;
538     } // getGrammarDescription(): XMLGrammarDescription
539

540     // DTDGrammar methods
541
public boolean isNamespaceAware () {
542         return true;
543     } // isNamespaceAware():boolean
544

545     Vector JavaDoc fImported = null;
546
547     public void setImportedGrammars(Vector JavaDoc importedGrammars) {
548         fImported = importedGrammars;
549     }
550
551     public Vector JavaDoc getImportedGrammars() {
552         return fImported;
553     }
554
555     /**
556      * Returns this grammar's target namespace.
557      */

558     public final String JavaDoc getTargetNamespace() {
559         return fTargetNamespace;
560     } // getTargetNamespace():String
561

562     /**
563      * register one global attribute
564      */

565     public void addGlobalAttributeDecl(XSAttributeDecl decl) {
566         fGlobalAttrDecls.put(decl.fName, decl);
567     }
568
569     /**
570      * register one global attribute group
571      */

572     public void addGlobalAttributeGroupDecl(XSAttributeGroupDecl decl) {
573         fGlobalAttrGrpDecls.put(decl.fName, decl);
574     }
575
576     /**
577      * register one global element
578      */

579     public void addGlobalElementDecl(XSElementDecl decl) {
580         fGlobalElemDecls.put(decl.fName, decl);
581
582         // if there is a substitution group affiliation, store in an array,
583
// for further constraint checking: UPA, PD, EDC
584
if (decl.fSubGroup != null) {
585             if (fSubGroupCount == fSubGroups.length)
586                 fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
587             fSubGroups[fSubGroupCount++] = decl;
588         }
589     }
590
591     /**
592      * register one global group
593      */

594     public void addGlobalGroupDecl(XSGroupDecl decl) {
595         fGlobalGroupDecls.put(decl.fName, decl);
596     }
597
598     /**
599      * register one global notation
600      */

601     public void addGlobalNotationDecl(XSNotationDecl decl) {
602         fGlobalNotationDecls.put(decl.fName, decl);
603     }
604
605     /**
606      * register one global type
607      */

608     public void addGlobalTypeDecl(XSTypeDefinition decl) {
609         fGlobalTypeDecls.put(decl.getName(), decl);
610     }
611
612     /**
613      * register one identity constraint
614      */

615     public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl) {
616         elmDecl.addIDConstraint(decl);
617         fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
618     }
619
620     /**
621      * get one global attribute
622      */

623     public final XSAttributeDecl getGlobalAttributeDecl(String JavaDoc declName) {
624         return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
625     }
626
627     /**
628      * get one global attribute group
629      */

630     public final XSAttributeGroupDecl getGlobalAttributeGroupDecl(String JavaDoc declName) {
631         return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
632     }
633
634     /**
635      * get one global element
636      */

637     public final XSElementDecl getGlobalElementDecl(String JavaDoc declName) {
638         return(XSElementDecl)fGlobalElemDecls.get(declName);
639     }
640
641     /**
642      * get one global group
643      */

644     public final XSGroupDecl getGlobalGroupDecl(String JavaDoc declName) {
645         return(XSGroupDecl)fGlobalGroupDecls.get(declName);
646     }
647
648     /**
649      * get one global notation
650      */

651     public final XSNotationDecl getGlobalNotationDecl(String JavaDoc declName) {
652         return(XSNotationDecl)fGlobalNotationDecls.get(declName);
653     }
654
655     /**
656      * get one global type
657      */

658     public final XSTypeDefinition getGlobalTypeDecl(String JavaDoc declName) {
659         return(XSTypeDefinition)fGlobalTypeDecls.get(declName);
660     }
661
662     /**
663      * get one identity constraint
664      */

665     public final IdentityConstraint getIDConstraintDecl(String JavaDoc declName) {
666         return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
667     }
668
669     /**
670      * get one identity constraint
671      */

672     public final boolean hasIDConstraints() {
673         return fGlobalIDConstraintDecls.getLength() > 0;
674     }
675
676     // array to store complex type decls
677
private static final int INITIAL_SIZE = 16;
678     private static final int INC_SIZE = 16;
679
680     private int fCTCount = 0;
681     private XSComplexTypeDecl[] fComplexTypeDecls = new XSComplexTypeDecl[INITIAL_SIZE];
682     private SimpleLocator[] fCTLocators = new SimpleLocator[INITIAL_SIZE];
683
684     // an array to store groups being redefined by restriction
685
// even-numbered elements are the derived groups, odd-numbered ones their bases
686
private static final int REDEFINED_GROUP_INIT_SIZE = 2;
687     private int fRGCount = 0;
688     private XSGroupDecl[] fRedefinedGroupDecls = new XSGroupDecl[REDEFINED_GROUP_INIT_SIZE];
689     private SimpleLocator[] fRGLocators = new SimpleLocator[REDEFINED_GROUP_INIT_SIZE/2];
690
691     // a flag to indicate whether we have checked the 3 constraints on this
692
// grammar.
693
boolean fFullChecked = false;
694
695     /**
696      * add one complex type decl: for later constraint checking
697      */

698     public void addComplexTypeDecl(XSComplexTypeDecl decl, SimpleLocator locator) {
699         if (fCTCount == fComplexTypeDecls.length) {
700             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE);
701             fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE);
702         }
703         fCTLocators[fCTCount] = locator;
704         fComplexTypeDecls[fCTCount++] = decl;
705     }
706
707     /**
708      * add a group redefined by restriction: for later constraint checking
709      */

710     public void addRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, SimpleLocator locator) {
711         if (fRGCount == fRedefinedGroupDecls.length) {
712             // double array size each time.
713
fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1);
714             fRGLocators = resize(fRGLocators, fRGCount);
715         }
716         fRGLocators[fRGCount/2] = locator;
717         fRedefinedGroupDecls[fRGCount++] = derived;
718         fRedefinedGroupDecls[fRGCount++] = base;
719     }
720
721     /**
722      * get all complex type decls: for later constraint checking
723      */

724     final XSComplexTypeDecl[] getUncheckedComplexTypeDecls() {
725         if (fCTCount < fComplexTypeDecls.length) {
726             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
727             fCTLocators = resize(fCTLocators, fCTCount);
728         }
729         return fComplexTypeDecls;
730     }
731
732     /**
733      * get the error locator of all complex type decls
734      */

735     final SimpleLocator[] getUncheckedCTLocators() {
736         if (fCTCount < fCTLocators.length) {
737             fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
738             fCTLocators = resize(fCTLocators, fCTCount);
739         }
740         return fCTLocators;
741     }
742
743     /**
744      * get all redefined groups: for later constraint checking
745      */

746     final XSGroupDecl[] getRedefinedGroupDecls() {
747         if (fRGCount < fRedefinedGroupDecls.length) {
748             fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
749             fRGLocators = resize(fRGLocators, fRGCount/2);
750         }
751         return fRedefinedGroupDecls;
752     }
753
754     /**
755      * get the error locator of all redefined groups
756      */

757     final SimpleLocator[] getRGLocators() {
758         if (fRGCount < fRedefinedGroupDecls.length) {
759             fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
760             fRGLocators = resize(fRGLocators, fRGCount/2);
761         }
762         return fRGLocators;
763     }
764
765     /**
766      * after the first-round checking, some types don't need to be checked
767      * against UPA again. here we trim the array to the proper size.
768      */

769     final void setUncheckedTypeNum(int newSize) {
770         fCTCount = newSize;
771         fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
772         fCTLocators = resize(fCTLocators, fCTCount);
773     }
774
775     // used to store all substitution group information declared in
776
// this namespace
777
private int fSubGroupCount = 0;
778     private XSElementDecl[] fSubGroups = new XSElementDecl[INITIAL_SIZE];
779
780     /**
781      * get all substitution group information: for the 3 constraint checking
782      */

783     final XSElementDecl[] getSubstitutionGroups() {
784         if (fSubGroupCount < fSubGroups.length)
785             fSubGroups = resize(fSubGroups, fSubGroupCount);
786         return fSubGroups;
787     }
788
789     // anyType and anySimpleType: because there are so many places where
790
// we need direct access to these two types
791
public final static XSComplexTypeDecl fAnyType = new XSAnyType();
792     private static class XSAnyType extends XSComplexTypeDecl {
793         public XSAnyType () {
794             fName = SchemaSymbols.ATTVAL_ANYTYPE;
795             super.fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
796             fBaseType = this;
797             fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
798             fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED;
799
800             fParticle = null;
801             fAttrGrp = null;
802         }
803
804         // overridden methods
805
public void setValues(String JavaDoc name, String JavaDoc targetNamespace,
806                 XSTypeDefinition baseType, short derivedBy, short schemaFinal,
807                 short block, short contentType,
808                 boolean isAbstract, XSAttributeGroupDecl attrGrp,
809                 XSSimpleType simpleType, XSParticleDecl particle) {
810             // don't allow this.
811
}
812
813         public void setName(String JavaDoc name){
814             // don't allow this.
815
}
816
817         public void setIsAbstractType() {
818             // null implementation
819
}
820
821         public void setContainsTypeID() {
822             // null implementation
823
}
824
825         public void setIsAnonymous() {
826             // null implementation
827
}
828
829         public void reset() {
830             // null implementation
831
}
832
833         public XSObjectList getAttributeUses() {
834             return new XSObjectListImpl(null, 0);
835         }
836
837         public XSAttributeGroupDecl getAttrGrp() {
838             XSWildcardDecl wildcard = new XSWildcardDecl();
839             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
840             XSAttributeGroupDecl attrGrp = new XSAttributeGroupDecl();
841             attrGrp.fAttributeWC = wildcard;
842             return attrGrp;
843         }
844
845         public XSWildcard getAttributeWildcard() {
846             XSWildcardDecl wildcard = new XSWildcardDecl();
847             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
848             return wildcard;
849         }
850
851         public XSParticle getParticle() {
852             // the wildcard used in anyType (content and attribute)
853
// the spec will change strict to skip for anyType
854
XSWildcardDecl wildcard = new XSWildcardDecl();
855             wildcard.fProcessContents = XSWildcardDecl.PC_LAX;
856             // the particle for the content wildcard
857
XSParticleDecl particleW = new XSParticleDecl();
858             particleW.fMinOccurs = 0;
859             particleW.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
860             particleW.fType = XSParticleDecl.PARTICLE_WILDCARD;
861             particleW.fValue = wildcard;
862             // the model group of a sequence of the above particle
863
XSModelGroupImpl group = new XSModelGroupImpl();
864             group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
865             group.fParticleCount = 1;
866             group.fParticles = new XSParticleDecl[1];
867             group.fParticles[0] = particleW;
868             // the content of anyType: particle of the above model group
869
XSParticleDecl particleG = new XSParticleDecl();
870             particleG.fType = XSParticleDecl.PARTICLE_MODELGROUP;
871             particleG.fValue = group;
872         
873             return particleG;
874         }
875
876         public XSObjectList getAnnotations() {
877             return null;
878         }
879     }
880     private static class BuiltinAttrDecl extends XSAttributeDecl {
881         public BuiltinAttrDecl(String JavaDoc name, String JavaDoc tns,
882                 XSSimpleType type, short scope) {
883             fName = name;
884             super.fTargetNamespace = tns;
885             fType = type;
886             fScope = scope;
887         }
888
889         public void setValues(String JavaDoc name, String JavaDoc targetNamespace,
890                 XSSimpleType simpleType, short constraintType, short scope,
891                 ValidatedInfo valInfo, XSComplexTypeDecl enclosingCT) {
892             // ignore this call.
893
}
894
895         public void reset () {
896             // also ignore this call.
897
}
898         public XSAnnotation getAnnotation() {
899             return null;
900         }
901     } // class BuiltinAttrDecl
902

903     // the grammars to hold components of the schema namespace
904
public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS);
905     
906     public final static Schema4Annotations SG_Schema4Annotations = new Schema4Annotations();
907
908     public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
909
910     // the grammars to hold components of the schema-instance namespace
911
public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI);
912
913     static final XSComplexTypeDecl[] resize(XSComplexTypeDecl[] oldArray, int newSize) {
914         XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
915         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
916         return newArray;
917     }
918
919     static final XSGroupDecl[] resize(XSGroupDecl[] oldArray, int newSize) {
920         XSGroupDecl[] newArray = new XSGroupDecl[newSize];
921         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
922         return newArray;
923     }
924
925     static final XSElementDecl[] resize(XSElementDecl[] oldArray, int newSize) {
926         XSElementDecl[] newArray = new XSElementDecl[newSize];
927         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
928         return newArray;
929     }
930
931     static final SimpleLocator[] resize(SimpleLocator[] oldArray, int newSize) {
932         SimpleLocator[] newArray = new SimpleLocator[newSize];
933         System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
934         return newArray;
935     }
936
937     // XSNamespaceItem methods
938

939     // the max index / the max value of XSObject type
940
private static final short MAX_COMP_IDX = XSTypeDefinition.SIMPLE_TYPE;
941     private static final boolean[] GLOBAL_COMP = {false, // null
942
true, // attribute
943
true, // element
944
true, // type
945
false, // attribute use
946
true, // attribute group
947
true, // group
948
false, // model group
949
false, // particle
950
false, // wildcard
951
false, // idc
952
true, // notation
953
false, // annotation
954
false, // facet
955
false, // multi value facet
956
true, // complex type
957
true // simple type
958
};
959                                                  
960     // store a certain kind of components from all namespaces
961
private XSNamedMap[] fComponents = null;
962
963     // store the documents and their locations contributing to this namespace
964
// REVISIT: use StringList and XSObjectList for there fields.
965
private Vector JavaDoc fDocuments = null;
966     private Vector JavaDoc fLocations = null;
967     
968     public synchronized void addDocument(Object JavaDoc document, String JavaDoc location) {
969         if (fDocuments == null) {
970             fDocuments = new Vector JavaDoc();
971             fLocations = new Vector JavaDoc();
972         }
973         fDocuments.addElement(document);
974         fLocations.addElement(location);
975     }
976     
977     /**
978      * [schema namespace]
979      * @see <a HREF="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a>
980      * @return The target namespace of this item.
981      */

982     public String JavaDoc getSchemaNamespace() {
983         return fTargetNamespace;
984     }
985
986     // annotation support
987
synchronized DOMParser getDOMParser() {
988         if (fDOMParser != null) return fDOMParser;
989         // REVISIT: when schema handles XML 1.1, will need to
990
// revisit this (and the practice of not prepending an XML decl to the annotation string
991
IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable);
992         // note that this should never produce errors or require
993
// entity resolution, so just a barebones configuration with
994
// a couple of feature set will do fine
995
config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
996         config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
997         fDOMParser = new DOMParser(config);
998         return fDOMParser;
999     }
1000
1001    synchronized SAXParser getSAXParser() {
1002        if (fSAXParser != null) return fSAXParser;
1003        // REVISIT: when schema handles XML 1.1, will need to
1004
// revisit this (and the practice of not prepending an XML decl to the annotation string
1005
IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable);
1006        // note that this should never produce errors or require
1007
// entity resolution, so just a barebones configuration with
1008
// a couple of feature set will do fine
1009
config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
1010        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
1011        fSAXParser = new SAXParser(config);
1012        return fSAXParser;
1013    }
1014
1015    /**
1016     * [schema components]: a list of top-level components, i.e. element
1017     * declarations, attribute declarations, etc.
1018     * @param objectType The type of the declaration, i.e.
1019     * <code>ELEMENT_DECLARATION</code>. Note that
1020     * <code>XSTypeDefinition.SIMPLE_TYPE</code> and
1021     * <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
1022     * <code>objectType</code> to retrieve only complex types or simple
1023     * types, instead of all types.
1024     * @return A list of top-level definition of the specified type in
1025     * <code>objectType</code> or an empty <code>XSNamedMap</code> if no
1026     * such definitions exist.
1027     */

1028    public synchronized XSNamedMap getComponents(short objectType) {
1029        if (objectType <= 0 || objectType > MAX_COMP_IDX ||
1030            !GLOBAL_COMP[objectType]) {
1031            return XSNamedMapImpl.EMPTY_MAP;
1032        }
1033        
1034        if (fComponents == null)
1035            fComponents = new XSNamedMap[MAX_COMP_IDX+1];
1036
1037        // get the hashtable for this type of components
1038
if (fComponents[objectType] == null) {
1039            SymbolHash table = null;
1040            switch (objectType) {
1041            case XSConstants.TYPE_DEFINITION:
1042            case XSTypeDefinition.COMPLEX_TYPE:
1043            case XSTypeDefinition.SIMPLE_TYPE:
1044                table = fGlobalTypeDecls;
1045                break;
1046            case XSConstants.ATTRIBUTE_DECLARATION:
1047                table = fGlobalAttrDecls;
1048                break;
1049            case XSConstants.ELEMENT_DECLARATION:
1050                table = fGlobalElemDecls;
1051                break;
1052            case XSConstants.ATTRIBUTE_GROUP:
1053                table = fGlobalAttrGrpDecls;
1054                break;
1055            case XSConstants.MODEL_GROUP_DEFINITION:
1056                table = fGlobalGroupDecls;
1057                break;
1058            case XSConstants.NOTATION_DECLARATION:
1059                table = fGlobalNotationDecls;
1060                break;
1061            }
1062            
1063            // for complex/simple types, create a special implementation,
1064
// which take specific types out of the hash table
1065
if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
1066                objectType == XSTypeDefinition.SIMPLE_TYPE) {
1067                fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
1068            }
1069            else {
1070                fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
1071            }
1072        }
1073        
1074        return fComponents[objectType];
1075    }
1076
1077    /**
1078     * Convenience method. Returns a top-level simple or complex type
1079     * definition.
1080     * @param name The name of the definition.
1081     * @return An <code>XSTypeDefinition</code> or null if such definition
1082     * does not exist.
1083     */

1084    public XSTypeDefinition getTypeDefinition(String JavaDoc name) {
1085        return getGlobalTypeDecl(name);
1086    }
1087
1088    /**
1089     * Convenience method. Returns a top-level attribute declaration.
1090     * @param name The name of the declaration.
1091     * @return A top-level attribute declaration or null if such declaration
1092     * does not exist.
1093     */

1094    public XSAttributeDeclaration getAttributeDeclaration(String JavaDoc name) {
1095        return getGlobalAttributeDecl(name);
1096    }
1097
1098    /**
1099     * Convenience method. Returns a top-level element declaration.
1100     * @param name The name of the declaration.
1101     * @return A top-level element declaration or null if such declaration
1102     * does not exist.
1103     */

1104    public XSElementDeclaration getElementDeclaration(String JavaDoc name) {
1105        return getGlobalElementDecl(name);
1106    }
1107
1108    /**
1109     * Convenience method. Returns a top-level attribute group definition.
1110     * @param name The name of the definition.
1111     * @return A top-level attribute group definition or null if such
1112     * definition does not exist.
1113     */

1114    public XSAttributeGroupDefinition getAttributeGroup(String JavaDoc name) {
1115        return getGlobalAttributeGroupDecl(name);
1116    }
1117
1118    /**
1119     * Convenience method. Returns a top-level model group definition.
1120     *
1121     * @param name The name of the definition.
1122     * @return A top-level model group definition definition or null if such
1123     * definition does not exist.
1124     */

1125    public XSModelGroupDefinition getModelGroupDefinition(String JavaDoc name) {
1126        return getGlobalGroupDecl(name);
1127    }
1128
1129    /**
1130     * Convenience method. Returns a top-level notation declaration.
1131     *
1132     * @param name The name of the declaration.
1133     * @return A top-level notation declaration or null if such declaration
1134     * does not exist.
1135     */

1136    public XSNotationDeclaration getNotationDeclaration(String JavaDoc name) {
1137        return getGlobalNotationDecl(name);
1138    }
1139
1140
1141    /**
1142     * [document location]
1143     * @see <a HREF="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a>
1144     * @return a list of document information item
1145     */

1146    public StringList getDocumentLocations() {
1147        return new StringListImpl(fLocations);
1148    }
1149    
1150    /**
1151     * Return an <code>XSModel</code> that represents components in this schema
1152     * grammar.
1153     *
1154     * @return an <code>XSModel</code> representing this schema grammar
1155     */

1156    public XSModel toXSModel() {
1157        return new XSModelImpl(new SchemaGrammar[]{this});
1158    }
1159
1160    public XSModel toXSModel(XSGrammar[] grammars) {
1161        if (grammars == null || grammars.length == 0)
1162            return toXSModel();
1163
1164        int len = grammars.length;
1165        boolean hasSelf = false;
1166        for (int i = 0; i < len; i++) {
1167            if (grammars[i] == this) {
1168                hasSelf = true;
1169                break;
1170            }
1171        }
1172
1173        SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1];
1174        for (int i = 0; i < len; i++)
1175            gs[i] = (SchemaGrammar)grammars[i];
1176        if (!hasSelf)
1177            gs[len] = this;
1178        return new XSModelImpl(gs);
1179    }
1180
1181    /**
1182     * @see org.apache.xerces.xs.XSNamespaceItem#getAnnotations()
1183     */

1184    public XSObjectList getAnnotations() {
1185        return new XSObjectListImpl(fAnnotations, fNumAnnotations);
1186    }
1187
1188    public void addAnnotation(XSAnnotationImpl annotation) {
1189        if(annotation == null)
1190            return;
1191        if(fAnnotations == null) {
1192            fAnnotations = new XSAnnotationImpl[2];
1193        } else if(fNumAnnotations == fAnnotations.length) {
1194            XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1];
1195            System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations);
1196            fAnnotations = newArray;
1197        }
1198        fAnnotations[fNumAnnotations++] = annotation;
1199    }
1200
1201} // class SchemaGrammar
1202
Popular Tags