internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas)
 {
     if (item == null)
     {
         return null;
     }
     if ((qname == null) || qname.IsEmpty)
     {
         return null;
     }
     string str = item.GetType().Name + ":" + qname.ToString();
     ArrayList list = (ArrayList) this.ObjectCache[str];
     if (list == null)
     {
         list = new ArrayList();
         this.ObjectCache[str] = list;
     }
     for (int i = 0; i < list.Count; i++)
     {
         XmlSchemaObject obj2 = (XmlSchemaObject) list[i];
         if (obj2 == item)
         {
             return obj2;
         }
         if (this.Match(obj2, item, true))
         {
             return obj2;
         }
         this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace }));
         this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string) this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string) this.looks[item]));
     }
     list.Add(item);
     return item;
 }
		public XsdValidationState Create (XmlSchemaObject xsobj)
		{
			string typeName = xsobj.GetType ().Name;
			switch (typeName) {
			case "XmlSchemaElement":
				return AddElement ((XmlSchemaElement) xsobj);
			case "XmlSchemaSequence":
				return AddSequence ((XmlSchemaSequence) xsobj);
			case "XmlSchemaChoice":
				return AddChoice ((XmlSchemaChoice) xsobj);
			case "XmlSchemaAll":
				return AddAll ((XmlSchemaAll) xsobj);
			case "XmlSchemaAny":
				return AddAny ((XmlSchemaAny) xsobj);
			case "EmptyParticle":
				return AddEmpty ();
			default:
				// GroupRef should not appear
				throw new InvalidOperationException ("Should not occur.");
			}
		}
