protected virtual void Visit(XmlSchemaSimpleTypeUnion union)
 {
     foreach (var simpleType in union.BaseMemberTypes)
     {
         Traverse(simpleType);
     }
 }
        public XmlSchemaSimpleType CreateCogsDataType()
        {
            XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();

            simpleType.Name = "cogsDate";
            simpleType.AddSchemaDocumentation("A union of dateTime, date, gYearMonth, gYear, and duration which allows for the use of a date-time combination (YYYY-MM-DDTHH:MM:SS), date (YYYYY-MM-DD), year-month (YYYY-MM), year (YYYY), and duration (PnYnMnDnHnMnS) as valid values.");

            XmlSchemaSimpleTypeUnion simpleTypeUnion = new XmlSchemaSimpleTypeUnion();

            simpleType.Content = simpleTypeUnion;

            simpleTypeUnion.MemberTypes = new XmlQualifiedName[]
            {
                XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.DateTime).QualifiedName,
                XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.Date).QualifiedName,
                XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.GYearMonth).QualifiedName,
                XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.GYear).QualifiedName,
                XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.Duration).QualifiedName
            };

            /*
             * simpleTypeUnion.BaseTypes.Add(XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.DateTime));
             * simpleTypeUnion.BaseTypes.Add(XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.Date));
             * simpleTypeUnion.BaseTypes.Add(XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.GYearMonth));
             * simpleTypeUnion.BaseTypes.Add(XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.GYear));
             * simpleTypeUnion.BaseTypes.Add(XmlSchemaSimpleType.GetBuiltInSimpleType(XmlTypeCode.Duration));
             */
            CogsSchema.Items.Add(simpleType);

            return(simpleType);
        }
Exemple #3
0
 private void Write12_XmlSchemaSimpleTypeUnion(XmlSchemaSimpleTypeUnion o)
 {
     if (o != null)
     {
         this.WriteStartElement("union");
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttributes(o.UnhandledAttributes, o);
         if (o.MemberTypes != null)
         {
             ArrayList list = new ArrayList();
             for (int i = 0; i < o.MemberTypes.Length; i++)
             {
                 list.Add(o.MemberTypes[i]);
             }
             list.Sort(new QNameComparer());
             this.w.Append(",");
             this.w.Append("memberTypes=");
             for (int j = 0; j < list.Count; j++)
             {
                 this.w.Append(((XmlQualifiedName)list[j]).ToString());
                 this.w.Append(",");
             }
         }
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteSortedItems(o.BaseTypes);
         this.WriteEndElement();
     }
 }
        void Write12_XmlSchemaSimpleTypeUnion(XmlSchemaSimpleTypeUnion o)
        {
            if ((object)o == null)
            {
                return;
            }
            WriteStartElement("union");

            WriteAttribute(@"id", @"", ((System.String)o.@Id));
            WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);

            if (o.MemberTypes != null)
            {
                ArrayList list = new ArrayList();
                for (int i = 0; i < o.MemberTypes.Length; i++)
                {
                    list.Add(o.MemberTypes[i]);
                }
                list.Sort(new QNameComparer());

                w.Append(",");
                w.Append("memberTypes=");

                for (int i = 0; i < list.Count; i++)
                {
                    XmlQualifiedName q = (XmlQualifiedName)list[i];
                    w.Append(q.ToString());
                    w.Append(",");
                }
            }
            Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
            WriteSortedItems(o.@BaseTypes);
            WriteEndElement();
        }
        void GetExpectedValues(XmlSchemaSimpleType st, XmlIntellisenseList list)
        {
            if (st == null)
            {
                return;
            }
            if (st.Datatype != null)
            {
                switch (st.Datatype.TypeCode)
                {
                case XmlTypeCode.Language:
                    foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures))
                    {
                        list.Add(ci.Name, ci.DisplayName);
                    }
                    list.Sort();
                    break;

                case XmlTypeCode.Boolean:
                    list.Add("0", null);
                    list.Add("1", null);
                    list.Add("true", null);
                    list.Add("false", null);
                    break;
                }
            }

            if (st.Content is XmlSchemaSimpleTypeList)
            {
                XmlSchemaSimpleTypeList ce = (XmlSchemaSimpleTypeList)st.Content;
                GetExpectedValues(ce.ItemType, list);
            }
            else if (st.Content is XmlSchemaSimpleTypeUnion)
            {
                XmlSchemaSimpleTypeUnion cr = (XmlSchemaSimpleTypeUnion)st.Content;
                if (cr.BaseMemberTypes != null)
                {
                    foreach (XmlSchemaSimpleType bt in cr.BaseMemberTypes)
                    {
                        GetExpectedValues(bt, list);
                    }
                }
            }
            else if (st.Content is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction cr = (XmlSchemaSimpleTypeRestriction)st.Content;
                GetExpectedValues(FindSchemaType(cr.BaseTypeName), list);
                foreach (XmlSchemaFacet f in cr.Facets)
                {
                    if (f is XmlSchemaEnumerationFacet)
                    {
                        XmlSchemaEnumerationFacet ef = (XmlSchemaEnumerationFacet)f;
                        list.Add(ef.Value, GetAnnotation(ef, SchemaCache.AnnotationNode.Tooltip, null));
                    }
                }
            }
            return;
        }
 public override void Check(ConformanceCheckContext ctx, XmlSchemaSimpleTypeUnion value)
 {
     if (value.MemberTypes != null)
     {
         foreach (XmlQualifiedName name in value.MemberTypes)
         {
             CheckSchemaQName(ctx, value, name);
         }
     }
 }
        protected override void Visit(XmlSchemaSimpleTypeUnion union)
        {
            PushNode(SimpleTypeStructureNodeType.Union, union);

            foreach (var baseMemberType in union.BaseMemberTypes)
            {
                Traverse(baseMemberType);
            }

            PopNode();
        }
 void GetAttributeValueCompletionData(XmlCompletionDataList data, XmlSchemaSimpleTypeUnion union)
 {
     foreach (XmlSchemaObject schemaObject in union.BaseTypes)
     {
         var simpleType = schemaObject as XmlSchemaSimpleType;
         if (simpleType != null)
         {
             GetAttributeValueCompletionData(data, simpleType);
         }
     }
 }
