internal ConstraintStruct(CompiledIdentityConstraint constraint)
 {
     this.constraint     = constraint;
     this.tableDim       = constraint.Fields.Length;
     this.axisFields     = new ArrayList();          // empty fields
     this.axisSelector   = new SelectorActiveAxis(constraint.Selector, this);
     this.qualifiedTable = new Hashtable();
 }
 internal ConstraintStruct (CompiledIdentityConstraint constraint) {
     this.constraint = constraint;
     this.tableDim = constraint.Fields.Length;
     this.axisFields = new ArrayList();              // empty fields
     this.axisSelector = new SelectorActiveAxis (constraint.Selector, this);
     if (this.constraint.Role != CompiledIdentityConstraint.ConstraintRole.Keyref) {
         this.qualifiedTable = new Hashtable();
     }
 }
Exemplo n.º 3
0
 internal ConstraintStruct (CompiledIdentityConstraint constraint) {
     this.constraint = constraint;
     this.tableDim = constraint.Fields.Length;
     this.constraintTable = new ArrayList();         // empty table
     this.currentRow = 0;
     this.axisFields = new ArrayList();              // empty fields
     this.axisSelector = new ActiveAxis (constraint.Selector);
     this.qualifiedTable = new Hashtable();
 
 }
 private void CompileIdentityConstraint(XmlSchemaIdentityConstraint xi)
 {
     if (xi.IsProcessing)
     {
         xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         base.SendValidationEvent("Sch_IdentityConstraintCircularRef", xi);
     }
     else if (xi.CompiledConstraint == null)
     {
         xi.IsProcessing = true;
         CompiledIdentityConstraint constraint = null;
         try
         {
             SchemaNamespaceManager nsmgr = new SchemaNamespaceManager(xi);
             constraint = new CompiledIdentityConstraint(xi, nsmgr);
             if (xi is XmlSchemaKeyref)
             {
                 XmlSchemaIdentityConstraint constraint2 = (XmlSchemaIdentityConstraint) this.schema.IdentityConstraints[((XmlSchemaKeyref) xi).Refer];
                 if (constraint2 == null)
                 {
                     throw new XmlSchemaException("Sch_UndeclaredIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 this.CompileIdentityConstraint(constraint2);
                 if (constraint2.CompiledConstraint == null)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidIdentityConstraint", ((XmlSchemaKeyref) xi).Refer.ToString(), xi);
                 }
                 if (constraint2.Fields.Count != xi.Fields.Count)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidCardin", xi.QualifiedName.ToString(), xi);
                 }
                 if (constraint2.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref)
                 {
                     throw new XmlSchemaException("Sch_ReftoKeyref", xi.QualifiedName.ToString(), xi);
                 }
             }
             xi.CompiledConstraint = constraint;
         }
         catch (XmlSchemaException exception)
         {
             if (exception.SourceSchemaObject == null)
             {
                 exception.SetSource(xi);
             }
             base.SendValidationEvent(exception);
             xi.CompiledConstraint = CompiledIdentityConstraint.Empty;
         }
         finally
         {
             xi.IsProcessing = false;
         }
     }
 }
 private void CompileElement(XmlSchemaElement xe)
 {
     if (xe.IsProcessing)
     {
         base.SendValidationEvent("Sch_ElementCircularRef", xe);
     }
     else if (xe.ElementDecl == null)
     {
         xe.IsProcessing = true;
         SchemaElementDecl decl = null;
         try
         {
             if (!xe.RefName.IsEmpty)
             {
                 XmlSchemaElement element = (XmlSchemaElement) this.schema.Elements[xe.RefName];
                 if (element == null)
                 {
                     throw new XmlSchemaException("Sch_UndeclaredElement", xe.RefName.ToString(), xe);
                 }
                 this.CompileElement(element);
                 if (element.ElementDecl == null)
                 {
                     throw new XmlSchemaException("Sch_RefInvalidElement", xe.RefName.ToString(), xe);
                 }
                 xe.SetElementType(element.ElementSchemaType);
                 decl = element.ElementDecl.Clone();
             }
             else
             {
                 if (xe.SchemaType != null)
                 {
                     xe.SetElementType(xe.SchemaType);
                 }
                 else if (!xe.SchemaTypeName.IsEmpty)
                 {
                     xe.SetElementType(this.GetAnySchemaType(xe.SchemaTypeName));
                     if (xe.ElementSchemaType == null)
                     {
                         throw new XmlSchemaException("Sch_UndeclaredType", xe.SchemaTypeName.ToString(), xe);
                     }
                 }
                 else if (!xe.SubstitutionGroup.IsEmpty)
                 {
                     XmlSchemaElement element2 = (XmlSchemaElement) this.schema.Elements[xe.SubstitutionGroup];
                     if (element2 == null)
                     {
                         throw new XmlSchemaException("Sch_UndeclaredEquivClass", xe.SubstitutionGroup.Name.ToString(CultureInfo.InvariantCulture), xe);
                     }
                     if (element2.IsProcessing)
                     {
                         return;
                     }
                     this.CompileElement(element2);
                     if (element2.ElementDecl == null)
                     {
                         xe.SetElementType(XmlSchemaComplexType.AnyType);
                         decl = XmlSchemaComplexType.AnyType.ElementDecl.Clone();
                     }
                     else
                     {
                         xe.SetElementType(element2.ElementSchemaType);
                         decl = element2.ElementDecl.Clone();
                     }
                 }
                 else
                 {
                     xe.SetElementType(XmlSchemaComplexType.AnyType);
                     decl = XmlSchemaComplexType.AnyType.ElementDecl.Clone();
                 }
                 if (decl == null)
                 {
                     if (xe.ElementSchemaType is XmlSchemaComplexType)
                     {
                         XmlSchemaComplexType complexType = (XmlSchemaComplexType) xe.ElementSchemaType;
                         this.CompileComplexType(complexType);
                         if (complexType.ElementDecl != null)
                         {
                             decl = complexType.ElementDecl.Clone();
                         }
                     }
                     else if (xe.ElementSchemaType is XmlSchemaSimpleType)
                     {
                         XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) xe.ElementSchemaType;
                         this.CompileSimpleType(simpleType);
                         if (simpleType.ElementDecl != null)
                         {
                             decl = simpleType.ElementDecl.Clone();
                         }
                     }
                 }
                 decl.Name = xe.QualifiedName;
                 decl.IsAbstract = xe.IsAbstract;
                 XmlSchemaComplexType elementSchemaType = xe.ElementSchemaType as XmlSchemaComplexType;
                 if (elementSchemaType != null)
                 {
                     decl.IsAbstract |= elementSchemaType.IsAbstract;
                 }
                 decl.IsNillable = xe.IsNillable;
                 decl.Block |= xe.BlockResolved;
             }
             if (decl.Datatype != null)
             {
                 decl.Datatype.VerifySchemaValid(this.schema.Notations, xe);
             }
             if (((xe.DefaultValue != null) || (xe.FixedValue != null)) && (decl.ContentValidator != null))
             {
                 if (decl.ContentValidator.ContentType == XmlSchemaContentType.TextOnly)
                 {
                     if (xe.DefaultValue != null)
                     {
                         decl.Presence = SchemaDeclBase.Use.Default;
                         decl.DefaultValueRaw = xe.DefaultValue;
                     }
                     else
                     {
                         decl.Presence = SchemaDeclBase.Use.Fixed;
                         decl.DefaultValueRaw = xe.FixedValue;
                     }
                     if (decl.Datatype != null)
                     {
                         decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, base.NameTable, new SchemaNamespaceManager(xe), true);
                     }
                 }
                 else if ((decl.ContentValidator.ContentType != XmlSchemaContentType.Mixed) || !decl.ContentValidator.IsEmptiable)
                 {
                     throw new XmlSchemaException("Sch_ElementCannotHaveValue", xe);
                 }
             }
             if (xe.HasConstraints)
             {
                 XmlSchemaObjectCollection constraints = xe.Constraints;
                 CompiledIdentityConstraint[] constraintArray = new CompiledIdentityConstraint[constraints.Count];
                 int num = 0;
                 for (int i = 0; i < constraints.Count; i++)
                 {
                     XmlSchemaIdentityConstraint xi = (XmlSchemaIdentityConstraint) constraints[i];
                     this.CompileIdentityConstraint(xi);
                     constraintArray[num++] = xi.CompiledConstraint;
                 }
                 decl.Constraints = constraintArray;
             }
             decl.SchemaElement = xe;
             xe.ElementDecl = decl;
         }
         catch (XmlSchemaException exception)
         {
             if (exception.SourceSchemaObject == null)
             {
                 exception.SetSource(xe);
             }
             base.SendValidationEvent(exception);
             xe.ElementDecl = SchemaElementDecl.Empty;
         }
         finally
         {
             xe.IsProcessing = false;
         }
     }
 }
        private void CompileElement(XmlSchemaElement xe) {
            if (xe.IsProcessing) {
                SendValidationEvent(Res.Sch_ElementCircularRef, xe);
                return;
            }
            if (xe.ElementDecl != null) {
                return;
            }
            xe.IsProcessing = true;
            SchemaElementDecl decl = null;
            try {
                if (!xe.RefName.IsEmpty) {
                    XmlSchemaElement e = (XmlSchemaElement)elements[xe.RefName];
                    if (e == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredElement, xe.RefName.ToString(), xe);
                    }  
                    CompileElement(e);
                    if (e.ElementDecl == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidElement, xe.RefName.ToString(), xe);
                    }
                    xe.SetElementType(e.ElementSchemaType);
                    decl = e.ElementDecl.Clone();
                }
                else {
                    if (xe.SchemaType != null) {
                        xe.SetElementType(xe.SchemaType);
                    }
                    else if (!xe.SchemaTypeName.IsEmpty) {
                        xe.SetElementType(GetAnySchemaType(xe.SchemaTypeName));
                        if (xe.ElementSchemaType == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredType, xe.SchemaTypeName.ToString(), xe);   
                        }
                    }
                    else  if (!xe.SubstitutionGroup.IsEmpty) {
                        XmlSchemaElement examplar = (XmlSchemaElement)elements[xe.SubstitutionGroup];
                        if (examplar == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredEquivClass, xe.SubstitutionGroup.Name.ToString(CultureInfo.InvariantCulture), xe);   
                        }
                        if (examplar.IsProcessing) { //Circular subst group; already detected by now
                            return;
                        }
                        CompileElement(examplar);
                        if (examplar.ElementDecl == null) { //If head is invalid, fall back to AnyType
                            xe.SetElementType(XmlSchemaComplexType.AnyType);
                            decl = XmlSchemaComplexType.AnyType.ElementDecl.Clone();
                        }
                        else {
                            xe.SetElementType(examplar.ElementSchemaType);
                            decl = examplar.ElementDecl.Clone();
                        }
                    }
                    else {
                        xe.SetElementType(XmlSchemaComplexType.AnyType);
                        decl = XmlSchemaComplexType.AnyType.ElementDecl.Clone();
                    }
            
                    if (decl == null) {
                        Debug.Assert(xe.ElementSchemaType != null);
                        if (xe.ElementSchemaType is XmlSchemaComplexType) {
                            XmlSchemaComplexType complexType = (XmlSchemaComplexType)xe.ElementSchemaType;
                            CompileComplexType(complexType);
                            if (complexType.ElementDecl != null) {
                                decl = complexType.ElementDecl.Clone();
//                                decl.LocalElements = complexType.LocalElementDecls;
                            }
                        } 
                        else if (xe.ElementSchemaType is XmlSchemaSimpleType) {
                            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)xe.ElementSchemaType;
                            CompileSimpleType(simpleType);
                            if (simpleType.ElementDecl != null) {
                                decl = simpleType.ElementDecl.Clone();
                            }
                        } 
                    }
                    Debug.Assert(decl != null);
                    decl.Name = xe.QualifiedName;
                    decl.IsAbstract = xe.IsAbstract;
                    XmlSchemaComplexType ct = xe.ElementSchemaType as XmlSchemaComplexType;
                    if (ct != null) {
                        decl.IsAbstract |= ct.IsAbstract; 
                    }
                    decl.IsNillable = xe.IsNillable;
                    decl.Block |= xe.BlockResolved;
                }
                if (decl.Datatype != null) {
                    decl.Datatype.VerifySchemaValid(notations, xe);
                }

                if (xe.DefaultValue != null || xe.FixedValue != null) {
                    if (decl.ContentValidator != null) {
                        if (decl.ContentValidator.ContentType == XmlSchemaContentType.TextOnly || (decl.ContentValidator.ContentType == XmlSchemaContentType.Mixed && decl.ContentValidator.IsEmptiable)) {
                            if (xe.DefaultValue != null) {
                                decl.Presence = SchemaDeclBase.Use.Default; 
                                decl.DefaultValueRaw = xe.DefaultValue;
                            }
                            else {
                                decl.Presence = SchemaDeclBase.Use.Fixed; 
                                decl.DefaultValueRaw = xe.FixedValue;
                            }
                            if (decl.Datatype != null) {
                                if (decl.Datatype.TypeCode == XmlTypeCode.Id) {
                                    SendValidationEvent(Res.Sch_DefaultIdValue, xe);
                                }
                                else {
                                    decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xe), true);
                                }
                            }
                            else { //Mixed with emptiable particle
                                decl.DefaultValueTyped = DatatypeImplementation.AnySimpleType.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xe));
                            }
                        }
                        else {
                            throw new XmlSchemaException(Res.Sch_ElementCannotHaveValue, xe);
                        }
                    }
                }
                if (xe.HasConstraints) {
                    XmlSchemaObjectCollection constraints = xe.Constraints;
                    CompiledIdentityConstraint[] compiledConstraints = new CompiledIdentityConstraint[constraints.Count];
                    int idx = 0;
                    for (int i = 0; i < constraints.Count; ++i) {
                        XmlSchemaIdentityConstraint constraint = (XmlSchemaIdentityConstraint)constraints[i];
                        CompileIdentityConstraint(constraint);
                        compiledConstraints[idx ++] = constraint.CompiledConstraint;
                    }
                    decl.Constraints = compiledConstraints;
                }
                decl.SchemaElement = xe; //So this is available for PSVI
                xe.ElementDecl = decl;
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xe);
                }
                SendValidationEvent(e);
                xe.ElementDecl = SchemaElementDecl.Empty;
            } 
            finally {
                xe.IsProcessing = false;
            }
        }
        private void CompileIdentityConstraint (XmlSchemaIdentityConstraint xi) { 
            if (xi.IsProcessing) {
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                SendValidationEvent(Res.Sch_IdentityConstraintCircularRef, xi);
                return;
            }

            if (xi.CompiledConstraint != null) {
                return;
            }
            
            xi.IsProcessing = true;
            CompiledIdentityConstraint compic = null;
            try {
                SchemaNamespaceManager xnmgr = new SchemaNamespaceManager(xi);
                compic = new CompiledIdentityConstraint(xi, xnmgr);
                if (xi is XmlSchemaKeyref) {
                    XmlSchemaIdentityConstraint ic = (XmlSchemaIdentityConstraint)this.identityConstraints[((XmlSchemaKeyref)xi).Refer];
                    if (ic == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }     
                    CompileIdentityConstraint(ic);
                    if (ic.CompiledConstraint == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidIdentityConstraint, ((XmlSchemaKeyref)xi).Refer.ToString(), xi);
                    }
                    // keyref has the different cardinality with the key it referred
                    if (ic.Fields.Count != xi.Fields.Count) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidCardin, xi.QualifiedName.ToString(), xi);
                    }
                    // keyref can only refer to key/unique
                    if (ic.CompiledConstraint.Role == CompiledIdentityConstraint.ConstraintRole.Keyref) {
                        throw new XmlSchemaException(Res.Sch_ReftoKeyref, xi.QualifiedName.ToString(), xi);
                    }
                }
                xi.CompiledConstraint = compic;
            }
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xi);
                }
                SendValidationEvent(e);
                xi.CompiledConstraint = CompiledIdentityConstraint.Empty;       
                // empty is better than null here, stop quickly when circle referencing
            } 
            finally {
                xi.IsProcessing = false;
            }

        }
