Exemple #1
0
 private void AddReferenceAttributes(XmlSchemaObjectCollection attributes, XmlSchema schema)
 {
     SchemaHelper.AddSchemaImport(Globals.SerializationNamespace, schema);
     schema.Namespaces.Add(Globals.SerPrefixForSchema, Globals.SerializationNamespace);
     attributes.Add(IdAttribute);
     attributes.Add(RefAttribute);
 }
 void GetAttributeCompletionData(XmlCompletionDataList data, XmlSchemaObjectCollection attributes)
 {
     foreach (XmlSchemaObject schemaObject in attributes)
     {
         var attribute = schemaObject as XmlSchemaAttribute;
         if (attribute != null)
         {
             if (!IsProhibitedAttribute(attribute))
             {
                 data.AddAttribute(attribute);
             }
             else
             {
                 prohibitedAttributes.Add(attribute);
             }
         }
         else
         {
             var attributeGroupRef = schemaObject as XmlSchemaAttributeGroupRef;
             if (attributeGroupRef != null)
             {
                 GetAttributeCompletionData(data, attributeGroupRef);
             }
         }
     }
 }
 private static void CopyAllItemTypes(XmlSchema source, XmlSchemaObjectCollection destination)
 {
     for (int i = 0; i < source.Items.Count; i++)
     {
         if (!destination.Contains(source.Items[i]))
         {
             destination.Add(source.Items[i]);
         }
     }
 }
        private void AddExternalSchemas(XmlSchemaObjectCollection includes)
        {
            /// @todo handle imports in an extendable manner (via ExtPoint).
            XmlSchema xmlSchema =
                XmlUtils.GetSchema(_assemblyLoaderService.LoadAssembly("jingxian.core.runtime"), "jingxian.core.runtime.Schemas.xml.xsd");
            XmlSchemaImport xmlImport = new XmlSchemaImport();

            xmlImport.Schema    = xmlSchema;
            xmlImport.Namespace = xmlSchema.TargetNamespace;

            includes.Add(xmlImport);
        }
Exemple #5
0
    private void method_7(XmlNode A_0, XmlSchemaObjectCollection A_1)
    {
        int num = 7;
        XmlSchemaAttribute item = new XmlSchemaAttribute {
            Name = A_0.Attributes[BookmarkStart.b("䌬丮尰嘲", 7)].Value
        };
        XmlAttribute attribute2 = A_0.Attributes[BookmarkStart.b("夬嘮䄰嘲", 7)];
        XmlAttribute attribute3 = A_0.Attributes[BookmarkStart.b("䬬䘮䤰嘲儴", 7)];

        if (this.string_3.Contains(attribute2.Value))
        {
            item.SchemaTypeName = new XmlQualifiedName(attribute2.Value, BookmarkStart.b("䔬嬮䔰䌲༴ᠶᘸ䰺䨼䠾潀㑂癄楆♈㥊⩌恎捐捒敔晖癘͚ၜ፞㉠b൤ɦѨ੪", num));
        }
        else
        {
            item.SchemaTypeName = new XmlQualifiedName(attribute2.Value);
        }
        if (attribute3 != null)
        {
            item.FixedValue = attribute3.Value;
        }
        A_1.Add(item);
    }
