Пример #1
0
        private void FillAttributeFieldValue(object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, object identity, IXmlLineInfo lineInfo, int depth)
        {
            if (this.FieldFound)
            {
                throw new ValException(String.Format("The key value was already found as '{0}'{1}.", Identity,
                                                     (this.FieldHasLineInfo ?
                                                      String.Format(CultureInfo.InvariantCulture, " at line {0}, position {1}", FieldLineNumber, FieldLinePosition) :
                                                      "")),
                                       sender, sourceUri, entry.OwnerSequence.SourceSchemaIdentity, null);
            }
            XmlSchemaDatatype   dt = schemaType as XmlSchemaDatatype;
            XmlSchemaSimpleType st = schemaType as XmlSchemaSimpleType;

            if (dt == null && st != null)
            {
                dt = st.Datatype;
            }
            try {
                if (!this.SetIdentityField(identity, false, dt as XsdAnySimpleType, depth, lineInfo))
                {
                    throw new ValException("Two or more identical field was found.",
                                           sender, sourceUri, entry.OwnerSequence.SourceSchemaIdentity, null);
                }
                // HACK: This is not logical. Attributes will never be "cosuming",
                // so I used it as a temporary mark to sign it is validated *just now*.
                this.Consuming  = true;
                this.FieldFound = true;
            } catch (Exception ex) {
                throw new ValException("Failed to read typed value.", sender, sourceUri, entry.OwnerSequence.SourceSchemaIdentity, ex);
            }
        }
Пример #2
0
        // In this method, attributes are ignored.
        // It might throw Exception.
        public void ProcessMatch(bool isAttribute, ArrayList qnameStack, object sender, XmlNameTable nameTable, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo li, int depth, string attrName, string attrNS, object attrValue, bool isXsiNil, ArrayList currentKeyFieldConsumers)
        {
            for (int i = 0; i < KeyFields.Count; i++)
            {
                XsdKeyEntryField keyField = KeyFields [i];
                XsdIdentityPath  path     = keyField.Matches(isAttribute, sender, nameTable, qnameStack, sourceUri, schemaType, nsResolver, li, depth, attrName, attrNS, attrValue);
                if (path == null)
                {
                    continue;
                }

                if (keyField.FieldFound)
                {
                    // HACK: This is not logical by nature. Attributes never be cosuming,
                    // so I used it as a temporary mark to sign it is *just* validated now.
                    if (!keyField.Consuming)
                    {
                        throw new ValException("Two or more matching field was found.",
                                               sender, sourceUri, this.OwnerSequence.SourceSchemaIdentity, null);
                    }
                    else
                    {
                        keyField.Consuming = false;
                    }
                }
                if (keyField.Consumed)
                {
                    continue;
                }

                if (isXsiNil && !keyField.SetIdentityField(Guid.Empty, true, XsdAnySimpleType.Instance, depth, li))
                {
                    throw new ValException("Two or more identical field was found.", sender, sourceUri, OwnerSequence.SourceSchemaIdentity, null);
                }
                XmlSchemaComplexType ct = schemaType as XmlSchemaComplexType;
                if (ct != null &&
                    (ct.ContentType == XmlSchemaContentType.Empty || ct.ContentType == XmlSchemaContentType.ElementOnly) &&
                    schemaType != XmlSchemaComplexType.AnyType)
                {
                    throw new ValException("Specified schema type is complex type, which is not allowed for identity constraints.", sender, sourceUri, OwnerSequence.SourceSchemaIdentity, null);
                }
                keyField.FieldFound      = true;
                keyField.FieldFoundPath  = path;
                keyField.FieldFoundDepth = depth;
                keyField.Consuming       = true;
                if (li != null && li.HasLineInfo())
                {
                    keyField.FieldHasLineInfo  = true;
                    keyField.FieldLineNumber   = li.LineNumber;
                    keyField.FieldLinePosition = li.LinePosition;
                }
                currentKeyFieldConsumers.Add(keyField);
            }
        }
Пример #3
0
        // if matchesAttr then check attributes; otherwise check elements.
        internal XsdIdentityPath Matches(bool matchesAttr, object sender, XmlNameTable nameTable, ArrayList qnameStack, string sourceUri, object schemaType, NSResolver nsResolver, IXmlLineInfo lineInfo, int depth, string attrName, string attrNS, object attrValue)
        {
            XsdIdentityPath matchedAttrPath = null;

            for (int i = 0; i < field.Paths.Length; i++)
            {
                XsdIdentityPath path        = field.Paths [i];
                bool            isAttribute = path.IsAttribute;
                if (matchesAttr != isAttribute)
                {
                    continue;
                }
                XsdIdentityStep step;
                if (path.IsAttribute)
                {
                    step = path.OrderedSteps [path.OrderedSteps.Length - 1];
                    bool match = false;
                    if (step.IsAnyName || step.NsName != null)
                    {
                        if (step.IsAnyName || attrNS == step.NsName)
                        {
                            match = true;
                        }
                    }
                    else if (step.Name == attrName && step.Namespace == attrNS)
                    {
                        match = true;
                    }
                    if (!match)
                    {
                        continue;
                    }
                    // first -1 is to reduce attr path step, next -1 is to reduce Attribute's depth in XmlReader.
                    if (entry.StartDepth + (path.OrderedSteps.Length - 1) != depth - 1)
                    {
                        continue;                         // matched at different nest level
                    }
                    matchedAttrPath = path;
                }
                if (FieldFound && (depth > this.FieldFoundDepth && this.FieldFoundPath == path))
                {
                    continue;                     // don't return; other fields might hit errorneously.
                }
                // Only "." hits.
                if (path.OrderedSteps.Length == 0)
                {
                    if (depth == entry.StartDepth)
                    {
                        return(path);
                    }
                    else
                    {
                        continue;
                    }
                }
                // It does not hit as yet (too shallow to hit).
                if (depth - entry.StartDepth < path.OrderedSteps.Length - 1)
                {
                    continue;
                }

                int iter = path.OrderedSteps.Length;
                if (isAttribute)
                {
                    iter--;
                }
                if (path.Descendants && depth < entry.StartDepth + iter)
                {
                    continue;
                }
                else if (!path.Descendants && depth != entry.StartDepth + iter)
                {
                    continue;
                }

                iter--;

                for (; iter >= 0; iter--)
                {
                    step = path.OrderedSteps [iter];
                    if (step.IsCurrent || step.IsAnyName)
                    {
                        continue;
                    }
                    XmlQualifiedName qname = (XmlQualifiedName)qnameStack [entry.StartDepth + iter + (isAttribute ? 0 : 1)];
                    if (step.NsName != null && qname.Namespace == step.NsName)
                    {
                        continue;
                    }
                    if ((step.Name == "*" || step.Name == qname.Name) &&
                        step.Namespace == qname.Namespace)
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                if (iter >= 0)                  // i.e. did not match against the path.
                {
                    continue;
                }

                if (!matchesAttr)
                {
                    return(path);
                }
            }
            if (matchedAttrPath != null)
            {
                this.FillAttributeFieldValue(sender, nameTable, sourceUri, schemaType, nsResolver, attrValue, lineInfo, depth);
                if (this.Identity != null)
                {
                    return(matchedAttrPath);
                }
            }
            return(null);
        }