Exemplo n.º 8
0
        private void CompileElement(XmlSchemaElement xe) {
            if (xe.Validating) {
                SendValidationEvent(Res.Sch_ElementCircularRef, xe);
                return;
            }
            if (xe.ElementDecl != null) {
                return;
            }
            xe.Validating = true;
            SchemaElementDecl decl = null;
            try {
                if (!xe.RefName.IsEmpty) {
                    XmlSchemaElement e = (XmlSchemaElement)this.schema.Elements[xe.RefName];
                    if (e == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredElement, xe.RefName.ToString(), xe);
                    }  
                    CompileElement(e);
                    if (e.ElementDecl == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidElement, xe.RefName.ToString(), xe);
                    }
                    xe.SetElementType(e.ElementType);
                    decl = e.ElementDecl.Clone();
                }
                else {
                    if (xe.SchemaType != null) {
                        xe.SetElementType(xe.SchemaType);
                    }
                    else if (!xe.SchemaTypeName.IsEmpty) {
                        XmlSchemaDatatype datatype;
                        xe.SetElementType(GetAnySchemaType(xe.SchemaTypeName, out datatype));
                        if (xe.ElementType == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredType, xe.SchemaTypeName.ToString(), xe);   
                        }
                    }
                    else  if (!xe.SubstitutionGroup.IsEmpty) {
                        XmlSchemaElement examplar = (XmlSchemaElement)this.schema.Elements[xe.SubstitutionGroup];
                        if (examplar == null) {
                            throw new XmlSchemaException(Res.Sch_UndeclaredEquivClass, xe.SubstitutionGroup.Name.ToString(), xe);   
                        }
                        CompileElement(examplar);
                        xe.SetElementType(examplar.ElementType);
                        decl = examplar.ElementDecl.Clone();
                    }
                    else {
                        xe.SetElementType(XmlSchemaDatatype.AnyType);
                        decl = SchemaElementDecl.CreateAnyTypeElementDecl();
                    }
            
                    if (decl == null) {
                        Debug.Assert(xe.ElementType != null);
                        if (xe.ElementType is XmlSchemaComplexType) {
                            XmlSchemaComplexType complexType = (XmlSchemaComplexType)xe.ElementType;
                            CompileComplexType(complexType);
                            if (complexType.ElementDecl != null) {
                                decl = complexType.ElementDecl.Clone();
                                decl.LocalElements = complexType.LocalElementDecls;
                            }
                        } 
                        else if (xe.ElementType is XmlSchemaSimpleType) {
                            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)xe.ElementType;
                            CompileSimpleType(simpleType);
                            if (simpleType.ElementDecl != null) {
                                decl = simpleType.ElementDecl.Clone();
                            }
                        } 
                        else {
                            decl = new SchemaElementDecl((XmlSchemaDatatype)xe.ElementType, this.schemaNames);
                        }
                    }
                    decl.Name = xe.QualifiedName;
                    decl.IsAbstract = xe.IsAbstract;
                    XmlSchemaComplexType ct = xe.ElementType as XmlSchemaComplexType;
                    if (ct != null) {
                        decl.IsAbstract |= ct.IsAbstract; 
                    }
                    decl.IsNillable = xe.IsNillable;
                    decl.Block |= xe.BlockResolved;
                }
                if (decl.Datatype != null) {
                    decl.Datatype.VerifySchemaValid(this.schema, xe);
                }

                if (xe.DefaultValue != null || xe.FixedValue != null) {
                    if (decl.Content.ContentType == CompiledContentModel.Type.Text) {
                        if (xe.DefaultValue != null) {
                            decl.Presence = SchemaDeclBase.Use.Default; 
                            decl.DefaultValueTyped = decl.Datatype.ParseValue(xe.DefaultValue, this.nameTable, this.namespaceManager);
                        }
                        else {
                            decl.Presence = SchemaDeclBase.Use.Fixed; 
                            decl.DefaultValueTyped = decl.Datatype.ParseValue(xe.FixedValue, this.nameTable, this.namespaceManager);
                        }
                    }
                    else if (decl.Content.ContentType != CompiledContentModel.Type.Mixed || !decl.Content.IsEmptiable) {
                        throw new XmlSchemaException(Res.Sch_ElementCannotHaveValue, xe);
                    }            
                }
                if (xe.HasConstraints) {
                    XmlSchemaObjectCollection constraints = xe.Constraints;
                    CompiledIdentityConstraint[] compiledConstraints = new CompiledIdentityConstraint[constraints.Count];
                    int idx = 0;
                    foreach(XmlSchemaIdentityConstraint constraint in constraints) {
                        CompileIdentityConstraint (constraint);
                        compiledConstraints[idx ++] = constraint.CompiledConstraint;
                    }
                    decl.Constraints = compiledConstraints;
                }
                xe.ElementDecl = decl;
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xe);
                }
                SendValidationEvent(e);
                xe.ElementDecl = SchemaElementDecl.Empty;
            } 
            finally {
                xe.Validating = false;
            }
        }