public bool Execute(XmlSchema schema, string targetNamespace, bool loadExternals) {
rootSchema = schema; //Need to lock main schema here
Xmlns = NameTable.Add("xmlns");
NsXsi = NameTable.Add(XmlReservedNs.NsXsi);
rootSchema.ImportedSchemas.Clear();
rootSchema.ImportedNamespaces.Clear();
//Add root schema to the schemaLocations table
if (rootSchema.BaseUri != null) {
if (schemaLocations[rootSchema.BaseUri] == null) {
schemaLocations.Add(rootSchema.BaseUri, rootSchema);
}
}
//Check targetNamespace for rootSchema
if (rootSchema.TargetNamespace != null) {
if (targetNamespace == null) {
targetNamespace = rootSchema.TargetNamespace;
}
else if (targetNamespace != rootSchema.TargetNamespace) {
SendValidationEvent(Res.Sch_MismatchTargetNamespaceEx, targetNamespace, rootSchema.TargetNamespace, rootSchema);
}
}
else if (targetNamespace != null && targetNamespace.Length != 0) { //if schema.TargetNamespace == null & targetNamespace != null, we will force the schema components into targetNamespace
rootSchema = GetChameleonSchema(targetNamespace, rootSchema); //Chameleon include at top-level
}
if (loadExternals && xmlResolver != null) {
LoadExternals(rootSchema);
}
BuildSchemaList(rootSchema);
int schemaIndex = 0;
XmlSchema listSchema;
try {
//Accquire locks on all schema objects; Need to lock only on pre-created schemas and not parsed schemas
for (schemaIndex = 0; schemaIndex < lockList.Count; schemaIndex++) {
listSchema = (XmlSchema)lockList.GetByIndex(schemaIndex);
Monitor.Enter(listSchema);
listSchema.IsProcessing = false; //Reset processing flag from LoadExternals
}
//Preprocess
rootSchemaForRedefine = rootSchema;
Preprocess(rootSchema, targetNamespace, rootSchema.ImportedSchemas);
if (redefinedList != null) { //If there were redefines
foreach (RedefineEntry redefineEntry in redefinedList) {
PreprocessRedefine(redefineEntry);
}
}
}
finally { //Releasing locks in finally block
if (schemaIndex == lockList.Count) {
schemaIndex--;
}
for (int i = schemaIndex; schemaIndex >= 0; schemaIndex--) {
listSchema = (XmlSchema)lockList.GetByIndex(schemaIndex);
listSchema.IsProcessing = false; //Reset processing flag from Preprocess
if (listSchema == Preprocessor.GetBuildInSchema()) { //dont re-set compiled flags for xml namespace schema
Monitor.Exit(listSchema);
continue;
}
listSchema.IsCompiledBySet = false;
listSchema.IsPreprocessed = !HasErrors;
Monitor.Exit(listSchema); //Release locks on all schema objects
}
}
rootSchema.IsPreprocessed = !HasErrors; //For chameleon at top-level
return !HasErrors;
}