Exemple #9
0
        /// <summary>
        /// Creates a simple type that is the union of two other types
        /// </summary>
        /// <param name="Name">The name of the type</param>
        /// <param name="ValidTypes">List of valid types for the union</param>
        /// <returns>A simple type which will match the given pattern</returns>
        static XmlSchemaSimpleType CreateSimpleTypeFromUnion(string Name, params XmlSchemaType[] ValidTypes)
        {
            XmlSchemaSimpleTypeUnion Union = new XmlSchemaSimpleTypeUnion();

            foreach (XmlSchemaType ValidType in ValidTypes)
            {
                Union.BaseTypes.Add(ValidType);
            }

            XmlSchemaSimpleType UnionType = new XmlSchemaSimpleType();

            UnionType.Name    = Name;
            UnionType.Content = Union;
            return(UnionType);
        }
Exemple #10
0
        private static void createEnum(PropertyInfo pi, Dictionary <Type, XmlSchemaType> xmlTypes, XmlSchema xmlSchema)
        {
            // Create enum
            var res = new XmlSchemaSimpleTypeRestriction();

            res.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.NmToken).QualifiedName;

            foreach (var o in Enum.GetNames(pi.PropertyType))
            {
                res.Facets.Add(new XmlSchemaEnumerationFacet
                {
                    Value = (o.Substring(0, 1).ToLower() + o.Substring(1))
                });
            }

            XmlSchemaSimpleType st = new XmlSchemaSimpleType
            {
                Content = res
            };

            // For flags must create a union of the values & string
            if (CustomAttributeHelper.Has <System.FlagsAttribute>(pi.PropertyType))
            {
                XmlSchemaSimpleType st2 = new XmlSchemaSimpleType();
                st2.Name = getXmlTypeName(pi.PropertyType);


                var union = new XmlSchemaSimpleTypeUnion();

                XmlSchemaSimpleType st3 = new XmlSchemaSimpleType();
                var res3 = new XmlSchemaSimpleTypeRestriction();
                res3.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName;
                st3.Content       = res3;

                union.BaseTypes.Add(st);
                union.BaseTypes.Add(st3);

                st2.Content = union;
                xmlSchema.Items.Add(st2);
                xmlTypes[pi.PropertyType] = st2;
            }
            else
            {
                st.Name = getXmlTypeName(pi.PropertyType);
                xmlSchema.Items.Add(st);
                xmlTypes[pi.PropertyType] = st;
            }
        }
        string GetBuiltInType(XmlSchemaSimpleType st)
        {
            if (st == null)
            {
                return(string.Empty);
            }

            if (st.Content is XmlSchemaSimpleTypeRestriction)
            {
                return(GetBuiltInTypeName(GetContentBaseType(st.Content)));
            }
            else if (st.Content is XmlSchemaSimpleTypeList)
            {
                string s = GetBuiltInTypeName(GetContentBaseType(st.Content));
                return(s + " " + s + " ...");
            }
            else if (st.Content is XmlSchemaSimpleTypeUnion)
            {
                XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion)st.Content;
                string utype = null;


                if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
                {
                    return("string");
                }

                foreach (XmlQualifiedName mt in uni.MemberTypes)
                {
                    string qn = GetBuiltInTypeName(mt);
                    if (utype != null && qn != utype)
                    {
                        return("string");
                    }
                    else
                    {
                        utype = qn;
                    }
                }
                return(utype);
            }
            else
            {
                return("string");
            }
        }
