* Special constructor to create the grammars for the schema namespaces
*
* @param grammar
*/
public BuiltinSchemaGrammar(int grammar, short schemaVersion) {
SchemaDVFactory schemaFactory;
if (schemaVersion == Constants.SCHEMA_VERSION_1_0) {
schemaFactory = SchemaDVFactory.getInstance();
}
else if (schemaVersion == Constants.SCHEMA_VERSION_1_1) {
schemaFactory = SchemaDVFactory.getInstance(SCHEMA11_FACTORY_CLASS);
}
else {
schemaFactory = SchemaDVFactory.getInstance(EXTENDED_SCHEMA_FACTORY_CLASS);
}
if (grammar == GRAMMAR_XS) {
// target namespace
fTargetNamespace = SchemaSymbols.URI_SCHEMAFORSCHEMA;
// grammar description
fGrammarDescription = new XSDDescription();
fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
fGrammarDescription.setNamespace(SchemaSymbols.URI_SCHEMAFORSCHEMA);
// no global decls other than types
fGlobalAttrDecls = new SymbolHash(1);
fGlobalAttrGrpDecls = new SymbolHash(1);
fGlobalElemDecls = new SymbolHash(1);
fGlobalGroupDecls = new SymbolHash(1);
fGlobalNotationDecls = new SymbolHash(1);
fGlobalIDConstraintDecls = new SymbolHash(1);
// no extended global decls
fGlobalAttrDeclsExt = new SymbolHash(1);
fGlobalAttrGrpDeclsExt = new SymbolHash(1);
fGlobalElemDeclsExt = new SymbolHash(1);
fGlobalGroupDeclsExt = new SymbolHash(1);
fGlobalNotationDeclsExt = new SymbolHash(1);
fGlobalIDConstraintDeclsExt = new SymbolHash(1);
fGlobalTypeDeclsExt = new SymbolHash(1);
// all global element decls table
fAllGlobalElemDecls = new SymbolHash(1);
// get all built-in types
fGlobalTypeDecls = schemaFactory.getBuiltInTypes();
// assign the built-in schema grammar as the XSNamespaceItem
// for each of the built-in simple type definitions.
int length = fGlobalTypeDecls.getLength();
XSTypeDefinition [] typeDefinitions = new XSTypeDefinition[length];
fGlobalTypeDecls.getValues(typeDefinitions, 0);
for (int i = 0; i < length; ++i) {
XSTypeDefinition xtd = typeDefinitions[i];
if (xtd instanceof XSSimpleTypeDecl) {
((XSSimpleTypeDecl) xtd).setNamespaceItem(this);
}
}
// add anyType
final XSComplexTypeDecl anyType = getXSAnyType(schemaVersion);
fGlobalTypeDecls.put(anyType.getName(), anyType);
}
else if (grammar == GRAMMAR_XSI) {
// target namespace
fTargetNamespace = SchemaSymbols.URI_XSI;
// grammar description
fGrammarDescription = new XSDDescription();
fGrammarDescription.fContextType = XSDDescription.CONTEXT_PREPARSE;
fGrammarDescription.setNamespace(SchemaSymbols.URI_XSI);
// no global decls other than attributes
fGlobalAttrGrpDecls = new SymbolHash(1);
fGlobalElemDecls = new SymbolHash(1);
fGlobalGroupDecls = new SymbolHash(1);
fGlobalNotationDecls = new SymbolHash(1);
fGlobalIDConstraintDecls = new SymbolHash(1);
fGlobalTypeDecls = new SymbolHash(1);
// no extended global decls
fGlobalAttrDeclsExt = new SymbolHash(1);
fGlobalAttrGrpDeclsExt = new SymbolHash(1);
fGlobalElemDeclsExt = new SymbolHash(1);
fGlobalGroupDeclsExt = new SymbolHash(1);
fGlobalNotationDeclsExt = new SymbolHash(1);
fGlobalIDConstraintDeclsExt = new SymbolHash(1);
fGlobalTypeDeclsExt = new SymbolHash(1);
// no all global element decls
fAllGlobalElemDecls = new SymbolHash(1);
// 4 attributes, so initialize the size as 4*2 = 8
fGlobalAttrDecls = new SymbolHash(8);
String name = null;
String tns = null;
XSSimpleType type = null;
short scope = XSConstants.SCOPE_GLOBAL;
// xsi:type
name = SchemaSymbols.XSI_TYPE;
tns = SchemaSymbols.URI_XSI;
type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_QNAME);
fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
// xsi:nil
name = SchemaSymbols.XSI_NIL;
tns = SchemaSymbols.URI_XSI;
type = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_BOOLEAN);
fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));
XSSimpleType anyURI = schemaFactory.getBuiltInType(SchemaSymbols.ATTVAL_ANYURI);
// xsi:schemaLocation
name = SchemaSymbols.XSI_SCHEMALOCATION;
tns = SchemaSymbols.URI_XSI;
type = schemaFactory.createTypeList("#AnonType_schemaLocation", SchemaSymbols.URI_XSI, (short)0, anyURI, null);
if (type instanceof XSSimpleTypeDecl) {
((XSSimpleTypeDecl)type).setAnonymous(true);
}
fGlobalAttrDecls.put(name, new BuiltinAttrDecl(name, tns, type, scope));