Exemple #6
0
        private void AddXMLProperties(XmlSchemaElement parent, XmlSchemaObjectCollection items, XmlSchemaObjectCollection attributes, PropertyInfo[] properties)
        {
            foreach (PropertyInfo property in properties)
            {
                if (IsValidProperty(property))
                {
                    string propertyName = property.Name;
                    if (propertyName.Equals("Item") && property.DeclaringType.Name.StartsWith("List`"))
                    {
                        if (!parent.Name.Equals("Items"))
                        {
                            propertyName = StringUtils.ToSingular(parent.Name);
                        }
                        else
                        {
                            propertyName = property.PropertyType.Name;
                        }
                    }

                    string xmlPropertyType = GetPropertyTypeName(property.PropertyType, TDataExchangeFormat.Xml);

                    if (property.GetCustomAttributes <XmlAttributeAttribute>().FirstOrDefault() != null)
                    {
                        XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                        attribute.Name           = propertyName;
                        attribute.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE);
                        if (attribute.Name.Equals("type"))
                        {
                            attribute.Use = XmlSchemaUse.Optional;
                        }
                        attributes.Add(attribute);
                    }
                    else
                    {
                        XmlSchemaElement propertyElement = new XmlSchemaElement();
                        propertyElement.Name = propertyName;

                        if (xmlPropertyType.Equals("array") || xmlPropertyType.Equals("object"))
                        {
                            XmlSchemaComplexType complexType = new XmlSchemaComplexType();
                            propertyElement.SchemaType = complexType;

                            XmlSchemaGroupBase sequence = null;
                            if (xmlPropertyType.Equals("array"))
                            {
                                sequence = new XmlSchemaSequence();
                                sequence.MinOccursString = "0";
                                sequence.MaxOccursString = "unbounded";

                                if (parent != null)
                                {
                                    // nested empty collections shouldn't have to exist.
                                    propertyElement.UnhandledAttributes          = new XmlAttribute[1];
                                    propertyElement.UnhandledAttributes[0]       = new XmlDocument().CreateAttribute("minOccurs");
                                    propertyElement.UnhandledAttributes[0].Value = "0";
                                }
                            }
                            else
                            {
                                sequence = new XmlSchemaAll();
                            }

                            AddXMLProperties(propertyElement, sequence.Items, complexType.Attributes, property.PropertyType.GetProperties());

                            if (sequence.Items.Count > 0)
                            {
                                complexType.Particle = sequence;
                            }
                        }
                        else
                        {
                            propertyElement.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE);
                        }
                        items.Add(propertyElement);
                    }
                }
            }
        }