Exemple #3
0
        /// <summary>
        /// Adds a schema item to the schema if the item is not a duplicate.
        /// </summary>
        /// <param name="schema">A Schema that the item may be added to.</param>
        /// <param name="item">A schema item to add.</param>
        /// <returns></returns>
        private bool AddSchemaItem(XmlSchema schema, XmlSchemaObject item)
        {
            bool conflictingTypes = false;
            bool isDuplicate = false;
            string itemName = null;
            if (item is XmlSchemaElement)
                itemName = ((XmlSchemaElement)item).Name;
            else if (item is XmlSchemaComplexType)
                itemName = ((XmlSchemaComplexType)item).Name;
            else if (item is XmlSchemaSimpleType)
                itemName = ((XmlSchemaSimpleType)item).Name;
            else
            {
                Logger.WriteLine("        Unsupported schema type " + item.GetType().ToString() + " detected.", LogLevel.Verbose);
                return false;
            }

            foreach (XmlSchemaObject obj in schema.Items)
            {
                if (obj is XmlSchemaElement)
                {
                    if (((XmlSchemaElement)obj).Name == itemName)
                    {
                        if (item is XmlSchemaElement)
                        {
                            XmlSchemaElement element = (XmlSchemaElement)item;
                            if (element.SchemaTypeName != ((XmlSchemaElement)obj).SchemaTypeName)
                                conflictingTypes = true;
                            isDuplicate = true;
                        }
                        else
                            conflictingTypes = true;    
                        break;
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    if (((XmlSchemaSimpleType)obj).Name == itemName)
                    {
                        if (item is XmlSchemaSimpleType)
                            isDuplicate = true;
                        else
                            conflictingTypes = true;
                        break;
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    if (((XmlSchemaComplexType)obj).Name == itemName)
                    {
                        if (item is XmlSchemaComplexType)
                            isDuplicate = true;
                        else
                            conflictingTypes = true;
                        break;
                    }
                }
            }
            
            // If conflicting type names are detected throw
            if (conflictingTypes)
            {
                string errMsg = "\nException: Conflicting parameter \"" + itemName + "\" detected in schema " + schema.TargetNamespace + ".";
                      errMsg += "Multiple operation parameters with the same name that reference different types results in invalid schema.";
                      errMsg += "Change the name of this parameter in code.";
                throw new Exception(errMsg);
            }

            // If this is a new item add it to the schema
            if (!isDuplicate)
                    schema.Items.Add(item);
                else
                    Logger.WriteLine("        Duplicate parameter \"" + itemName + "\" detected in schema " + schema.TargetNamespace + ". Duplicate was discarded.", LogLevel.Normal);

            return isDuplicate;
        }
 static void ErrorHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.HelpExampleGeneratorSchemaObjectNotSupported, schemaObject.GetType().Name)));
 }
 private static string GetSchemaObjectType(XmlSchemaObject extension)
 {
     const int xmlSchemaPrefixLength = 9; // == "XmlSchema".Length;
     return extension.GetType().Name.Substring(xmlSchemaPrefixLength);
 }
 internal void Depends(XmlSchemaObject item, ArrayList refs)
 {
     if ((item != null) && (this.scope[item] == null))
     {
         Type c = item.GetType();
         if (typeof(XmlSchemaType).IsAssignableFrom(c))
         {
             XmlQualifiedName empty = XmlQualifiedName.Empty;
             XmlSchemaType o = null;
             XmlSchemaParticle particle = null;
             XmlSchemaObjectCollection attributes = null;
             if (item is XmlSchemaComplexType)
             {
                 XmlSchemaComplexType type3 = (XmlSchemaComplexType) item;
                 if (type3.ContentModel != null)
                 {
                     XmlSchemaContent content = type3.ContentModel.Content;
                     if (content is XmlSchemaComplexContentRestriction)
                     {
                         empty = ((XmlSchemaComplexContentRestriction) content).BaseTypeName;
                         attributes = ((XmlSchemaComplexContentRestriction) content).Attributes;
                     }
                     else if (content is XmlSchemaSimpleContentRestriction)
                     {
                         XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
                         if (restriction.BaseType != null)
                         {
                             o = restriction.BaseType;
                         }
                         else
                         {
                             empty = restriction.BaseTypeName;
                         }
                         attributes = restriction.Attributes;
                     }
                     else if (content is XmlSchemaComplexContentExtension)
                     {
                         XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
                         attributes = extension.Attributes;
                         particle = extension.Particle;
                         empty = extension.BaseTypeName;
                     }
                     else if (content is XmlSchemaSimpleContentExtension)
                     {
                         XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content;
                         attributes = extension2.Attributes;
                         empty = extension2.BaseTypeName;
                     }
                 }
                 else
                 {
                     attributes = type3.Attributes;
                     particle = type3.Particle;
                 }
                 if (particle is XmlSchemaGroupRef)
                 {
                     XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle;
                     particle = ((XmlSchemaGroup) this.schemas.Find(ref2.RefName, typeof(XmlSchemaGroup), false)).Particle;
                 }
                 else if (particle is XmlSchemaGroupBase)
                 {
                     particle = (XmlSchemaGroupBase) particle;
                 }
             }
             else if (item is XmlSchemaSimpleType)
             {
                 XmlSchemaSimpleType type4 = (XmlSchemaSimpleType) item;
                 XmlSchemaSimpleTypeContent content2 = type4.Content;
                 if (content2 is XmlSchemaSimpleTypeRestriction)
                 {
                     o = ((XmlSchemaSimpleTypeRestriction) content2).BaseType;
                     empty = ((XmlSchemaSimpleTypeRestriction) content2).BaseTypeName;
                 }
                 else if (content2 is XmlSchemaSimpleTypeList)
                 {
                     XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content2;
                     if ((list.ItemTypeName != null) && !list.ItemTypeName.IsEmpty)
                     {
                         empty = list.ItemTypeName;
                     }
                     if (list.ItemType != null)
                     {
                         o = list.ItemType;
                     }
                 }
                 else if (content2 is XmlSchemaSimpleTypeRestriction)
                 {
                     empty = ((XmlSchemaSimpleTypeRestriction) content2).BaseTypeName;
                 }
                 else if (c == typeof(XmlSchemaSimpleTypeUnion))
                 {
                     XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion) item).MemberTypes;
                     if (memberTypes != null)
                     {
                         for (int i = 0; i < memberTypes.Length; i++)
                         {
                             XmlSchemaType type5 = (XmlSchemaType) this.schemas.Find(memberTypes[i], typeof(XmlSchemaType), false);
                             this.AddRef(refs, type5);
                         }
                     }
                 }
             }
             if (((o == null) && !empty.IsEmpty) && (empty.Namespace != "http://www.w3.org/2001/XMLSchema"))
             {
                 o = (XmlSchemaType) this.schemas.Find(empty, typeof(XmlSchemaType), false);
             }
             if (o != null)
             {
                 this.AddRef(refs, o);
             }
             if (particle != null)
             {
                 this.Depends(particle, refs);
             }
             if (attributes != null)
             {
                 for (int j = 0; j < attributes.Count; j++)
                 {
                     this.Depends(attributes[j], refs);
                 }
             }
         }
         else if (c == typeof(XmlSchemaElement))
         {
             XmlSchemaElement element = (XmlSchemaElement) item;
             if (!element.SubstitutionGroup.IsEmpty && (element.SubstitutionGroup.Namespace != "http://www.w3.org/2001/XMLSchema"))
             {
                 XmlSchemaElement element2 = (XmlSchemaElement) this.schemas.Find(element.SubstitutionGroup, typeof(XmlSchemaElement), false);
                 this.AddRef(refs, element2);
             }
             if (!element.RefName.IsEmpty)
             {
                 element = (XmlSchemaElement) this.schemas.Find(element.RefName, typeof(XmlSchemaElement), false);
                 this.AddRef(refs, element);
             }
             else if (!element.SchemaTypeName.IsEmpty)
             {
                 XmlSchemaType type6 = (XmlSchemaType) this.schemas.Find(element.SchemaTypeName, typeof(XmlSchemaType), false);
                 this.AddRef(refs, type6);
             }
             else
             {
                 this.Depends(element.SchemaType, refs);
             }
         }
         else if (c == typeof(XmlSchemaGroup))
         {
             this.Depends(((XmlSchemaGroup) item).Particle);
         }
         else if (c == typeof(XmlSchemaGroupRef))
         {
             XmlSchemaGroup group = (XmlSchemaGroup) this.schemas.Find(((XmlSchemaGroupRef) item).RefName, typeof(XmlSchemaGroup), false);
             this.AddRef(refs, group);
         }
         else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(c))
         {
             foreach (XmlSchemaObject obj2 in ((XmlSchemaGroupBase) item).Items)
             {
                 this.Depends(obj2, refs);
             }
         }
         else if (c == typeof(XmlSchemaAttributeGroupRef))
         {
             XmlSchemaAttributeGroup group2 = (XmlSchemaAttributeGroup) this.schemas.Find(((XmlSchemaAttributeGroupRef) item).RefName, typeof(XmlSchemaAttributeGroup), false);
             this.AddRef(refs, group2);
         }
         else if (c == typeof(XmlSchemaAttributeGroup))
         {
             foreach (XmlSchemaObject obj3 in ((XmlSchemaAttributeGroup) item).Attributes)
             {
                 this.Depends(obj3, refs);
             }
         }
         else if (c == typeof(XmlSchemaAttribute))
         {
             XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
             if (!attribute.RefName.IsEmpty)
             {
                 attribute = (XmlSchemaAttribute) this.schemas.Find(attribute.RefName, typeof(XmlSchemaAttribute), false);
                 this.AddRef(refs, attribute);
             }
             else if (!attribute.SchemaTypeName.IsEmpty)
             {
                 XmlSchemaType type7 = (XmlSchemaType) this.schemas.Find(attribute.SchemaTypeName, typeof(XmlSchemaType), false);
                 this.AddRef(refs, type7);
             }
             else
             {
                 this.Depends(attribute.SchemaType, refs);
             }
         }
         if (typeof(XmlSchemaAnnotated).IsAssignableFrom(c))
         {
             XmlAttribute[] unhandledAttributes = ((XmlSchemaAnnotated) item).UnhandledAttributes;
             if (unhandledAttributes != null)
             {
                 for (int k = 0; k < unhandledAttributes.Length; k++)
                 {
                     XmlAttribute attribute2 = unhandledAttributes[k];
                     if ((attribute2.LocalName == "arrayType") && (attribute2.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/"))
                     {
                         string str;
                         XmlQualifiedName name = TypeScope.ParseWsdlArrayType(attribute2.Value, out str, item);
                         XmlSchemaType type8 = (XmlSchemaType) this.schemas.Find(name, typeof(XmlSchemaType), false);
                         this.AddRef(refs, type8);
                     }
                 }
             }
         }
     }
 }
        internal bool Match(XmlSchemaObject o1, XmlSchemaObject o2, bool shareTypes) {
            if (o1 == o2)
                return true;
            if (o1.GetType() != o2.GetType())
                return false;
            if (Hash[o1] == null)
                Hash[o1] = GetHash(o1);
            int hash1 = (int)Hash[o1];
            int hash2 = GetHash(o2);
            if (hash1 != hash2)
                return false;

            if (shareTypes)
                return CompositeHash(o1, hash1) == CompositeHash(o2, hash2);
            return true;
        }
 static void ErrorHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context)
 {
     throw new InvalidOperationException(String.Format("Schema object {0} not supported.", schemaObject.GetType().Name));
 }