Exemple #12
0
        private void AddEnumRestriction(XmlSchemaAttribute attribute, Type enumType)
        {
            XmlSchemaSimpleType simpleType;

            if (!this.enumTypes.TryGetValue(enumType, out simpleType))
            {
                simpleType      = new XmlSchemaSimpleType();
                simpleType.Name = enumType.Name + "Type";

                // let's try to get the documentation
                XmlDocument enumDocumentation = null;
                if (!this.Parent.IgnoreDocumentation)
                {
                    enumDocumentation = this.documentationLoader.GetDocumentation(enumType.Assembly);
                }

                // we create an union around it...
                XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
                union.MemberTypes  = new XmlQualifiedName[] { new XmlQualifiedName("msb:non_empty_string") };
                simpleType.Content = union;

                XmlSchemaSimpleType restrictionType = new XmlSchemaSimpleType();
                union.BaseTypes.Add(restrictionType);
                XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                restrictionType.Content  = restriction;
                restriction.BaseTypeName = new XmlQualifiedName("xs:string");

                foreach (string enumValue in Enum.GetNames(enumType))
                {
                    XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet();
                    facet.Value = enumValue;
                    restriction.Facets.Add(facet);

                    if (enumDocumentation != null)
                    {
                        AnnotateFacet(enumType, enumValue, enumDocumentation, facet);
                    }
                }

                this.enumTypes.Add(enumType, simpleType);
                this.schema.Items.Add(simpleType);
            }

            attribute.SchemaTypeName = new XmlQualifiedName("msb:" + simpleType.Name);
        }
Exemple #13
0
        public static XmlSchemaSimpleType[] GetUnionMemberTypes(this XmlSchemaSimpleType type)
        {
            Debug.Assert(type != null);
            Debug.Assert(type.Datatype.Variety == XmlSchemaDatatypeVariety.Union);

            XmlSchemaSimpleTypeUnion unionContent = type.Content as XmlSchemaSimpleTypeUnion;

            if (unionContent != null)  //directly derived by union
            {
                return(unionContent.BaseMemberTypes);
            }
            else
            {
                Debug.Assert(type.DerivedBy == XmlSchemaDerivationMethod.Restriction);
                XmlSchemaSimpleType baseType = type.BaseXmlSchemaType as XmlSchemaSimpleType;
                return(baseType.GetUnionMemberTypes());
            }
        }
        public static XmlSchemaSimpleType[] GetUnionMemberTypes(this XmlSchemaSimpleType type)
        {
            XmlSchemaSimpleType[] unionMemberTypes;
            Debug.Assert(type != null);
            Debug.Assert(type.Datatype.Variety == XmlSchemaDatatypeVariety.Union);
            XmlSchemaSimpleTypeUnion unionContent = type.Content as XmlSchemaSimpleTypeUnion;

            if (unionContent == null)
            {
                Debug.Assert(type.DerivedBy == XmlSchemaDerivationMethod.Restriction);
                unionMemberTypes = (type.BaseXmlSchemaType as XmlSchemaSimpleType).GetUnionMemberTypes();
            }
            else
            {
                unionMemberTypes = unionContent.BaseMemberTypes;
            }
            return(unionMemberTypes);
        }