Exemple #7
0
            protected XmlSchemaComplexType FindOrCreateComplexType(Type t)
            {
                XmlSchemaComplexType ct;
                string typeId = GenerateIDFromType(t);

                ct = FindComplexTypeByID(typeId);
                if (ct != null)
                {
                    return(ct);
                }

                ct      = new XmlSchemaComplexType();
                ct.Name = typeId;

                // Force mixed attribute for tasks names in the mixedTaskNames array.  Fixes Bug#: 3058913
                if (Array.IndexOf(mixedTaskNames, ct.Name) != -1)
                {
                    ct.IsMixed = true;
                }

                // add complex type to collection immediately to avoid stack
                // overflows, when we allow a type to be nested
                _nantComplexTypes.Add(typeId, ct);

#if NOT_IMPLEMENTED
                //
                // TODO - add task/type documentation in the future
                //

                ct.Annotation = new XmlSchemaAnnotation();
                XmlSchemaDocumentation doc = new XmlSchemaDocumentation();
                ct.Annotation.Items.Add(doc);
                doc.Markup = ...;
#endif

                XmlSchemaSequence         group1 = null;
                XmlSchemaObjectCollection attributesCollection = ct.Attributes;

                foreach (MemberInfo memInfo in t.GetMembers(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (memInfo.DeclaringType.Equals(typeof(object)))
                    {
                        continue;
                    }

                    //Check for any return type that is derived from Element

                    // add Attributes
                    TaskAttributeAttribute taskAttrAttr = (TaskAttributeAttribute)
                                                          Attribute.GetCustomAttribute(memInfo, typeof(TaskAttributeAttribute),
                                                                                       false);
                    BuildElementAttribute buildElemAttr = (BuildElementAttribute)
                                                          Attribute.GetCustomAttribute(memInfo, typeof(BuildElementAttribute),
                                                                                       false);

                    if (taskAttrAttr != null)
                    {
                        XmlSchemaAttribute newAttr = CreateXsdAttribute(taskAttrAttr.Name, taskAttrAttr.Required);
                        attributesCollection.Add(newAttr);
                    }
                    else if (buildElemAttr != null)
                    {
                        // Create individial choice for any individual child Element
                        Decimal min = 0;

                        if (buildElemAttr.Required)
                        {
                            min = 1;
                        }

                        XmlSchemaElement childElement = new XmlSchemaElement();
                        childElement.MinOccurs = min;
                        childElement.MaxOccurs = 1;
                        childElement.Name      = buildElemAttr.Name;

                        //XmlSchemaGroupBase elementGroup = CreateXsdSequence(min, Decimal.MaxValue);

                        Type childType;

                        // We will only process child elements if they are defined for Properties or Fields, this should be enforced by the AttributeUsage on the Attribute class
                        if (memInfo is PropertyInfo)
                        {
                            childType = ((PropertyInfo)memInfo).PropertyType;
                        }
                        else if (memInfo is FieldInfo)
                        {
                            childType = ((FieldInfo)memInfo).FieldType;
                        }
                        else if (memInfo is MethodInfo)
                        {
                            MethodInfo method = (MethodInfo)memInfo;
                            if (method.GetParameters().Length == 1)
                            {
                                childType = method.GetParameters()[0].ParameterType;
                            }
                            else
                            {
                                throw new ApplicationException("Method should have one parameter.");
                            }
                        }
                        else
                        {
                            throw new ApplicationException("Member Type != Field/Property/Method");
                        }

                        BuildElementArrayAttribute buildElementArrayAttribute = (BuildElementArrayAttribute)
                                                                                Attribute.GetCustomAttribute(memInfo, typeof(BuildElementArrayAttribute), false);

                        // determine type of child elements

                        if (buildElementArrayAttribute != null)
                        {
                            if (buildElementArrayAttribute.ElementType == null)
                            {
                                if (childType.IsArray)
                                {
                                    childType = childType.GetElementType();
                                }
                                else
                                {
                                    Type elementType = null;

                                    // locate Add method with 1 parameter, type of that parameter is parameter type
                                    foreach (MethodInfo method in childType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
                                    {
                                        if (method.Name == "Add" && method.GetParameters().Length == 1)
                                        {
                                            ParameterInfo parameter = method.GetParameters()[0];
                                            elementType = parameter.ParameterType;
                                            break;
                                        }
                                    }

                                    childType = elementType;
                                }
                            }
                            else
                            {
                                childType = buildElementArrayAttribute.ElementType;
                            }

                            if (childType == null || !typeof(Element).IsAssignableFrom(childType))
                            {
                                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                                       ResourceUtils.GetString("NA1140"), memInfo.DeclaringType.FullName, memInfo.Name));
                            }
                        }

                        BuildElementCollectionAttribute buildElementCollectionAttribute = (BuildElementCollectionAttribute)Attribute.GetCustomAttribute(memInfo, typeof(BuildElementCollectionAttribute), false);
                        if (buildElementCollectionAttribute != null)
                        {
                            XmlSchemaComplexType collectionType = new XmlSchemaComplexType();
                            XmlSchemaSequence    sequence       = new XmlSchemaSequence();
                            collectionType.Particle = sequence;

                            sequence.MinOccurs       = 0;
                            sequence.MaxOccursString = "unbounded";

                            XmlSchemaElement itemType = new XmlSchemaElement();
                            itemType.Name           = buildElementCollectionAttribute.ChildElementName;
                            itemType.SchemaTypeName = FindOrCreateComplexType(childType).QualifiedName;

                            sequence.Items.Add(itemType);

                            childElement.SchemaType = collectionType;
                        }
                        else
                        {
                            childElement.SchemaTypeName = FindOrCreateComplexType(childType).QualifiedName;
                        }

                        // lazy init of sequence
                        if (group1 == null)
                        {
                            group1      = CreateXsdSequence(0, Decimal.MaxValue);
                            ct.Particle = group1;
                        }

                        group1.Items.Add(childElement);
                    }
                }

                // allow attributes from other namespace
                ct.AnyAttribute                 = new XmlSchemaAnyAttribute();
                ct.AnyAttribute.Namespace       = "##other";
                ct.AnyAttribute.ProcessContents = XmlSchemaContentProcessing.Skip;

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

                return(ct);
            }