Exemple #9
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
 internal bool Match(XmlSchemaObject o1, XmlSchemaObject o2, bool shareTypes)
 {
     if (o1 != o2)
     {
         if (o1.GetType() != o2.GetType())
         {
             return false;
         }
         if (this.Hash[o1] == null)
         {
             this.Hash[o1] = this.GetHash(o1);
         }
         int hash = (int) this.Hash[o1];
         int num2 = this.GetHash(o2);
         if (hash != num2)
         {
             return false;
         }
         if (shareTypes)
         {
             return (this.CompositeHash(o1, hash) == this.CompositeHash(o2, num2));
         }
     }
     return true;
 }
        private void FillXsltArgumentList(XsltArgumentList argumentList, string prefix, XmlSchemaObject obj)
        {
            var topic = (obj == null) ? null : Context.TopicManager.GetTopic(obj);
            var itemType = (obj == null) ? string.Empty : obj.GetType().Name.Substring(9).ToLower();
            var itemNamespace = (obj == null) ? string.Empty : obj.GetSchema().TargetNamespace ?? string.Empty;
            var itemUri = (topic == null) ? string.Empty : topic.LinkUri;

            argumentList.AddParam(prefix + "ItemType", string.Empty, itemType);
            argumentList.AddParam(prefix + "ItemNamespace", string.Empty, itemNamespace);
            argumentList.AddParam(prefix + "ItemUri", string.Empty, itemUri);
        }
Exemple #12
0
        public static List<XmlSchemaElement> GetAllElements(XmlSchemaObject obj, bool recursive, List<XmlSchemaElement> allElements)
        {
            List<XmlSchemaElement> elements  = new List<XmlSchemaElement>();

            // Element
            if (obj.GetType().Equals(typeof(XmlSchemaElement)))
            {
                XmlSchemaElement element  = (XmlSchemaElement)obj;

                XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;

                if (complexType != null)
                {
                    #region sequence
                    /// Get the sequence particle of the complex type.
                    XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;
                    if (sequence != null)
                    {
                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaObject childElement in sequence.Items)
                        {
                            elements = GetElements(childElement, elements, recursive, allElements);
                        }
                    }

                    #endregion

                    #region choice
                    // check if it is e choice
                    XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice;
                    if (choice != null)
                    {
                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaObject childElement in choice.Items)
                        {
                            elements = GetElements(childElement, elements, recursive, allElements);
                        }
                    }
                    #endregion
                }
            }

            if (obj.GetType().Equals(typeof(XmlSchemaComplexType)))
            {
                XmlSchemaComplexType complexType = obj as XmlSchemaComplexType;

                if (complexType != null)
                {
                    #region sequence
                    /// Get the sequence particle of the complex type.
                    XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;
                    if (sequence != null)
                    {
                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaObject childElement in sequence.Items)
                        {
                            elements = GetElements(childElement, elements, recursive, allElements);
                        }
                    }

                    #endregion

                    #region choice
                    // check if it is e choice
                    XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice;
                    if (choice != null)
                    {
                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaObject childElement in choice.Items)
                        {
                            elements = GetElements(childElement, elements, recursive, allElements);
                        }
                    }
                    #endregion
                }
            }

            if (obj is XmlSchemaGroup)
            {
                XmlSchemaGroup group = obj as XmlSchemaGroup;

              #region sequence
                    /// Get the sequence particle of the complex type.
                    XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence;
                    if (sequence != null)
                    {
                        // Iterate over each XmlSchemaElement in the Items collection.
                        foreach (XmlSchemaObject childElement in sequence.Items)
                        {
                            elements = GetElements(childElement, elements, recursive, allElements);
                        }
                    }

              #endregion

                #region choice
                // check if it is e choice
                XmlSchemaChoice choice = group.Particle as XmlSchemaChoice;
                if (choice != null)
                {
                    // Iterate over each XmlSchemaElement in the Items collection.
                    foreach (XmlSchemaObject childElement in choice.Items)
                    {
                        elements = GetElements(childElement, elements, recursive, allElements);
                    }
                }
                #endregion

            }

            //if (obj is XmlSchemaSequence)
            //{
            //    // Iterate over each XmlSchemaElement in the Items collection.
            //    foreach (XmlSchemaObject childElement in ((XmlSchemaSequence)obj).Items)
            //    {
            //        elements = GetAllElements(childElement, recursive, allElements);
            //    }
            //}

            //if (obj is XmlSchemaChoice)
            //{
            //    // Iterate over each XmlSchemaElement in the Items collection.
            //    foreach (XmlSchemaObject childElement in ((XmlSchemaChoice)obj).Items)
            //    {
            //        elements = GetAllElements(childElement, recursive, allElements);
            //    }
            //}

            return elements;
        }