Exemple #15
0
        string FindBuiltInType(XmlSchemaSimpleType st)
        {
            if (st.Content is XmlSchemaSimpleTypeRestriction)
            {
                return(FindBuiltInType(GetContentBaseType(st.Content)));
            }
            else if (st.Content is XmlSchemaSimpleTypeList)
            {
                string s = FindBuiltInType(GetContentBaseType(st.Content));
                return(s + " " + s + " ...");
            }
            else if (st.Content is XmlSchemaSimpleTypeUnion)
            {
                // Check if all types of the union are equal. If not, then will use anyType.
                XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion)st.Content;
                string utype = null;

                // Anonymous types are unique
                if (uni.BaseTypes.Count != 0 &&
                    (uni.MemberTypes == null || uni.MemberTypes.Length != 0))
                {
                    return("string");
                }

                foreach (XmlQualifiedName mt in uni.MemberTypes)
                {
                    string qn = FindBuiltInType(mt);
                    if (utype != null && qn != utype)
                    {
                        return("string");
                    }
                    else
                    {
                        utype = qn;
                    }
                }
                return(utype);
            }
            else
            {
                return("string");
            }
        }
            protected override void Visit(XmlSchemaSimpleTypeUnion union)
            {
                foreach (var baseMemberType in union.BaseMemberTypes)
                {
                    if (!baseMemberType.QualifiedName.IsEmpty)
                    {
                        continue;
                    }

                    _writer.WriteArtItemWithText(ArtItem.Union, "Union");
                    return;
                }

                _writer.StartArtItem(ArtItem.Union);

                var isFirst = true;

                foreach (var baseMemberType in union.BaseMemberTypes)
                {
                    if (isFirst)
                    {
                        _writer.WriteString(", ");
                        isFirst = false;
                    }

                    var topic = _context.TopicManager.GetTopic(baseMemberType);
                    if (topic != null)
                    {
                        _writer.WriteTopicLink(topic);
                    }
                    else
                    {
                        _writer.WriteString(baseMemberType.QualifiedName.Name);
                    }
                }

                _writer.EndArtItem();
            }
Exemple #17
0
        private string CreateEnumSimpleType(string enumString, XmlSchema schema)
        {
            var acceptableValues = enumString.Split(',').Select(s => s.Trim()).ToList();

            var simpleType = new XmlSchemaSimpleType();
            var union      = new XmlSchemaSimpleTypeUnion();

            union.MemberTypes  = new XmlQualifiedName[] { new XmlQualifiedName("xmlLayout:mvvmPattern") };
            simpleType.Content = union;

            var nestedSimpleType = new XmlSchemaSimpleType();

            union.BaseTypes.Add(nestedSimpleType);

            var restriction = new XmlSchemaSimpleTypeRestriction()
            {
                BaseTypeName = new XmlQualifiedName("xs:token")
            };

            nestedSimpleType.Content = restriction;

            foreach (var value in acceptableValues)
            {
                restriction.Facets.Add(new XmlSchemaEnumerationFacet {
                    Value = value
                });
            }

            var enumName = "enum" + enumPatterns.Count;

            simpleType.Name = enumName;

            schema.Items.Add(simpleType);

            enumPatterns.Add(enumString, enumName);

            return(enumName);
        }