Exemple #8
0
        void ExportMembersMapSchema(XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute)
        {
            particle = null;
            XmlSchemaSequence seq = new XmlSchemaSequence();

            ICollection members = map.ElementMembers;

            if (members != null && !map.HasSimpleContent)
            {
                foreach (XmlTypeMapMemberElement member in members)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, member))
                    {
                        continue;
                    }

                    Type memType = member.GetType();
                    if (memType == typeof(XmlTypeMapMemberFlatList))
                    {
                        XmlSchemaParticle part = GetSchemaArrayElement(schema, member.ElementInfo);
                        if (part != null)
                        {
                            seq.Items.Add(part);
                        }
                    }
                    else if (memType == typeof(XmlTypeMapMemberAnyElement))
                    {
                        seq.Items.Add(GetSchemaArrayElement(schema, member.ElementInfo));
                    }
                    else if (memType == typeof(XmlTypeMapMemberElement))
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo [0],
                                         member.DefaultValue, true, new XmlSchemaObjectContainer(seq));
                    }
                    else
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo[0],
                                         true, new XmlSchemaObjectContainer(seq));
                    }
                }
            }

            if (seq.Items.Count > 0)
            {
                particle = seq;
            }

            // Write attributes

            ICollection attributes = map.AttributeMembers;

            if (attributes != null)
            {
                foreach (XmlTypeMapMemberAttribute attr in attributes)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, attr))
                    {
                        continue;
                    }
                    outAttributes.Add(GetSchemaAttribute(schema, attr, true));
                }
            }

            XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;

            if (anyAttrMember != null)
            {
                anyAttribute = new XmlSchemaAnyAttribute();
            }
            else
            {
                anyAttribute = null;
            }
        }