Exemple #13
0
        private static List<XmlSchemaElement> GetElements(XmlSchemaObject element, List<XmlSchemaElement> list, bool recursive, List<XmlSchemaElement> allElements)
        {
            // Element
            if (element.GetType().Equals(typeof(XmlSchemaElement)))
            {
                XmlSchemaElement child = (XmlSchemaElement)element;

                if (child.Name != null)
                {
                    if (list.Where(e => e.Name.Equals(child.Name)).Count() == 0)
                    {
                        //if (!child.SchemaTypeName.Name.Equals(parentTypeName))
                        //{

                        list.Add(child);

                        if (recursive)
                        {

                            Debug.WriteLine("--<" + child.Name);

                            XmlSchemaComplexType complexType = child.ElementSchemaType as XmlSchemaComplexType;
                            if (complexType != null)
                            {
                                #region sequence

                                /// Get the sequence particle of the complex type.
                                XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;
                                if (sequence != null)
                                {
                                    // Iterate over each XmlSchemaElement in the Items collection.
                                    foreach (XmlSchemaObject childElement in sequence.Items)
                                    {
                                        list = GetElements(childElement, list, recursive, allElements);
                                    }
                                }

                                #endregion

                                #region choice

                                // check if it is e choice
                                XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice;
                                if (choice != null)
                                {
                                    // Iterate over each XmlSchemaElement in the Items collection.
                                    foreach (XmlSchemaObject childElement in choice.Items)
                                    {
                                        list = GetElements(childElement, list, recursive, allElements);
                                    }
                                }

                                #endregion
                            }
                        }

                        //}
                    }
                }
                else
                {
                    if (child.RefName != null)
                    {
                        XmlSchemaElement refElement = allElements.Where(e => e.QualifiedName.Equals(child.RefName)).FirstOrDefault();
                        if (refElement != null)
                        {
                            list.Add(refElement);

                            if (recursive)
                            {

                                Debug.WriteLine("--<" + refElement.Name);

                                XmlSchemaComplexType complexType = refElement.ElementSchemaType as XmlSchemaComplexType;
                                if (complexType != null)
                                {
                                    #region sequence
                                    /// Get the sequence particle of the complex type.
                                    XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;
                                    if (sequence != null)
                                    {
                                        // Iterate over each XmlSchemaElement in the Items collection.
                                        foreach (XmlSchemaObject childElement in sequence.Items)
                                        {
                                            list = GetElements(childElement, list, recursive, allElements);
                                        }
                                    }

                                    #endregion

                                    #region choice
                                    // check if it is e choice
                                    XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice;
                                    if (choice != null)
                                    {
                                        // Iterate over each XmlSchemaElement in the Items collection.
                                        foreach (XmlSchemaObject childElement in choice.Items)
                                        {
                                            list = GetElements(childElement, list, recursive, allElements);
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
            else
                if (element.GetType().Equals(typeof(XmlSchemaChoice)))
            {
                XmlSchemaChoice choice = (XmlSchemaChoice)element;

                // Iterate over each XmlSchemaElement in the Items collection.
                foreach (XmlSchemaObject childElement in choice.Items)
                {
                    list = GetElements(childElement, list, recursive, allElements);
                }
            }
            else
                if (element.GetType().Equals(typeof(XmlSchemaSequence)))
            {
                XmlSchemaSequence sequence = (XmlSchemaSequence)element;

                // Iterate over each XmlSchemaElement in the Items collection.
                foreach (XmlSchemaObject childElement in sequence.Items)
                {
                    list = GetElements(childElement, list, recursive, allElements);
                }
            }

            return list;
        }
 public static Exception UnexpectedSchemaObjectType(XmlSchemaObject schemaObject)
 {
     var message = string.Format(CultureInfo.CurrentCulture, Resources.ExceptionBuilderUnexpectedSchemaObjectType, schemaObject.GetType());
     return new NotImplementedException(message);
 }
Exemple #15
0
        private void Dispatch(XmlSchemaObject o)
        {
            if (o == null)
                return;

            if (o is XmlSchemaSimpleType)
            {
                VisitSimpleType((XmlSchemaSimpleType)o);
            }
            else if (o is XmlSchemaComplexType)
            {
                VisitComplexType((XmlSchemaComplexType)o);
            }
            else if (o is XmlSchemaAttribute)
            {
                VisitXmlSchemaAttribute((XmlSchemaAttribute)o);
            }
            else if (o is XmlSchemaElement)
            {
                VisitXmlSchemaElement((XmlSchemaElement)o);
            }
            else if (o is XmlSchemaSimpleTypeRestriction)
            {
                VisitXmlSchemaSimpleTypeRestriction((XmlSchemaSimpleTypeRestriction)o);
            }
            else if (o is XmlSchemaAttributeGroup)
            {
                VisitXmlSchemaAttributeGroup((XmlSchemaAttributeGroup)o);
            }
            else if (o is XmlSchemaAttributeGroupRef)
            {
                VisitXmlSchemaAttributeGroupRef((XmlSchemaAttributeGroupRef)o);
            }
            else if (o is XmlSchemaSequence)
            {
                VisitXmlSchemaSequence((XmlSchemaSequence)o);
            }
            else if (o is XmlSchemaChoice)
            {
                VisitXmlSchemaChoice((XmlSchemaChoice)o);
            }
            else if (o is XmlSchemaGroup)
            {
                VisitXmlSchemaGroup((XmlSchemaGroup)o);
            }
            else if (o is XmlSchemaGroupRef)
            {
                VisitXmlSchemaGroupRef((XmlSchemaGroupRef)o);
            }
            else
                Assert.Fail("Unexpected " + o + " " + o.GetType());
        }
Exemple #16
0
        void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            compilationItems = new XmlSchemaObjectCollection();
            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                if (ext == null)
                {
                    error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
                    continue;
                }

                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                Stream stream = null;
                string url    = null;
                if (resolver != null)
                {
                    url = GetResolvedUri(resolver, ext.SchemaLocation);
                    if (handledUris.Contains(url))
                    {
                        // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
                        continue;
                    }
                    handledUris.Add(url, url);
                    try {
                        stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream;
                    } catch (Exception) {
                        // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
                        warn(handler, "Could not resolve schema location URI: " + url);
                        stream = null;
                    }
                }

                // Process redefinition children in advance.
                XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
                if (redefine != null)
                {
                    for (int j = 0; j < redefine.Items.Count; j++)
                    {
                        XmlSchemaObject redefinedObj = redefine.Items [j];
                        redefinedObj.isRedefinedComponent = true;
                        redefinedObj.isRedefineChild      = true;
                        if (redefinedObj is XmlSchemaType ||
                            redefinedObj is XmlSchemaGroup ||
                            redefinedObj is XmlSchemaAttributeGroup)
                        {
                            compilationItems.Add(redefinedObj);
                        }
                        else
                        {
                            error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
                        }
                    }
                }

                XmlSchema includedSchema = null;
                if (stream == null)
                {
                    // It is missing schema components.
                    missedSubComponents = true;
                    continue;
                }
                else
                {
                    XmlTextReader xtr = null;
                    try {
                        xtr            = new XmlTextReader(url, stream, nameTable);
                        includedSchema = XmlSchema.Read(xtr, handler);
                    } finally {
                        if (xtr != null)
                        {
                            xtr.Close();
                        }
                    }
                    includedSchema.schemas = schemas;
                }
                includedSchema.SetParent();
                ext.Schema = includedSchema;

                // Set - actual - target namespace for the included schema * before compilation*.
                XmlSchemaImport import = ext as XmlSchemaImport;
                if (import != null)
                {
                    if (TargetNamespace == includedSchema.TargetNamespace)
                    {
                        error(handler, "Target namespace must be different from that of included schema.");
                        continue;
                    }
                    else if (includedSchema.TargetNamespace != import.Namespace)
                    {
                        error(handler, "Attribute namespace and its importing schema's target namespace must be the same.");
                        continue;
                    }
                }
                else
                {
                    if (TargetNamespace == null &&
                        includedSchema.TargetNamespace != null)
                    {
                        error(handler, "Target namespace is required to include a schema which has its own target namespace");
                        continue;
                    }
                    else if (TargetNamespace != null &&
                             includedSchema.TargetNamespace == null)
                    {
                        includedSchema.TargetNamespace = TargetNamespace;
                    }
                }

                // Do not compile included schema here.

                AddExternalComponentsTo(includedSchema, compilationItems);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
Exemple #17
0
        private TreeNode DecSchem(XmlSchemaObject obj, TreeNode node)
        {
            TreeNode newNode = node;

            XmlSchemaAnnotation annot = obj as XmlSchemaAnnotation;
            XmlSchemaAttribute attrib = obj as XmlSchemaAttribute;
            XmlSchemaFacet facet = obj as XmlSchemaFacet;
            XmlSchemaDocumentation doc = obj as XmlSchemaDocumentation;
            XmlSchemaAppInfo appInfo = obj as XmlSchemaAppInfo;
            XmlSchemaElement element = obj as XmlSchemaElement;
            XmlSchemaSimpleType simpleType = obj as XmlSchemaSimpleType;
            XmlSchemaComplexType complexType = obj as XmlSchemaComplexType;

            if (node == schemaTree.Nodes[0])
            {
                if (attrib != null)
                    if (attrib.Name != null)
                        comboGlobal.Items.Add(new NodeElementType(attrib.Name, attrib));
                else if (element != null)
                    if (element.Name != null)
                        comboGlobal.Items.Add(new NodeElementType(element.Name, element));
                else if (simpleType != null)
                    if (simpleType.Name != null)
                        comboGlobal.Items.Add(new NodeElementType(simpleType.Name, simpleType));
                else if (complexType != null)
                    if (complexType.Name != null)
                        comboGlobal.Items.Add(new NodeElementType(complexType.Name, complexType));
            }

            if (annot != null)
            {
                newNode = new TreeNode("--annotation--");
                newNode.Tag = annot;
                newNode.ImageIndex = 4;
                newNode.SelectedImageIndex = 4;
                node.Nodes.Add(newNode);
                foreach (XmlSchemaObject schemaObject in annot.Items)
                {
                    DecSchem(schemaObject, newNode);
                }
            }
            else
                if (attrib != null)
                {
                    newNode = new TreeNode(attrib.QualifiedName.Name);
                    newNode.Tag = attrib;
                    newNode.ImageIndex = 7;
                    newNode.SelectedImageIndex = 7;
                    node.Nodes.Add(newNode);
                }
                else
                    if (facet != null)
                    {
                        newNode = new TreeNode(facet.ToString());
                        newNode.Tag = facet;
                        newNode.ImageIndex = 8;
                        newNode.SelectedImageIndex = 8;
                        node.Nodes.Add(newNode);
                    }
                    else
                        if (doc != null)
                        {
                            newNode = new TreeNode("--documentation--");
                            newNode.Tag = doc;
                            newNode.ImageIndex = 5;
                            newNode.SelectedImageIndex = 5;
                            node.Nodes.Add(newNode);
                        }
                        else
                            if (appInfo != null)
                            {
                                newNode = new TreeNode("--app info--");
                                newNode.Tag = annot;
                                newNode.ImageIndex = 6;
                                newNode.SelectedImageIndex = 6;
                                node.Nodes.Add(newNode);
                            }
                            else
                                if (element != null)
                                {
                                    XmlSchemaSimpleType st = element.SchemaType as XmlSchemaSimpleType;
                                    XmlSchemaComplexType ct = element.SchemaType as XmlSchemaComplexType;

                                    if (st != null)
                                    {
                                        TreeNode node2 = DecSchem(st, newNode);
                                        node2.Text = element.Name;
                                    }
                                    else if (ct != null)
                                    {
                                        TreeNode node2 = DecSchem(ct, newNode);
                                        node2.Text = element.Name;
                                    }
                                    else
                                    {
                                        newNode = new TreeNode(element.QualifiedName.Name);
                                        newNode.Tag = element;
                                        newNode.ImageIndex = 1;
                                        newNode.SelectedImageIndex = 1;
                                        node.Nodes.Add(newNode);
                                    }
                                }
                                else
                                    if (simpleType != null)
                                    {
                                        newNode = new TreeNode(simpleType.QualifiedName.Name);
                                        newNode.Tag = simpleType;
                                        newNode.ImageIndex = 2;
                                        newNode.SelectedImageIndex = 2;
                                        node.Nodes.Add(newNode);
                                        XmlSchemaSimpleTypeRestriction rest = simpleType.Content as XmlSchemaSimpleTypeRestriction;
                                        if (rest != null)
                                        {
                                            foreach (XmlSchemaFacet schemaObject in rest.Facets)
                                            {
                                                DecSchem(schemaObject, newNode);
                                            }
                                        }
                                    }
                                    else
                                        if (complexType != null)
                                        {
                                            newNode = new TreeNode(complexType.Name);
                                            newNode.Tag = complexType;
                                            newNode.ImageIndex = 3;
                                            newNode.SelectedImageIndex = 3;
                                            node.Nodes.Add(newNode);

                                            XmlSchemaSequence seq = complexType.Particle as XmlSchemaSequence;
                                            if (seq != null)
                                            {
                                                foreach (XmlSchemaObject schemaObject in seq.Items)
                                                {
                                                    DecSchem(schemaObject, newNode);
                                                }
                                            }
                                        }

            foreach (PropertyInfo property in obj.GetType().GetProperties())
            {
                if (property.PropertyType.FullName == "System.Xml.Schema.XmlSchemaObjectCollection")
                {
                    XmlSchemaObjectCollection childObjectCollection = (XmlSchemaObjectCollection)property.GetValue(obj, null);
                    foreach (XmlSchemaObject schemaObject in childObjectCollection)
                    {
                        DecSchem(schemaObject, newNode);
                    }
                }
            }
            return newNode;
        }
 static void InvokeHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context)
 {
     if (++context.currentDepthLevel < MaxDepthLevel)
     {
         Action<XmlSchemaObject, HelpExampleGeneratorContext> action;
         Type objectType = schemaObject.GetType();
         if (context.objectHandler.TryGetValue(objectType, out action))
         {
             action(schemaObject, context);
         }
         else if (objectType.Name != "EmptyParticle")
         {
             throw new InvalidOperationException(String.Format("Handler for type {0} not found.", schemaObject.GetType().Name));
         }
         --context.currentDepthLevel;
     }
     else
     {
         throw new InvalidOperationException(String.Format("Max depth level reached at {0}.", schemaObject.GetType().Name));
     }
 }
        static string GetSchemaItem(XmlSchemaObject o, string ns, string details) {
            if (o == null) {
                return null;
            }
            while (o.Parent != null && !(o.Parent is XmlSchema)) {
                o = o.Parent;
            }
            if (ns == null || ns.Length == 0) {
                XmlSchemaObject tmp = o;
                while (tmp.Parent != null) {
                    tmp = tmp.Parent;
                }
                if (tmp is XmlSchema) {
                    ns = ((XmlSchema)tmp).TargetNamespace;
                }
            }
            string item = null;
            if (o is XmlSchemaNotation) {
                item = Res.GetString(Res.XmlSchemaNamedItem, ns, "notation", ((XmlSchemaNotation)o).Name, details);
            }
            else if (o is XmlSchemaGroup) {
                item = Res.GetString(Res.XmlSchemaNamedItem, ns, "group", ((XmlSchemaGroup)o).Name, details);
            }
            else if (o is XmlSchemaElement) {
                XmlSchemaElement e = ((XmlSchemaElement)o);
                if (e.Name == null || e.Name.Length == 0) {
                    XmlQualifiedName parentName = GetParentName(o);
                    // Element reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    item = Res.GetString(Res.XmlSchemaElementReference, e.RefName.ToString(), parentName.Name, parentName.Namespace);
                }
                else {
                    item = Res.GetString(Res.XmlSchemaNamedItem, ns, "element", e.Name, details);
                }
            }
            else if (o is XmlSchemaType) {
                item = Res.GetString(Res.XmlSchemaNamedItem, ns, o.GetType() == typeof(XmlSchemaSimpleType) ? "simpleType" : "complexType", ((XmlSchemaType)o).Name, details);
            }
            else if (o is XmlSchemaAttributeGroup) {
                item = Res.GetString(Res.XmlSchemaNamedItem, ns, "attributeGroup", ((XmlSchemaAttributeGroup)o).Name, details);
            }
            else if (o is XmlSchemaAttribute) {
                XmlSchemaAttribute a = ((XmlSchemaAttribute)o);
                if (a.Name == null || a.Name.Length == 0) {
                    XmlQualifiedName parentName = GetParentName(o);
                    // Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    return Res.GetString(Res.XmlSchemaAttributeReference, a.RefName.ToString(), parentName.Name, parentName.Namespace);
                }
                else {
                    item = Res.GetString(Res.XmlSchemaNamedItem, ns, "attribute", a.Name, details);
                }

            }
            else if (o is XmlSchemaContent) {
                XmlQualifiedName parentName = GetParentName(o);
                // Check content definition of schema type '{0}' from namespace '{1}'. {2}
                item = Res.GetString(Res.XmlSchemaContentDef, parentName.Name, parentName.Namespace, details);
            }
            else if (o is XmlSchemaExternal) {
                string itemType = o is XmlSchemaImport ? "import" : o is XmlSchemaInclude ? "include" : o is XmlSchemaRedefine ? "redefine" : o.GetType().Name;
                item = Res.GetString(Res.XmlSchemaItem, ns, itemType, details);
            }
            else if (o is XmlSchema) {
                item = Res.GetString(Res.XmlSchema, ns, details);
            }
            else {
                item = Res.GetString(Res.XmlSchemaNamedItem, ns, o.GetType().Name, null, details);
            }

            return item;
        }
        internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) {
            if (item == null)
                return null;
            if (qname == null || qname.IsEmpty) 
                return null;

            string key = item.GetType().Name + ":" + qname.ToString();
            ArrayList list = (ArrayList)ObjectCache[key];
            if (list == null) {
                list = new ArrayList();
                ObjectCache[key] = list;
            }

            for (int i = 0; i < list.Count; i++) {
                XmlSchemaObject cachedItem = (XmlSchemaObject)list[i];
                if (cachedItem == item)
                    return cachedItem;

                if (Match(cachedItem, item, true)) {
                    return cachedItem;
                }
                else {
                    Warnings.Add(Res.GetString(Res.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
                    Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]);
                }
            }
            // no match found we need to insert the new type in the cache
            list.Add(item);
            return item;
        }
Exemple #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <remarks></remarks>
 /// <seealso cref=""/>
 /// <param name="xmlSchemaObject"></param>
 /// <returns></returns>
 private XmlSchemaComplexType findParentElement(XmlSchemaObject xmlSchemaObject)
 {
     if(!xmlSchemaObject.GetType().Equals(typeof(XmlSchemaComplexType)))
     {
         if(xmlSchemaObject.Parent!=null)
             return findParentElement(xmlSchemaObject.Parent);
         else
             return (XmlSchemaComplexType)xmlSchemaObject;
     }
     else
         return (XmlSchemaComplexType)xmlSchemaObject;
 }
        internal void Depends(XmlSchemaObject item, ArrayList refs) {
            if (item == null || scope[item] != null)
                return;

            Type t = item.GetType();
            if (typeof(XmlSchemaType).IsAssignableFrom(t)) {
                XmlQualifiedName baseName = XmlQualifiedName.Empty;
                XmlSchemaType baseType = null;
                XmlSchemaParticle particle = null;
                XmlSchemaObjectCollection attributes = null;

                if (item is XmlSchemaComplexType) {
                    XmlSchemaComplexType ct = (XmlSchemaComplexType)item;
                    if (ct.ContentModel != null) {
                        XmlSchemaContent content = ct.ContentModel.Content;
                        if (content is XmlSchemaComplexContentRestriction) {
                            baseName = ((XmlSchemaComplexContentRestriction)content).BaseTypeName;
                            attributes = ((XmlSchemaComplexContentRestriction)content).Attributes;
                        }
                        else if (content is XmlSchemaSimpleContentRestriction) {
                            XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
                            if (restriction.BaseType != null)
                                baseType = restriction.BaseType;
                            else
                                baseName = restriction.BaseTypeName;
                            attributes = restriction.Attributes;
                        }
                        else if (content is XmlSchemaComplexContentExtension) {
                            XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
                            attributes = extension.Attributes;
                            particle = extension.Particle;
                            baseName = extension.BaseTypeName;
                        }
                        else if (content is XmlSchemaSimpleContentExtension) {
                            XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
                            attributes = extension.Attributes;
                            baseName = extension.BaseTypeName;
                        }
                    }
                    else {
                        attributes = ct.Attributes;
                        particle = ct.Particle;
                    }
                    if (particle is XmlSchemaGroupRef) {
                        XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle;
                        particle = ((XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle;
                    }
                    else if (particle is XmlSchemaGroupBase) {
                        particle = (XmlSchemaGroupBase)particle;
                    }
                }
                else if (item is XmlSchemaSimpleType) {
                    XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)item;
                    XmlSchemaSimpleTypeContent content = simpleType.Content;
                    if (content is XmlSchemaSimpleTypeRestriction) {
                        baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType;
                        baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
                    }
                    else if (content is XmlSchemaSimpleTypeList) {
                        XmlSchemaSimpleTypeList list  = (XmlSchemaSimpleTypeList)content;
                        if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty)
                            baseName = list.ItemTypeName;
                        if (list.ItemType != null) {
                            baseType = list.ItemType;
                        }
                    }
                    else if (content is XmlSchemaSimpleTypeRestriction) {
                        baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName;
                    }
                    else if (t == typeof(XmlSchemaSimpleTypeUnion)) {
                        XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes;
                        
                        if (memberTypes != null) {
                            for (int i = 0; i < memberTypes.Length; i++) {
                                XmlSchemaType type = (XmlSchemaType)schemas.Find(memberTypes[i], typeof(XmlSchemaType), false);
                                AddRef(refs, type);
                            }
                        }
                    }
                }
                if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace)
                    baseType = (XmlSchemaType)schemas.Find(baseName, typeof(XmlSchemaType), false);

                if (baseType != null) {
                    AddRef(refs, baseType);
                }
                if (particle != null) {
                    Depends(particle, refs);
                }
                if (attributes != null) {
                    for (int i = 0; i < attributes.Count; i++) {
                        Depends(attributes[i], refs);
                    }
                }
            }
            else if (t == typeof(XmlSchemaElement)) {
                XmlSchemaElement el = (XmlSchemaElement)item;
                if (!el.SubstitutionGroup.IsEmpty) {
                    if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace) {
                        XmlSchemaElement head = (XmlSchemaElement)schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false);
                        AddRef(refs, head);
                    }
                }
                if (!el.RefName.IsEmpty) {
                    el = (XmlSchemaElement)schemas.Find(el.RefName, typeof(XmlSchemaElement), false);
                    AddRef(refs, el);
                }
                else if (!el.SchemaTypeName.IsEmpty) {
                    XmlSchemaType type = (XmlSchemaType)schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false);
                    AddRef(refs, type);
                }
                else {
                    Depends(el.SchemaType, refs);
                }
            }
            else if (t == typeof(XmlSchemaGroup)) {
                Depends(((XmlSchemaGroup)item).Particle);
            }
            else if (t == typeof(XmlSchemaGroupRef)) {
                XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false);
                AddRef(refs, group);
            }
            else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t)) {
                foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items) {
                    Depends(o, refs);
                }
            }
            else if (t == typeof(XmlSchemaAttributeGroupRef)) {
                XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false);
                AddRef(refs, group);
            }
            else if (t == typeof(XmlSchemaAttributeGroup)) {
                foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes) {
                    Depends(o, refs);
                }
            }
            else if (t == typeof(XmlSchemaAttribute)) {
                XmlSchemaAttribute at = (XmlSchemaAttribute)item;
                if (!at.RefName.IsEmpty) {
                    at = (XmlSchemaAttribute)schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false);
                    AddRef(refs, at);
                }
                else if (!at.SchemaTypeName.IsEmpty) {
                    XmlSchemaType type = (XmlSchemaType)schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false);
                    AddRef(refs, type);
                }
                else {
                    Depends(at.SchemaType, refs);
                }
            }
            if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t)) {
                XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes;

                if (attrs != null) {
                    for (int i = 0; i < attrs.Length; i++) {
                        XmlAttribute attribute = attrs[i];
                        if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace) {
                            string dims;
                            XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item);
                            XmlSchemaType type = (XmlSchemaType)schemas.Find(qname, typeof(XmlSchemaType), false);
                            AddRef(refs, type);
                        }
                    }
                }
            }
        }
 private static string GetSchemaItem(XmlSchemaObject o, string ns, string details)
 {
     if (o != null)
     {
         while ((o.Parent != null) && !(o.Parent is XmlSchema))
         {
             o = o.Parent;
         }
         if ((ns == null) || (ns.Length == 0))
         {
             XmlSchemaObject parent = o;
             while (parent.Parent != null)
             {
                 parent = parent.Parent;
             }
             if (parent is XmlSchema)
             {
                 ns = ((XmlSchema) parent).TargetNamespace;
             }
         }
         if (o is XmlSchemaNotation)
         {
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, "notation", ((XmlSchemaNotation) o).Name, details });
         }
         if (o is XmlSchemaGroup)
         {
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, "group", ((XmlSchemaGroup) o).Name, details });
         }
         if (o is XmlSchemaElement)
         {
             XmlSchemaElement element = (XmlSchemaElement) o;
             if ((element.Name == null) || (element.Name.Length == 0))
             {
                 XmlQualifiedName parentName = GetParentName(o);
                 return System.Web.Services.Res.GetString("XmlSchemaElementReference", new object[] { element.RefName.ToString(), parentName.Name, parentName.Namespace });
             }
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, "element", element.Name, details });
         }
         if (o is XmlSchemaType)
         {
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, (o.GetType() == typeof(XmlSchemaSimpleType)) ? "simpleType" : "complexType", ((XmlSchemaType) o).Name, details });
         }
         if (o is XmlSchemaAttributeGroup)
         {
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, "attributeGroup", ((XmlSchemaAttributeGroup) o).Name, details });
         }
         if (o is XmlSchemaAttribute)
         {
             XmlSchemaAttribute attribute = (XmlSchemaAttribute) o;
             if ((attribute.Name == null) || (attribute.Name.Length == 0))
             {
                 XmlQualifiedName name2 = GetParentName(o);
                 return System.Web.Services.Res.GetString("XmlSchemaAttributeReference", new object[] { attribute.RefName.ToString(), name2.Name, name2.Namespace });
             }
             return System.Web.Services.Res.GetString("XmlSchemaNamedItem", new object[] { ns, "attribute", attribute.Name, details });
         }
         if (o is XmlSchemaContent)
         {
             XmlQualifiedName name3 = GetParentName(o);
             return System.Web.Services.Res.GetString("XmlSchemaContentDef", new object[] { name3.Name, name3.Namespace, details });
         }
         if (o is XmlSchemaExternal)
         {
             string str2 = (o is XmlSchemaImport) ? "import" : ((o is XmlSchemaInclude) ? "include" : ((o is XmlSchemaRedefine) ? "redefine" : o.GetType().Name));
             return System.Web.Services.Res.GetString("XmlSchemaItem", new object[] { ns, str2, details });
         }
         if (o is XmlSchema)
         {
             return System.Web.Services.Res.GetString("XmlSchema", new object[] { ns, details });
         }
         object[] args = new object[4];
         args[0] = ns;
         args[1] = o.GetType().Name;
         args[3] = details;
         return System.Web.Services.Res.GetString("XmlSchemaNamedItem", args);
     }
     return null;
 }
        void Write3_XmlSchemaObject(XmlSchemaObject o) {
           if ((object)o == null) return;
            System.Type t = o.GetType();

            if (t == typeof(XmlSchemaComplexType)) {
                Write35_XmlSchemaComplexType((XmlSchemaComplexType)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleType)) {
                Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o);
                return;
            }
            else if (t == typeof(XmlSchemaElement)) {
                Write46_XmlSchemaElement((XmlSchemaElement)o);
                return;
            }
            else if (t == typeof(XmlSchemaAppInfo)) {
                Write7_XmlSchemaAppInfo((XmlSchemaAppInfo)o);
                return;
            }
            else if (t == typeof(XmlSchemaDocumentation)) {
                Write6_XmlSchemaDocumentation((XmlSchemaDocumentation)o);
                return;
            }
            else if (t == typeof(XmlSchemaAnnotation)) {
                Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o);
                return;
            }
            else if (t == typeof(XmlSchemaGroup)) {
                Write57_XmlSchemaGroup((XmlSchemaGroup)o);
                return;
            }
            else if (t == typeof(XmlSchemaXPath)) {
                Write49_XmlSchemaXPath("xpath", "", (XmlSchemaXPath)o);
                return;
            }
            else if (t == typeof(XmlSchemaIdentityConstraint)) {
                Write48_XmlSchemaIdentityConstraint((XmlSchemaIdentityConstraint)o);
                return;
            }
            else if (t == typeof(XmlSchemaUnique)) {
                Write51_XmlSchemaUnique((XmlSchemaUnique)o);
                return;
            }
            else if (t == typeof(XmlSchemaKeyref)) {
                Write50_XmlSchemaKeyref((XmlSchemaKeyref)o);
                return;
            }
            else if (t == typeof(XmlSchemaKey)) {
                Write47_XmlSchemaKey((XmlSchemaKey)o);
                return;
            }
            else if (t == typeof(XmlSchemaGroupRef)) {
                Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)o);
                return;
            }
            else if (t == typeof(XmlSchemaAny)) {
                Write53_XmlSchemaAny((XmlSchemaAny)o);
                return;
            }
            else if (t == typeof(XmlSchemaSequence)) {
                Write54_XmlSchemaSequence((XmlSchemaSequence)o);
                return;
            }
            else if (t == typeof(XmlSchemaChoice)) {
                Write52_XmlSchemaChoice((XmlSchemaChoice)o);
                return;
            }
            else if (t == typeof(XmlSchemaAll)) {
                Write43_XmlSchemaAll((XmlSchemaAll)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContentRestriction)) {
                Write56_XmlSchemaComplexContentRestriction((XmlSchemaComplexContentRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContentExtension)) {
                Write42_XmlSchemaComplexContentExtension((XmlSchemaComplexContentExtension)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContentRestriction)) {
                Write40_XmlSchemaSimpleContentRestriction((XmlSchemaSimpleContentRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContentExtension)) {
                Write38_XmlSchemaSimpleContentExtension((XmlSchemaSimpleContentExtension)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContent)) {
                Write41_XmlSchemaComplexContent((XmlSchemaComplexContent)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContent)) {
                Write36_XmlSchemaSimpleContent((XmlSchemaSimpleContent)o);
                return;
            }
            else if (t == typeof(XmlSchemaAnyAttribute)) {
                Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttributeGroupRef)) {
                Write32_XmlSchemaAttributeGroupRef((XmlSchemaAttributeGroupRef)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttributeGroup)) {
                Write31_XmlSchemaAttributeGroup((XmlSchemaAttributeGroup)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeRestriction)) {
                Write15_XmlSchemaSimpleTypeRestriction((XmlSchemaSimpleTypeRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeList)) {
                Write14_XmlSchemaSimpleTypeList((XmlSchemaSimpleTypeList)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeUnion)) {
                Write12_XmlSchemaSimpleTypeUnion((XmlSchemaSimpleTypeUnion)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttribute)) {
                Write1_XmlSchemaAttribute((XmlSchemaAttribute)o);
                return;
            }
        }
 static void InvokeHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context)
 {
     if (++context.currentDepthLevel < MaxDepthLevel)
     {
         Action<XmlSchemaObject, HelpExampleGeneratorContext> action;
         Type objectType = schemaObject.GetType();
         if (context.objectHandler.TryGetValue(objectType, out action))
         {
             action(schemaObject, context);
         }
         else if (objectType.Name != "EmptyParticle")
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.HelpExampleGeneratorHandlerNotFound, schemaObject.GetType().Name)));
         }
         --context.currentDepthLevel;
     }
     else
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.HelpExampleGeneratorMaxDepthLevelReached, schemaObject.GetType().Name)));
     }
 }