Exemple #18
0
        static void Check(ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
        {
            if (value == null)
            {
                return;
            }

            if (visitedObjects.Contains(value))
            {
                return;
            }
            visitedObjects.Add(value, value);

            if (value is XmlSchemaImport)
            {
                XmlSchemaImport so = (XmlSchemaImport)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAll)
            {
                XmlSchemaAll so = (XmlSchemaAll)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAnnotation)
            {
                XmlSchemaAnnotation so = (XmlSchemaAnnotation)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaAttribute)
            {
                XmlSchemaAttribute so = (XmlSchemaAttribute)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaAttributeGroup)
            {
                XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
            }
            else if (value is XmlSchemaAttributeGroupRef)
            {
                XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaChoice)
            {
                XmlSchemaChoice so = (XmlSchemaChoice)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaComplexContent)
            {
                XmlSchemaComplexContent so = (XmlSchemaComplexContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaComplexContentExtension)
            {
                XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexContentRestriction)
            {
                XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaComplexType)
            {
                XmlSchemaComplexType so = (XmlSchemaComplexType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.ContentModel);
                Check(ctx, checker, visitedObjects, so.Particle);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                Check(ctx, checker, visitedObjects, so.ContentTypeParticle);
                Check(ctx, checker, visitedObjects, so.AttributeWildcard);
            }
            else if (value is XmlSchemaElement)
            {
                XmlSchemaElement so = (XmlSchemaElement)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.SchemaType);
                CheckObjects(ctx, checker, visitedObjects, so.Constraints);
            }
            else if (value is XmlSchemaGroup)
            {
                XmlSchemaGroup so = (XmlSchemaGroup)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Particle);
            }
            else if (value is XmlSchemaGroupRef)
            {
                XmlSchemaGroupRef so = (XmlSchemaGroupRef)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaIdentityConstraint)
            {
                XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Fields);
                Check(ctx, checker, visitedObjects, so.Selector);
            }
            else if (value is XmlSchemaKeyref)
            {
                XmlSchemaKeyref so = (XmlSchemaKeyref)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaRedefine)
            {
                XmlSchemaRedefine so = (XmlSchemaRedefine)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSequence)
            {
                XmlSchemaSequence so = (XmlSchemaSequence)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Items);
            }
            else if (value is XmlSchemaSimpleContent)
            {
                XmlSchemaSimpleContent so = (XmlSchemaSimpleContent)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleContentExtension)
            {
                XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
            }
            else if (value is XmlSchemaSimpleContentRestriction)
            {
                XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Attributes);
                Check(ctx, checker, visitedObjects, so.AnyAttribute);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType so = (XmlSchemaSimpleType)value;
                checker.Check(ctx, so);
                Check(ctx, checker, visitedObjects, so.Content);
            }
            else if (value is XmlSchemaSimpleTypeList)
            {
                XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList)value;
                checker.Check(ctx, so);
            }
            else if (value is XmlSchemaSimpleTypeRestriction)
            {
                XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction)value;
                checker.Check(ctx, so);
                CheckObjects(ctx, checker, visitedObjects, so.Facets);
            }
            else if (value is XmlSchemaSimpleTypeUnion)
            {
                XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion)value;
                checker.Check(ctx, so);
            }
        }
Exemple #19
0
        Type GetClrType(XmlQualifiedName qname)
        {
            while (this.schema.SchemaTypes[qname] != null)
            {
                XmlSchemaSimpleType xst = this.schema.SchemaTypes[qname] as XmlSchemaSimpleType;
                if (xst != null)
                {
                    XmlSchemaSimpleTypeRestriction str = xst.Content as XmlSchemaSimpleTypeRestriction;
                    if (str != null)
                    {
                        qname = str.BaseTypeName;
                        continue;
                    }
                    XmlSchemaSimpleTypeUnion stu = xst.Content as XmlSchemaSimpleTypeUnion;
                    if (stu != null)
                    {
                        if (stu.MemberTypes.Length == 0)
                        {
                            return(null);           // can't determine the type
                        }
                        qname = stu.MemberTypes[0]; // Needs just the first, since all types should map to
                        // the same primitive type
                    }
                    else
                    {
                        return(null);  // cant't determine the type
                    }
                }
                // In some cases the element has a type by itself but
                // has additional attributes
                XmlSchemaComplexType ct = this.schema.SchemaTypes[qname] as XmlSchemaComplexType;
                if (ct != null)
                {
                    qname = GetBaseTypeName(ct);
                    if (qname == null)
                    {
                        return(null);   // xs:any or such things... That means: no own type
                    }
                }
            }

            switch (qname.Name)
            {
            case "boolean":
                return(typeof(bool));

            case "byte":
                return(typeof(byte));

            case "date":
            case "time":
            case "dateTime":
                return(typeof(DateTime));

            case "decimal":
                return(typeof(decimal));

            case "double":
                return(typeof(double));

            case "duration":
                return(typeof(TimeSpan));

            case "long":
                return(typeof(long));

            case "int":               // limited to 32 bits
            case "negativeInteger":
            case "nonNegativeInteger":
            case "nonPositiveInteger":
            case "positiveInteger":
            case "integer":              // unlimited number without fractional part
                return(typeof(int));

            case "short":
                return(typeof(short));

            case "unsignedByte":
                return(typeof(byte));

            case "unsignedInt":
                return(typeof(uint));

            case "unsignedLong":
                return(typeof(ulong));

            case "unsignedShort":
                return(typeof(ushort));

            default:
                return(typeof(string));
            }
        }