Exemple #9
0
        ///<summary>Generate XML schema for the given types
        ///</summary>
        ///<param name="ns">Default namespace</param>
        ///<param name="types">Types to include into schema</param>
        ///<param name="root">Root element</param>
        ///<param name="interfaces">Interface types</param>
        ///<returns>Built schema</returns>
        public static XmlSchema BuildSchema(string ns, Type[] types, Type root, Type[] interfaces)
        {
            XmlSchema xmlSchema = new XmlSchema();

            xmlSchema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            xmlSchema.Namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlSchema.ElementFormDefault   = XmlSchemaForm.Qualified;
            xmlSchema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            xmlSchema.Namespaces.Add("ns", ns);
            xmlSchema.TargetNamespace = ns;

            // Comment
            XmlSchemaAnnotation    annotation     = new XmlSchemaAnnotation();
            XmlSchemaDocumentation documentation  = new XmlSchemaDocumentation();
            XmlDocument            helperDocument = new XmlDocument();
            string comment = String.Format("  XML schema for {0} , generated at {1}  ", ns, DateTime.Now.ToString());

            documentation.Markup = new XmlNode[1] {
                helperDocument.CreateComment(comment)
            };
            annotation.Items.Add(documentation);
            xmlSchema.Items.Add(annotation);

            // Create group "action" to refer to any action
            var ints = new Dictionary <Type, XmlSchemaGroup>();

            if (interfaces != null)
            {
                foreach (var intf in interfaces)
                {
                    var action = new XmlSchemaGroup();
                    action.Name     = getXmlTypeName(intf);
                    action.Particle = new XmlSchemaChoice();
                    xmlSchema.Items.Add(action);
                    ints.Add(intf, action);
                }
            }

            Dictionary <Type, XmlSchemaType> xmlTypes = new Dictionary <Type, XmlSchemaType>();

            foreach (var type in types)
            {
                // If it does not have our XML header - skip it
                var na = (CustomAttributeHelper.First <XsTypeAttribute>(type));
                if (na == null)
                {
                    continue;
                }


                // Check if it is complex or simple
                XmlSchemaComplexType ct = new XmlSchemaComplexType();
                ct.Name = getXmlTypeName(type);


                XmlSchemaObjectCollection attr = createComplexType(type, ct, ns, ints);

                // Add the new element as an option to the "action" group
                foreach (var i in ints)
                {
                    bool isAction = (type.FindInterfaces((tp, nu) => tp == i.Key, null).Length != 0);
                    if (isAction)
                    {
                        foreach (var tp in CustomAttributeHelper.All <XsTypeAttribute>(type))
                        {
                            if (!string.IsNullOrEmpty(tp.Name))
                            {
                                i.Value.Particle.Items.Add(new XmlSchemaElement
                                {
                                    Name           = tp.Name,
                                    MinOccurs      = 0,
                                    SchemaTypeName = new XmlQualifiedName(ct.Name, ns)
                                });
                            }
                        }
                    }
                }

                // Work with attributes
                foreach (var o in generateAttributes(xmlSchema, type, xmlTypes, ns))
                {
                    attr.Add(o);
                }

                if (na.AnyAttribute)
                {
                    ct.AnyAttribute = new XmlSchemaAnyAttribute
                    {
                        ProcessContents = XmlSchemaContentProcessing.Skip
                    };
                }


                // Add type to the list
                xmlTypes.Add(type, ct);
                xmlSchema.Items.Add(ct);

                if (root.IsAssignableFrom(type))
                {
                    // Add all variations of Script names as element
                    foreach (var o in CustomAttributeHelper.All <XsTypeAttribute>(root))
                    {
                        xmlSchema.Items.Add(new XmlSchemaElement
                        {
                            Name           = o.Name,
                            SchemaTypeName = new XmlQualifiedName(xmlTypes[typeof(Script)].Name, ns)
                        });
                    }
                }
            }
            return(xmlSchema);
        }
        private void ExportMembersMapSchema(XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute)
        {
            particle = null;
            XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
            ICollection       elementMembers    = map.ElementMembers;

            if (elementMembers != null && !map.HasSimpleContent)
            {
                foreach (object obj in elementMembers)
                {
                    XmlTypeMapMemberElement xmlTypeMapMemberElement = (XmlTypeMapMemberElement)obj;
                    if (baseMap == null || !this.DefinedInBaseMap(baseMap, xmlTypeMapMemberElement))
                    {
                        Type type = xmlTypeMapMemberElement.GetType();
                        if (type == typeof(XmlTypeMapMemberFlatList))
                        {
                            XmlSchemaParticle schemaArrayElement = this.GetSchemaArrayElement(schema, xmlTypeMapMemberElement.ElementInfo);
                            if (schemaArrayElement != null)
                            {
                                xmlSchemaSequence.Items.Add(schemaArrayElement);
                            }
                        }
                        else if (type == typeof(XmlTypeMapMemberAnyElement))
                        {
                            xmlSchemaSequence.Items.Add(this.GetSchemaArrayElement(schema, xmlTypeMapMemberElement.ElementInfo));
                        }
                        else if (type == typeof(XmlTypeMapMemberElement))
                        {
                            this.GetSchemaElement(schema, (XmlTypeMapElementInfo)xmlTypeMapMemberElement.ElementInfo[0], xmlTypeMapMemberElement.DefaultValue, true, new XmlSchemaExporter.XmlSchemaObjectContainer(xmlSchemaSequence));
                        }
                        else
                        {
                            this.GetSchemaElement(schema, (XmlTypeMapElementInfo)xmlTypeMapMemberElement.ElementInfo[0], true, new XmlSchemaExporter.XmlSchemaObjectContainer(xmlSchemaSequence));
                        }
                    }
                }
            }
            if (xmlSchemaSequence.Items.Count > 0)
            {
                particle = xmlSchemaSequence;
            }
            ICollection attributeMembers = map.AttributeMembers;

            if (attributeMembers != null)
            {
                foreach (object obj2 in attributeMembers)
                {
                    XmlTypeMapMemberAttribute xmlTypeMapMemberAttribute = (XmlTypeMapMemberAttribute)obj2;
                    if (baseMap == null || !this.DefinedInBaseMap(baseMap, xmlTypeMapMemberAttribute))
                    {
                        outAttributes.Add(this.GetSchemaAttribute(schema, xmlTypeMapMemberAttribute, true));
                    }
                }
            }
            XmlTypeMapMember defaultAnyAttributeMember = map.DefaultAnyAttributeMember;

            if (defaultAnyAttributeMember != null)
            {
                anyAttribute = new XmlSchemaAnyAttribute();
            }
            else
            {
                anyAttribute = null;
            }
        }