Exemple #20
0
        void PopulatePluginType(XmlSchemaComplexType complexType, PluginElementAttribute pluginAttr)
        {
            if (pluginAttr.Named)
            {
                var nameAttr = new XmlSchemaAttribute();
                nameAttr.Name = "name";
                nameAttr.Annotate("{0} name.".Fmt(pluginAttr.PluginType.Name));
                nameAttr.Use = XmlSchemaUse.Optional;

                complexType.Attributes.Add(nameAttr);
            }

            var typeAttr = new XmlSchemaAttribute();

            typeAttr.Name = pluginAttr.AttributeName;
            typeAttr.Use  = XmlSchemaUse.Required;
            typeAttr.Annotate("Specify the class name of a Peach {0}. You can implement your own {1}s as needed.".Fmt(
                                  pluginAttr.PluginType.Name,
                                  pluginAttr.PluginType.Name.ToLower()
                                  ));

            var restrictEnum = new XmlSchemaSimpleTypeRestriction();

            restrictEnum.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);

            foreach (var item in ClassLoader.GetAllByAttribute <PluginAttribute>((t, a) => a.Type == pluginAttr.PluginType && a.IsDefault && !a.IsTest))
            {
                restrictEnum.Facets.Add(MakePluginFacet(item.Key, item.Value));
            }

            var enumType = new XmlSchemaSimpleType();

            enumType.Content = restrictEnum;

            var restrictLen = new XmlSchemaSimpleTypeRestriction();

            restrictLen.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
            restrictLen.Facets.Add(new XmlSchemaMaxLengthFacet()
            {
                Value = "1024"
            });

            var userType = new XmlSchemaSimpleType();

            userType.Content = restrictLen;

            var union = new XmlSchemaSimpleTypeUnion();

            union.BaseTypes.Add(userType);
            union.BaseTypes.Add(enumType);

            var schemaType = new XmlSchemaSimpleType();

            schemaType.Content = union;

            typeAttr.SchemaType = schemaType;

            complexType.Attributes.Add(typeAttr);

            if (!objElemCache.ContainsKey(typeof(PluginParam)))
            {
                AddElement("Param", typeof(PluginParam), null);
            }


            var schemaElem = new XmlSchemaElement();

            schemaElem.RefName = new XmlQualifiedName("Param", schema.TargetNamespace);

            XmlSchemaGroupBase schemaParticle;

            if (pluginAttr.PluginType == typeof(Transformer))
            {
                schemaParticle = new XmlSchemaChoice();
                schemaParticle.MinOccursString = "0";
                schemaParticle.MaxOccursString = "unbounded";

                var transElem = new XmlSchemaElement();
                transElem.RefName = new XmlQualifiedName("Transformer", schema.TargetNamespace);
                schemaParticle.Items.Add(transElem);
            }
            else
            {
                schemaParticle             = new XmlSchemaSequence();
                schemaElem.MinOccursString = "0";
                schemaElem.MaxOccursString = "unbounded";
            }

            schemaParticle.Items.Add(schemaElem);

            complexType.Particle = schemaParticle;
        }
Exemple #21
0
 public virtual void Check(ConformanceCheckContext ctx, XmlSchemaSimpleTypeUnion value)
 {
 }
Exemple #22
0
 private static void Equal(XmlSchemaSimpleTypeUnion expected, XmlSchemaSimpleTypeUnion actual)
 {
     throw new NotImplementedException();
 }
Exemple #23
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        //<xs:simpleType name="StringOrIntType">
        XmlSchemaSimpleType StringOrIntType = new XmlSchemaSimpleType();

        StringOrIntType.Name = "StringOrIntType";
        schema.Items.Add(StringOrIntType);

        // <xs:union>
        XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();

        StringOrIntType.Content = union;

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType1 = new XmlSchemaSimpleType();

        union.BaseTypes.Add(simpleType1);

        // <xs:restriction base="xs:string"/>
        XmlSchemaSimpleTypeRestriction restriction1 = new XmlSchemaSimpleTypeRestriction();

        restriction1.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        simpleType1.Content       = restriction1;

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType2 = new XmlSchemaSimpleType();

        union.BaseTypes.Add(simpleType2);

        // <xs:restriction base="xs:int"/>
        XmlSchemaSimpleTypeRestriction restriction2 = new XmlSchemaSimpleTypeRestriction();

        restriction2.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
        simpleType2.Content       = restriction2;


        // <xs:element name="size" type="StringOrIntType"/>
        XmlSchemaElement elementSize = new XmlSchemaElement();

        elementSize.Name           = "size";
        elementSize.SchemaTypeName = new XmlQualifiedName("StringOrIntType");
        schema.Items.Add(elementSize);

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
Exemple #24
0
            protected XmlSchemaSimpleType FindOrCreateSimpleType(Type type)
            {
                XmlSchemaSimpleType simpleType;
                string typeId = GenerateSimpleIDFromType(type);

                simpleType = FindSimpleTypeByID(typeId);
                if (simpleType != null)
                {
                    return(simpleType);
                }

                simpleType      = new XmlSchemaSimpleType();
                simpleType.Name = typeId;

                _nantSimpleTypes.Add(typeId, simpleType);

                if (type.Equals(typeof(Boolean)) || type.Equals(typeof(bool)))
                {
                    XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
                    simpleType.Content = union;

                    XmlSchemaSimpleType boolType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(boolType);

                    XmlSchemaSimpleType wildcardType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(wildcardType);
                    XmlSchemaSimpleTypeRestriction wildcardRestriction = new XmlSchemaSimpleTypeRestriction();
                    wildcardType.Content             = wildcardRestriction;
                    wildcardRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
                    XmlSchemaPatternFacet wildcard = new XmlSchemaPatternFacet();
                    wildcardRestriction.Facets.Add(wildcard);
                    wildcard.Value = ".*";

                    XmlSchemaSimpleTypeRestriction boolRestriction = new XmlSchemaSimpleTypeRestriction();
                    boolRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
                    boolType.Content             = boolRestriction;
                    XmlSchemaEnumerationFacet trueValue = new XmlSchemaEnumerationFacet();
                    boolRestriction.Facets.Add(trueValue);
                    trueValue.Value = "True";
                    XmlSchemaEnumerationFacet falseValue = new XmlSchemaEnumerationFacet();
                    boolRestriction.Facets.Add(falseValue);
                    falseValue.Value = "False";

                    XmlSchemaSimpleType propertiesType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(propertiesType);
                    XmlSchemaSimpleTypeRestriction propertyRestriction = new XmlSchemaSimpleTypeRestriction();
                    propertiesType.Content           = propertyRestriction;
                    propertyRestriction.BaseTypeName = new XmlQualifiedName("CIFactory.Properties", _nantSchema.TargetNamespace);
                }
                else if (type.IsSubclassOf(typeof(Enum)))
                {
                    XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
                    simpleType.Content = union;

                    XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(enumType);

                    XmlSchemaSimpleType wildcardType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(wildcardType);
                    XmlSchemaSimpleTypeRestriction wildcardRestriction = new XmlSchemaSimpleTypeRestriction();
                    wildcardType.Content             = wildcardRestriction;
                    wildcardRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
                    XmlSchemaPatternFacet wildcard = new XmlSchemaPatternFacet();
                    wildcardRestriction.Facets.Add(wildcard);
                    wildcard.Value = ".*";

                    XmlSchemaSimpleTypeRestriction enumRestriction = new XmlSchemaSimpleTypeRestriction();
                    enumType.Content             = enumRestriction;
                    enumRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

                    foreach (String EnumName in System.Enum.GetNames(type))
                    {
                        XmlSchemaEnumerationFacet enumValue = new XmlSchemaEnumerationFacet();
                        enumRestriction.Facets.Add(enumValue);
                        enumValue.Value = EnumName;
                    }

                    XmlSchemaSimpleType propertiesType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(propertiesType);
                    XmlSchemaSimpleTypeRestriction propertyRestriction = new XmlSchemaSimpleTypeRestriction();
                    propertiesType.Content           = propertyRestriction;
                    propertyRestriction.BaseTypeName = new XmlQualifiedName("CIFactory.Properties", _nantSchema.TargetNamespace);
                }
                else if (type.Equals(typeof(CallTask)))
                {
                    XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
                    simpleType.Content = union;

                    XmlSchemaSimpleType targetType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(targetType);

                    XmlSchemaSimpleType wildcardType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(wildcardType);
                    XmlSchemaSimpleTypeRestriction wildcardRestriction = new XmlSchemaSimpleTypeRestriction();
                    wildcardType.Content             = wildcardRestriction;
                    wildcardRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
                    XmlSchemaPatternFacet wildcard = new XmlSchemaPatternFacet();
                    wildcardRestriction.Facets.Add(wildcard);
                    wildcard.Value = ".*";

                    XmlSchemaSimpleTypeRestriction targetRestriction = new XmlSchemaSimpleTypeRestriction();
                    targetType.Content             = targetRestriction;
                    targetRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

                    foreach (String TargetName in this.TargetNames)
                    {
                        XmlSchemaEnumerationFacet target = new XmlSchemaEnumerationFacet();
                        targetRestriction.Facets.Add(target);
                        target.Value = TargetName;
                    }

                    XmlSchemaSimpleType propertiesType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(propertiesType);
                    XmlSchemaSimpleTypeRestriction propertyRestriction = new XmlSchemaSimpleTypeRestriction();
                    propertiesType.Content           = propertyRestriction;
                    propertyRestriction.BaseTypeName = new XmlQualifiedName("CIFactory.Properties", _nantSchema.TargetNamespace);
                }
                else if (type.Equals(typeof(PropertyTask)))
                {
                    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
                    simpleType.Content = restriction;

                    restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

                    XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
                    restriction.Facets.Add(enumeration);
                    enumeration.Value = "${}";

                    foreach (String PropertyName in this.PropertyNames)
                    {
                        XmlSchemaEnumerationFacet property = new XmlSchemaEnumerationFacet();
                        restriction.Facets.Add(property);
                        property.Value = String.Format("${{{0}}}", PropertyName);
                    }
                }
                else
                {
                    XmlSchemaSimpleTypeUnion union = new XmlSchemaSimpleTypeUnion();
                    simpleType.Content = union;

                    XmlSchemaSimpleType wildcardType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(wildcardType);
                    XmlSchemaSimpleTypeRestriction wildcardRestriction = new XmlSchemaSimpleTypeRestriction();
                    wildcardType.Content             = wildcardRestriction;
                    wildcardRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
                    XmlSchemaPatternFacet wildcard = new XmlSchemaPatternFacet();
                    wildcardRestriction.Facets.Add(wildcard);
                    wildcard.Value = ".*";

                    XmlSchemaSimpleType propertiesType = new XmlSchemaSimpleType();
                    union.BaseTypes.Add(propertiesType);
                    XmlSchemaSimpleTypeRestriction propertyRestriction = new XmlSchemaSimpleTypeRestriction();
                    propertiesType.Content           = propertyRestriction;
                    propertyRestriction.BaseTypeName = new XmlQualifiedName("CIFactory.Properties", _nantSchema.TargetNamespace);
                }

                Schema.Items.Add(simpleType);
                Compile();

                return(simpleType);
            }